{l s='Recherche par' mod='filtervp'} {$name}
+{l s='Recherche par' mod='filtervp'}
-
@@ -18,7 +18,6 @@
diff --git a/modules/categoryscroll/ajax.php b/modules/categoryscroll/ajax.php index c8400186..e17f3e6f 100755 --- a/modules/categoryscroll/ajax.php +++ b/modules/categoryscroll/ajax.php @@ -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( @@ -22,56 +27,70 @@ $result = array( 'endreached' => FALSE, ); -if($id_category && $p && $id_category > 1) { - if(Module::isInstalled('privatesales')) { - include(dirname(__FILE__).'/../privatesales/Sale.php'); +if ($id_category && $p && $id_category > 1) { + // Private Sales + if (Module::isInstalled('privatesales')) { + include dirname(__FILE__).'/../privatesales/Sale.php'; $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(); $category = new Category($id_category, $cookie->id_lang); $customer = new Customer((int) $cookie->id_customer); - 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) ) { + 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) ) { + $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{ + else { $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; } else { - if (!empty($f)){ - if (Tools::getValue('init')){ - $cat_products = $category->getProductsByAttributes($cookie->id_lang, $f, $p, $n, $orderBy, $orderWay); + if (!empty($cookie->filters_value)) { + if (Tools::getValue('init')) { + $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); + else { + $cat_products = $category->getProductsByAttributes($cookie->id_lang, $cookie->filters_value, $p+1, $n, $orderBy, $orderWay); } } - else{ - if (Tools::getValue('init')){ + else { + if (Tools::getValue('init')) { $cat_products = $category->getProducts($cookie->id_lang, $p, $n, $orderBy, $orderWay); } - 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); } - if(!$cat_products) { + if (!$cat_products) { $smarty->assign('products', array()); } else { $smarty->assign('products', $cat_products); @@ -81,7 +100,7 @@ if($id_category && $p && $id_category > 1) { } $attributes = array(); $id_attributes = array(); - foreach(Db::getInstance()->ExecuteS(' + foreach (Db::getInstance()->ExecuteS(' SELECT pa.`id_product`, pa.`quantity`, ag.`public_name` as `group`, al.`name`, al.`id_attribute` FROM `'._DB_PREFIX_.'product_attribute` pa, `'._DB_PREFIX_.'product_attribute_combination` ac, `'._DB_PREFIX_.'attribute` a, `'._DB_PREFIX_.'attribute_lang` al, `'._DB_PREFIX_.'attribute_group_lang` ag WHERE pa.`id_product` IN ('.implode(', ', $id_products).') @@ -95,17 +114,17 @@ if($id_category && $p && $id_category > 1) { AND ag.`id_attribute_group` IN(75, 9, 272, 172) ORDER BY pa.`id_product` ASC, ag.`public_name` ASC, al.`name` ASC ') as $attr) { - if(!isset($attributes[$attr['id_product']])) { + if (!isset($attributes[$attr['id_product']])) { $attributes[$attr['id_product']] = array(); } - if(!isset($attributes[$attr['id_product']][$attr['group']])) { + if (!isset($attributes[$attr['id_product']][$attr['group']])) { $attributes[$attr['id_product']][$attr['group']] = array(); } - if(!isset($id_attributes[$attr['id_product']])) { + if (!isset($id_attributes[$attr['id_product']])) { $id_attributes[$attr['id_product']] = array(); } - if(!in_array($attr['id_attribute'], $id_attributes[$attr['id_product']])) { + if (!in_array($attr['id_attribute'], $id_attributes[$attr['id_product']])) { $attributes[$attr['id_product']][$attr['group']][] = array( 'name' => $attr['name'], 'quantity' => $attr['quantity'], @@ -147,14 +166,16 @@ 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'); $category = new Category($id_category, $cookie->id_lang); - if($category->active) { + if ($category->active) { $nbProducts = $category->getProducts(NULL, NULL, NULL, $orderBy, $orderWay, true); - if($p >= $nbProducts / $n) { + if ($p >= $nbProducts / $n) { $result['endreached'] = TRUE; } else { $cat_products = $category->getProducts($cookie->id_lang, $p + 1, $n, $orderBy, $orderWay); @@ -165,7 +186,7 @@ if($id_category && $p && $id_category > 1) { $id_products[] = $p['id_product']; } $attributes = array(); - foreach(Db::getInstance()->ExecuteS(' + foreach (Db::getInstance()->ExecuteS(' SELECT pa.`id_product`, pa.`quantity`, ag.`public_name` as `group`, al.`name` FROM `'._DB_PREFIX_.'product_attribute` pa, `'._DB_PREFIX_.'product_attribute_combination` ac, `'._DB_PREFIX_.'attribute` a, `'._DB_PREFIX_.'attribute_lang` al, `'._DB_PREFIX_.'attribute_group_lang` ag WHERE pa.`id_product` IN ('.implode(', ', $id_products).') @@ -178,10 +199,10 @@ if($id_category && $p && $id_category > 1) { AND pa.`quantity` > 0 ORDER BY pa.`id_product` ASC, ag.`public_name` ASC, al.`name` ASC ') as $attr) { - if(!isset($attributes[$attr['id_product']])) { + if (!isset($attributes[$attr['id_product']])) { $attributes[$attr['id_product']] = array(); } - if(!isset($attributes[$attr['id_product']][$attr['group']])) { + if (!isset($attributes[$attr['id_product']][$attr['group']])) { $attributes[$attr['id_product']][$attr['group']] = array(); } $attributes[$attr['id_product']][$attr['group']][] = array( @@ -200,4 +221,5 @@ if($id_category && $p && $id_category > 1) { } else { $result['error'] = 'invalid_request'; } + echo json_encode(array($result)); diff --git a/modules/filtervp/filter.tpl b/modules/filtervp/filter.tpl index df7f2a34..9bdc2a58 100755 --- a/modules/filtervp/filter.tpl +++ b/modules/filtervp/filter.tpl @@ -1,7 +1,7 @@ {if count($sizes) > 0} -