diff --git a/modules/blocklayered/blocklayered.php b/modules/blocklayered/blocklayered.php index 859337e26..4fa5dcab6 100644 --- a/modules/blocklayered/blocklayered.php +++ b/modules/blocklayered/blocklayered.php @@ -260,14 +260,14 @@ class BlockLayered extends Module 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`, `id_shop`) - SELECT pac.id_attribute, pa.id_product, ag.id_attribute_group, '.(version_compare(_PS_VERSION_,'1.5','>') ? 'product_attribute_shop.`id_shop`' : '1').' - FROM '._DB_PREFIX_.'product_attribute pa - '.(version_compare(_PS_VERSION_,'1.5','>') ? Shop::addSqlAssociation('product_attribute', 'pa') : '').' + SELECT pac.id_attribute, pa.id_product, ag.id_attribute_group, product_attribute_shop.`id_shop` + FROM '._DB_PREFIX_.'product_attribute pa'. + Shop::addSqlAssociation('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 '.(version_compare(_PS_VERSION_,'1.5','>') ? ', product_attribute_shop.`id_shop`' : '')); + GROUP BY a.id_attribute, pa.id_product , product_attribute_shop.`id_shop`'); return 1; } @@ -486,8 +486,7 @@ class BlockLayered extends Module public function hookProductListAssign($params) { global $smarty; - if (version_compare(_PS_VERSION_,'1.5','<') && !Configuration::get('PS_LAYERED_INDEXED') - || version_compare(_PS_VERSION_,'1.5','>') && !Configuration::getGlobalValue('PS_LAYERED_INDEXED')) + if (!Configuration::getGlobalValue('PS_LAYERED_INDEXED')) return; // Inform the hook was executed $params['hookExecuted'] = true; @@ -568,14 +567,11 @@ class BlockLayered extends Module $default_form_language = (int)(Configuration::get('PS_LANG_DEFAULT')); $lang_value = array(); - if (version_compare(_PS_VERSION_,'1.5','>')) $return = ' '; - else - $return = ''; - + $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']); @@ -596,8 +592,7 @@ class BlockLayered extends Module '.$this->l('Invalid characters:').' <>;=#{}_ 

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

'; - if (version_compare(_PS_VERSION_,'1.5','<')) - $return .= $this->displayFlags($languages, $default_form_language, 'flag_fields', 'url_name', true, true); + $return .= '
@@ -611,9 +606,7 @@ class BlockLayered extends Module

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

'; - - if (version_compare(_PS_VERSION_,'1.5','<')) - $return .= $this->displayFlags($languages, $default_form_language, 'flag_fields', 'meta_title', true, true); + $return .= '
@@ -655,13 +648,10 @@ class BlockLayered extends Module $default_form_language = (int)(Configuration::get('PS_LANG_DEFAULT')); $lang_value = array(); - if (version_compare(_PS_VERSION_,'1.5','>')) - $return = ' + $return = ' '; - else - $return = ''; $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS( 'SELECT url_name, meta_title, id_lang FROM '._DB_PREFIX_.'layered_indexable_attribute_lang_value @@ -683,8 +673,7 @@ class BlockLayered extends Module '.$this->l('Invalid characters:').' <>;=#{}_ 

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

'; - if (version_compare(_PS_VERSION_,'1.5','<')) - $return .= $this->displayFlags($languages, $default_form_language, 'flag_fields', 'url_name', true, true); + $return .= '
@@ -698,8 +687,7 @@ class BlockLayered extends Module

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

'; - if (version_compare(_PS_VERSION_,'1.5','<')) - $return .= $this->displayFlags($languages, $default_form_language, 'flag_fields', 'meta_title', true, true); + $return .= '
@@ -788,13 +776,10 @@ class BlockLayered extends Module else $on = (bool)$indexable; - if (version_compare(_PS_VERSION_,'1.5','>')) - $return = ' - '; - else - $return = ''; + $return = ' + '; $return .= '
@@ -810,8 +795,7 @@ class BlockLayered extends Module '.$this->l('Invalid characters:').' <>;=#{}_ 

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

'; - if (version_compare(_PS_VERSION_,'1.5','<')) - $return .= $this->displayFlags($languages, $default_form_language, 'flag_fields', 'url_name', true, true); + $return .= '
@@ -825,8 +809,7 @@ class BlockLayered extends Module

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

'; - if (version_compare(_PS_VERSION_,'1.5','<')) - $return .= $this->displayFlags($languages, $default_form_language, 'flag_fields', 'meta_title', true, true); + $return .= '
@@ -862,13 +845,10 @@ class BlockLayered extends Module else $on = (bool)$indexable; - if (version_compare(_PS_VERSION_,'1.5','>')) - $return = ' - '; - else - $return = ''; + $return = ' + '; $return .= '
@@ -884,8 +864,7 @@ class BlockLayered extends Module '.$this->l('Invalid characters:').' <>;=#{}_ 

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

'; - if (version_compare(_PS_VERSION_,'1.5','<')) - $return .= $this->displayFlags($languages, $default_form_language, 'flag_fields', 'url_name', true, true); + $return .= '
@@ -899,8 +878,7 @@ class BlockLayered extends Module

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

'; - if (version_compare(_PS_VERSION_,'1.5','<')) - $return .= $this->displayFlags($languages, $default_form_language, 'flag_fields', 'meta_title', true, true); + $return .= '
@@ -938,30 +916,18 @@ class BlockLayered extends Module private static function indexPrices($cursor = null, $full = false, $ajax = false, $smart = false) { if ($full) - if (version_compare(_PS_VERSION_,'1.5','>')) - $nb_products = (int)Db::getInstance()->getValue(' - SELECT count(DISTINCT p.`id_product`) - FROM '._DB_PREFIX_.'product p - INNER JOIN `'._DB_PREFIX_.'product_shop` ps - ON (ps.`id_product` = p.`id_product` AND ps.`active` = 1 AND ps.`visibility` IN ("both", "catalog"))'); + $nb_products = (int)Db::getInstance()->getValue(' + SELECT count(DISTINCT p.`id_product`) + FROM '._DB_PREFIX_.'product p + INNER JOIN `'._DB_PREFIX_.'product_shop` ps + ON (ps.`id_product` = p.`id_product` AND ps.`active` = 1 AND ps.`visibility` IN ("both", "catalog"))'); else - $nb_products = (int)Db::getInstance()->getValue(' - SELECT count(DISTINCT p.`id_product`) - FROM '._DB_PREFIX_.'product p - WHERE `active` = 1 AND `visibility` IN ("both", "catalog")'); - else - if (version_compare(_PS_VERSION_,'1.5','>')) - $nb_products = (int)Db::getInstance()->getValue(' - SELECT COUNT(DISTINCT p.`id_product`) FROM `'._DB_PREFIX_.'product` p - INNER JOIN `'._DB_PREFIX_.'product_shop` ps - ON (ps.`id_product` = p.`id_product` AND ps.`active` = 1 AND ps.`visibility` IN ("both", "catalog")) - LEFT JOIN `'._DB_PREFIX_.'layered_price_index` psi ON (psi.id_product = p.id_product) - WHERE psi.id_product IS NULL'); - else - $nb_products = (int)Db::getInstance()->getValue(' - SELECT COUNT(DISTINCT p.`id_product`) FROM `'._DB_PREFIX_.'product` p - LEFT JOIN `'._DB_PREFIX_.'layered_price_index` psi ON (psi.id_product = p.id_product) - WHERE `active` = 1 AND `visibility` IN ("both", "catalog") AND psi.id_product IS NULL'); + $nb_products = (int)Db::getInstance()->getValue(' + SELECT COUNT(DISTINCT p.`id_product`) FROM `'._DB_PREFIX_.'product` p + INNER JOIN `'._DB_PREFIX_.'product_shop` ps + ON (ps.`id_product` = p.`id_product` AND ps.`active` = 1 AND ps.`visibility` IN ("both", "catalog")) + LEFT JOIN `'._DB_PREFIX_.'layered_price_index` psi ON (psi.id_product = p.id_product) + WHERE psi.id_product IS NULL'); $max_executiontime = @ini_get('max_execution_time'); if ($max_executiontime > 5 || $max_executiontime <= 0) @@ -994,11 +960,8 @@ class BlockLayered extends Module return '{"cursor": '.$cursor.', "count": '.($nb_products).'}'; else { - if (version_compare(_PS_VERSION_,'1.5','>')) - Configuration::updateGlobalValue('PS_LAYERED_INDEXED', 1); - else - Configuration::updateValue('PS_LAYERED_INDEXED', 1); - + Configuration::updateGlobalValue('PS_LAYERED_INDEXED', 1); + if ($ajax) return '{"result": "ok"}'; else @@ -1017,7 +980,6 @@ class BlockLayered extends Module $cursor = 0; if ($full) - if (version_compare(_PS_VERSION_,'1.5','>')) $query = ' SELECT p.`id_product` FROM `'._DB_PREFIX_.'product` p @@ -1025,15 +987,7 @@ class BlockLayered extends Module ON (ps.`id_product` = p.`id_product` AND ps.`active` = 1 AND ps.`visibility` IN ("both", "catalog")) GROUP BY p.`id_product` ORDER BY p.`id_product` LIMIT '.(int)$cursor.','.(int)$length; - else - $query = ' - SELECT p.`id_product` - FROM `'._DB_PREFIX_.'product` p - WHERE `active` = 1 AND `visibility` IN ("both", "catalog") - GROUP BY p.`id_product` - ORDER BY p.`id_product` LIMIT '.(int)$cursor.','.(int)$length; else - if (version_compare(_PS_VERSION_,'1.5','>')) $query = ' SELECT p.`id_product` FROM `'._DB_PREFIX_.'product` p @@ -1043,14 +997,6 @@ class BlockLayered extends Module WHERE psi.id_product IS NULL GROUP BY p.`id_product` ORDER BY p.`id_product` LIMIT 0,'.(int)$length; - else - $query = ' - SELECT p.`id_product` - FROM `'._DB_PREFIX_.'product` p - LEFT JOIN `'._DB_PREFIX_.'layered_price_index` psi ON (psi.id_product = p.id_product) - WHERE `active` = 1 AND `visibility` IN ("both", "catalog") AND psi.id_product IS NULL - GROUP BY p.`id_product` - ORDER BY p.`id_product` LIMIT 0,'.(int)$length; foreach (Db::getInstance()->executeS($query) as $product) self::indexProductPrices((int)$product['id_product'], ($smart && $full)); @@ -1069,24 +1015,15 @@ class BlockLayered extends Module $groups = array(); } - $shop_list = array(); - if (version_compare(_PS_VERSION_,'1.5','>')) - $shop_list = Shop::getShops(false, null, true); - else - $shop_list[] = 0; + $shop_list = Shop::getShops(false, null, true); foreach ($shop_list as $id_shop) { static $currency_list = null; if (is_null($currency_list)) - { - if (version_compare(_PS_VERSION_,'1.5','>')) - $currency_list = Currency::getCurrencies(false, 1, new Shop($id_shop)); - else - $currency_list = Currency::getCurrencies(false, 1); - } - + $currency_list = Currency::getCurrencies(false, 1, new Shop($id_shop)); + $min_price = array(); $max_price = array(); @@ -1094,26 +1031,14 @@ class BlockLayered extends Module 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','>')) - $max_tax_rate = Db::getInstance()->getValue(' - SELECT max(t.rate) max_rate - FROM `'._DB_PREFIX_.'product_shop` p - LEFT JOIN `'._DB_PREFIX_.'tax_rules_group` trg ON (trg.id_tax_rules_group = p.id_tax_rules_group AND p.id_shop = '.(int)$shop_list.') - 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)$id_product.' - GROUP BY id_product'); - else - $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)$id_product.' - GROUP BY id_product'); - } + $max_tax_rate = Db::getInstance()->getValue(' + SELECT max(t.rate) max_rate + FROM `'._DB_PREFIX_.'product_shop` p + LEFT JOIN `'._DB_PREFIX_.'tax_rules_group` trg ON (trg.id_tax_rules_group = p.id_tax_rules_group AND p.id_shop = '.(int)$shop_list.') + 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)$id_product.' + GROUP BY id_product'); else $max_tax_rate = 0; @@ -1244,10 +1169,7 @@ class BlockLayered extends Module // Title attributes (ex: /, ) $description = strtolower(rtrim(substr($description, 0, -2))); // kewords attributes (ex: , , ) - if (version_compare(_PS_VERSION_, '1.5', '>')) - $category_metas = Meta::getMetaTags($id_lang, 'category', $title); - else - $category_metas = Tools::getMetaTags($id_lang, '', $title); + $category_metas = Meta::getMetaTags($id_lang, 'category', $title); if (!empty($title)) { @@ -1261,22 +1183,12 @@ class BlockLayered extends Module if (!empty($keywords)) $smarty->assign('meta_keywords', rtrim($category_title.', '.$keywords.', '.$category_metas['meta_keywords'], ', ')); - if (version_compare(_PS_VERSION_, '1.5', '>')) - { - $this->context->controller->addJS(($this->_path).'blocklayered.js'); - $this->context->controller->addJS(_PS_JS_DIR_.'jquery/jquery-ui-1.8.10.custom.min.js'); - $this->context->controller->addJQueryUI('ui.slider'); - $this->context->controller->addCSS(($this->_path).'blocklayered-15.css', 'all'); - $this->context->controller->addJQueryPlugin('scrollTo'); - } - else - { - Tools::addJS(($this->_path).'blocklayered.js'); - Tools::addJS(_PS_JS_DIR_.'jquery/jquery-ui-1.8.10.custom.min.js'); - Tools::addCSS(_PS_CSS_DIR_.'jquery-ui-1.8.10.custom.css', 'all'); - Tools::addCSS(($this->_path).'blocklayered.css', 'all'); - Tools::addJS(_PS_JS_DIR_.'jquery/jquery.scrollTo-1.4.2-min.js'); - } + + $this->context->controller->addJS(($this->_path).'blocklayered.js'); + $this->context->controller->addJS(_PS_JS_DIR_.'jquery/jquery-ui-1.8.10.custom.min.js'); + $this->context->controller->addJQueryUI('ui.slider'); + $this->context->controller->addCSS(($this->_path).'blocklayered-15.css', 'all'); + $this->context->controller->addJQueryPlugin('scrollTo'); $filters = $this->getSelectedFilters(); @@ -1356,8 +1268,7 @@ class BlockLayered extends Module if ($filter_block['nbr_filterBlocks'] == 0) return false; - if (basename($_SERVER['PHP_SELF']) == 'category.php' && version_compare(_PS_VERSION_, '1.5', '<') - || version_compare(_PS_VERSION_, '1.5', '>') && Dispatcher::getInstance()->getController() == 'category') + if (Dispatcher::getInstance()->getController() == 'category') return ' - - '; - $id_lang = (int)$cookie->id_lang; - - } + $this->context->controller->addJQueryPlugin('fancybox'); + $this->context->controller->addJQueryUI('ui.sortable'); + $this->context->controller->addJQueryUI('ui.draggable'); + $this->context->controller->addJQueryUI('effects.transfer'); + $id_lang = Context::getContext()->cookie->id_lang; $html .= ' '; } - if (version_compare(_PS_VERSION_,'1.5','>') && !empty($id_layered_filter)) + if (!empty($id_layered_filter)) { if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_ALL) { @@ -4003,12 +3821,11 @@ class BlockLayered extends Module $done_categories = array(); $alias = 'p'; $join_product_attribute = $join_product = ''; - if (version_compare(_PS_VERSION_,'1.5','>')) - { - $alias = 'product_shop'; - $join_product = Shop::addSqlAssociation('product', 'p'); - $join_product_attribute = Shop::addSqlAssociation('product_attribute', 'pa'); - } + + $alias = 'product_shop'; + $join_product = Shop::addSqlAssociation('product', 'p'); + $join_product_attribute = Shop::addSqlAssociation('product_attribute', 'pa'); + $attribute_groups = self::query(' SELECT a.id_attribute, a.id_attribute_group @@ -4063,10 +3880,7 @@ class BlockLayered extends Module GROUP BY p.id_product'); - if (version_compare(_PS_VERSION_,'1.5','>')) - $shop_list = Shop::getShops(false, null, true); - else - $shop_list = array(0); + $shop_list = Shop::getShops(false, null, true); $to_insert = false; while ($product = $db->nextRow($result)) @@ -4148,14 +3962,11 @@ class BlockLayered extends Module Db::getInstance()->execute('INSERT INTO '._DB_PREFIX_.'layered_filter(name, filters, n_categories, date_add) VALUES (\''.sprintf($this->l('My template %s'), date('Y-m-d')).'\', \''.pSQL(serialize($filter_data)).'\', '.count($filter_data['categories']).', NOW())'); - if (version_compare(_PS_VERSION_,'1.5','>')) - { - $last_id = Db::getInstance()->Insert_ID(); - Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'layered_filter_shop WHERE `id_layered_filter` = '.$last_id); - foreach ($shop_list as $id_shop) - Db::getInstance()->execute('INSERT INTO '._DB_PREFIX_.'layered_filter_shop (`id_layered_filter`, `id_shop`) - VALUES('.$last_id.', '.(int)$id_shop.')'); - } + $last_id = Db::getInstance()->Insert_ID(); + Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'layered_filter_shop WHERE `id_layered_filter` = '.$last_id); + foreach ($shop_list as $id_shop) + Db::getInstance()->execute('INSERT INTO '._DB_PREFIX_.'layered_filter_shop (`id_layered_filter`, `id_shop`) + VALUES('.$last_id.', '.(int)$id_shop.')'); $this->buildLayeredCategories(); } @@ -4177,7 +3988,7 @@ class BlockLayered extends Module $values = false; foreach ($res as $filter_template) { - $data = self::unSerialize($filter_template['filters']); + $data = Tools::unSerialize($filter_template['filters']); foreach ($data['categories'] as $id_category) { $n = 0; @@ -4220,18 +4031,4 @@ class BlockLayered extends Module if ($values) Db::getInstance()->execute(rtrim($sql_to_insert, ',')); } - - /** - * Define our own Tools::unSerialize() (since 1.5), to be available in PrestaShop 1.4 - */ - protected static function unSerialize($serialized) - { - if (method_exists('Tools', 'unserialize')) - return Tools::unSerialize($serialized); - - if (is_string($serialized) && (strpos($serialized, 'O:') === false || !preg_match('/(^|;|{|})O:[0-9]+:"/', $serialized))) - return @unserialize($serialized); - - return false; - } }