diff --git a/modules/blocklayered/blocklayered-ajax-back.php b/modules/blocklayered/blocklayered-ajax-back.php index e69192e7d..409a6ae90 100644 --- a/modules/blocklayered/blocklayered-ajax-back.php +++ b/modules/blocklayered/blocklayered-ajax-back.php @@ -40,5 +40,4 @@ if (isset($_GET['categoryBox']) AND is_array($_GET['categoryBox'])) $value = (int)$value; $blockLayered = new BlockLayered(); -echo $blockLayered->ajaxCallBackOffice((isset($_GET['categoryBox']) AND is_array($_GET['categoryBox'])) ? $_GET['categoryBox'] : array(), -(isset($_GET['id_layered_filter']) AND !empty($_GET['id_layered_filter'])) ? (int)$_GET['id_layered_filter'] : array()); \ No newline at end of file +echo $blockLayered->ajaxCallBackOffice(Tools::getValue('categoryBox'), Tools::getValue('id_layered_filter')); diff --git a/modules/blocklayered/blocklayered.php b/modules/blocklayered/blocklayered.php index cc163f2fa..a3233b0e3 100644 --- a/modules/blocklayered/blocklayered.php +++ b/modules/blocklayered/blocklayered.php @@ -108,6 +108,7 @@ class BlockLayered extends Module Db::getInstance()->Execute('DROP TABLE IF EXISTS '._DB_PREFIX_.'layered_indexable_feature_lang_value'); Db::getInstance()->Execute('DROP TABLE IF EXISTS '._DB_PREFIX_.'layered_category'); Db::getInstance()->Execute('DROP TABLE IF EXISTS '._DB_PREFIX_.'layered_filter'); + Db::getInstance()->Execute('DROP TABLE IF EXISTS '._DB_PREFIX_.'layered_filter_shop'); Db::getInstance()->Execute('DROP TABLE IF EXISTS '._DB_PREFIX_.'layered_product_attribute'); return parent::uninstall(); } @@ -454,7 +455,8 @@ class BlockLayered extends Module public function hookProductListAssign($params) { global $smarty; - if (!Configuration::get('PS_LAYERED_INDEXED')) + if (version_compare(_PS_VERSION_,'1.5','<') && !Configuration::get('PS_LAYERED_INDEXED') + || version_compare(_PS_VERSION_,'1.5','>') && !Configuration::getGlobalValue('PS_LAYERED_INDEXED')) return; // Inform the hook was executed $params['hookExecuted'] = true; @@ -881,7 +883,11 @@ class BlockLayered extends Module return '{"cursor": '.$cursor.', "count": '.($nbProducts).'}'; else { - Configuration::updateValue('PS_LAYERED_INDEXED', 1); + if (version_compare(_PS_VERSION_,'1.5','>')) + Configuration::updateGlobalValue('PS_LAYERED_INDEXED', 1); + else + Configuration::updateValue('PS_LAYERED_INDEXED', 1); + if ($ajax) return '{"result": "ok"}'; else @@ -1175,6 +1181,25 @@ class BlockLayered extends Module $_POST['categoryBox'][] = (int)$category['id_category']; } + if (version_compare(_PS_VERSION_,'1.5','>')) + { + $id_layered_filter = (int)$_POST['id_layered_filter']; + if (!$id_layered_filter) + $id_layered_filter = (int)Db::getInstance()->Insert_ID(); + + $shop_list = array(); + foreach ($_POST['checkBoxShopAsso_layered_filter'] as $id_asso_object => $row) + { + foreach ($row as $id_shop => $value) + { + $assos[] = array('id_object' => (int)$id_layered_filter, 'id_shop' => (int)$id_shop); + $shop_list[] = (int)$id_shop; + } + } + } + else + $shop_list = array(0); + if (count($_POST['categoryBox'])) { /* Clean categoryBox before use */ @@ -1182,16 +1207,22 @@ class BlockLayered extends Module foreach ($_POST['categoryBox'] as &$categoryBoxTmp) $categoryBoxTmp = (int)$categoryBoxTmp; - Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'layered_category WHERE id_category IN ('.implode(',', array_map('intval', $_POST['categoryBox'])).')'); + Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'layered_category + WHERE + id_category IN ('.implode(',', array_map('intval', $_POST['categoryBox'])).') + AND id_shop IN ('.implode(',', $shop_list).')'); $filterValues = array(); foreach ($_POST['categoryBox'] as $idc) $filterValues['categories'][] = (int)$idc; + + - $sqlToInsert = 'INSERT INTO '._DB_PREFIX_.'layered_category (id_category, id_value, type, position, filter_show_limit, filter_type) VALUES '; + $sqlToInsert = 'INSERT INTO '._DB_PREFIX_.'layered_category (id_category, id_shop, id_value, type, position, filter_show_limit, filter_type) VALUES '; foreach ($_POST['categoryBox'] as $id_category_layered) { $n = 0; + foreach ($_POST as $key => $value) if (substr($key, 0, 17) == 'layered_selection' && $value == 'on') { @@ -1207,25 +1238,27 @@ class BlockLayered extends Module 'filter_show_limit' => (int)$limit ); $n++; - - if ($key == 'layered_selection_stock') - $sqlToInsert .= '('.(int)$id_category_layered.',NULL,\'quantity\','.(int)$n.', '.(int)$limit.', '.(int)$type.'),'; - else if ($key == 'layered_selection_subcategories') - $sqlToInsert .= '('.(int)$id_category_layered.',NULL,\'category\','.(int)$n.', '.(int)$limit.', '.(int)$type.'),'; - else if ($key == 'layered_selection_condition') - $sqlToInsert .= '('.(int)$id_category_layered.',NULL,\'condition\','.(int)$n.', '.(int)$limit.', '.(int)$type.'),'; - else if ($key == 'layered_selection_weight_slider') - $sqlToInsert .= '('.(int)$id_category_layered.',NULL,\'weight\','.(int)$n.', '.(int)$limit.', '.(int)$type.'),'; - else if ($key == 'layered_selection_price_slider') - $sqlToInsert .= '('.(int)$id_category_layered.',NULL,\'price\','.(int)$n.', '.(int)$limit.', '.(int)$type.'),'; - else if ($key == 'layered_selection_manufacturer') - $sqlToInsert .= '('.(int)$id_category_layered.',NULL,\'manufacturer\','.(int)$n.', '.(int)$limit.', '.(int)$type.'),'; - else if (substr($key, 0, 21) == 'layered_selection_ag_') - $sqlToInsert .= '('.(int)$id_category_layered.','.(int)str_replace('layered_selection_ag_', '', $key).', - \'id_attribute_group\','.(int)$n.', '.(int)$limit.', '.(int)$type.'),'; - else if (substr($key, 0, 23) == 'layered_selection_feat_') - $sqlToInsert .= '('.(int)$id_category_layered.','.(int)str_replace('layered_selection_feat_', '', $key).', - \'id_feature\','.(int)$n.', '.(int)$limit.', '.(int)$type.'),'; + foreach ($shop_list as $id_shop) + { + if ($key == 'layered_selection_stock') + $sqlToInsert .= '('.(int)$id_category_layered.', '.(int)$id_shop.', NULL,\'quantity\','.(int)$n.', '.(int)$limit.', '.(int)$type.'),'; + else if ($key == 'layered_selection_subcategories') + $sqlToInsert .= '('.(int)$id_category_layered.', '.(int)$id_shop.', NULL,\'category\','.(int)$n.', '.(int)$limit.', '.(int)$type.'),'; + else if ($key == 'layered_selection_condition') + $sqlToInsert .= '('.(int)$id_category_layered.', '.(int)$id_shop.', NULL,\'condition\','.(int)$n.', '.(int)$limit.', '.(int)$type.'),'; + else if ($key == 'layered_selection_weight_slider') + $sqlToInsert .= '('.(int)$id_category_layered.', '.(int)$id_shop.', NULL,\'weight\','.(int)$n.', '.(int)$limit.', '.(int)$type.'),'; + else if ($key == 'layered_selection_price_slider') + $sqlToInsert .= '('.(int)$id_category_layered.', '.(int)$id_shop.', NULL,\'price\','.(int)$n.', '.(int)$limit.', '.(int)$type.'),'; + else if ($key == 'layered_selection_manufacturer') + $sqlToInsert .= '('.(int)$id_category_layered.', '.(int)$id_shop.', NULL,\'manufacturer\','.(int)$n.', '.(int)$limit.', '.(int)$type.'),'; + else if (substr($key, 0, 21) == 'layered_selection_ag_') + $sqlToInsert .= '('.(int)$id_category_layered.', '.(int)$id_shop.', '.(int)str_replace('layered_selection_ag_', '', $key).', + \'id_attribute_group\','.(int)$n.', '.(int)$limit.', '.(int)$type.'),'; + else if (substr($key, 0, 23) == 'layered_selection_feat_') + $sqlToInsert .= '('.(int)$id_category_layered.', '.(int)$id_shop.', '.(int)str_replace('layered_selection_feat_', '', $key).', + \'id_feature\','.(int)$n.', '.(int)$limit.', '.(int)$type.'),'; + } } } @@ -1239,7 +1272,16 @@ class BlockLayered extends Module if (isset($_POST['id_layered_filter']) && $_POST['id_layered_filter']) $valuesToInsert['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', $valuesToInsert, 'INSERT'); + + if (version_compare(_PS_VERSION_,'1.5','>')) + { + Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'layered_filter_shop WHERE `id_layered_filter` = '.(int)$id_layered_filter); + + foreach ($assos as $asso) + Db::getInstance()->execute('INSERT INTO layered_filter_shop (`id_layered_filter`, `id_shop`) + VALUES('.$id_layered_filter.', '.(int)$asso['id_shop'].')'); + } $html .= '
'.(version_compare(_PS_VERSION_,'1.5','>') ? '' : ''). $this->l('Your filter').' "'.Tools::safeOutput(Tools::getValue('layered_tpl_name')).'" '. @@ -1296,7 +1338,8 @@ class BlockLayered extends Module '.$this->l('Indexes and caches').' '; - if (!Configuration::get('PS_LAYERED_INDEXED')) + if (version_compare(_PS_VERSION_,'1.5','<') &&!Configuration::get('PS_LAYERED_INDEXED') + || version_compare(_PS_VERSION_,'1.5','>') && !Configuration::getGlobalValue('PS_LAYERED_INDEXED')) $html .= ' '; } + + if (version_compare(_PS_VERSION_,'1.5','>') && !empty($id_layered_filter)) + { + $helper = new Helper(); + $helper->id = (int)$id_layered_filter; + $helper->table = 'layered_filter'; + $helper->identifier = 'id_layered_filter'; + $helper->base_folder = Tools::getValue('base_folder').'/themes/template/'; + + $html .= ' +
'.$helper->renderAssoShop().'
+ '; + } return $html; } @@ -3280,6 +3371,7 @@ class BlockLayered extends Module Db::getInstance()->Execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'layered_category` ( `id_layered_category` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, + `id_shop` INT(11) UNSIGNED NOT NULL, `id_category` INT(10) UNSIGNED NOT NULL, `id_value` INT(10) UNSIGNED NULL DEFAULT \'0\', `type` ENUM(\'category\',\'id_feature\',\'id_attribute_group\',\'quantity\',\'condition\',\'manufacturer\',\'weight\',\'price\') NOT NULL, @@ -3297,6 +3389,13 @@ class BlockLayered extends Module `filters` TEXT NULL, `n_categories` INT(10) UNSIGNED NOT NULL, `date_add` DATETIME NOT NULL)'); + + Db::getInstance()->Execute(' + CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'layered_filter_shop` ( + `id_layered_filter` INT(10) UNSIGNED NOT NULL, + `id_shop` INT(11) UNSIGNED NOT NULL, + PRIMARY KEY (`id_layered_filter`, `id_shop`), + KEY `id_shop` (`id_shop`))'); } public function rebuildLayeredCache($productsIds = array(), $categoriesIds = array()) @@ -3364,63 +3463,70 @@ class BlockLayered extends Module if (!empty($product['features'])) $f = array_flip(explode(',', $product['features'])); - $queryCategory = 'INSERT INTO '._DB_PREFIX_.'layered_category (id_category, id_value, type, position) VALUES '; + if (version_compare(_PS_VERSION_,'1.5','>')) + $shop_list = Shop::getShops(false, null, true); + else + $shop_list = array(0); + + $queryCategory = 'INSERT INTO '._DB_PREFIX_.'layered_category (id_category, id_shop, id_value, type, position) VALUES '; $toInsert = false; - foreach ($c as $id_category => $category) - { - if (!isset($nCategories[(int)$id_category])) - $nCategories[(int)$id_category] = 1; - if (!isset($doneCategories[(int)$id_category]['cat'])) + foreach ($shop_list as $id_shop) + foreach ($c as $id_category => $category) { - $doneCategories[(int)$id_category]['cat'] = true; - $queryCategory .= '('.(int)$id_category.',NULL,\'category\','.(int)$nCategories[(int)$id_category]++.'),'; - $toInsert = true; - } - foreach ($a as $kAttribute => $attribute) - if (!isset($doneCategories[(int)$id_category]['a'.(int)$attributeGroupsById[(int)$kAttribute]])) + if (!isset($nCategories[(int)$id_category])) + $nCategories[(int)$id_category] = 1; + if (!isset($doneCategories[(int)$id_category]['cat'])) { - $doneCategories[(int)$id_category]['a'.(int)$attributeGroupsById[(int)$kAttribute]] = true; - $queryCategory .= '('.(int)$id_category.','.(int)$attributeGroupsById[(int)$kAttribute].',\'id_attribute_group\','.(int)$nCategories[(int)$id_category]++.'),'; + $doneCategories[(int)$id_category]['cat'] = true; + $queryCategory .= '('.(int)$id_category.', '.(int)$id_shop.', NULL,\'category\','.(int)$nCategories[(int)$id_category]++.'),'; $toInsert = true; } - foreach ($f as $kFeature => $feature) - if (!isset($doneCategories[(int)$id_category]['f'.(int)$featuresById[(int)$kFeature]])) + foreach ($a as $kAttribute => $attribute) + if (!isset($doneCategories[(int)$id_category]['a'.(int)$attributeGroupsById[(int)$kAttribute]])) + { + $doneCategories[(int)$id_category]['a'.(int)$attributeGroupsById[(int)$kAttribute]] = true; + $queryCategory .= '('.(int)$id_category.', '.(int)$id_shop.','.(int)$attributeGroupsById[(int)$kAttribute].',\'id_attribute_group\','.(int)$nCategories[(int)$id_category]++.'),'; + $toInsert = true; + } + foreach ($f as $kFeature => $feature) + if (!isset($doneCategories[(int)$id_category]['f'.(int)$featuresById[(int)$kFeature]])) + { + $doneCategories[(int)$id_category]['f'.(int)$featuresById[(int)$kFeature]] = true; + $queryCategory .= '('.(int)$id_category.', '.(int)$id_shop.', '.(int)$featuresById[(int)$kFeature].',\'id_feature\','.(int)$nCategories[(int)$id_category]++.'),'; + $toInsert = true; + } + if (!isset($doneCategories[(int)$id_category]['q'])) { - $doneCategories[(int)$id_category]['f'.(int)$featuresById[(int)$kFeature]] = true; - $queryCategory .= '('.(int)$id_category.','.(int)$featuresById[(int)$kFeature].',\'id_feature\','.(int)$nCategories[(int)$id_category]++.'),'; + $doneCategories[(int)$id_category]['q'] = true; + $queryCategory .= '('.(int)$id_category.', '.(int)$id_shop.', NULL,\'quantity\','.(int)$nCategories[(int)$id_category]++.'),'; + $toInsert = true; + } + if (!isset($doneCategories[(int)$id_category]['m'])) + { + $doneCategories[(int)$id_category]['m'] = true; + $queryCategory .= '('.(int)$id_category.', '.(int)$id_shop.', NULL,\'manufacturer\','.(int)$nCategories[(int)$id_category]++.'),'; + $toInsert = true; + } + if (!isset($doneCategories[(int)$id_category]['c'])) + { + $doneCategories[(int)$id_category]['c'] = true; + $queryCategory .= '('.(int)$id_category.', '.(int)$id_shop.', NULL,\'condition\','.(int)$nCategories[(int)$id_category]++.'),'; + $toInsert = true; + } + if (!isset($doneCategories[(int)$id_category]['w'])) + { + $doneCategories[(int)$id_category]['w'] = true; + $queryCategory .= '('.(int)$id_category.', '.(int)$id_shop.', NULL,\'weight\','.(int)$nCategories[(int)$id_category]++.'),'; + $toInsert = true; + } + if (!isset($doneCategories[(int)$id_category]['p'])) + { + $doneCategories[(int)$id_category]['p'] = true; + $queryCategory .= '('.(int)$id_category.', '.(int)$id_shop.', NULL,\'price\','.(int)$nCategories[(int)$id_category]++.'),'; $toInsert = true; } - if (!isset($doneCategories[(int)$id_category]['q'])) - { - $doneCategories[(int)$id_category]['q'] = true; - $queryCategory .= '('.(int)$id_category.',NULL,\'quantity\','.(int)$nCategories[(int)$id_category]++.'),'; - $toInsert = true; } - if (!isset($doneCategories[(int)$id_category]['m'])) - { - $doneCategories[(int)$id_category]['m'] = true; - $queryCategory .= '('.(int)$id_category.',NULL,\'manufacturer\','.(int)$nCategories[(int)$id_category]++.'),'; - $toInsert = true; - } - if (!isset($doneCategories[(int)$id_category]['c'])) - { - $doneCategories[(int)$id_category]['c'] = true; - $queryCategory .= '('.(int)$id_category.',NULL,\'condition\','.(int)$nCategories[(int)$id_category]++.'),'; - $toInsert = true; - } - if (!isset($doneCategories[(int)$id_category]['w'])) - { - $doneCategories[(int)$id_category]['w'] = true; - $queryCategory .= '('.(int)$id_category.',NULL,\'weight\','.(int)$nCategories[(int)$id_category]++.'),'; - $toInsert = true; - } - if (!isset($doneCategories[(int)$id_category]['p'])) - { - $doneCategories[(int)$id_category]['p'] = true; - $queryCategory .= '('.(int)$id_category.',NULL,\'price\','.(int)$nCategories[(int)$id_category]++.'),'; - $toInsert = true; - } - } + if ($toInsert) Db::getInstance()->Execute(rtrim($queryCategory, ',')); } diff --git a/modules/blocklayered/fr.php b/modules/blocklayered/fr.php index 094082748..9726011cd 100644 --- a/modules/blocklayered/fr.php +++ b/modules/blocklayered/fr.php @@ -56,6 +56,7 @@ $_MODULE['<{blocklayered}prestashop>blocklayered_62f5d708d6ad1fa1ddd9429a65cccbe $_MODULE['<{blocklayered}prestashop>blocklayered_fe0619d5f4999e09c622e32da7e7566a'] = 'spécifiques'; $_MODULE['<{blocklayered}prestashop>blocklayered_b0b5ccb4a195a07fd3eed14affb8695f'] = 'Catégories'; $_MODULE['<{blocklayered}prestashop>blocklayered_ef7de3f485174ff47f061ad27d83d0ee'] = 'sélectionnée(s)'; +$_MODULE['<{blocklayered}prestashop>blocklayered_c2d0bf5ad42279c519cdcb4a94eb46b6'] = 'Association de boutique'; $_MODULE['<{blocklayered}prestashop>blocklayered_f72c75bdf80dc88b2529162f4947edc8'] = 'S\'il vous plaît sélectionnez au moins une catégorie spécifique ou choisissez « Toutes catégories ».'; $_MODULE['<{blocklayered}prestashop>blocklayered_64646db703ca003a37bd1e73977a3a4d'] = 'Catégories utilisant ce modèle'; $_MODULE['<{blocklayered}prestashop>blocklayered_d758a9754eb9f36db05c22ad0c77e38e'] = 'Sélectionnez une ou plusieurs catégories utilisant ce modèle';