diff --git a/modules/blocklayered/blocklayered.php b/modules/blocklayered/blocklayered.php index 95f603b60..e8f9796c1 100644 --- a/modules/blocklayered/blocklayered.php +++ b/modules/blocklayered/blocklayered.php @@ -1,6 +1,6 @@ * @copyright 2007-2011 PrestaShop SA -* @version Release: $Revision$ +* @version Release: $Revision: 10659 $ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registred Trademark & Property of PrestaShop SA */ @@ -32,12 +32,14 @@ class BlockLayered extends Module { private $products; private $nbr_products; + + private $page = 1; public function __construct() { $this->name = 'blocklayered'; $this->tab = 'front_office_features'; - $this->version = 1.5; + $this->version = '1.7'; $this->author = 'PrestaShop'; $this->need_instance = 0; @@ -45,8 +47,11 @@ class BlockLayered extends Module $this->displayName = $this->l('Layered navigation block'); $this->description = $this->l('Displays a block with layered navigation filters.'); + + if ((int)Tools::getValue('p')) + $this->page = (int)Tools::getValue('p'); } - + public function install() { if (parent::install() && $this->registerHook('leftColumn') && $this->registerHook('header') && $this->registerHook('footer') @@ -60,20 +65,21 @@ class BlockLayered extends Module { Configuration::updateValue('PS_LAYERED_HIDE_0_VALUES', 0); Configuration::updateValue('PS_LAYERED_SHOW_QTIES', 1); - + Configuration::updateValue('PS_LAYERED_FULL_TREE', 1); + $this->rebuildLayeredStructure(); $this->rebuildLayeredCache(); self::installPriceIndexTable(); $this->installFriendlyUrlTable(); $this->installIndexableAttributeTable(); $this->installProductAttributeTable(); - + $this->indexUrl(); $this->indexAttribute(); - + if (Db::getInstance()->getValue('SELECT COUNT(*) FROM `'._DB_PREFIX_.'product`') < 10000) // Lock price indexation if too many products self::fullPricesIndexProcess(); - + return true; } else @@ -89,8 +95,9 @@ class BlockLayered extends Module /* Delete all configurations */ Configuration::deleteByName('PS_LAYERED_HIDE_0_VALUES'); Configuration::deleteByName('PS_LAYERED_SHOW_QTIES'); + Configuration::deleteByName('PS_LAYERED_FULL_TREE'); Configuration::deleteByName('PS_LAYERED_INDEXED'); - + Db::getInstance()->Execute('DROP TABLE IF EXISTS '._DB_PREFIX_.'layered_price_index'); Db::getInstance()->Execute('DROP TABLE IF EXISTS '._DB_PREFIX_.'layered_friendly_url'); Db::getInstance()->Execute('DROP TABLE IF EXISTS '._DB_PREFIX_.'layered_indexable_attribute_group'); @@ -102,11 +109,11 @@ class BlockLayered extends Module Db::getInstance()->Execute('DROP TABLE IF EXISTS '._DB_PREFIX_.'layered_product_attribute'); return parent::uninstall(); } - + private static function installPriceIndexTable() { Db::getInstance()->Execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'layered_price_index`'); - + Db::getInstance()->Execute(' CREATE TABLE `'._DB_PREFIX_.'layered_price_index` ( `id_product` INT NOT NULL, `id_currency` INT NOT NULL, @@ -114,7 +121,7 @@ class BlockLayered extends Module PRIMARY KEY (`id_product`, `id_currency`), INDEX `id_currency` (`id_currency`), INDEX `price_min` (`price_min`), INDEX `price_max` (`price_max`)) ENGINE = '._MYSQL_ENGINE_); } - + private function installFriendlyUrlTable() { Db::getInstance()->Execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'layered_friendly_url`'); @@ -129,7 +136,7 @@ class BlockLayered extends Module Db::getInstance()->Execute('CREATE INDEX `url_key` ON `'._DB_PREFIX_.'layered_friendly_url`(url_key(5))'); } - + private function installIndexableAttributeTable() { // Attributes Groups @@ -142,7 +149,7 @@ class BlockLayered extends Module Db::getInstance()->Execute(' INSERT INTO `'._DB_PREFIX_.'layered_indexable_attribute_group` SELECT id_attribute_group, 1 FROM `'._DB_PREFIX_.'attribute_group`'); - + Db::getInstance()->Execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'layered_indexable_attribute_group_lang_value`'); Db::getInstance()->Execute(' CREATE TABLE `'._DB_PREFIX_.'layered_indexable_attribute_group_lang_value` ( @@ -151,7 +158,7 @@ class BlockLayered extends Module `url_name` VARCHAR(20), `meta_title` VARCHAR(20), PRIMARY KEY (`id_attribute_group`, `id_lang`)) ENGINE = '._MYSQL_ENGINE_); - + // Attributes Db::getInstance()->Execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'layered_indexable_attribute_lang_value`'); Db::getInstance()->Execute(' @@ -161,8 +168,8 @@ class BlockLayered extends Module `url_name` VARCHAR(20), `meta_title` VARCHAR(20), PRIMARY KEY (`id_attribute`, `id_lang`)) ENGINE = '._MYSQL_ENGINE_); - - + + // Features Db::getInstance()->Execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'layered_indexable_feature`'); Db::getInstance()->Execute(' @@ -170,11 +177,11 @@ class BlockLayered extends Module `id_feature` INT NOT NULL, `indexable` BOOL NOT NULL DEFAULT 0, PRIMARY KEY (`id_feature`)) ENGINE = '._MYSQL_ENGINE_); - + Db::getInstance()->Execute(' INSERT INTO `'._DB_PREFIX_.'layered_indexable_feature` SELECT id_feature, 1 FROM `'._DB_PREFIX_.'feature`'); - + Db::getInstance()->Execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'layered_indexable_feature_lang_value`'); Db::getInstance()->Execute(' CREATE TABLE `'._DB_PREFIX_.'layered_indexable_feature_lang_value` ( @@ -183,7 +190,7 @@ class BlockLayered extends Module `url_name` VARCHAR(20) NOT NULL, `meta_title` VARCHAR(20), PRIMARY KEY (`id_feature`, `id_lang`)) ENGINE = '._MYSQL_ENGINE_); - + // Features values Db::getInstance()->Execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'layered_indexable_feature_value_lang_value`'); Db::getInstance()->Execute(' @@ -194,9 +201,9 @@ class BlockLayered extends Module `meta_title` VARCHAR(20), PRIMARY KEY (`id_feature_value`, `id_lang`)) ENGINE = '._MYSQL_ENGINE_); } - + /** - * + * * create table product attribute */ public function installProductAttributeTable() @@ -210,9 +217,9 @@ class BlockLayered extends Module KEY `id_attribute` (`id_attribute`) ) ENGINE= '._MYSQL_ENGINE_); } - + /** - * + * * Generate data product attribute */ public function indexAttribute($id_product = null) @@ -221,16 +228,16 @@ class BlockLayered extends Module Db::getInstance()->execute('TRUNCATE '._DB_PREFIX_.'layered_product_attribute'); else Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'layered_product_attribute WHERE id_product = '.(int)$id_product); - - Db::getInstance()->Execute('INSERT INTO `'._DB_PREFIX_.'layered_product_attribute` (`id_attribute`, `id_product`, `id_attribute_group`) - SELECT pac.id_attribute, pa.id_product, ag.id_attribute_group - FROM '._DB_PREFIX_.'product_attribute pa - INNER JOIN '._DB_PREFIX_.'product_attribute_combination pac ON pac.id_product_attribute = pa.id_product_attribute - INNER JOIN '._DB_PREFIX_.'attribute a ON (a.id_attribute = pac.id_attribute) + + Db::getInstance()->Execute('INSERT INTO `'._DB_PREFIX_.'layered_product_attribute` (`id_attribute`, `id_product`, `id_attribute_group`) + SELECT pac.id_attribute, pa.id_product, ag.id_attribute_group + FROM '._DB_PREFIX_.'product_attribute pa + INNER JOIN '._DB_PREFIX_.'product_attribute_combination pac ON pac.id_product_attribute = pa.id_product_attribute + INNER JOIN '._DB_PREFIX_.'attribute a ON (a.id_attribute = pac.id_attribute) INNER JOIN '._DB_PREFIX_.'attribute_group ag ON ag.id_attribute_group = a.id_attribute_group '.(is_null($id_product) ? '' : 'AND pa.id_product = '.(int)$id_product).' GROUP BY a.id_attribute, pa.id_product'); - + return 1; } /* @@ -240,7 +247,7 @@ class BlockLayered extends Module { if ($truncate) Db::getInstance()->execute('TRUNCATE '._DB_PREFIX_.'layered_friendly_url'); - + $attributeValuesByLang = 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 @@ -282,7 +289,7 @@ class BlockLayered extends Module 'type' => $filter['type']); } break; - + case 'id_feature': $features = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT fl.name name, fl.id_feature id_name, fvl.id_feature_value id_value, fvl.value value, fl.id_lang, fl.id_lang, @@ -312,7 +319,7 @@ class BlockLayered extends Module 'type' => $filter['type']); } break; - + case 'category': $categories = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT cl.name, cl.id_lang, c.id_category @@ -330,13 +337,13 @@ class BlockLayered extends Module 'category_name' => $filter['link_rewrite'], 'type' => $filter['type']); } break; - + case 'manufacturer': $manufacturers = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT m.name as name,l.id_lang as id_lang, id_manufacturer FROM '._DB_PREFIX_.'manufacturer m , '._DB_PREFIX_.'lang l WHERE l.id_lang = '.(int)$filter['id_lang'].' '); - + foreach ($manufacturers as $manufacturer) { if (!isset($attributeValuesByLang[$manufacturer['id_lang']])) @@ -348,7 +355,7 @@ class BlockLayered extends Module 'category_name' => $filter['link_rewrite'], 'type' => $filter['type']); } break; - + case 'quantity': $avaibility_list = array( $this->translateWord('Not available', (int)$filter['id_lang']), @@ -359,7 +366,7 @@ class BlockLayered extends Module 'id_name' => null, 'value' => $quantity, 'id_value' => $key, 'id_id_value' => 0, 'category_name' => $filter['link_rewrite'], 'type' => $filter['type']); break; - + case 'condition': $condition_list = array( 'new' => $this->translateWord('New', (int)$filter['id_lang']), @@ -372,7 +379,7 @@ class BlockLayered extends Module 'category_name' => $filter['link_rewrite'], 'type' => $filter['type']); break; } - + // Foreach langs foreach ($attributeValuesByLang as $id_lang => $attributeValues) { @@ -401,8 +408,8 @@ class BlockLayered extends Module else return 1; } - - public function translateWord($string, $id_lang ) + + public function translateWord($string, $id_lang ) { static $_MODULES = array(); global $_MODULE; @@ -423,7 +430,7 @@ class BlockLayered extends Module $_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); - + if (isset($_MODULES[$id_lang][$currentKey])) $ret = stripslashes($_MODULES[$id_lang][$currentKey]); else if (isset($_MODULES[$id_lang][Tools::strtolower($currentKey)])) @@ -437,7 +444,7 @@ class BlockLayered extends Module return str_replace('"', '"', $ret); } - + public function hookProductListAssign($params) { global $smarty; @@ -453,18 +460,18 @@ class BlockLayered extends Module if (is_array($filterBlock['title_values'])) foreach ($filterBlock['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); // Need a nofollow on the pagination links? $smarty->assign('no_follow', $filterBlock['nofollow']); } - + public function hookAfterSaveProduct($params) { if (!$params['id_product']) return; - + self::indexProductPrices((int)$params['id_product']); $this->indexAttribute((int)$params['id_product']); } @@ -473,10 +480,10 @@ class BlockLayered extends Module { if (!$params['id_feature'] || Tools::getValue('layered_indexable') === false) return; - + Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'layered_indexable_feature WHERE id_feature = '.(int)$params['id_feature']); Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'layered_indexable_feature VALUES ('.(int)$params['id_feature'].', '.(int)Tools::getValue('layered_indexable').')'); - + Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'layered_indexable_feature_lang_value WHERE id_feature = '.(int)$params['id_feature']); // don't care about the id_lang foreach (Language::getLanguages(false) as $language) { @@ -492,7 +499,7 @@ class BlockLayered extends Module { if (!$params['id_feature_value']) return; - + Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'layered_indexable_feature_value_lang_value WHERE id_feature_value = '.(int)$params['id_feature_value']); // don't care about the id_lang foreach (Language::getLanguages(false) as $language) { @@ -503,25 +510,25 @@ class BlockLayered extends Module \''.pSQL(Tools::safeOutput(Tools::getValue('meta_title_'.$id_lang), true)).'\')'); } } - + public function hookAfterDeleteFeatureValue($params) { if (!$params['id_feature_value']) return; Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'layered_indexable_feature_value_lang_value WHERE id_feature_value = '.(int)$params['id_feature_value']); } - + public function hookPostProcessFeatureValue($params) { $this->hookPostProcessAttributeGroup($params); } - + public function hookFeatureValueForm($params) { $languages = Language::getLanguages(false); $default_form_language = (int)(Configuration::get('PS_LANG_DEFAULT')); $langValue = array(); - + $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS( 'SELECT url_name, meta_title, id_lang FROM '._DB_PREFIX_.'layered_indexable_feature_value_lang_value WHERE id_feature_value = '.(int)$params['id_feature_value']); @@ -559,12 +566,12 @@ class BlockLayered extends Module '; return $return; } - + public function hookAfterSaveAttribute($params) { if (!$params['id_attribute']) return; - + Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'layered_indexable_attribute_lang_value WHERE id_attribute = '.(int)$params['id_attribute']); // don't care about the id_lang foreach (Language::getLanguages(false) as $language) { @@ -575,25 +582,25 @@ class BlockLayered extends Module \''.pSQL(Tools::safeOutput(Tools::getValue('meta_title_'.$id_lang), true)).'\')'); } } - + public function hookAfterDeleteAttribute($params) { if (!$params['id_attribute']) return; Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'layered_indexable_attribute_lang_value WHERE id_attribute = '.(int)$params['id_attribute']); } - + public function hookPostProcessAttribute($params) { $this->hookPostProcessAttributeGroup($params); } - + public function hookAttributeForm($params) { $languages = Language::getLanguages(false); $default_form_language = (int)(Configuration::get('PS_LANG_DEFAULT')); $langValue = array(); - + $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS( 'SELECT url_name, meta_title, id_lang FROM '._DB_PREFIX_.'layered_indexable_attribute_lang_value WHERE id_attribute = '.(int)$params['id_attribute']); @@ -631,7 +638,7 @@ class BlockLayered extends Module '; return $return; } - + public function hookPostProcessFeature($params) { $this->hookPostProcessAttributeGroup($params); @@ -643,12 +650,12 @@ class BlockLayered extends Module return; Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'layered_indexable_feature WHERE id_feature = '.(int)$params['id_feature']); } - + public function hookAfterSaveAttributeGroup($params) { if (!$params['id_attribute_group'] || Tools::getValue('layered_indexable') === false) return; - + Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'layered_indexable_attribute_group WHERE id_attribute_group = '.(int)$params['id_attribute_group']); Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'layered_indexable_attribute_group VALUES ('.(int)$params['id_attribute_group'].', '.(int)Tools::getValue('layered_indexable').')'); @@ -662,7 +669,7 @@ class BlockLayered extends Module \''.pSQL(Tools::safeOutput(Tools::getValue('meta_title_'.$id_lang), true)).'\')'); } } - + public function hookPostProcessAttributeGroup($params) { // Limit to one call @@ -670,7 +677,7 @@ class BlockLayered extends Module if ($once) return; $once = true; - + $errors = array(); foreach (Language::getLanguages(false) as $language) { @@ -683,7 +690,7 @@ class BlockLayered extends Module } } } - + public function hookAfterDeleteAttributeGroup($params) { if (!$params['id_attribute_group']) @@ -692,7 +699,7 @@ class BlockLayered extends Module Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'layered_indexable_attribute_group WHERE id_attribute_group = '.(int)$params['id_attribute_group']); Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'layered_indexable_attribute_group_lang_value WHERE id_attribute_group = '.(int)$params['id_attribute_group']); } - + public function hookAttributeGroupForm($params) { $languages = Language::getLanguages(false); @@ -700,7 +707,7 @@ class BlockLayered extends Module $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(); - + $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']); @@ -752,27 +759,27 @@ class BlockLayered extends Module '; return $return; } - + public function hookFeatureForm($params) { $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(); - + $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']); - - + + if ($indexable === false) $on = true; else $on = (bool)$indexable; - + $return = '
'.$this->l('Your filter').' "'.Tools::safeOutput(Tools::getValue('layered_tpl_name')).'" '.
((isset($_POST['id_layered_filter']) && $_POST['id_layered_filter']) ? $this->l('was updated successfully.') : $this->l('was added successfully.')).'
'.$this->l('Settings saved successfully').'
@@ -1199,14 +1218,14 @@ class BlockLayered extends Module
else if (isset($_GET['deleteFilterTemplate']))
{
$layeredValues = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
- SELECT filters
- FROM '._DB_PREFIX_.'layered_filter
+ SELECT filters
+ FROM '._DB_PREFIX_.'layered_filter
WHERE id_layered_filter = '.(int)$_GET['id_layered_filter']);
-
+
if ($layeredValues)
{
Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'layered_filter WHERE id_layered_filter = '.(int)$_GET['id_layered_filter'].' LIMIT 1');
-
+
$html .= '
'.$this->l('Filters template deleted, categories updated (reverted to default Filters template).').'
@@ -1220,7 +1239,7 @@ class BlockLayered extends Module