Merge remote-tracking branch 'origin/ticket/r16686-filter_back'

This commit is contained in:
Michael RICOIS 2018-03-19 10:19:01 +01:00
commit 893da877e8
4 changed files with 119 additions and 86 deletions

View File

@ -12,8 +12,13 @@ $order = array(
'quantity', 'quantity',
); );
// Category
$id_category = (int) Tools::getValue('c'); $id_category = (int) Tools::getValue('c');
// Page
$p = (int) Tools::getValue('p'); $p = (int) Tools::getValue('p');
// Filters value - attribute
$f = Tools::getValue('f'); $f = Tools::getValue('f');
$result = array( $result = array(
@ -23,42 +28,57 @@ $result = array(
); );
if ($id_category && $p && $id_category > 1) { if ($id_category && $p && $id_category > 1) {
// Private Sales
if (Module::isInstalled('privatesales')) { if (Module::isInstalled('privatesales')) {
include(dirname(__FILE__).'/../privatesales/Sale.php'); include dirname(__FILE__).'/../privatesales/Sale.php';
$sale = Sale::getSaleFromCategory($id_category); $sale = Sale::getSaleFromCategory($id_category);
if ($cookie->isLogged() || !$cookie->isLogged() && $sale->pub == 1) { if ($cookie->isLogged() || !$cookie->isLogged() && $sale->pub == 1) {
// Reset filters
if (empty($f)) {
$cookie->filters_category = null;
$cookie->filters_value = null;
}
// Add filters
else {
$cookie->filters_category = $id_category;
$cookie->filters_value = $f;
}
$cookie->write();
$now = mktime(); $now = mktime();
$category = new Category($id_category, $cookie->id_lang); $category = new Category($id_category, $cookie->id_lang);
$customer = new Customer((int) $cookie->id_customer); $customer = new Customer((int) $cookie->id_customer);
if( ($sale !== NULL if( ($sale !== null
&& $sale->enabled && $sale->enabled
&& strtotime($sale->date_start) < $now && strtotime($sale->date_start) < $now
&& strtotime($sale->date_end) > $now && strtotime($sale->date_end) > $now
&& count(array_intersect(($cookie->isLogged()? Customer::getGroupsStatic((int) $cookie->id_customer): array(1)), $sale->groups) > 0) && count(array_intersect(($cookie->isLogged()? Customer::getGroupsStatic((int) $cookie->id_customer): array(1)), $sale->groups) > 0)
&& $category->active) || ($customer->isMemberOfGroup(2) == 1) ) { && $category->active)
|| ($customer->isMemberOfGroup(2) == 1) ) {
$n = (int) Configuration::get('PS_PRODUCTS_PER_PAGE', 10); $n = (int) Configuration::get('PS_PRODUCTS_PER_PAGE', 10);
$orderBy = $order[Configuration::get('PS_PRODUCTS_ORDER_BY', 1)]; $orderBy = $order[Configuration::get('PS_PRODUCTS_ORDER_BY', 1)];
$orderWay = (Configuration::get('PS_PRODUCTS_ORDER_WAY', 0) == 0? 'ASC': 'DESC'); $orderWay = (Configuration::get('PS_PRODUCTS_ORDER_WAY', 0) == 0? 'ASC': 'DESC');
if (!empty($f)){ if (!empty($cookie->filters_value)) {
$nbProducts = count($category->getProductsByAttributes($cookie->id_lang, $f, false, false)); $nbProducts = count($category->getProductsByAttributes($cookie->id_lang, $cookie->filters_value, false, false));
} }
else { else {
$nbProducts = $category->getProducts(NULL, NULL, NULL, $orderBy, $orderWay, true); $nbProducts = $category->getProducts(NULL, NULL, NULL, $orderBy, $orderWay, true);
} }
// if($p >= $nbProducts / $n) {
if ($p >= $nbProducts / $n && !Tools::getValue('init')) { if ($p >= $nbProducts / $n && !Tools::getValue('init')) {
$result['endreached'] = TRUE; $result['endreached'] = TRUE;
} else { } else {
if (!empty($f)){ if (!empty($cookie->filters_value)) {
if (Tools::getValue('init')) { if (Tools::getValue('init')) {
$cat_products = $category->getProductsByAttributes($cookie->id_lang, $f, $p, $n, $orderBy, $orderWay); $cat_products = $category->getProductsByAttributes($cookie->id_lang, $cookie->filters_value, $p, $n, $orderBy, $orderWay);
} }
else { else {
$cat_products = $category->getProductsByAttributes($cookie->id_lang, $f, $p+1, $n, $orderBy, $orderWay); $cat_products = $category->getProductsByAttributes($cookie->id_lang, $cookie->filters_value, $p+1, $n, $orderBy, $orderWay);
} }
} }
else { else {
@ -68,7 +88,6 @@ if($id_category && $p && $id_category > 1) {
else { else {
$cat_products = $category->getProducts($cookie->id_lang, $p + 1, $n, $orderBy, $orderWay); $cat_products = $category->getProducts($cookie->id_lang, $p + 1, $n, $orderBy, $orderWay);
} }
// $cat_products = $category->getProducts($cookie->id_lang, $p + 1, $n, $orderBy, $orderWay);
} }
if (!$cat_products) { if (!$cat_products) {
@ -147,7 +166,9 @@ if($id_category && $p && $id_category > 1) {
} else { } else {
$result['error'] = 'permission_denied'; $result['error'] = 'permission_denied';
} }
} else { }
// No private sales
else {
$n = (int) Configuration::get('PS_PRODUCTS_PER_PAGE', 10); $n = (int) Configuration::get('PS_PRODUCTS_PER_PAGE', 10);
$orderBy = $order[Configuration::get('PS_PRODUCTS_ORDER_BY', 1)]; $orderBy = $order[Configuration::get('PS_PRODUCTS_ORDER_BY', 1)];
$orderWay = (Configuration::get('PS_PRODUCTS_ORDER_WAY', 0) == 0? 'ASC': 'DESC'); $orderWay = (Configuration::get('PS_PRODUCTS_ORDER_WAY', 0) == 0? 'ASC': 'DESC');
@ -200,4 +221,5 @@ if($id_category && $p && $id_category > 1) {
} else { } else {
$result['error'] = 'invalid_request'; $result['error'] = 'invalid_request';
} }
echo json_encode(array($result)); echo json_encode(array($result));

View File

@ -1,7 +1,7 @@
{if count($sizes) > 0} {if count($sizes) > 0}
<div class="block_filter"> <div class="block_filter">
<div class="content"> <div class="content">
<h4 class="open">{l s='Recherche par' mod='filtervp'} {$name}</h4> <h4 class="open">{l s='Recherche par' mod='filtervp'}</h4>
<div class="content_filter"> <div class="content_filter">
<ul id="filters"> <ul id="filters">
@ -18,7 +18,6 @@
</div> </div>
{/if} {/if}
<script> <script>
{literal} {literal}
$(document).ready(function() { $(document).ready(function() {

View File

@ -1,9 +1,11 @@
<?php <?php
class Filtervp extends Module { class Filtervp extends Module
{
const FILTER_ID = 75; const FILTER_ID = 75;
const FILTER_SIZE = 272; const FILTER_SIZE = 272;
public function __construct() { public function __construct()
{
$this->name = 'filtervp'; $this->name = 'filtervp';
$this->tab = 'front_office_features'; $this->tab = 'front_office_features';
$this->version = '1.0'; $this->version = '1.0';
@ -14,16 +16,18 @@ class Filtervp extends Module {
$this->description = $this->l('Enable to filter by size in VP.'); $this->description = $this->l('Enable to filter by size in VP.');
} }
public function install() { public function install()
{
if (!parent::install() if (!parent::install()
OR !$this->registerHook('displayLeftVP')) { || !$this->registerHook('displayLeftVP')) {
return FALSE; return false;
} }
return TRUE; return true;
} }
public function hookdisplayLeftVP($params) { public function hookdisplayLeftVP($params)
{
global $smarty; global $smarty;
$sizes = self::getAllValueAttr(Filtervp::FILTER_ID, Tools::getValue('id_category')); $sizes = self::getAllValueAttr(Filtervp::FILTER_ID, Tools::getValue('id_category'));
@ -46,7 +50,8 @@ class Filtervp extends Module {
return $this->display(__FILE__, 'filter.tpl'); return $this->display(__FILE__, 'filter.tpl');
} }
public static function getAllValueAttr($id_attr, $id_cat){ public static function getAllValueAttr($id_attr, $id_cat)
{
global $cookie; global $cookie;
$id_lang = $cookie->id_lang; $id_lang = $cookie->id_lang;
@ -68,12 +73,16 @@ class Filtervp extends Module {
ORDER BY ORDER BY
al.`name` ASC al.`name` ASC
'); ');
return $results; return $results;
} }
public static function getAttrName($id_attr){ public static function getAttrName($id_attr)
{
global $cookie; global $cookie;
$id_lang = $cookie->id_lang; $id_lang = $cookie->id_lang;
return Db::getInstance()->getValue(' return Db::getInstance()->getValue('
SELECT SELECT
`public_name` `public_name`
@ -83,5 +92,4 @@ class Filtervp extends Module {
'); ');
} }
} }

View File

@ -1,6 +1,8 @@
<?php <?php
class CategoryController extends CategoryControllerCore { class CategoryController extends CategoryControllerCore
public function preProcess() { {
public function preProcess()
{
global $site_version_front; global $site_version_front;
global $cookie; global $cookie;
@ -38,7 +40,7 @@ class CategoryController extends CategoryControllerCore {
'category' => $this->category, 'category' => $this->category,
'HOOK_PRIVATESALES_CATEGORY' => Module::hookExec('privatesales_category', array('sale' => $sale)), 'HOOK_PRIVATESALES_CATEGORY' => Module::hookExec('privatesales_category', array('sale' => $sale)),
'HOOK_LEFT_COLUMN_VP' => Module::hookExec('displayleftVP', array('id_category' => $id_category)), 'HOOK_LEFT_COLUMN_VP' => Module::hookExec('displayleftVP', array('id_category' => $id_category)),
'is_sale_home' => ($sale? $sale->id_category == $id_category: FALSE), 'is_sale_home' => ($sale ? $sale->id_category == $id_category : false),
'other_sales' => $other_sales, 'other_sales' => $other_sales,
'last_qties' => (int)Configuration::get('PS_LAST_QTIES'), 'last_qties' => (int)Configuration::get('PS_LAST_QTIES'),
'HOOK_PRIVATESALES_LISTING' => Module::hookExec('privatesales_listing', array('other_sales_category' => $other_sales, 'futuresales' => array())), 'HOOK_PRIVATESALES_LISTING' => Module::hookExec('privatesales_listing', array('other_sales_category' => $other_sales, 'futuresales' => array())),
@ -46,7 +48,8 @@ class CategoryController extends CategoryControllerCore {
} }
} }
public function setMedia() { public function setMedia()
{
parent::setMedia(); parent::setMedia();
global $css_files; global $css_files;
@ -58,11 +61,13 @@ class CategoryController extends CategoryControllerCore {
$js_files[] = _PS_JS_DIR_.'/jquery.flexslider-min.js'; $js_files[] = _PS_JS_DIR_.'/jquery.flexslider-min.js';
} }
public function productListAssign() { public function productListAssign()
{
global $cookie; global $cookie;
$hookExecuted = false; $hookExecuted = false;
Module::hookExec('productListAssign', array('nbProducts' => &$this->nbProducts, 'catProducts' => &$this->cat_products, 'hookExecuted' => &$hookExecuted)); Module::hookExec('productListAssign', array('nbProducts' => &$this->nbProducts, 'catProducts' => &$this->cat_products, 'hookExecuted' => &$hookExecuted));
if (!$hookExecuted) { // The hook was not executed, standard working if (!$hookExecuted) { // The hook was not executed, standard working
self::$smarty->assign('categoryNameComplement', ''); self::$smarty->assign('categoryNameComplement', '');
$this->nbProducts = $this->category->getProducts(NULL, NULL, NULL, $this->orderBy, $this->orderWay, TRUE, TRUE, FALSE, 1, TRUE/*, ((($sale = self::$smarty->getTemplateVars('sale')) !== NULL) && (int) $sale->id > 0 && $sale->avail_only == TRUE? TRUE: FALSE)*/); $this->nbProducts = $this->category->getProducts(NULL, NULL, NULL, $this->orderBy, $this->orderWay, TRUE, TRUE, FALSE, 1, TRUE/*, ((($sale = self::$smarty->getTemplateVars('sale')) !== NULL) && (int) $sale->id > 0 && $sale->avail_only == TRUE? TRUE: FALSE)*/);
@ -73,19 +78,11 @@ class CategoryController extends CategoryControllerCore {
(int)($this->n), (int)($this->n),
$this->orderBy, $this->orderBy,
$this->orderWay, $this->orderWay,
FALSE, false,
TRUE, true,
FALSE, false,
1, 1,
TRUE/*, true
(
(
(
$sale = self::$smarty->getTemplateVars('sale')
) !== NULL
)
&& (int) $sale->id > 0 && $sale->avail_only == TRUE? TRUE: FALSE
)*/
); );
$id_products = array(); $id_products = array();
@ -150,7 +147,14 @@ class CategoryController extends CategoryControllerCore {
self::$smarty->assign('images', $images); self::$smarty->assign('images', $images);
self::$smarty->assign('categoryProductAttributes', $attributes); self::$smarty->assign('categoryProductAttributes', $attributes);
} else { // Hook executed, use the override
// Filters
$id_category = Tools::getValue('id_category');
if ($cookie->filters_category == $id_category && !empty($cookie->filters_value)) {
$this->cat_products = $this->category->getProductsByAttributes($cookie->id_lang, $cookie->filters_value, (int)$this->p, (int)$this->n, $this->orderBy, $this->orderWay);
}
}
else { // Hook executed, use the override
$this->pagination((int)$this->nbProducts); // Pagination must be call after "getProducts" $this->pagination((int)$this->nbProducts); // Pagination must be call after "getProducts"
} }
self::$smarty->assign('nb_products', (int)$this->nbProducts); self::$smarty->assign('nb_products', (int)$this->nbProducts);