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

View File

@ -1,7 +1,7 @@
{if count($sizes) > 0}
<div class="block_filter">
<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">
<ul id="filters">
@ -18,7 +18,6 @@
</div>
{/if}
<script>
{literal}
$(document).ready(function() {

View File

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

View File

@ -1,6 +1,8 @@
<?php
class CategoryController extends CategoryControllerCore {
public function preProcess() {
class CategoryController extends CategoryControllerCore
{
public function preProcess()
{
global $site_version_front;
global $cookie;
@ -38,7 +40,7 @@ class CategoryController extends CategoryControllerCore {
'category' => $this->category,
'HOOK_PRIVATESALES_CATEGORY' => Module::hookExec('privatesales_category', array('sale' => $sale)),
'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,
'last_qties' => (int)Configuration::get('PS_LAST_QTIES'),
'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();
global $css_files;
@ -58,11 +61,13 @@ class CategoryController extends CategoryControllerCore {
$js_files[] = _PS_JS_DIR_.'/jquery.flexslider-min.js';
}
public function productListAssign() {
public function productListAssign()
{
global $cookie;
$hookExecuted = false;
Module::hookExec('productListAssign', array('nbProducts' => &$this->nbProducts, 'catProducts' => &$this->cat_products, 'hookExecuted' => &$hookExecuted));
if (!$hookExecuted) { // The hook was not executed, standard working
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)*/);
@ -73,19 +78,11 @@ class CategoryController extends CategoryControllerCore {
(int)($this->n),
$this->orderBy,
$this->orderWay,
FALSE,
TRUE,
FALSE,
false,
true,
false,
1,
TRUE/*,
(
(
(
$sale = self::$smarty->getTemplateVars('sale')
) !== NULL
)
&& (int) $sale->id > 0 && $sale->avail_only == TRUE? TRUE: FALSE
)*/
true
);
$id_products = array();
@ -150,7 +147,14 @@ class CategoryController extends CategoryControllerCore {
self::$smarty->assign('images', $images);
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"
}
self::$smarty->assign('nb_products', (int)$this->nbProducts);