diff --git a/modules/blocklayered/blocklayered.php b/modules/blocklayered/blocklayered.php index b14172b5b..44625b809 100644 --- a/modules/blocklayered/blocklayered.php +++ b/modules/blocklayered/blocklayered.php @@ -68,6 +68,8 @@ class BlockLayered extends Module Configuration::updateValue('PS_LAYERED_FULL_TREE', 1); Configuration::updateValue('PS_LAYERED_FILTER_PRICE_USETAX', 1); Configuration::updateValue('PS_LAYERED_FILTER_CATEGORY_DEPTH', 1); + Configuration::updateValue('PS_LAYERED_FILTER_INDEX_QTY', 0); + Configuration::updateValue('PS_LAYERED_FILTER_INDEX_CDT', 0); $this->rebuildLayeredStructure(); @@ -105,6 +107,8 @@ class BlockLayered extends Module Configuration::deleteByName('PS_LAYERED_INDEXED'); Configuration::deleteByName('PS_LAYERED_FILTER_PRICE_USETAX'); Configuration::deleteByName('PS_LAYERED_FILTER_CATEGORY_DEPTH'); + Configuration::deleteByName('PS_LAYERED_FILTER_INDEX_QTY'); + Configuration::deleteByName('PS_LAYERED_FILTER_INDEX_CDT'); Db::getInstance()->execute('DROP TABLE IF EXISTS '._DB_PREFIX_.'layered_price_index'); Db::getInstance()->execute('DROP TABLE IF EXISTS '._DB_PREFIX_.'layered_friendly_url'); @@ -260,7 +264,7 @@ class BlockLayered extends Module if ($truncate) Db::getInstance()->execute('TRUNCATE '._DB_PREFIX_.'layered_friendly_url'); - $attributeValuesByLang = array(); + $attribute_values_by_lang = array(); $filters = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('SELECT lc.*, id_lang, name, link_rewrite, cl.id_category FROM '._DB_PREFIX_.'layered_category lc INNER JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = lc.id_category AND lc.id_category <> 1 ) @@ -287,11 +291,11 @@ class BlockLayered extends Module WHERE a.id_attribute_group = '.(int)$filter['id_value'].' AND agl.id_lang = al.id_lang AND agl.id_lang = '.(int)$filter['id_lang']); foreach ($attributes as $attribute) { - if (!isset($attributeValuesByLang[$attribute['id_lang']])) - $attributeValuesByLang[$attribute['id_lang']] = array(); - if (!isset($attributeValuesByLang[$attribute['id_lang']]['c'.$attribute['id_name']])) - $attributeValuesByLang[$attribute['id_lang']]['c'.$attribute['id_name']] = array(); - $attributeValuesByLang[$attribute['id_lang']]['c'.$attribute['id_name']][] = array( + if (!isset($attribute_values_by_lang[$attribute['id_lang']])) + $attribute_values_by_lang[$attribute['id_lang']] = array(); + if (!isset($attribute_values_by_lang[$attribute['id_lang']]['c'.$attribute['id_name']])) + $attribute_values_by_lang[$attribute['id_lang']]['c'.$attribute['id_name']] = array(); + $attribute_values_by_lang[$attribute['id_lang']]['c'.$attribute['id_name']][] = array( 'name' => (!empty($attribute['name_url_name']) ? $attribute['name_url_name'] : $attribute['name']), 'id_name' => 'c'.$attribute['id_name'], 'value' => (!empty($attribute['value_url_name']) ? $attribute['value_url_name'] : $attribute['value']), @@ -317,11 +321,11 @@ class BlockLayered extends Module WHERE fl.id_feature = '.(int)$filter['id_value'].' AND fvl.id_lang = fl.id_lang AND fvl.id_lang = '.(int)$filter['id_lang']); foreach ($features as $feature) { - if (!isset($attributeValuesByLang[$feature['id_lang']])) - $attributeValuesByLang[$feature['id_lang']] = array(); - if (!isset($attributeValuesByLang[$feature['id_lang']]['f'.$feature['id_name']])) - $attributeValuesByLang[$feature['id_lang']]['f'.$feature['id_name']] = array(); - $attributeValuesByLang[$feature['id_lang']]['f'.$feature['id_name']][] = array( + if (!isset($attribute_values_by_lang[$feature['id_lang']])) + $attribute_values_by_lang[$feature['id_lang']] = array(); + if (!isset($attribute_values_by_lang[$feature['id_lang']]['f'.$feature['id_name']])) + $attribute_values_by_lang[$feature['id_lang']]['f'.$feature['id_name']] = array(); + $attribute_values_by_lang[$feature['id_lang']]['f'.$feature['id_name']][] = array( 'name' => (!empty($feature['name_url_name']) ? $feature['name_url_name'] : $feature['name']), 'id_name' => 'f'.$feature['id_name'], 'value' => (!empty($feature['value_url_name']) ? $feature['value_url_name'] : $feature['value']), @@ -340,11 +344,11 @@ class BlockLayered extends Module WHERE cl.id_lang = '.(int)$filter['id_lang']); foreach ($categories as $category) { - if (!isset($attributeValuesByLang[$category['id_lang']])) - $attributeValuesByLang[$category['id_lang']] = array(); - if (!isset($attributeValuesByLang[$category['id_lang']]['category'])) - $attributeValuesByLang[$category['id_lang']]['category'] = array(); - $attributeValuesByLang[$category['id_lang']]['category'][] = array('name' => $this->l('Categories'), + if (!isset($attribute_values_by_lang[$category['id_lang']])) + $attribute_values_by_lang[$category['id_lang']] = array(); + if (!isset($attribute_values_by_lang[$category['id_lang']]['category'])) + $attribute_values_by_lang[$category['id_lang']]['category'] = array(); + $attribute_values_by_lang[$category['id_lang']]['category'][] = array('name' => $this->l('Categories'), 'id_name' => null, 'value' => $category['name'], 'id_value' => $category['id_category'], 'category_name' => $filter['link_rewrite'], 'type' => $filter['type']); } @@ -358,11 +362,11 @@ class BlockLayered extends Module foreach ($manufacturers as $manufacturer) { - if (!isset($attributeValuesByLang[$manufacturer['id_lang']])) - $attributeValuesByLang[$manufacturer['id_lang']] = array(); - if (!isset($attributeValuesByLang[$manufacturer['id_lang']]['manufacturer'])) - $attributeValuesByLang[$manufacturer['id_lang']]['manufacturer'] = array(); - $attributeValuesByLang[$manufacturer['id_lang']]['manufacturer'][] = array('name' => $this->translateWord('Manufacturer', $manufacturer['id_lang']), + if (!isset($attribute_values_by_lang[$manufacturer['id_lang']])) + $attribute_values_by_lang[$manufacturer['id_lang']] = array(); + if (!isset($attribute_values_by_lang[$manufacturer['id_lang']]['manufacturer'])) + $attribute_values_by_lang[$manufacturer['id_lang']]['manufacturer'] = array(); + $attribute_values_by_lang[$manufacturer['id_lang']]['manufacturer'][] = array('name' => $this->translateWord('Manufacturer', $manufacturer['id_lang']), 'id_name' => null, 'value' => $manufacturer['name'], 'id_value' => $manufacturer['id_manufacturer'], 'category_name' => $filter['link_rewrite'], 'type' => $filter['type']); } @@ -374,7 +378,7 @@ class BlockLayered extends Module $this->translateWord('In stock', (int)$filter['id_lang']) ); foreach ($avaibility_list as $key => $quantity) - $attributeValuesByLang[$filter['id_lang']]['quantity'][] = array('name' => $this->translateWord('Availability', (int)$filter['id_lang']), + $attribute_values_by_lang[$filter['id_lang']]['quantity'][] = array('name' => $this->translateWord('Availability', (int)$filter['id_lang']), 'id_name' => null, 'value' => $quantity, 'id_value' => $key, 'id_id_value' => 0, 'category_name' => $filter['link_rewrite'], 'type' => $filter['type']); break; @@ -386,32 +390,32 @@ class BlockLayered extends Module 'refurbished' => $this->translateWord('Refurbished', (int)$filter['id_lang']) ); foreach ($condition_list as $key => $condition) - $attributeValuesByLang[$filter['id_lang']]['condition'][] = array('name' => $this->translateWord('Condition', (int)$filter['id_lang']), + $attribute_values_by_lang[$filter['id_lang']]['condition'][] = array('name' => $this->translateWord('Condition', (int)$filter['id_lang']), 'id_name' => null, 'value' => $condition, 'id_value' => $key, 'category_name' => $filter['link_rewrite'], 'type' => $filter['type']); break; } // Foreach langs - foreach ($attributeValuesByLang as $id_lang => $attributeValues) + foreach ($attribute_values_by_lang as $id_lang => $attribute_values) { // Foreach attributes generate a couple "/_". For example: color_blue - foreach ($attributeValues as $attribute) + foreach ($attribute_values as $attribute) foreach ($attribute as $param) { - $selectedFilters = array(); + $selected_filters = array(); $link = '/'.str_replace('-', '_', Tools::link_rewrite($param['name'])).'-'.str_replace('-', '_', Tools::link_rewrite($param['value'])); - $selectedFilters[$param['type']] = array(); + $selected_filters[$param['type']] = array(); if (!isset($param['id_id_value'])) $param['id_id_value'] = $param['id_value']; - $selectedFilters[$param['type']][$param['id_id_value']] = $param['id_value']; - $urlKey = md5($link); - $idLayeredFriendlyUrl = Db::getInstance()->getValue('SELECT id_layered_friendly_url - FROM `'._DB_PREFIX_.'layered_friendly_url` WHERE `id_lang` = '.$id_lang.' AND `url_key` = \''.$urlKey.'\''); - if ($idLayeredFriendlyUrl == false) + $selected_filters[$param['type']][$param['id_id_value']] = $param['id_value']; + $url_key = md5($link); + $id_layered_friendly_url = Db::getInstance()->getValue('SELECT id_layered_friendly_url + FROM `'._DB_PREFIX_.'layered_friendly_url` WHERE `id_lang` = '.$id_lang.' AND `url_key` = \''.$url_key.'\''); + if ($id_layered_friendly_url == false) { - Db::getInstance()->AutoExecute(_DB_PREFIX_.'layered_friendly_url', array('url_key' => $urlKey, 'data' => serialize($selectedFilters), 'id_lang' => $id_lang), 'INSERT'); - $idLayeredFriendlyUrl = Db::getInstance()->Insert_ID(); + Db::getInstance()->AutoExecute(_DB_PREFIX_.'layered_friendly_url', array('url_key' => $url_key, 'data' => serialize($selected_filters), 'id_lang' => $id_lang), 'INSERT'); + $id_layered_friendly_url = Db::getInstance()->Insert_ID(); } } } @@ -440,17 +444,17 @@ class BlockLayered extends Module // set array key to lowercase for 1.3 compatibility $_MODULES[$id_lang] = array_change_key_case($_MODULES[$id_lang]); - $currentKey = '<{'.strtolower( $this->name).'}'.strtolower(_THEME_NAME_).'>'.strtolower($this->name).'_'.md5($string); - $defaultKey = '<{'.strtolower( $this->name).'}prestashop>'.strtolower($this->name).'_'.md5($string); + $current_key = '<{'.strtolower( $this->name).'}'.strtolower(_THEME_NAME_).'>'.strtolower($this->name).'_'.md5($string); + $default_key = '<{'.strtolower( $this->name).'}prestashop>'.strtolower($this->name).'_'.md5($string); - if (isset($_MODULES[$id_lang][$currentKey])) - $ret = stripslashes($_MODULES[$id_lang][$currentKey]); - else if (isset($_MODULES[$id_lang][Tools::strtolower($currentKey)])) - $ret = stripslashes($_MODULES[$id_lang][Tools::strtolower($currentKey)]); - else if (isset($_MODULES[$id_lang][$defaultKey])) - $ret = stripslashes($_MODULES[$id_lang][$defaultKey]); - else if (isset($_MODULES[$id_lang][Tools::strtolower($defaultKey)])) - $ret = stripslashes($_MODULES[$id_lang][Tools::strtolower($defaultKey)]); + if (isset($_MODULES[$id_lang][$current_key])) + $ret = stripslashes($_MODULES[$id_lang][$current_key]); + else if (isset($_MODULES[$id_lang][Tools::strtolower($current_key)])) + $ret = stripslashes($_MODULES[$id_lang][Tools::strtolower($current_key)]); + else if (isset($_MODULES[$id_lang][$default_key])) + $ret = stripslashes($_MODULES[$id_lang][$default_key]); + else if (isset($_MODULES[$id_lang][Tools::strtolower($default_key)])) + $ret = stripslashes($_MODULES[$id_lang][Tools::strtolower($default_key)]); else $ret = stripslashes($string); @@ -467,17 +471,17 @@ class BlockLayered extends Module $params['hookExecuted'] = true; // List of product to overrride categoryController $params['catProducts'] = array(); - $selectedFilters = $this->getSelectedFilters(); - $filterBlock = self::getFilterBlock($selectedFilters); + $selected_filters = $this->getSelectedFilters(); + $filter_block = self::getFilterBlock($selected_filters); $title = ''; - if (is_array($filterBlock['title_values'])) - foreach ($filterBlock['title_values'] as $key => $val) + if (is_array($filter_block['title_values'])) + foreach ($filter_block['title_values'] as $key => $val) $title .= ' – '.$key.' '.implode('/', $val); $smarty->assign('categoryNameComplement', $title); - $this->getProducts($selectedFilters, $params['catProducts'], $params['nbProducts'], $p, $n, $pages_nb, $start, $stop, $range); + $this->getProducts($selected_filters, $params['catProducts'], $params['nbProducts'], $p, $n, $pages_nb, $start, $stop, $range); // Need a nofollow on the pagination links? - $smarty->assign('no_follow', $filterBlock['no_follow']); + $smarty->assign('no_follow', $filter_block['no_follow']); } public function hookAfterSaveProduct($params) @@ -540,7 +544,7 @@ class BlockLayered extends Module { $languages = Language::getLanguages(false); $default_form_language = (int)(Configuration::get('PS_LANG_DEFAULT')); - $langValue = array(); + $lang_value = array(); if (version_compare(_PS_VERSION_,'1.5','>')) $return = ' @@ -555,7 +559,7 @@ class BlockLayered extends Module WHERE id_feature_value = '.(int)$params['id_feature_value']); if ($result) foreach ($result as $data) - $langValue[$data['id_lang']] = array('url_name' => $data['url_name'], 'meta_title' => $data['meta_title']); + $lang_value[$data['id_lang']] = array('url_name' => $data['url_name'], 'meta_title' => $data['meta_title']); $return .= '
@@ -566,7 +570,7 @@ class BlockLayered extends Module foreach ($languages as $language) $return .= '
- + '.$this->l('Invalid characters:').' <>;=#{}_ 

'.$this->l('Specific format in url block layered generation').'

'; @@ -582,7 +586,7 @@ class BlockLayered extends Module foreach ($languages as $language) $return .= '
- +

'.$this->l('Specific format for meta title').'

'; @@ -627,7 +631,7 @@ class BlockLayered extends Module { $languages = Language::getLanguages(false); $default_form_language = (int)(Configuration::get('PS_LANG_DEFAULT')); - $langValue = array(); + $lang_value = array(); if (version_compare(_PS_VERSION_,'1.5','>')) $return = ' @@ -642,7 +646,7 @@ class BlockLayered extends Module WHERE id_attribute = '.(int)$params['id_attribute']); if ($result) foreach ($result as $data) - $langValue[$data['id_lang']] = array('url_name' => $data['url_name'], 'meta_title' => $data['meta_title']); + $lang_value[$data['id_lang']] = array('url_name' => $data['url_name'], 'meta_title' => $data['meta_title']); $return .= '
@@ -653,7 +657,7 @@ class BlockLayered extends Module foreach ($languages as $language) $return .= '
- + '.$this->l('Invalid characters:').' <>;=#{}_ 

'.$this->l('Specific format in url block layered generation').'

'; @@ -669,7 +673,7 @@ class BlockLayered extends Module foreach ($languages as $language) $return .= '
- +

'.$this->l('Specific format for meta title').'

'; if (version_compare(_PS_VERSION_,'1.5','<')) @@ -748,14 +752,14 @@ class BlockLayered extends Module $default_form_language = (int)(Configuration::get('PS_LANG_DEFAULT')); $indexable = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT indexable FROM '._DB_PREFIX_.'layered_indexable_attribute_group WHERE id_attribute_group = '.(int)$params['id_attribute_group']); - $langValue = array(); + $lang_value = array(); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS( 'SELECT url_name, meta_title, id_lang FROM '._DB_PREFIX_.'layered_indexable_attribute_group_lang_value WHERE id_attribute_group = '.(int)$params['id_attribute_group']); if ($result) foreach ($result as $data) - $langValue[$data['id_lang']] = array('url_name' => $data['url_name'], 'meta_title' => $data['meta_title']); + $lang_value[$data['id_lang']] = array('url_name' => $data['url_name'], 'meta_title' => $data['meta_title']); if ($indexable === false) $on = true; @@ -780,7 +784,7 @@ class BlockLayered extends Module foreach ($languages as $language) $return .= '
- + '.$this->l('Invalid characters:').' <>;=#{}_ 

'.$this->l('Specific format in url block layered generation').'

'; @@ -796,7 +800,7 @@ class BlockLayered extends Module foreach ($languages as $language) $return .= '
- +

'.$this->l('Specific format for meta title').'

'; if (version_compare(_PS_VERSION_,'1.5','<')) @@ -821,14 +825,14 @@ class BlockLayered extends Module $languages = Language::getLanguages(false); $default_form_language = (int)(Configuration::get('PS_LANG_DEFAULT')); $indexable = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT indexable FROM '._DB_PREFIX_.'layered_indexable_feature WHERE id_feature = '.(int)$params['id_feature']); - $langValue = array(); + $lang_value = array(); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS( 'SELECT url_name, meta_title, id_lang FROM '._DB_PREFIX_.'layered_indexable_feature_lang_value WHERE id_feature = '.(int)$params['id_feature']); if ($result) foreach ($result as $data) - $langValue[$data['id_lang']] = array('url_name' => $data['url_name'], 'meta_title' => $data['meta_title']); + $lang_value[$data['id_lang']] = array('url_name' => $data['url_name'], 'meta_title' => $data['meta_title']); if ($indexable === false) @@ -854,7 +858,7 @@ class BlockLayered extends Module foreach ($languages as $language) $return .= '
- + '.$this->l('Invalid characters:').' <>;=#{}_ 

'.$this->l('Specific format in url block layered generation').'

'; @@ -870,7 +874,7 @@ class BlockLayered extends Module foreach ($languages as $language) $return .= '
- +

'.$this->l('Specific format for meta title').'

'; if (version_compare(_PS_VERSION_,'1.5','<')) @@ -912,27 +916,27 @@ class BlockLayered extends Module private static function indexPrices($cursor = null, $full = false, $ajax = false, $smart = false) { if ($full) - $nbProducts = (int)Db::getInstance()->getValue('SELECT count(*) FROM '._DB_PREFIX_.'product WHERE `active` = 1'); + $nb_products = (int)Db::getInstance()->getValue('SELECT count(*) FROM '._DB_PREFIX_.'product WHERE `active` = 1'); else - $nbProducts = (int)Db::getInstance()->getValue( + $nb_products = (int)Db::getInstance()->getValue( 'SELECT COUNT(*) FROM `'._DB_PREFIX_.'product` p LEFT JOIN `'._DB_PREFIX_.'layered_price_index` psi ON (psi.id_product = p.id_product) WHERE `active` = 1 AND psi.id_product IS NULL'); - $maxExecutionTime = @ini_get('max_execution_time'); - if ($maxExecutionTime > 5 || $maxExecutionTime <= 0) - $maxExecutionTime = 5; + $max_executiontime = @ini_get('max_execution_time'); + if ($max_executiontime > 5 || $max_executiontime <= 0) + $max_executiontime = 5; - $startTime = microtime(true); + $start_time = microtime(true); do { $cursor = (int)self::indexPricesUnbreakable((int)$cursor, $full, $smart); - $timeElapsed = microtime(true) - $startTime; + $time_elapsed = microtime(true) - $start_time; } - while ($cursor < $nbProducts && (Tools::getMemoryLimit()) > memory_get_peak_usage() && $timeElapsed < $maxExecutionTime); + while ($cursor < $nb_products && (Tools::getMemoryLimit()) > memory_get_peak_usage() && $time_elapsed < $max_executiontime); - if (($nbProducts > 0 && !$full || $cursor < $nbProducts && $full) && !$ajax) + if (($nb_products > 0 && !$full || $cursor < $nb_products && $full) && !$ajax) { $token = substr(Tools::encrypt('blocklayered/index'), 0, 10); if (Tools::usingSecureMode()) @@ -944,10 +948,10 @@ class BlockLayered extends Module self::indexPrices((int)$cursor, (int)$full); return $cursor; } - if ($ajax && $nbProducts > 0 && $cursor < $nbProducts && $full) - return '{"cursor": '.$cursor.', "count": '.($nbProducts - $cursor).'}'; - else if ($ajax && $nbProducts > 0 && !$full) - return '{"cursor": '.$cursor.', "count": '.($nbProducts).'}'; + if ($ajax && $nb_products > 0 && $cursor < $nb_products && $full) + return '{"cursor": '.$cursor.', "count": '.($nb_products - $cursor).'}'; + else if ($ajax && $nb_products > 0 && !$full) + return '{"cursor": '.$cursor.', "count": '.($nb_products).'}'; else { if (version_compare(_PS_VERSION_,'1.5','>')) @@ -992,7 +996,7 @@ class BlockLayered extends Module return (int)($cursor + $length); } - public static function indexProductPrices($idProduct, $smart = true) + public static function indexProductPrices($id_product, $smart = true) { static $groups = null; @@ -1014,117 +1018,117 @@ class BlockLayered extends Module foreach ($shop_list as $id_shop) { - static $currencyList = null; + static $currency_list = null; - if (is_null($currencyList)) + if (is_null($currency_list)) { if (version_compare(_PS_VERSION_,'1.5','>')) - $currencyList = Currency::getCurrencies(false, 1, new Shop($id_shop)); + $currency_list = Currency::getCurrencies(false, 1, new Shop($id_shop)); else - $currencyList = Currency::getCurrencies(false, 1); + $currency_list = Currency::getCurrencies(false, 1); } - $minPrice = array(); - $maxPrice = array(); + $min_price = array(); + $max_price = array(); if ($smart) - Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'layered_price_index` WHERE `id_product` = '.(int)$idProduct.' AND `id_shop` = '.(int)$id_shop); + Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'layered_price_index` WHERE `id_product` = '.(int)$id_product.' AND `id_shop` = '.(int)$id_shop); if (Configuration::get('PS_LAYERED_FILTER_PRICE_USETAX')) { if (version_compare(_PS_VERSION_,'1.5','>')) - $maxTaxRate = Db::getInstance()->getValue(' + $max_tax_rate = Db::getInstance()->getValue(' SELECT max(t.rate) max_rate FROM `'._DB_PREFIX_.'product_tax_rules_group_shop` p LEFT JOIN `'._DB_PREFIX_.'tax_rules_group` trg ON (trg.id_tax_rules_group = p.id_tax_rules_group) LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (tr.id_tax_rules_group = trg.id_tax_rules_group) LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.id_tax = tr.id_tax AND t.active = 1) - WHERE id_product = '.(int)$idProduct.' + WHERE id_product = '.(int)$id_product.' GROUP BY id_product'); else - $maxTaxRate = Db::getInstance()->getValue(' + $max_tax_rate = Db::getInstance()->getValue(' SELECT max(t.rate) max_rate FROM `'._DB_PREFIX_.'product` p LEFT JOIN `'._DB_PREFIX_.'tax_rules_group` trg ON (trg.id_tax_rules_group = p.id_tax_rules_group) LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (tr.id_tax_rules_group = trg.id_tax_rules_group) LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.id_tax = tr.id_tax AND t.active = 1) - WHERE id_product = '.(int)$idProduct.' + WHERE id_product = '.(int)$id_product.' GROUP BY id_product'); } else - $maxTaxRate = 0; + $max_tax_rate = 0; - $productMinPrices = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' + $product_min_prices = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT id_shop, id_currency, id_country, id_group, from_quantity FROM `'._DB_PREFIX_.'specific_price` - WHERE id_product = '.(int)$idProduct); + WHERE id_product = '.(int)$id_product); // Get min price - foreach ($currencyList as $currency) + foreach ($currency_list as $currency) { - $price = Product::priceCalculation($id_shop, (int)$idProduct, null, null, null, null, + $price = Product::priceCalculation($id_shop, (int)$id_product, null, null, null, null, $currency['id_currency'], null, null, false, 6, false, true, true, - $specificPriceOutput, true); + $specific_price_output, true); - if (!isset($maxPrice[$currency['id_currency']])) - $maxPrice[$currency['id_currency']] = 0; - if (!isset($minPrice[$currency['id_currency']])) - $minPrice[$currency['id_currency']] = null; - if ($price > $maxPrice[$currency['id_currency']]) - $maxPrice[$currency['id_currency']] = $price; + if (!isset($max_price[$currency['id_currency']])) + $max_price[$currency['id_currency']] = 0; + if (!isset($min_price[$currency['id_currency']])) + $min_price[$currency['id_currency']] = null; + if ($price > $max_price[$currency['id_currency']]) + $max_price[$currency['id_currency']] = $price; if ($price == 0) continue; - if (is_null($minPrice[$currency['id_currency']]) || $price < $minPrice[$currency['id_currency']]) - $minPrice[$currency['id_currency']] = $price; + if (is_null($min_price[$currency['id_currency']]) || $price < $min_price[$currency['id_currency']]) + $min_price[$currency['id_currency']] = $price; } - foreach ($productMinPrices as $specificPrice) - foreach ($currencyList as $currency) + foreach ($product_min_prices as $specific_price) + foreach ($currency_list as $currency) { - if ($specificPrice['id_currency'] && $specificPrice['id_currency'] != $currency['id_currency']) + if ($specific_price['id_currency'] && $specific_price['id_currency'] != $currency['id_currency']) continue; - $price = Product::priceCalculation((($specificPrice['id_shop'] == 0) ? null : (int)$specificPrice['id_shop']), (int)$idProduct, - null, (($specificPrice['id_country'] == 0) ? null : $specificPrice['id_country']), null, null, - $currency['id_currency'], (($specificPrice['id_group'] == 0) ? null : $specificPrice['id_group']), - $specificPrice['from_quantity'], false, 6, false, true, true, $specificPriceOutput, true); + $price = Product::priceCalculation((($specific_price['id_shop'] == 0) ? null : (int)$specific_price['id_shop']), (int)$id_product, + null, (($specific_price['id_country'] == 0) ? null : $specific_price['id_country']), null, null, + $currency['id_currency'], (($specific_price['id_group'] == 0) ? null : $specific_price['id_group']), + $specific_price['from_quantity'], false, 6, false, true, true, $specific_price_output, true); - if (!isset($maxPrice[$currency['id_currency']])) - $maxPrice[$currency['id_currency']] = 0; - if (!isset($minPrice[$currency['id_currency']])) - $minPrice[$currency['id_currency']] = null; - if ($price > $maxPrice[$currency['id_currency']]) - $maxPrice[$currency['id_currency']] = $price; + if (!isset($max_price[$currency['id_currency']])) + $max_price[$currency['id_currency']] = 0; + if (!isset($min_price[$currency['id_currency']])) + $min_price[$currency['id_currency']] = null; + if ($price > $max_price[$currency['id_currency']]) + $max_price[$currency['id_currency']] = $price; if ($price == 0) continue; - if (is_null($minPrice[$currency['id_currency']]) || $price < $minPrice[$currency['id_currency']]) - $minPrice[$currency['id_currency']] = $price; + if (is_null($min_price[$currency['id_currency']]) || $price < $min_price[$currency['id_currency']]) + $min_price[$currency['id_currency']] = $price; } foreach ($groups as $group) - foreach ($currencyList as $currency) + foreach ($currency_list as $currency) { - $price = Product::priceCalculation(null, (int)$idProduct, null, null, null, null, (int)$currency['id_currency'], (int)$group['id_group'], - null, false, 6, false, true, true, $specificPriceOutput, true); + $price = Product::priceCalculation(null, (int)$id_product, null, null, null, null, (int)$currency['id_currency'], (int)$group['id_group'], + null, false, 6, false, true, true, $specific_price_output, true); - if (!isset($maxPrice[$currency['id_currency']])) - $maxPrice[$currency['id_currency']] = 0; - if (!isset($minPrice[$currency['id_currency']])) - $minPrice[$currency['id_currency']] = null; - if ($price > $maxPrice[$currency['id_currency']]) - $maxPrice[$currency['id_currency']] = $price; + if (!isset($max_price[$currency['id_currency']])) + $max_price[$currency['id_currency']] = 0; + if (!isset($min_price[$currency['id_currency']])) + $min_price[$currency['id_currency']] = null; + if ($price > $max_price[$currency['id_currency']]) + $max_price[$currency['id_currency']] = $price; if ($price == 0) continue; - if (is_null($minPrice[$currency['id_currency']]) || $price < $minPrice[$currency['id_currency']]) - $minPrice[$currency['id_currency']] = $price; + if (is_null($min_price[$currency['id_currency']]) || $price < $min_price[$currency['id_currency']]) + $min_price[$currency['id_currency']] = $price; } $values = array(); - foreach ($currencyList as $currency) - $values[] = '('.(int)$idProduct.', + foreach ($currency_list as $currency) + $values[] = '('.(int)$id_product.', '.(int)$currency['id_currency'].', '.$id_shop.', - '.(int)$minPrice[$currency['id_currency']].', - '.(int)Tools::ps_round($maxPrice[$currency['id_currency']] * (100 + $maxTaxRate) / 100, 0).')'; + '.(int)$min_price[$currency['id_currency']].', + '.(int)Tools::ps_round($max_price[$currency['id_currency']] * (100 + $max_tax_rate) / 100, 0).')'; Db::getInstance()->execute(' INSERT INTO `'._DB_PREFIX_.'layered_price_index` (id_product, id_currency, id_shop, price_min, price_max) @@ -1148,41 +1152,51 @@ class BlockLayered extends Module global $smarty, $cookie; // No filters => module disable - if ($filterBlock = $this->getFilterBlock($this->getSelectedFilters())) - if ($filterBlock['nbr_filterBlocks'] == 0) + if ($filter_block = $this->getFilterBlock($this->getSelectedFilters())) + if ($filter_block['nbr_filterBlocks'] == 0) return false; if (Tools::getValue('id_category', Tools::getValue('id_category_layered', 1)) == 1) return; - $idLang = (int)$cookie->id_lang; + $id_lang = (int)$cookie->id_lang; $category = new Category((int)Tools::getValue('id_category')); // Generate meta title and meta description + $category_title = (empty($category->meta_title[$id_lang]) ? $category->name[$id_lang] : $category->meta_title[$id_lang]); $title = ''; + $description = ''; $keywords = ''; - if (is_array($filterBlock['title_values'])) - foreach ($filterBlock['title_values'] as $key => $val) + if (is_array($filter_block['meta_values'])) + foreach ($filter_block['meta_values'] as $key => $val) { - $title .= $key.' '.implode('/', $val).' '; - $keywords .= $key.' '.implode('/', $val).', '; + if (!empty($val['title'])) + $val['title'] = $val['title'].' '; + + foreach ($val['values'] as $value) { + $title .= $category_title.' '.$val['title'].$value.' - '; + $description .= $category_title.' '.$val['title'].$value.', '; + $keywords .= $val['title'].$value.', '; + } } - $title = strtolower(rtrim($title)); - - $categoryMetas = Tools::getMetaTags($idLang, '', $title); - $categoryTitle = (empty($category->meta_title[$idLang]) ? $category->name[$idLang] : $category->meta_title[$idLang]); + // Title attributes (ex: / - ) + $title = strtolower(rtrim(substr($title, 0, -3))); + // Title attributes (ex: /, ) + $description = strtolower(rtrim(substr($description, 0, -2))); + // kewords attributes (ex: , , ) + $category_metas = Tools::getMetaTags($id_lang, '', $title); if (!empty($title)) { - $smarty->assign('meta_title', $categoryTitle.substr($categoryMetas['meta_title'], 2)); - $smarty->assign('meta_description', $categoryTitle.' '.$title.'. '.$categoryMetas['meta_description']); + $smarty->assign('meta_title', ucfirst(substr($category_metas['meta_title'], 3))); + $smarty->assign('meta_description', $description.'. '.$category_metas['meta_description']); } else - $smarty->assign('meta_title', $categoryMetas['meta_title']); + $smarty->assign('meta_title', $category_metas['meta_title']); $keywords = substr(strtolower($keywords), 0, 1000); if (!empty($keywords)) - $smarty->assign('meta_keywords', rtrim($categoryTitle.', '.$keywords.', '.$categoryMetas['meta_keywords'], ', ')); + $smarty->assign('meta_keywords', rtrim($category_title.', '.$keywords.', '.$category_metas['meta_keywords'], ', ')); if (version_compare(_PS_VERSION_,'1.5','>')) { @@ -1359,13 +1373,13 @@ class BlockLayered extends Module { /* Clean categoryBox before use */ if (isset($_POST['categoryBox']) && is_array($_POST['categoryBox'])) - foreach ($_POST['categoryBox'] as &$categoryBoxTmp) - $categoryBoxTmp = (int)$categoryBoxTmp; + foreach ($_POST['categoryBox'] as &$category_box_tmp) + $category_box_tmp = (int)$category_box_tmp; - $filterValues = array(); + $filter_values = array(); foreach ($_POST['categoryBox'] as $idc) - $filterValues['categories'][] = (int)$idc; - $filterValues['shop_list'] = $shop_list; + $filter_values['categories'][] = (int)$idc; + $filter_values['shop_list'] = $shop_list; $values = false; foreach ($_POST['categoryBox'] as $id_category_layered) @@ -1381,22 +1395,22 @@ class BlockLayered extends Module if (Tools::getValue($key.'_filter_show_limit')) $limit = Tools::getValue($key.'_filter_show_limit'); - $filterValues[$key] = array( + $filter_values[$key] = array( 'filter_type' => (int)$type, 'filter_show_limit' => (int)$limit ); } } - $valuesToInsert = array( + $values_to_insert = array( 'name' => pSQL(Tools::getValue('layered_tpl_name')), - 'filters' => pSQL(serialize($filterValues)), - 'n_categories' => (int)count($filterValues['categories']), + 'filters' => pSQL(serialize($filter_values)), + 'n_categories' => (int)count($filter_values['categories']), 'date_add' => date('Y-m-d H:i:s')); if (isset($_POST['id_layered_filter']) && $_POST['id_layered_filter']) - $valuesToInsert['id_layered_filter'] = (int)Tools::getValue('id_layered_filter'); + $values_to_insert['id_layered_filter'] = (int)Tools::getValue('id_layered_filter'); - Db::getInstance()->autoExecute(_DB_PREFIX_.'layered_filter', $valuesToInsert, 'INSERT'); + Db::getInstance()->autoExecute(_DB_PREFIX_.'layered_filter', $values_to_insert, 'INSERT'); $this->buildLayeredCategories(); $html .= '
'.(version_compare(_PS_VERSION_,'1.5','>') ? '' : ''). @@ -1407,11 +1421,13 @@ class BlockLayered extends Module } else if (Tools::isSubmit('submitLayeredSettings')) { - Configuration::updateValue('PS_LAYERED_HIDE_0_VALUES', Tools::getValue('ps_layered_hide_0_values')); - Configuration::updateValue('PS_LAYERED_SHOW_QTIES', Tools::getValue('ps_layered_show_qties')); - Configuration::updateValue('PS_LAYERED_FULL_TREE', Tools::getValue('ps_layered_full_tree')); - Configuration::updateValue('PS_LAYERED_FILTER_PRICE_USETAX', Tools::getValue('ps_layered_filter_price_usetax')); + Configuration::updateValue('PS_LAYERED_HIDE_0_VALUES', (int)Tools::getValue('ps_layered_hide_0_values')); + Configuration::updateValue('PS_LAYERED_SHOW_QTIES', (int)Tools::getValue('ps_layered_show_qties')); + Configuration::updateValue('PS_LAYERED_FULL_TREE', (int)Tools::getValue('ps_layered_full_tree')); + Configuration::updateValue('PS_LAYERED_FILTER_PRICE_USETAX', (int)Tools::getValue('ps_layered_filter_price_usetax')); Configuration::updateValue('PS_LAYERED_FILTER_CATEGORY_DEPTH', (int)Tools::getValue('ps_layered_filter_category_depth')); + Configuration::updateValue('PS_LAYERED_FILTER_INDEX_QTY', (int)Tools::getValue('ps_layered_filter_index_availability')); + Configuration::updateValue('PS_LAYERED_FILTER_INDEX_CDT', (int)Tools::getValue('ps_layered_filter_index_condition')); $html .= '
'. @@ -1420,12 +1436,12 @@ class BlockLayered extends Module } else if (isset($_GET['deleteFilterTemplate'])) { - $layeredValues = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' + $layered_values = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' SELECT filters FROM '._DB_PREFIX_.'layered_filter WHERE id_layered_filter = '.(int)$_GET['id_layered_filter']); - if ($layeredValues) + if ($layered_values) { Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'layered_filter WHERE id_layered_filter = '.(int)$_GET['id_layered_filter'].' LIMIT 1'); $this->buildLayeredCategories(); @@ -1466,10 +1482,10 @@ class BlockLayered extends Module }); '; - $categoryList = array(); + $category_ist = array(); foreach (Db::getInstance()->executeS('SELECT id_category FROM `'._DB_PREFIX_.'category`') as $category) if ($category['id_category'] != 1) - $categoryList[] = $category['id_category']; + $category_ist[] = $category['id_category']; if (Tools::usingSecureMode()) $domain = Tools::getShopDomainSsl(true); @@ -1627,10 +1643,10 @@ class BlockLayered extends Module
'.$this->l('Existing filters templates').''; - $filtersTemplates = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('SELECT * FROM '._DB_PREFIX_.'layered_filter ORDER BY date_add DESC'); - if (count($filtersTemplates)) + $filters_templates = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('SELECT * FROM '._DB_PREFIX_.'layered_filter ORDER BY date_add DESC'); + if (count($filters_templates)) { - $html .= '

'.count($filtersTemplates).' '.$this->l('filters templates are configured:').'

+ $html .= '

'.count($filters_templates).' '.$this->l('filters templates are configured:').'

@@ -1640,22 +1656,22 @@ class BlockLayered extends Module '; - foreach ($filtersTemplates as $filtersTemplate) + foreach ($filters_templates as $filters_template) { /* Clean request URI first */ $_SERVER['REQUEST_URI'] = preg_replace('/&deleteFilterTemplate=[0-9]*&id_layered_filter=[0-9]*/', '', $_SERVER['REQUEST_URI']); $html .= ' - - - - + + + + '; @@ -1734,7 +1750,7 @@ class BlockLayered extends Module
  • '.$this->l('Press "Save this selection" or close the window to save').'
  • '; - $selectedCat = array(); + $selected_cat = array(); // Translations are not automatic for the moment ;) if (version_compare(_PS_VERSION_,'1.5','>')) { @@ -1746,7 +1762,7 @@ class BlockLayered extends Module else $root_category = array('id_category' => '0', 'name' => $this->l('Root')); $helper = new Helper(); - $html .= $helper->renderCategoryTree(null, $selectedCat, 'categoryBox'); + $html .= $helper->renderCategoryTree(null, $selected_cat, 'categoryBox'); } else { @@ -1759,7 +1775,7 @@ class BlockLayered extends Module 'Uncheck All' => $this->l('Uncheck All'), 'search' => $this->l('Search a category') ); - $html .= Helper::renderAdminCategorieTree($trads, $selectedCat, 'categoryBox'); + $html .= Helper::renderAdminCategorieTree($trads, $selected_cat, 'categoryBox'); } $html .= ' @@ -2001,7 +2017,7 @@ class BlockLayered extends Module
    - +
    @@ -2054,6 +2070,24 @@ class BlockLayered extends Module '.$this->l('No').' +
    + + + + + + +
    '.$this->l('ID').''.$this->l('Actions').'
    '.(int)$filtersTemplate['id_layered_filter'].''.$filtersTemplate['name'].''.(int)$filtersTemplate['n_categories'].''.Tools::displayDate($filtersTemplate['date_add'], (int)$cookie->id_lang, true).''.(int)$filters_template['id_layered_filter'].''.$filters_template['name'].''.(int)$filters_template['n_categories'].''.Tools::displayDate($filters_template['date_add'], (int)$cookie->id_lang, true).' - + - +
    '.$this->l('Allow indexing robots (google, yahoo, bing, ...) to use condition filter').' + '.$this->l('Yes').' + '.$this->l('Yes').' + '.$this->l('No').' + '.$this->l('No').' +
    '.$this->l('Allow indexing robots (google, yahoo, bing, ...) to use availability filter').' + '.$this->l('Yes').' + '.$this->l('Yes').' + '.$this->l('No').' + '.$this->l('No').' +

    @@ -2076,82 +2110,82 @@ class BlockLayered extends Module else $url = preg_replace('/\/(?:\w*)\/(?:[0-9]+[-\w]*)([^\?]*)\??.*/', '$1', Tools::safeOutput($_SERVER['REQUEST_URI'], true)); - $urlAttributes = explode('/', $url); - array_shift($urlAttributes); - $selectedFilters = array('category' => array()); - if (!empty($urlAttributes)) + $url_attributes = explode('/', $url); + array_shift($url_attributes); + $selected_filters = array('category' => array()); + if (!empty($url_attributes)) { - foreach ($urlAttributes as $urlAttribute) + foreach ($url_attributes as $url_attribute) { - $urlParameters = explode('-', $urlAttribute); - $attributeName = array_shift($urlParameters); - if ($attributeName == 'page') - $this->page = (int)$urlParameters[0]; - else if (in_array($attributeName, array('price', 'weight'))) - $selectedFilters[$attributeName] = array($urlParameters[0], $urlParameters[1]); + $url_parameters = explode('-', $url_attribute); + $attribute_name = array_shift($url_parameters); + if ($attribute_name == 'page') + $this->page = (int)$url_parameters[0]; + else if (in_array($attribute_name, array('price', 'weight'))) + $selected_filters[$attribute_name] = array($url_parameters[0], $url_parameters[1]); else { - foreach ($urlParameters as $urlParameter) + foreach ($url_parameters as $url_parameter) { - $data = Db::getInstance()->getValue('SELECT data FROM `'._DB_PREFIX_.'layered_friendly_url` WHERE `url_key` = \''.md5('/'.$attributeName.'-'.$urlParameter).'\''); + $data = Db::getInstance()->getValue('SELECT data FROM `'._DB_PREFIX_.'layered_friendly_url` WHERE `url_key` = \''.md5('/'.$attribute_name.'-'.$url_parameter).'\''); if ($data) - foreach (unserialize($data) as $keyParams => $params) + foreach (unserialize($data) as $key_params => $params) { - if (!isset($selectedFilters[$keyParams])) - $selectedFilters[$keyParams] = array(); - foreach ($params as $keyParam => $param) + if (!isset($selected_filters[$key_params])) + $selected_filters[$key_params] = array(); + foreach ($params as $key_param => $param) { - if (!isset($selectedFilters[$keyParams][$keyParam])) - $selectedFilters[$keyParams][$keyParam] = array(); - $selectedFilters[$keyParams][$keyParam] = $param; + if (!isset($selected_filters[$key_params][$key_param])) + $selected_filters[$key_params][$key_param] = array(); + $selected_filters[$key_params][$key_param] = $param; } } } } } - return $selectedFilters; + return $selected_filters; } } /* Analyze all the filters selected by the user and store them into a tab */ - $selectedFilters = array('category' => array(), 'manufacturer' => array(), 'quantity' => array(), 'condition' => array()); + $selected_filters = array('category' => array(), 'manufacturer' => array(), 'quantity' => array(), 'condition' => array()); foreach ($_GET as $key => $value) if (substr($key, 0, 8) == 'layered_') { preg_match('/^(.*)_[0-9|new|used|refurbished|slider]+$/', substr($key, 8, strlen($key) - 8), $res); if (isset($res[1])) { - $tmpTab = explode('_', $value); - $value = $tmpTab[0]; + $tmp_tab = explode('_', $value); + $value = $tmp_tab[0]; $id_key = false; - if (isset($tmpTab[1])) - $id_key = $tmpTab[1]; + if (isset($tmp_tab[1])) + $id_key = $tmp_tab[1]; if ($res[1] == 'condition' && in_array($value, array('new', 'used', 'refurbished'))) - $selectedFilters['condition'][] = $value; + $selected_filters['condition'][] = $value; else if ($res[1] == 'quantity' && (!$value || $value == 1)) - $selectedFilters['quantity'][] = $value; + $selected_filters['quantity'][] = $value; else if (in_array($res[1], array('category', 'manufacturer'))) { - if (!isset($selectedFilters[$res[1].($id_key ? '_'.$id_key : '')])) - $selectedFilters[$res[1].($id_key ? '_'.$id_key : '')] = array(); - $selectedFilters[$res[1].($id_key ? '_'.$id_key : '')][] = (int)$value; + if (!isset($selected_filters[$res[1].($id_key ? '_'.$id_key : '')])) + $selected_filters[$res[1].($id_key ? '_'.$id_key : '')] = array(); + $selected_filters[$res[1].($id_key ? '_'.$id_key : '')][] = (int)$value; } else if (in_array($res[1], array('id_attribute_group', 'id_feature'))) { - if (!isset($selectedFilters[$res[1]])) - $selectedFilters[$res[1]] = array(); - $selectedFilters[$res[1]][(int)$value] = $id_key.'_'.(int)$value; + if (!isset($selected_filters[$res[1]])) + $selected_filters[$res[1]] = array(); + $selected_filters[$res[1]][(int)$value] = $id_key.'_'.(int)$value; } else if ($res[1] == 'weight') - $selectedFilters[$res[1]] = $tmpTab; + $selected_filters[$res[1]] = $tmp_tab; else if ($res[1] == 'price') - $selectedFilters[$res[1]] = $tmpTab; + $selected_filters[$res[1]] = $tmp_tab; } } - return $selectedFilters; + return $selected_filters; } - public function getProductByFilters($selectedFilters = array()) + public function getProductByFilters($selected_filters = array()) { global $cookie; @@ -2163,30 +2197,30 @@ class BlockLayered extends Module if ($id_parent == 1) return false; - $queryFiltersWhere = ' AND p.active = 1'; - $queryFiltersFrom = ''; + $query_filters_where = ' AND p.active = 1'; + $query_filters_from = ''; $parent = new Category((int)$id_parent); - if (!count($selectedFilters['category'])) + if (!count($selected_filters['category'])) { if (Configuration::get('PS_LAYERED_FULL_TREE')) - $queryFiltersFrom .= ' INNER JOIN '._DB_PREFIX_.'category_product cp + $query_filters_from .= ' INNER JOIN '._DB_PREFIX_.'category_product cp ON p.id_product = cp.id_product INNER JOIN '._DB_PREFIX_.'category c ON (c.id_category = cp.id_category AND '.(Configuration::get('PS_LAYERED_FULL_TREE') ? 'c.nleft >= '.(int)$parent->nleft.' AND c.nright <= '.(int)$parent->nright : 'c.id_category = '.(int)$id_parent).' AND c.active = 1)'; else - $queryFiltersFrom .= ' INNER JOIN '._DB_PREFIX_.'category_product cp + $query_filters_from .= ' INNER JOIN '._DB_PREFIX_.'category_product cp ON p.id_product = cp.id_product INNER JOIN '._DB_PREFIX_.'category c ON (c.id_category = cp.id_category AND c.id_category = '.(int)$id_parent.' AND c.active = 1)'; } - foreach ($selectedFilters as $key => $filterValues) + foreach ($selected_filters as $key => $filter_values) { - if (!count($filterValues)) + if (!count($filter_values)) continue; preg_match('/^(.*[^_0-9])/', $key, $res); @@ -2195,152 +2229,152 @@ class BlockLayered extends Module switch ($key) { case 'id_feature': - $subQueries = array(); - foreach ($filterValues as $filterValue) + $sub_queries = array(); + foreach ($filter_values as $filter_value) { - $filterValueArray = explode('_', $filterValue); - if (!isset($subQueries[$filterValueArray[0]])) - $subQueries[$filterValueArray[0]] = array(); - $subQueries[$filterValueArray[0]][] = 'fp.`id_feature_value` = '.(int)$filterValueArray[1]; + $filter_value_array = explode('_', $filter_value); + if (!isset($sub_queries[$filter_value_array[0]])) + $sub_queries[$filter_value_array[0]] = array(); + $sub_queries[$filter_value_array[0]][] = 'fp.`id_feature_value` = '.(int)$filter_value_array[1]; } - foreach ($subQueries as $subQuery) + foreach ($sub_queries as $sub_query) { - $queryFiltersWhere .= ' AND p.id_product IN (SELECT `id_product` FROM `'._DB_PREFIX_.'feature_product` fp WHERE '; - $queryFiltersWhere .= implode(' OR ', $subQuery).') '; + $query_filters_where .= ' AND p.id_product IN (SELECT `id_product` FROM `'._DB_PREFIX_.'feature_product` fp WHERE '; + $query_filters_where .= implode(' OR ', $sub_query).') '; } break; case 'id_attribute_group': - $subQueries = array(); + $sub_queries = array(); - foreach ($filterValues as $filterValue) + foreach ($filter_values as $filter_value) { - $filterValueArray = explode('_', $filterValue); - if (!isset($subQueries[$filterValueArray[0]])) - $subQueries[$filterValueArray[0]] = array(); - $subQueries[$filterValueArray[0]][] = 'pac.`id_attribute` = '.(int)$filterValueArray[1]; + $filter_value_array = explode('_', $filter_value); + if (!isset($sub_queries[$filter_value_array[0]])) + $sub_queries[$filter_value_array[0]] = array(); + $sub_queries[$filter_value_array[0]][] = 'pac.`id_attribute` = '.(int)$filter_value_array[1]; } - foreach ($subQueries as $subQuery) + foreach ($sub_queries as $sub_query) { - $queryFiltersWhere .= ' AND p.id_product IN (SELECT pa.`id_product` + $query_filters_where .= ' AND p.id_product IN (SELECT pa.`id_product` FROM `'._DB_PREFIX_.'product_attribute_combination` pac LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (pa.`id_product_attribute` = pac.`id_product_attribute`) WHERE '; - $queryFiltersWhere .= implode(' OR ', $subQuery).') '; + $query_filters_where .= implode(' OR ', $sub_query).') '; } break; case 'category': - $queryFiltersWhere .= ' AND p.id_product IN (SELECT id_product FROM '._DB_PREFIX_.'category_product cp WHERE '; - foreach ($selectedFilters['category'] as $id_category) - $queryFiltersWhere .= 'cp.`id_category` = '.(int)$id_category.' OR '; - $queryFiltersWhere = rtrim($queryFiltersWhere, 'OR ').')'; + $query_filters_where .= ' AND p.id_product IN (SELECT id_product FROM '._DB_PREFIX_.'category_product cp WHERE '; + foreach ($selected_filters['category'] as $id_category) + $query_filters_where .= 'cp.`id_category` = '.(int)$id_category.' OR '; + $query_filters_where = rtrim($query_filters_where, 'OR ').')'; break; case 'quantity': - if (count($selectedFilters['quantity']) == 2) + if (count($selected_filters['quantity']) == 2) break; if (version_compare(_PS_VERSION_,'1.5','>')) { - $queryFiltersWhere .= ' AND sa.quantity '.(!$selectedFilters['quantity'][0] ? '<=' : '>').' 0 '; - $queryFiltersFrom .= 'LEFT JOIN `'._DB_PREFIX_.'stock_available` sa ON (sa.id_product = p.id_product AND sa.id_shop = '.(int)Context::getContext()->shop->id.') '; + $query_filters_where .= ' AND sa.quantity '.(!$selected_filters['quantity'][0] ? '<=' : '>').' 0 '; + $query_filters_from .= 'LEFT JOIN `'._DB_PREFIX_.'stock_available` sa ON (sa.id_product = p.id_product AND sa.id_shop = '.(int)Context::getContext()->shop->id.') '; } else - $queryFiltersWhere .= ' AND p.quantity '.(!$selectedFilters['quantity'][0] ? '<=' : '>').' 0 '; + $query_filters_where .= ' AND p.quantity '.(!$selected_filters['quantity'][0] ? '<=' : '>').' 0 '; break; case 'manufacturer': - $queryFiltersWhere .= ' AND p.id_manufacturer IN ('.implode($selectedFilters['manufacturer'], ',').')'; + $query_filters_where .= ' AND p.id_manufacturer IN ('.implode($selected_filters['manufacturer'], ',').')'; break; case 'condition': - if (count($selectedFilters['condition']) == 3) + if (count($selected_filters['condition']) == 3) break; - $queryFiltersWhere .= ' AND p.condition IN ('; - foreach ($selectedFilters['condition'] as $cond) - $queryFiltersWhere .= '\''.$cond.'\','; - $queryFiltersWhere = rtrim($queryFiltersWhere, ',').')'; + $query_filters_where .= ' AND p.condition IN ('; + foreach ($selected_filters['condition'] as $cond) + $query_filters_where .= '\''.$cond.'\','; + $query_filters_where = rtrim($query_filters_where, ',').')'; break; case 'weight': - if ($selectedFilters['weight'][0] != 0 || $selectedFilters['weight'][1] != 0) - $queryFiltersWhere .= ' AND p.`weight` BETWEEN '.(float)($selectedFilters['weight'][0] - 0.001).' AND '.(float)($selectedFilters['weight'][1] + 0.001); + if ($selected_filters['weight'][0] != 0 || $selected_filters['weight'][1] != 0) + $query_filters_where .= ' AND p.`weight` BETWEEN '.(float)($selected_filters['weight'][0] - 0.001).' AND '.(float)($selected_filters['weight'][1] + 0.001); case 'price': - if (isset($selectedFilters['price'])) + if (isset($selected_filters['price'])) { - if ($selectedFilters['price'][0] !== '' || $selectedFilters['price'][1] !== '') + if ($selected_filters['price'][0] !== '' || $selected_filters['price'][1] !== '') { - $priceFilter = array(); - $priceFilter['min'] = (float)($selectedFilters['price'][0]); - $priceFilter['max'] = (float)($selectedFilters['price'][1]); + $price_filter = array(); + $price_filter['min'] = (float)($selected_filters['price'][0]); + $price_filter['max'] = (float)($selected_filters['price'][1]); } } else - $priceFilter = false; + $price_filter = false; break; } } if (version_compare(_PS_VERSION_,'1.5','>')) - $idCurrency = (int)Context::getContext()->currency->id; + $id_currency = (int)Context::getContext()->currency->id; else - $idCurrency = (int)Currency::getCurrent()->id; + $id_currency = (int)Currency::getCurrent()->id; - $priceFilterQueryIn = ''; // All products with price range between price filters limits - $priceFilterQueryOut = ''; // All products with a price filters limit on it price range - if (isset($priceFilter) && $priceFilter) + $price_filter_query_in = ''; // All products with price range between price filters limits + $price_filter_query_out = ''; // All products with a price filters limit on it price range + if (isset($price_filter) && $price_filter) { - $priceFilterQueryIn = 'INNER JOIN `'._DB_PREFIX_.'layered_price_index` psi + $price_filter_query_in = 'INNER JOIN `'._DB_PREFIX_.'layered_price_index` psi ON ( - psi.price_min >= '.(int)$priceFilter['min'].' - AND psi.price_max <= '.(int)$priceFilter['max'].' + psi.price_min >= '.(int)$price_filter['min'].' + AND psi.price_max <= '.(int)$price_filter['max'].' AND psi.`id_product` = p.`id_product` - AND psi.`id_currency` = '.$idCurrency.' + AND psi.`id_currency` = '.$id_currency.' )'; - $priceFilterQueryOut = 'INNER JOIN `'._DB_PREFIX_.'layered_price_index` psi + $price_filter_query_out = 'INNER JOIN `'._DB_PREFIX_.'layered_price_index` psi ON - ((psi.price_min < '.(int)$priceFilter['min'].' AND psi.price_max > '.(int)$priceFilter['min'].') + ((psi.price_min < '.(int)$price_filter['min'].' AND psi.price_max > '.(int)$price_filter['min'].') OR - (psi.price_max > '.(int)$priceFilter['max'].' AND psi.price_min < '.(int)$priceFilter['max'].')) + (psi.price_max > '.(int)$price_filter['max'].' AND psi.price_min < '.(int)$price_filter['max'].')) AND psi.`id_product` = p.`id_product` - AND psi.`id_currency` = '.$idCurrency; + AND psi.`id_currency` = '.$id_currency; } if (version_compare(_PS_VERSION_,'1.5','>')) - $queryFiltersFrom .= Shop::addSqlAssociation('product', 'p'); + $query_filters_from .= Shop::addSqlAssociation('product', 'p'); - $allProductsOut = self::query(' + $all_products_out = self::query(' SELECT p.`id_product` id_product FROM `'._DB_PREFIX_.'product` p - '.$priceFilterQueryOut.' - '.$queryFiltersFrom.' - WHERE 1 '.$queryFiltersWhere.' GROUP BY id_product'); + '.$price_filter_query_out.' + '.$query_filters_from.' + WHERE 1 '.$query_filters_where.' GROUP BY id_product'); - $allProductsIn = self::query(' + $all_products_in = self::query(' SELECT p.`id_product` id_product FROM `'._DB_PREFIX_.'product` p - '.$priceFilterQueryIn.' - '.$queryFiltersFrom.' - WHERE 1 '.$queryFiltersWhere.' GROUP BY id_product'); + '.$price_filter_query_in.' + '.$query_filters_from.' + WHERE 1 '.$query_filters_where.' GROUP BY id_product'); - $productIdList = array(); + $product_id_list = array(); - while ($product = DB::getInstance()->nextRow($allProductsIn)) - $productIdList[] = (int)$product['id_product']; + while ($product = DB::getInstance()->nextRow($all_products_in)) + $product_id_list[] = (int)$product['id_product']; - while ($product = DB::getInstance()->nextRow($allProductsOut)) - if (isset($priceFilter) && $priceFilter) + while ($product = DB::getInstance()->nextRow($all_products_out)) + if (isset($price_filter) && $price_filter) { $price = (int)Product::getPriceStatic($product['id_product'], Configuration::get('PS_LAYERED_FILTER_PRICE_USETAX')); // Cast to int because we don't care about cents - if ($price < $priceFilter['min'] || $price > $priceFilter['max']) + if ($price < $price_filter['min'] || $price > $price_filter['max']) continue; - $productIdList[] = (int)$product['id_product']; + $product_id_list[] = (int)$product['id_product']; } - $this->nbr_products = count($productIdList); + $this->nbr_products = count($product_id_list); if ($this->nbr_products == 0) $this->products = array(); @@ -2372,7 +2406,7 @@ class BlockLayered extends Module AND c.nright <= '.(int)$parent->nright : 'c.id_category = '.(int)$id_parent).' AND c.active = 1 AND pl.id_lang = '.(int)$cookie->id_lang.' - AND p.id_product IN ('.implode(',', $productIdList).')' + AND p.id_product IN ('.implode(',', $product_id_list).')' .' GROUP BY p.id_product ORDER BY '.Tools::getProductsOrder('by', Tools::getValue('orderby'), true).' '.Tools::getProductsOrder('way', Tools::getValue('orderway')). ' LIMIT '.(((int)$this->page - 1) * $n.','.$n)); } @@ -2387,7 +2421,7 @@ class BlockLayered extends Module return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql_query, false); } - public function getFilterBlock($selectedFilters = array()) + public function getFilterBlock($selected_filters = array()) { global $cookie; static $cache = null; @@ -2417,24 +2451,24 @@ class BlockLayered extends Module AND id_shop = '.$id_shop.' GROUP BY `type`, id_value ORDER BY position ASC'); // Remove all empty selected filters - foreach ($selectedFilters as $key => $value) + foreach ($selected_filters as $key => $value) switch ($key) { case 'price': case 'weight': if ($value[0] === '' && $value[1] === '') - unset($selectedFilters[$key]); + unset($selected_filters[$key]); break; default: if ($value == '') - unset($selectedFilters[$key]); + unset($selected_filters[$key]); break; } - $filterBlocks = array(); + $filter_blocks = array(); foreach ($filters as $filter) { - $sqlQuery = array('select' => '', 'from' => '', 'join' => '', 'where' => '', 'group' => '', 'second_query' => ''); + $sql_query = array('select' => '', 'from' => '', 'join' => '', 'where' => '', 'group' => '', 'second_query' => ''); switch ($filter['type']) { // conditions + quantities + weight + price @@ -2444,40 +2478,40 @@ class BlockLayered extends Module case 'quantity': if (version_compare(_PS_VERSION_,'1.5','>')) - $sqlQuery['select'] = 'SELECT p.`id_product`, p.`condition`, p.`id_manufacturer`, sa.`quantity`, p.`weight` '; + $sql_query['select'] = 'SELECT p.`id_product`, p.`condition`, p.`id_manufacturer`, sa.`quantity`, p.`weight` '; else - $sqlQuery['select'] = 'SELECT p.`id_product`, p.`condition`, p.`id_manufacturer`, p.`quantity`, p.`weight` '; - $sqlQuery['from'] = ' + $sql_query['select'] = 'SELECT p.`id_product`, p.`condition`, p.`id_manufacturer`, p.`quantity`, p.`weight` '; + $sql_query['from'] = ' FROM '._DB_PREFIX_.'product p '; - $sqlQuery['join'] = ' + $sql_query['join'] = ' INNER JOIN '._DB_PREFIX_.'category_product cp ON (cp.id_product = p.id_product) INNER JOIN '._DB_PREFIX_.'category c ON (c.id_category = cp.id_category AND '.(Configuration::get('PS_LAYERED_FULL_TREE') ? 'c.nleft >= '.(int)$parent->nleft.' AND c.nright <= '.(int)$parent->nright : 'c.id_category = '.(int)$id_parent).' AND c.active = 1) '; if (version_compare(_PS_VERSION_,'1.5','>')) - $sqlQuery['join'] .= 'LEFT JOIN `'._DB_PREFIX_.'stock_available` sa + $sql_query['join'] .= 'LEFT JOIN `'._DB_PREFIX_.'stock_available` sa ON (sa.id_product = p.id_product AND sa.id_shop = '.(int)$this->context->shop->id.') '; - $sqlQuery['where'] = 'WHERE p.`active` = 1 '; - $sqlQuery['group'] = ' GROUP BY p.id_product '; + $sql_query['where'] = 'WHERE p.`active` = 1 '; + $sql_query['group'] = ' GROUP BY p.id_product '; break; case 'manufacturer': - $sqlQuery['select'] = 'SELECT m.name, COUNT(DISTINCT p.id_product) nbr, m.id_manufacturer '; - $sqlQuery['from'] = ' + $sql_query['select'] = 'SELECT m.name, COUNT(DISTINCT p.id_product) nbr, m.id_manufacturer '; + $sql_query['from'] = ' FROM `'._DB_PREFIX_.'category_product` cp INNER JOIN `'._DB_PREFIX_.'category` c ON (c.id_category = cp.id_category) INNER JOIN '._DB_PREFIX_.'product p ON (p.id_product = cp.id_product AND p.active = 1) INNER JOIN '._DB_PREFIX_.'manufacturer m ON (m.id_manufacturer = p.id_manufacturer) '; - $sqlQuery['where'] = 'WHERE + $sql_query['where'] = 'WHERE '.(Configuration::get('PS_LAYERED_FULL_TREE') ? 'c.nleft >= '.(int)$parent->nleft.' AND c.nright <= '.(int)$parent->nright : 'c.id_category = '.(int)$id_parent).' AND c.active = 1 '; - $sqlQuery['group'] = ' GROUP BY p.id_manufacturer '; + $sql_query['group'] = ' GROUP BY p.id_manufacturer '; if (!Configuration::get('PS_LAYERED_HIDE_0_VALUES')) { - $sqlQuery['second_query'] = ' + $sql_query['second_query'] = ' SELECT m.name, 0 nbr, m.id_manufacturer FROM `'._DB_PREFIX_.'category_product` cp @@ -2495,11 +2529,11 @@ class BlockLayered extends Module break; case 'id_attribute_group':// attribute group - $sqlQuery['select'] = ' + $sql_query['select'] = ' SELECT COUNT(DISTINCT p.id_product) nbr, lpa.id_attribute_group, a.color, al.name attribute_name, agl.public_name attribute_group_name , lpa.id_attribute, ag.is_color_group, liagl.url_name name_url_name, liagl.meta_title name_meta_title, lial.url_name value_url_name, lial.meta_title value_meta_title'; - $sqlQuery['from'] = ' + $sql_query['from'] = ' FROM '._DB_PREFIX_.'layered_product_attribute lpa INNER JOIN '._DB_PREFIX_.'attribute a ON a.id_attribute = lpa.id_attribute @@ -2518,7 +2552,7 @@ class BlockLayered extends Module ON (liagl.id_attribute_group = lpa.id_attribute_group AND liagl.id_lang = '.(int)$cookie->id_lang.') LEFT JOIN '._DB_PREFIX_.'layered_indexable_attribute_lang_value lial ON (lial.id_attribute = lpa.id_attribute AND lial.id_lang = '.(int)$cookie->id_lang.') '; - $sqlQuery['where'] = 'WHERE a.id_attribute_group = '.(int)$filter['id_value'].' + $sql_query['where'] = 'WHERE a.id_attribute_group = '.(int)$filter['id_value'].' AND p.id_product IN ( SELECT id_product FROM '._DB_PREFIX_.'category_product cp @@ -2526,13 +2560,13 @@ class BlockLayered extends Module '.(Configuration::get('PS_LAYERED_FULL_TREE') ? 'c.nleft >= '.(int)$parent->nleft.' AND c.nright <= '.(int)$parent->nright : 'c.id_category = '.(int)$id_parent).' AND c.active = 1)) '; - $sqlQuery['group'] = ' + $sql_query['group'] = ' GROUP BY lpa.id_attribute ORDER BY id_attribute_group, id_attribute '; if (!Configuration::get('PS_LAYERED_HIDE_0_VALUES')) { - $sqlQuery['second_query'] = ' + $sql_query['second_query'] = ' SELECT 0 nbr, lpa.id_attribute_group, a.color, al.name attribute_name, agl.public_name attribute_group_name , lpa.id_attribute, ag.is_color_group, liagl.url_name name_url_name, liagl.meta_title name_meta_title, lial.url_name value_url_name, lial.meta_title value_meta_title @@ -2564,10 +2598,10 @@ class BlockLayered extends Module break; case 'id_feature': - $sqlQuery['select'] = 'SELECT fl.name feature_name, fp.id_feature, fv.id_feature_value, fvl.value, + $sql_query['select'] = 'SELECT fl.name feature_name, fp.id_feature, fv.id_feature_value, fvl.value, COUNT(DISTINCT p.id_product) nbr, lifl.url_name name_url_name, lifl.meta_title name_meta_title, lifvl.url_name value_url_name, lifvl.meta_title value_meta_title '; - $sqlQuery['from'] = ' + $sql_query['from'] = ' FROM '._DB_PREFIX_.'feature_product fp INNER JOIN '._DB_PREFIX_.'product p ON (p.id_product = fp.id_product AND p.active = 1) LEFT JOIN '._DB_PREFIX_.'feature_lang fl ON (fl.id_feature = fp.id_feature AND fl.id_lang = '.(int)$cookie->id_lang.') @@ -2577,7 +2611,7 @@ class BlockLayered extends Module ON (lifl.id_feature = fp.id_feature AND lifl.id_lang = '.(int)$cookie->id_lang.') LEFT JOIN '._DB_PREFIX_.'layered_indexable_feature_value_lang_value lifvl ON (lifvl.id_feature_value = fp.id_feature_value AND lifvl.id_lang = '.(int)$cookie->id_lang.') '; - $sqlQuery['where'] = 'WHERE p.`active` = 1 AND fp.id_feature = '.(int)$filter['id_value'].' + $sql_query['where'] = 'WHERE p.`active` = 1 AND fp.id_feature = '.(int)$filter['id_value'].' AND p.id_product IN ( SELECT id_product FROM '._DB_PREFIX_.'category_product cp @@ -2585,11 +2619,11 @@ class BlockLayered extends Module '.(Configuration::get('PS_LAYERED_FULL_TREE') ? 'c.nleft >= '.(int)$parent->nleft.' AND c.nright <= '.(int)$parent->nright : 'c.id_category = '.(int)$id_parent).' AND c.active = 1)) '; - $sqlQuery['group'] = 'GROUP BY fv.id_feature_value '; + $sql_query['group'] = 'GROUP BY fv.id_feature_value '; if (!Configuration::get('PS_LAYERED_HIDE_0_VALUES')) { - $sqlQuery['second_query'] = ' + $sql_query['second_query'] = ' SELECT fl.name feature_name, fp.id_feature, fv.id_feature_value, fvl.value, 0 nbr, lifl.url_name name_url_name, lifl.meta_title name_meta_title, lifvl.url_name value_url_name, lifvl.meta_title value_meta_title @@ -2614,14 +2648,14 @@ class BlockLayered extends Module if ($depth === false) $depth = 1; - $sqlQuery['select'] = ' + $sql_query['select'] = ' SELECT c.id_category, c.id_parent, cl.name, (SELECT count(DISTINCT p.id_product) # '; - $sqlQuery['from'] = ' + $sql_query['from'] = ' FROM '._DB_PREFIX_.'category_product cp LEFT JOIN '._DB_PREFIX_.'product p ON (p.id_product = cp.id_product AND p.active = 1) '; - $sqlQuery['where'] = ' + $sql_query['where'] = ' WHERE cp.id_category = c.id_category '; - $sqlQuery['group'] = ') count_products + $sql_query['group'] = ') count_products FROM '._DB_PREFIX_.'category c LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = c.id_category AND cl.id_lang = '.(int)$cookie->id_lang.') WHERE c.nleft > '.(int)$parent->nleft.' @@ -2630,49 +2664,49 @@ class BlockLayered extends Module GROUP BY c.id_category ORDER BY c.nleft, c.position'; } - foreach ($filters as $filterTmp) + foreach ($filters as $filter_tmp) { - $methodName = 'get'.ucfirst($filterTmp['type']).'FilterSubQuery'; - if (method_exists('BlockLayered', $methodName) && - (!in_array($filter['type'], array('price', 'weight')) && $filter['type'] != $filterTmp['type'] || $filter['type'] == $filterTmp['type'])) + $method_name = 'get'.ucfirst($filter_tmp['type']).'FilterSubQuery'; + if (method_exists('BlockLayered', $method_name) && + (!in_array($filter['type'], array('price', 'weight')) && $filter['type'] != $filter_tmp['type'] || $filter['type'] == $filter_tmp['type'])) { - if ($filter['type'] == $filterTmp['type'] && $filter['id_value'] == $filterTmp['id_value']) - $subQueryFilter = self::$methodName(array(), true); + if ($filter['type'] == $filter_tmp['type'] && $filter['id_value'] == $filter_tmp['id_value']) + $sub_query_filter = self::$method_name(array(), true); else { - if (!is_null($filterTmp['id_value'])) - $selected_filters_cleaned = $this->cleanFilterByIdValue(@$selectedFilters[$filterTmp['type']], $filterTmp['id_value']); + if (!is_null($filter_tmp['id_value'])) + $selected_filters_cleaned = $this->cleanFilterByIdValue(@$selected_filters[$filter_tmp['type']], $filter_tmp['id_value']); else - $selected_filters_cleaned = @$selectedFilters[$filterTmp['type']]; - $subQueryFilter = self::$methodName($selected_filters_cleaned, $filter['type'] == $filterTmp['type']); + $selected_filters_cleaned = @$selected_filters[$filter_tmp['type']]; + $sub_query_filter = self::$method_name($selected_filters_cleaned, $filter['type'] == $filter_tmp['type']); } - foreach ($subQueryFilter as $key => $value) - $sqlQuery[$key] .= $value; + foreach ($sub_query_filter as $key => $value) + $sql_query[$key] .= $value; } } $products = false; - if (!empty($sqlQuery['from'])) + if (!empty($sql_query['from'])) { if (version_compare(_PS_VERSION_,'1.5','>')) - $sqlQuery['from'] .= Shop::addSqlAssociation('product', 'p'); - $products = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sqlQuery['select']."\n".$sqlQuery['from']."\n".$sqlQuery['join']."\n".$sqlQuery['where']."\n".$sqlQuery['group']); + $sql_query['from'] .= Shop::addSqlAssociation('product', 'p'); + $products = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql_query['select']."\n".$sql_query['from']."\n".$sql_query['join']."\n".$sql_query['where']."\n".$sql_query['group']); } - foreach ($filters as $filterTmp) + foreach ($filters as $filter_tmp) { - $methodName = 'filterProductsBy'.ucfirst($filterTmp['type']); - if (method_exists('BlockLayered', $methodName) && - (!in_array($filter['type'], array('price', 'weight')) && $filter['type'] != $filterTmp['type'] || $filter['type'] == $filterTmp['type'])) - if ($filter['type'] == $filterTmp['type']) - $products = self::$methodName(array(), $products); + $method_name = 'filterProductsBy'.ucfirst($filter_tmp['type']); + if (method_exists('BlockLayered', $method_name) && + (!in_array($filter['type'], array('price', 'weight')) && $filter['type'] != $filter_tmp['type'] || $filter['type'] == $filter_tmp['type'])) + if ($filter['type'] == $filter_tmp['type']) + $products = self::$method_name(array(), $products); else - $products = self::$methodName(@$selectedFilters[$filterTmp['type']], $products); + $products = self::$method_name(@$selected_filters[$filter_tmp['type']], $products); } - if (!empty($sqlQuery['second_query'])) + if (!empty($sql_query['second_query'])) { - $res = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sqlQuery['second_query']); + $res = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql_query['second_query']); if ($res) $products = array_merge($products, $res); } @@ -2680,7 +2714,7 @@ class BlockLayered extends Module switch ($filter['type']) { case 'price': - $priceArray = array( + $price_array = array( 'type_lite' => 'price', 'type' => 'price', 'id_key' => 0, @@ -2696,52 +2730,52 @@ class BlockLayered extends Module if (isset($products) && $products) foreach ($products as $product) { - if (is_null($priceArray['min'])) + if (is_null($price_array['min'])) { - $priceArray['min'] = $product['price_min']; - $priceArray['values'][0] = $product['price_min']; + $price_array['min'] = $product['price_min']; + $price_array['values'][0] = $product['price_min']; } - else if ($priceArray['min'] > $product['price_min']) + else if ($price_array['min'] > $product['price_min']) { - $priceArray['min'] = $product['price_min']; - $priceArray['values'][0] = $product['price_min']; + $price_array['min'] = $product['price_min']; + $price_array['values'][0] = $product['price_min']; } - if ($priceArray['max'] < $product['price_max']) + if ($price_array['max'] < $product['price_max']) { - $priceArray['max'] = $product['price_max']; - $priceArray['values'][1] = $product['price_max']; + $price_array['max'] = $product['price_max']; + $price_array['values'][1] = $product['price_max']; } } - if ($priceArray['max'] != $priceArray['min'] && $priceArray['min'] != null) + if ($price_array['max'] != $price_array['min'] && $price_array['min'] != null) { if ($filter['filter_type'] == 2) { - $priceArray['list_of_values'] = array(); + $price_array['list_of_values'] = array(); $nbr_of_value = $filter['filter_show_limit']; if ($nbr_of_value < 2) $nbr_of_value = 4; - $delta = ($priceArray['max'] - $priceArray['min']) / $nbr_of_value; - $current_step = $priceArray['min']; + $delta = ($price_array['max'] - $price_array['min']) / $nbr_of_value; + $current_step = $price_array['min']; for ($i = 0; $i < $nbr_of_value; $i++) - $priceArray['list_of_values'][] = array( - (int)($priceArray['min'] + $i * $delta), - (int)($priceArray['min'] + ($i + 1) * $delta) + $price_array['list_of_values'][] = array( + (int)($price_array['min'] + $i * $delta), + (int)($price_array['min'] + ($i + 1) * $delta) ); } - if (isset($selectedFilters['price']) && isset($selectedFilters['price'][0]) - && isset($selectedFilters['price'][1])) + if (isset($selected_filters['price']) && isset($selected_filters['price'][0]) + && isset($selected_filters['price'][1])) { - $priceArray['values'][0] = $selectedFilters['price'][0]; - $priceArray['values'][1] = $selectedFilters['price'][1]; + $price_array['values'][0] = $selected_filters['price'][0]; + $price_array['values'][1] = $selected_filters['price'][1]; } - $filterBlocks[] = $priceArray; + $filter_blocks[] = $price_array; } break; case 'weight': - $weightArray = array( + $weight_array = array( 'type_lite' => 'weight', 'type' => 'weight', 'id_key' => 0, @@ -2757,37 +2791,37 @@ class BlockLayered extends Module if (isset($products) && $products) foreach ($products as $product) { - if (is_null($weightArray['min'])) + if (is_null($weight_array['min'])) { - $weightArray['min'] = $product['weight']; - $weightArray['values'][0] = $product['weight']; + $weight_array['min'] = $product['weight']; + $weight_array['values'][0] = $product['weight']; } - else if ($weightArray['min'] > $product['weight']) + else if ($weight_array['min'] > $product['weight']) { - $weightArray['min'] = $product['weight']; - $weightArray['values'][0] = $product['weight']; + $weight_array['min'] = $product['weight']; + $weight_array['values'][0] = $product['weight']; } - if ($weightArray['max'] < $product['weight']) + if ($weight_array['max'] < $product['weight']) { - $weightArray['max'] = $product['weight']; - $weightArray['values'][1] = $product['weight']; + $weight_array['max'] = $product['weight']; + $weight_array['values'][1] = $product['weight']; } } - if ($weightArray['max'] != $weightArray['min'] && $weightArray['min'] != null) + if ($weight_array['max'] != $weight_array['min'] && $weight_array['min'] != null) { - if (isset($selectedFilters['weight']) && isset($selectedFilters['weight'][0]) - && isset($selectedFilters['weight'][1])) + if (isset($selected_filters['weight']) && isset($selected_filters['weight'][0]) + && isset($selected_filters['weight'][1])) { - $weightArray['values'][0] = $selectedFilters['weight'][0]; - $weightArray['values'][1] = $selectedFilters['weight'][1]; + $weight_array['values'][0] = $selected_filters['weight'][0]; + $weight_array['values'][1] = $selected_filters['weight'][1]; } - $filterBlocks[] = $weightArray; + $filter_blocks[] = $weight_array; } break; case 'condition': - $conditionArray = array( + $condition_array = array( 'new' => array('name' => $this->l('New'),'nbr' => 0), 'used' => array('name' => $this->l('Used'), 'nbr' => 0), 'refurbished' => array('name' => $this->l('Refurbished'), @@ -2795,43 +2829,43 @@ class BlockLayered extends Module ); if (isset($products) && $products) foreach ($products as $product) - if (isset($selectedFilters['condition']) && in_array($product['condition'], $selectedFilters['condition'])) - $conditionArray[$product['condition']]['checked'] = true; - foreach ($conditionArray as $key => $condition) - if (isset($selectedFilters['condition']) && in_array($key, $selectedFilters['condition'])) - $conditionArray[$key]['checked'] = true; + if (isset($selected_filters['condition']) && in_array($product['condition'], $selected_filters['condition'])) + $condition_array[$product['condition']]['checked'] = true; + foreach ($condition_array as $key => $condition) + if (isset($selected_filters['condition']) && in_array($key, $selected_filters['condition'])) + $condition_array[$key]['checked'] = true; if (isset($products) && $products) foreach ($products as $product) - if (isset($conditionArray[$product['condition']])) - $conditionArray[$product['condition']]['nbr']++; - $filterBlocks[] = array( + if (isset($condition_array[$product['condition']])) + $condition_array[$product['condition']]['nbr']++; + $filter_blocks[] = array( 'type_lite' => 'condition', 'type' => 'condition', 'id_key' => 0, 'name' => $this->l('Condition'), - 'values' => $conditionArray, + 'values' => $condition_array, 'filter_show_limit' => $filter['filter_show_limit'], 'filter_type' => $filter['filter_type'] ); break; case 'quantity': - $quantityArray = array ( + $quantity_array = array ( 0 => array('name' => $this->l('Not available'), 'nbr' => 0), 1 => array('name' => $this->l('In stock'), 'nbr' => 0)); - foreach ($quantityArray as $key => $quantity) - if (isset($selectedFilters['quantity']) && in_array($key, $selectedFilters['quantity'])) - $quantityArray[$key]['checked'] = true; + foreach ($quantity_array as $key => $quantity) + if (isset($selected_filters['quantity']) && in_array($key, $selected_filters['quantity'])) + $quantity_array[$key]['checked'] = true; if (isset($products) && $products) foreach ($products as $product) - $quantityArray[(int)($product['quantity'] > 0)]['nbr']++; - $filterBlocks[] = array( + $quantity_array[(int)($product['quantity'] > 0)]['nbr']++; + $filter_blocks[] = array( 'type_lite' => 'quantity', 'type' => 'quantity', 'id_key' => 0, 'name' => $this->l('Availability'), - 'values' => $quantityArray, + 'values' => $quantity_array, 'filter_show_limit' => $filter['filter_show_limit'], 'filter_type' => $filter['filter_type'] ); @@ -2840,20 +2874,20 @@ class BlockLayered extends Module case 'manufacturer': if (isset($products) && $products) { - $manufaturersArray = array(); + $manufaturers_array = array(); foreach ($products as $manufacturer) { - if (!isset($manufaturersArray[$manufacturer['id_manufacturer']])) - $manufaturersArray[$manufacturer['id_manufacturer']] = array('name' => $manufacturer['name'], 'nbr' => $manufacturer['nbr']); - if (isset($selectedFilters['manufacturer']) && in_array((int)$manufacturer['id_manufacturer'], $selectedFilters['manufacturer'])) - $manufaturersArray[$manufacturer['id_manufacturer']]['checked'] = true; + if (!isset($manufaturers_array[$manufacturer['id_manufacturer']])) + $manufaturers_array[$manufacturer['id_manufacturer']] = array('name' => $manufacturer['name'], 'nbr' => $manufacturer['nbr']); + if (isset($selected_filters['manufacturer']) && in_array((int)$manufacturer['id_manufacturer'], $selected_filters['manufacturer'])) + $manufaturers_array[$manufacturer['id_manufacturer']]['checked'] = true; } - $filterBlocks[] = array( + $filter_blocks[] = array( 'type_lite' => 'manufacturer', 'type' => 'manufacturer', 'id_key' => 0, 'name' => $this->l('Manufacturer'), - 'values' => $manufaturersArray, + 'values' => $manufaturers_array, 'filter_show_limit' => $filter['filter_show_limit'], 'filter_type' => $filter['filter_type'] ); @@ -2861,13 +2895,13 @@ class BlockLayered extends Module break; case 'id_attribute_group': - $attributesArray = array(); + $attributes_array = array(); if (isset($products) && $products) { foreach ($products as $attributes) { - if (!isset($attributesArray[$attributes['id_attribute_group']])) - $attributesArray[$attributes['id_attribute_group']] = array ( + if (!isset($attributes_array[$attributes['id_attribute_group']])) + $attributes_array[$attributes['id_attribute_group']] = array ( 'type_lite' => 'id_attribute_group', 'type' => 'id_attribute_group', 'id_key' => (int)$attributes['id_attribute_group'], @@ -2880,8 +2914,8 @@ class BlockLayered extends Module 'filter_type' => $filter['filter_type'] ); - if (!isset($attributesArray[$attributes['id_attribute_group']]['values'][$attributes['id_attribute']])) - $attributesArray[$attributes['id_attribute_group']]['values'][$attributes['id_attribute']] = array( + if (!isset($attributes_array[$attributes['id_attribute_group']]['values'][$attributes['id_attribute']])) + $attributes_array[$attributes['id_attribute_group']]['values'][$attributes['id_attribute']] = array( 'color' => $attributes['color'], 'name' => $attributes['attribute_name'], 'nbr' => (int)$attributes['nbr'], @@ -2889,20 +2923,20 @@ class BlockLayered extends Module 'meta_title' => $attributes['value_meta_title'] ); - if (isset($selectedFilters['id_attribute_group'][$attributes['id_attribute']])) - $attributesArray[$attributes['id_attribute_group']]['values'][$attributes['id_attribute']]['checked'] = true; + if (isset($selected_filters['id_attribute_group'][$attributes['id_attribute']])) + $attributes_array[$attributes['id_attribute_group']]['values'][$attributes['id_attribute']]['checked'] = true; } - $filterBlocks = array_merge($filterBlocks, $attributesArray); + $filter_blocks = array_merge($filter_blocks, $attributes_array); } break; case 'id_feature': - $featureArray = array(); + $feature_array = array(); if (isset($products) && $products) { foreach ($products as $feature) { - if (!isset($featureArray[$feature['id_feature']])) - $featureArray[$feature['id_feature']] = array( + if (!isset($feature_array[$feature['id_feature']])) + $feature_array[$feature['id_feature']] = array( 'type_lite' => 'id_feature', 'type' => 'id_feature', 'id_key' => (int)$feature['id_feature'], @@ -2914,45 +2948,45 @@ class BlockLayered extends Module 'filter_type' => $filter['filter_type'] ); - if (!isset($featureArray[$feature['id_feature']]['values'][$feature['id_feature_value']])) - $featureArray[$feature['id_feature']]['values'][$feature['id_feature_value']] = array( + if (!isset($feature_array[$feature['id_feature']]['values'][$feature['id_feature_value']])) + $feature_array[$feature['id_feature']]['values'][$feature['id_feature_value']] = array( 'nbr' => (int)$feature['nbr'], 'name' => $feature['value'], 'url_name' => $feature['value_url_name'], 'meta_title' => $feature['value_meta_title'] ); - if (isset($selectedFilters['id_feature'][$feature['id_feature_value']])) - $featureArray[$feature['id_feature']]['values'][$feature['id_feature_value']]['checked'] = true; + if (isset($selected_filters['id_feature'][$feature['id_feature_value']])) + $feature_array[$feature['id_feature']]['values'][$feature['id_feature_value']]['checked'] = true; } - $filterBlocks = array_merge($filterBlocks, $featureArray); + $filter_blocks = array_merge($filter_blocks, $feature_array); } break; case 'category': - $tmpArray = array(); + $tmp_array = array(); if (isset($products) && $products) { - $categoriesWithProductsCount = 0; + $categories_with_products_count = 0; foreach ($products as $category) { - $tmpArray[$category['id_category']] = array( + $tmp_array[$category['id_category']] = array( 'name' => $category['name'], 'nbr' => (int)$category['count_products'] ); if ((int)$category['count_products']) - $categoriesWithProductsCount++; + $categories_with_products_count++; - if (isset($selectedFilters['category']) && in_array($category['id_category'], $selectedFilters['category'])) - $tmpArray[$category['id_category']]['checked'] = true; + if (isset($selected_filters['category']) && in_array($category['id_category'], $selected_filters['category'])) + $tmp_array[$category['id_category']]['checked'] = true; } - if ($categoriesWithProductsCount || !Configuration::get('PS_LAYERED_HIDE_0_VALUES')) - $filterBlocks[] = array ( + if ($categories_with_products_count || !Configuration::get('PS_LAYERED_HIDE_0_VALUES')) + $filter_blocks[] = array ( 'type_lite' => 'category', 'type' => 'category', 'id_key' => 0, 'name' => $this->l('Categories'), - 'values' => $tmpArray, + 'values' => $tmp_array, 'filter_show_limit' => $filter['filter_show_limit'], 'filter_type' => $filter['filter_type'] ); @@ -2963,7 +2997,7 @@ class BlockLayered extends Module } // All non indexable attribute and feature - $nonIndexable = array(); + $non_indexable = array(); // Get all non indexable attribute groups foreach (Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' @@ -2973,7 +3007,7 @@ class BlockLayered extends Module ON liag.id_attribute_group = agl.id_attribute_group WHERE indexable IS NULL OR indexable = 0 AND id_lang = '.(int)$cookie->id_lang) as $attribute) - $nonIndexable[] = Tools::link_rewrite($attribute['public_name']); + $non_indexable[] = Tools::link_rewrite($attribute['public_name']); // Get all non indexable features foreach (Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' @@ -2983,128 +3017,142 @@ class BlockLayered extends Module ON lif.id_feature = fl.id_feature WHERE indexable IS NULL OR indexable = 0 AND id_lang = '.(int)$cookie->id_lang) as $attribute) - $nonIndexable[] = Tools::link_rewrite($attribute['name']); + $non_indexable[] = Tools::link_rewrite($attribute['name']); //generate SEO link - $paramSelected = ''; + $param_selected = ''; $param_product_url = ''; - $optionCheckedArray = array(); - $paramGroupSelectedArray = array(); - $titleValues = array(); + $option_checked_array = array(); + $param_group_selected_array = array(); + $title_values = array(); + $meta_values = array(); $link = new Link(); - $linkBase = $link->getCategoryLink($id_parent, Category::getLinkRewrite($id_parent, (int)($cookie->id_lang)), (int)($cookie->id_lang)); - $filterBlockList = array(); + $link_base = $link->getCategoryLink($id_parent, Category::getLinkRewrite($id_parent, (int)($cookie->id_lang)), (int)($cookie->id_lang)); //get filters checked by group - foreach ($filterBlocks as $typeFilter) + foreach ($filter_blocks as $type_filter) { - $filterName = (!empty($typeFilter['url_name']) ? $typeFilter['url_name'] : $typeFilter['name']); + $filter_name = (!empty($type_filter['url_name']) ? $type_filter['url_name'] : $type_filter['name']); + $filter_meta = (!empty($type_filter['meta_title']) ? $type_filter['meta_title'] : ''); + $attr_key = $type_filter['type'].'_'.$type_filter['id_key']; - $paramGroupSelected = ''; - foreach ($typeFilter['values'] as $key => $value) + $param_group_selected = ''; + foreach ($type_filter['values'] as $key => $value) { if (is_array($value) && array_key_exists('checked', $value )) { - $valueName = !empty($value['url_name']) ? $value['url_name'] : $value['name']; - $paramGroupSelected .= '-'.str_replace('-', '_', Tools::link_rewrite($valueName)); - $paramGroupSelectedArray[Tools::link_rewrite($filterName)][] = Tools::link_rewrite($valueName); + $value_name = !empty($value['url_name']) ? $value['url_name'] : $value['name']; + $value_meta = !empty($value['meta_title']) ? $value['meta_title'] : $value['name']; + $param_group_selected .= '-'.str_replace('-', '_', Tools::link_rewrite($value_name)); + $param_group_selected_array[Tools::link_rewrite($filter_name)][] = Tools::link_rewrite($value_name); - if (!isset($titleValues[$filterName])) - $titleValues[$filterName] = array(); - $titleValues[$filterName][] = $valueName; + if (!isset($title_values[$filter_name])) + $title_values[$filter_name] = array(); + $title_values[$filter_name][] = $value_name; + if (!isset($meta_values[$attr_key])) + $meta_values[$attr_key] = array('title' => $filter_meta, 'values' => array()); + $meta_values[$attr_key]['values'][] = $value_meta; } else - $paramGroupSelectedArray[Tools::link_rewrite($filterName)][] = array(); + $param_group_selected_array[Tools::link_rewrite($filter_name)][] = array(); } - if (!empty($paramGroupSelected)) + if (!empty($param_group_selected)) { - $paramSelected .= '/'.str_replace('-', '_', Tools::link_rewrite($filterName)).$paramGroupSelected; - $optionCheckedArray[Tools::link_rewrite($filterName)] = $paramGroupSelected; + $param_selected .= '/'.str_replace('-', '_', Tools::link_rewrite($filter_name)).$param_group_selected; + $option_checked_array[Tools::link_rewrite($filter_name)] = $param_group_selected; } // select only attribute and group attribute to display an unique product combination link - if (!empty($paramGroupSelected) && $typeFilter['type'] == 'id_attribute_group') - $param_product_url .= '/'.str_replace('-', '_', Tools::link_rewrite($filterName)).$paramGroupSelected; + if (!empty($param_group_selected) && $type_filter['type'] == 'id_attribute_group') + $param_product_url .= '/'.str_replace('-', '_', Tools::link_rewrite($filter_name)).$param_group_selected; } if ($this->page > 1) - $paramSelected .= '/page-'.$this->page; + $param_selected .= '/page-'.$this->page; - $blackList = array('weight','price'); - $nofollow = false; - foreach ($filterBlocks as &$typeFilter) - { - $filterName = (!empty($typeFilter['url_name']) ? $typeFilter['url_name'] : $typeFilter['name']); + $blacklist = array('weight', 'price'); + + if (!Configuration::get('PS_LAYERED_FILTER_INDEX_CDT')) + $blacklist[] = 'condition'; - if (count($typeFilter) > 0 && !in_array($typeFilter['type'], $blackList)) + if (!Configuration::get('PS_LAYERED_FILTER_INDEX_QTY')) + $blacklist[] = 'quantity'; + + $nofollow = in_array($type_filter['type'], $blacklist); // true is in the blacklist + foreach ($filter_blocks as &$type_filter) + { + $filter_name = (!empty($type_filter['url_name']) ? $type_filter['url_name'] : $type_filter['name']); + + if (count($type_filter) > 0 && !isset($type_filter['slider'])) { - foreach ($typeFilter['values'] as $key => $values) + foreach ($type_filter['values'] as $key => $values) { - $nofollow = false; - $optionCheckedCloneArray = $optionCheckedArray; + $nofollow = in_array($type_filter['type'], $blacklist); + $option_checked_clone_array = $option_checked_array; // If not filters checked, add parameter - $valueName = !empty($values['url_name']) ? $values['url_name'] : $values['name']; - if (!in_array(Tools::link_rewrite($valueName), $paramGroupSelectedArray[Tools::link_rewrite($filterName)])) + $value_name = !empty($values['url_name']) ? $values['url_name'] : $values['name']; + if (!in_array(Tools::link_rewrite($value_name), $param_group_selected_array[Tools::link_rewrite($filter_name)])) { // Update parameter filter checked before - if (array_key_exists(Tools::link_rewrite($filterName), $optionCheckedArray)) + if (array_key_exists(Tools::link_rewrite($filter_name), $option_checked_array)) { - $optionCheckedCloneArray[Tools::link_rewrite($filterName)] = $optionCheckedCloneArray[Tools::link_rewrite($filterName)].'-'.str_replace('-', '_', Tools::link_rewrite($valueName)); + $option_checked_clone_array[Tools::link_rewrite($filter_name)] = $option_checked_clone_array[Tools::link_rewrite($filter_name)].'-'.str_replace('-', '_', Tools::link_rewrite($value_name)); $nofollow = true; } else - $optionCheckedCloneArray[Tools::link_rewrite($filterName)] = '-'.str_replace('-', '_', Tools::link_rewrite($valueName)); + $option_checked_clone_array[Tools::link_rewrite($filter_name)] = '-'.str_replace('-', '_', Tools::link_rewrite($value_name)); } else { // Remove selected parameters - $optionCheckedCloneArray[Tools::link_rewrite($filterName)] = str_replace('-'.str_replace('-', '_', Tools::link_rewrite($valueName)), '', $optionCheckedCloneArray[Tools::link_rewrite($filterName)]); - if (empty($optionCheckedCloneArray[Tools::link_rewrite($filterName)])) - unset($optionCheckedCloneArray[Tools::link_rewrite($filterName)]); + $option_checked_clone_array[Tools::link_rewrite($filter_name)] = str_replace('-'.str_replace('-', '_', Tools::link_rewrite($value_name)), '', $option_checked_clone_array[Tools::link_rewrite($filter_name)]); + if (empty($option_checked_clone_array[Tools::link_rewrite($filter_name)])) + unset($option_checked_clone_array[Tools::link_rewrite($filter_name)]); } $parameters = ''; - foreach ($optionCheckedCloneArray as $keyGroup => $valueGroup) - $parameters .= '/'.str_replace('-', '_', $keyGroup).$valueGroup; + foreach ($option_checked_clone_array as $key_group => $value_group) + $parameters .= '/'.str_replace('-', '_', $key_group).$value_group; // Check if there is an non indexable attribute or feature in the url - foreach ($nonIndexable as $value) + foreach ($non_indexable as $value) if (strpos($parameters, '/'.$value) !== false) $nofollow = true; // Write link by mode rewriting if (!Configuration::get('PS_REWRITING_SETTINGS')) - $typeFilter['values'][$key]['link'] = $linkBase.'&selected_filters='.$parameters; + $type_filter['values'][$key]['link'] = $link_base.'&selected_filters='.$parameters; else - $typeFilter['values'][$key]['link'] = $linkBase.$parameters; + $type_filter['values'][$key]['link'] = $link_base.$parameters; - $typeFilter['values'][$key]['rel'] = ($nofollow) ? 'nofollow' : ''; + $type_filter['values'][$key]['rel'] = ($nofollow) ? 'nofollow' : ''; } } } - $nFilters = 0; - if (isset($selectedFilters['price'])) - if ($priceArray['min'] == $selectedFilters['price'][0] && $priceArray['max'] == $selectedFilters['price'][1]) - unset($selectedFilters['price']); - if (isset($selectedFilters['weight'])) - if ($weightArray['min'] == $selectedFilters['weight'][0] && $weightArray['max'] == $selectedFilters['weight'][1]) - unset($selectedFilters['weight']); + $n_filters = 0; + if (isset($selected_filters['price'])) + if ($price_array['min'] == $selected_filters['price'][0] && $price_array['max'] == $selected_filters['price'][1]) + unset($selected_filters['price']); + if (isset($selected_filters['weight'])) + if ($weight_array['min'] == $selected_filters['weight'][0] && $weight_array['max'] == $selected_filters['weight'][1]) + unset($selected_filters['weight']); - foreach ($selectedFilters as $filters) - $nFilters += count($filters); + foreach ($selected_filters as $filters) + $n_filters += count($filters); $cache = array( 'layered_show_qties' => (int)Configuration::get('PS_LAYERED_SHOW_QTIES'), 'id_category_layered' => (int)$id_parent, - 'selected_filters' => $selectedFilters, - 'n_filters' => (int)$nFilters, - 'nbr_filterBlocks' => count($filterBlocks), - 'filters' => $filterBlocks, - 'title_values' => $titleValues, - 'current_friendly_url' => htmlentities($paramSelected), + 'selected_filters' => $selected_filters, + 'n_filters' => (int)$n_filters, + 'nbr_filterBlocks' => count($filter_blocks), + 'filters' => $filter_blocks, + 'title_values' => $title_values, + 'meta_values' => $meta_values, + 'current_friendly_url' => htmlentities($param_selected), 'param_product_url' => htmlentities($param_product_url), - 'no_follow' => (!empty($paramSelected) || $nofollow) + 'no_follow' => (!empty($param_selected) || $nofollow) ); return $cache; @@ -3123,15 +3171,15 @@ class BlockLayered extends Module return $selected_filters; } - public function generateFiltersBlock($selectedFilters) + public function generateFiltersBlock($selected_filters) { global $smarty; - if ($filterBlock = $this->getFilterBlock($selectedFilters)) + if ($filter_block = $this->getFilterBlock($selected_filters)) { - if ($filterBlock['nbr_filterBlocks'] == 0) + if ($filter_block['nbr_filterBlocks'] == 0) return false; - $smarty->assign($filterBlock); + $smarty->assign($filter_block); $smarty->assign('hide_0_values', Configuration::get('PS_LAYERED_HIDE_0_VALUES')); return $this->display(__FILE__, 'blocklayered.tpl'); @@ -3140,191 +3188,191 @@ class BlockLayered extends Module return false; } - private static function getPriceFilterSubQuery($filterValue) + private static function getPriceFilterSubQuery($filter_value) { if (version_compare(_PS_VERSION_,'1.5','>')) - $idCurrency = (int)Context::getContext()->currency->id; + $id_currency = (int)Context::getContext()->currency->id; else - $idCurrency = (int)Currency::getCurrent()->id; - $priceFilterQuery = ''; - if (isset($filterValue) && $filterValue) + $id_currency = (int)Currency::getCurrent()->id; + $price_filter_query = ''; + if (isset($filter_value) && $filter_value) { - $priceFilterQuery = ' - INNER JOIN `'._DB_PREFIX_.'layered_price_index` psi ON (psi.id_product = p.id_product AND psi.id_currency = '.(int)$idCurrency.' - AND psi.price_min <= '.(int)$filterValue[1].' AND psi.price_max >= '.(int)$filterValue[0].') '; + $price_filter_query = ' + INNER JOIN `'._DB_PREFIX_.'layered_price_index` psi ON (psi.id_product = p.id_product AND psi.id_currency = '.(int)$id_currency.' + AND psi.price_min <= '.(int)$filter_value[1].' AND psi.price_max >= '.(int)$filter_value[0].') '; } else { - $priceFilterQuery = ' + $price_filter_query = ' INNER JOIN `'._DB_PREFIX_.'layered_price_index` psi - ON (psi.id_product = p.id_product AND psi.id_currency = '.(int)$idCurrency.') '; + ON (psi.id_product = p.id_product AND psi.id_currency = '.(int)$id_currency.') '; } - return array('join' => $priceFilterQuery, 'select' => ', psi.price_min, psi.price_max'); + return array('join' => $price_filter_query, 'select' => ', psi.price_min, psi.price_max'); } - private static function filterProductsByPrice($filterValue, $productCollection) + private static function filterProductsByPrice($filter_value, $product_collection) { - if (empty($filterValue)) - return $productCollection; - foreach ($productCollection as $key => $product) + if (empty($filter_value)) + return $product_collection; + foreach ($product_collection as $key => $product) { - if (isset($filterValue) && $filterValue && isset($product['price_min']) && isset($product['id_product']) - && ((int)$filterValue[0] > $product['price_min'] || (int)$filterValue[1] < $product['price_max'])) + if (isset($filter_value) && $filter_value && isset($product['price_min']) && isset($product['id_product']) + && ((int)$filter_value[0] > $product['price_min'] || (int)$filter_value[1] < $product['price_max'])) { $price = Product::getPriceStatic($product['id_product'], Configuration::get('PS_LAYERED_FILTER_PRICE_USETAX')); - if ($price < $filterValue[0] || $price > $filterValue[1]) + if ($price < $filter_value[0] || $price > $filter_value[1]) continue; - unset($productCollection[$key]); + unset($product_collection[$key]); } } - return $productCollection; + return $product_collection; } - private static function getWeightFilterSubQuery($filterValue, $ignoreJoin) + private static function getWeightFilterSubQuery($filter_value, $ignore_join) { - if (isset($filterValue) && $filterValue) - if ($filterValue[0] != 0 || $filterValue[1] != 0) - return array('where' => ' AND p.`weight` BETWEEN '.(float)($filterValue[0] - 0.001).' AND '.(float)($filterValue[1] + 0.001).' '); + if (isset($filter_value) && $filter_value) + if ($filter_value[0] != 0 || $filter_value[1] != 0) + return array('where' => ' AND p.`weight` BETWEEN '.(float)($filter_value[0] - 0.001).' AND '.(float)($filter_value[1] + 0.001).' '); return array(); } - private static function getId_featureFilterSubQuery($filterValue, $ignoreJoin) + private static function getId_featureFilterSubQuery($filter_value, $ignore_join) { - if (empty($filterValue)) + if (empty($filter_value)) return array(); - $queryFilters = ' AND p.id_product IN (SELECT id_product FROM '._DB_PREFIX_.'feature_product fp WHERE '; - foreach ($filterValue as $filterVal) - $queryFilters .= 'fp.`id_feature_value` = '.(int)$filterVal.' OR '; - $queryFilters = rtrim($queryFilters, 'OR ').') '; + $query_filters = ' AND p.id_product IN (SELECT id_product FROM '._DB_PREFIX_.'feature_product fp WHERE '; + foreach ($filter_value as $filter_val) + $query_filters .= 'fp.`id_feature_value` = '.(int)$filter_val.' OR '; + $query_filters = rtrim($query_filters, 'OR ').') '; - return array('where' => $queryFilters); + return array('where' => $query_filters); } - private static function getId_attribute_groupFilterSubQuery($filterValue, $ignoreJoin) + private static function getId_attribute_groupFilterSubQuery($filter_value, $ignore_join) { - if (empty($filterValue)) + if (empty($filter_value)) return array(); - $queryFilters = ' + $query_filters = ' AND p.id_product IN (SELECT pa.`id_product` FROM `'._DB_PREFIX_.'product_attribute_combination` pac LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (pa.`id_product_attribute` = pac.`id_product_attribute`) WHERE '; - foreach ($filterValue as $filterVal) - $queryFilters .= 'pac.`id_attribute` = '.(int)$filterVal.' OR '; - $queryFilters = rtrim($queryFilters, 'OR ').') '; + foreach ($filter_value as $filter_val) + $query_filters .= 'pac.`id_attribute` = '.(int)$filter_val.' OR '; + $query_filters = rtrim($query_filters, 'OR ').') '; - return array('where' => $queryFilters); + return array('where' => $query_filters); } - private static function getCategoryFilterSubQuery($filterValue, $ignoreJoin) + private static function getCategoryFilterSubQuery($filter_value, $ignore_join) { - if (empty($filterValue)) + if (empty($filter_value)) return array(); - $queryFiltersJoin = ''; - $queryFiltersWhere = ' AND p.id_product IN (SELECT id_product FROM '._DB_PREFIX_.'category_product cp WHERE '; - foreach ($filterValue as $id_category) - $queryFiltersWhere .= 'cp.`id_category` = '.(int)$id_category.' OR '; - $queryFiltersWhere = rtrim($queryFiltersWhere, 'OR ').') '; + $query_filters_join = ''; + $query_filters_where = ' AND p.id_product IN (SELECT id_product FROM '._DB_PREFIX_.'category_product cp WHERE '; + foreach ($filter_value as $id_category) + $query_filters_where .= 'cp.`id_category` = '.(int)$id_category.' OR '; + $query_filters_where = rtrim($query_filters_where, 'OR ').') '; - return array('where' => $queryFiltersWhere, 'join' => $queryFiltersJoin); + return array('where' => $query_filters_where, 'join' => $query_filters_join); } - private static function getQuantityFilterSubQuery($filterValue, $ignoreJoin) + private static function getQuantityFilterSubQuery($filter_value, $ignore_join) { - if (count($filterValue) == 2 || empty($filterValue)) + if (count($filter_value) == 2 || empty($filter_value)) return array(); - $queryFiltersJoin = ''; + $query_filters_join = ''; if (version_compare(_PS_VERSION_,'1.5','>')) { - $queryFilters = ' AND sav.quantity '.(!$filterValue[0] ? '<=' : '>').' 0 '; - $queryFiltersJoin = 'LEFT JOIN `'._DB_PREFIX_.'stock_available` sav ON (sav.id_product = p.id_product AND sav.id_shop = '.(int)Context::getContext()->shop->id.') '; + $query_filters = ' AND sav.quantity '.(!$filter_value[0] ? '<=' : '>').' 0 '; + $query_filters_join = 'LEFT JOIN `'._DB_PREFIX_.'stock_available` sav ON (sav.id_product = p.id_product AND sav.id_shop = '.(int)Context::getContext()->shop->id.') '; } else - $queryFilters = ' AND p.quantity '.(!$filterValue[0] ? '<=' : '>').' 0 '; + $query_filters = ' AND p.quantity '.(!$filter_value[0] ? '<=' : '>').' 0 '; - return array('where' => $queryFilters, 'join' => $queryFiltersJoin); + return array('where' => $query_filters, 'join' => $query_filters_join); } - private static function getManufacturerFilterSubQuery($filterValue, $ignoreJoin) + private static function getManufacturerFilterSubQuery($filter_value, $ignore_join) { - if (empty($filterValue)) - $queryFilters = ''; + if (empty($filter_value)) + $query_filters = ''; else { - array_walk($filterValue, create_function('&$id_manufacturer', '$id_manufacturer = (int)$id_manufacturer;')); - $queryFilters = ' AND p.id_manufacturer IN ('.implode($filterValue, ',').')'; + array_walk($filter_value, create_function('&$id_manufacturer', '$id_manufacturer = (int)$id_manufacturer;')); + $query_filters = ' AND p.id_manufacturer IN ('.implode($filter_value, ',').')'; } - if ($ignoreJoin) - return array('where' => $queryFilters, 'select' => ', m.name'); + if ($ignore_join) + return array('where' => $query_filters, 'select' => ', m.name'); else - return array('where' => $queryFilters, 'select' => ', m.name', 'join' => 'LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.id_manufacturer = p.id_manufacturer) '); + return array('where' => $query_filters, 'select' => ', m.name', 'join' => 'LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.id_manufacturer = p.id_manufacturer) '); } - private static function getConditionFilterSubQuery($filterValue, $ignoreJoin) + private static function getConditionFilterSubQuery($filter_value, $ignore_join) { - if (count($filterValue) == 3 || empty($filterValue)) + if (count($filter_value) == 3 || empty($filter_value)) return array(); - $queryFilters = ' AND p.condition IN ('; - foreach ($filterValue as $cond) - $queryFilters .= '\''.$cond.'\','; - $queryFilters = rtrim($queryFilters, ',').') '; + $query_filters = ' AND p.condition IN ('; + foreach ($filter_value as $cond) + $query_filters .= '\''.$cond.'\','; + $query_filters = rtrim($query_filters, ',').') '; - return array('where' => $queryFilters); + return array('where' => $query_filters); } - public function ajaxCallBackOffice($categoryBox = array(), $id_layered_filter = null) + public function ajaxCallBackOffice($category_box = array(), $id_layered_filter = null) { global $cookie; if (!empty($id_layered_filter)) { - $layeredFilter = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('SELECT * FROM '._DB_PREFIX_.'layered_filter WHERE id_layered_filter = '.(int)$id_layered_filter); - if ($layeredFilter && isset($layeredFilter['filters']) && !empty($layeredFilter['filters'])) - $layeredValues = unserialize($layeredFilter['filters']); - if (isset($layeredValues['categories']) && count($layeredValues['categories'])) - foreach ($layeredValues['categories'] as $id_category) - $categoryBox[] = (int)$id_category; + $layered_filter = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('SELECT * FROM '._DB_PREFIX_.'layered_filter WHERE id_layered_filter = '.(int)$id_layered_filter); + if ($layered_filter && isset($layered_filter['filters']) && !empty($layered_filter['filters'])) + $layered_values = unserialize($layered_filter['filters']); + if (isset($layered_values['categories']) && count($layered_values['categories'])) + foreach ($layered_values['categories'] as $id_category) + $category_box[] = (int)$id_category; } /* Clean categoryBox before use */ - if (isset($categoryBox) && is_array($categoryBox)) - foreach ($categoryBox as &$value) + if (isset($category_box) && is_array($category_box)) + foreach ($category_box as &$value) $value = (int)$value; - $attributeGroups = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' + $attribute_groups = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT ag.id_attribute_group, ag.is_color_group, agl.name, COUNT(DISTINCT(a.id_attribute)) n FROM '._DB_PREFIX_.'attribute_group ag LEFT JOIN '._DB_PREFIX_.'attribute_group_lang agl ON (agl.id_attribute_group = ag.id_attribute_group) LEFT JOIN '._DB_PREFIX_.'attribute a ON (a.id_attribute_group = ag.id_attribute_group) - '.(count($categoryBox) ? ' + '.(count($category_box) ? ' LEFT JOIN '._DB_PREFIX_.'product_attribute_combination pac ON (pac.id_attribute = a.id_attribute) LEFT JOIN '._DB_PREFIX_.'product_attribute pa ON (pa.id_product_attribute = pac.id_product_attribute) LEFT JOIN '._DB_PREFIX_.'category_product cp ON (cp.id_product = pa.id_product)' : '').' WHERE agl.id_lang = '.(int)$cookie->id_lang. - (count($categoryBox) ? ' AND cp.id_category IN ('.implode(',', $categoryBox).')' : '').' + (count($category_box) ? ' AND cp.id_category IN ('.implode(',', $category_box).')' : '').' GROUP BY ag.id_attribute_group'); $features = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT fl.id_feature, fl.name, COUNT(DISTINCT(fv.id_feature_value)) n FROM '._DB_PREFIX_.'feature_lang fl LEFT JOIN '._DB_PREFIX_.'feature_value fv ON (fv.id_feature = fl.id_feature) - '.(count($categoryBox) ? ' + '.(count($category_box) ? ' LEFT JOIN '._DB_PREFIX_.'feature_product fp ON (fp.id_feature = fv.id_feature) LEFT JOIN '._DB_PREFIX_.'category_product cp ON (cp.id_product = fp.id_product)' : '').' WHERE (fv.custom IS NULL OR fv.custom = 0) AND fl.id_lang = '.(int)$cookie->id_lang. - (count($categoryBox) ? ' AND cp.id_category IN ('.implode(',', $categoryBox).')' : '').' + (count($category_box) ? ' AND cp.id_category IN ('.implode(',', $category_box).')' : '').' GROUP BY fl.id_feature'); - $nElements = count($attributeGroups) + count($features) + 4; - if ($nElements > 20) - $nElements = 20; + $n_elements = count($attribute_groups) + count($features) + 4; + if ($n_elements > 20) + $n_elements = 20; $html = ' -
    +

    '.$this->l('Available filters').' (0)

        @@ -3447,26 +3495,26 @@ class BlockLayered extends Module
      '; - if (count($attributeGroups)) + if (count($attribute_groups)) { $html .= '
        '; - foreach ($attributeGroups as $attributeGroup) + foreach ($attribute_groups as $attribute_group) $html .= '
      • - + - '.$this->l('Attribute group:').' '.$attributeGroup['name'].' ('.(int)$attributeGroup['n'].' '.($attributeGroup['n'] > 1 ? $this->l('attributes') : $this->l('attribute')).')'. - ($attributeGroup['is_color_group'] ? ' ' : '').' + '.$this->l('Attribute group:').' '.$attribute_group['name'].' ('.(int)$attribute_group['n'].' '.($attribute_group['n'] > 1 ? $this->l('attributes') : $this->l('attribute')).')'. + ($attribute_group['is_color_group'] ? ' ' : '').' - - @@ -3505,7 +3553,7 @@ class BlockLayered extends Module $html .= '
      '; - if (isset($layeredValues)) + if (isset($layered_values)) { $html .= '