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: