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 .= '
').
$this->l('Your filter').' "'.Tools::safeOutput(Tools::getValue('layered_tpl_name')).'" '.
@@ -1296,7 +1338,8 @@ class BlockLayered extends Module
';
- 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 .= '
+