diff --git a/admin-dev/themes/default/template/controllers/performance/helpers/form/form.tpl b/admin-dev/themes/default/template/controllers/performance/helpers/form/form.tpl index e1d7c29e2..ff1137e84 100644 --- a/admin-dev/themes/default/template/controllers/performance/helpers/form/form.tpl +++ b/admin-dev/themes/default/template/controllers/performance/helpers/form/form.tpl @@ -198,7 +198,7 @@ $('#smarty_up').val(1); }); - $('input[name="combination"], input[name="feature"]').change(function(){ + $('input[name="combination"], input[name="feature"], input[name="group"]').change(function(){ $('#features_detachables_up').val('true'); }); diff --git a/classes/Category.php b/classes/Category.php index ab2c78152..178c05e97 100644 --- a/classes/Category.php +++ b/classes/Category.php @@ -547,31 +547,30 @@ class CategoryCore extends ObjectModel */ public function getSubCategories($id_lang, $active = true) { - if (!Validate::isBool($active)) - die(Tools::displayError()); - - $groups = FrontController::getCurrentCustomerGroups(); - $sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '='.(int)Group::getCurrent()->id); + $sql_groups_where = ''; + $sql_groups_join = ''; + if (Configuration::get('PS_GROUP_FEATURE_ACTIVE')) + { + $sql_groups_join = 'LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = c.`id_category`)'; + $groups = FrontController::getCurrentCustomerGroups(); + $sql_groups_where = 'AND cg.`id_group` '.(count($groups) ? 'IN ('.implode(',', $groups).')' : '='.(int)Group::getCurrent()->id); + } $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' - SELECT c.*, cl.id_lang, cl.name, cl.description, cl.link_rewrite, cl.meta_title, cl.meta_keywords, cl.meta_description - FROM `'._DB_PREFIX_.'category` c - '.Shop::addSqlAssociation('category', 'c').' - LEFT JOIN `'._DB_PREFIX_.'category_lang` cl - ON (c.`id_category` = cl.`id_category` - AND `id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').') - LEFT JOIN `'._DB_PREFIX_.'category_group` cg - ON (cg.`id_category` = c.`id_category`) - WHERE `id_parent` = '.(int)$this->id.' - '.($active ? 'AND `active` = 1' : '').' - AND cg.`id_group` '.$sql_groups.' - GROUP BY c.`id_category` - ORDER BY `level_depth` ASC, category_shop.`position` ASC - '); + SELECT c.*, cl.id_lang, cl.name, cl.description, cl.link_rewrite, cl.meta_title, cl.meta_keywords, cl.meta_description + FROM `'._DB_PREFIX_.'category` c + '.Shop::addSqlAssociation('category', 'c').' + LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = '.(int)$id_lang.' '.Shop::addSqlRestrictionOnLang('cl').') + '.$sql_groups_join.' + WHERE `id_parent` = '.(int)$this->id.' + '.($active ? 'AND `active` = 1' : '').' + '.$sql_groups_where.' + GROUP BY c.`id_category` + ORDER BY `level_depth` ASC, category_shop.`position` ASC'); foreach ($result as &$row) { - $row['id_image'] = file_exists(_PS_CAT_IMG_DIR_.$row['id_category'].'.jpg') ? (int)$row['id_category'] : Language::getIsoById($id_lang).'-default'; + $row['id_image'] = Tools::file_exists_cache(_PS_CAT_IMG_DIR_.$row['id_category'].'.jpg') ? (int)$row['id_category'] : Language::getIsoById($id_lang).'-default'; $row['legend'] = 'no picture'; } return $result; diff --git a/classes/Group.php b/classes/Group.php index 08893046f..d010a6900 100644 --- a/classes/Group.php +++ b/classes/Group.php @@ -178,7 +178,8 @@ class GroupCore extends ObjectModel $this->truncateModulesRestrictions($this->id); // Refresh cache of feature detachable - Configuration::updateGlobalValue('PS_GROUP_FEATURE_ACTIVE', Group::isCurrentlyUsed()); + if (!Configuration::getGlobalValue('PS_GROUP_FEATURE_ACTIVE') && Group::isCurrentlyUsed()) + Configuration::updateGlobalValue('PS_GROUP_FEATURE_ACTIVE', 1); // Add default group (id 3) to customers without groups Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'customer_group` ( @@ -213,7 +214,7 @@ class GroupCore extends ObjectModel } /** - * This method is allow to know if a Discount entity is currently used + * This method is allow to know if there are other groups than the default ones * @since 1.5.0.1 * @param $table * @param $has_active_column @@ -221,12 +222,7 @@ class GroupCore extends ObjectModel */ public static function isCurrentlyUsed($table = null, $has_active_column = false) { - // We don't use the parent method, for specific clause reason (id_group != 3) - return (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' - SELECT `id_group` - FROM `'._DB_PREFIX_.'group` - WHERE `id_group` != '.(int)Configuration::get('PS_CUSTOMER_GROUP').' - '); + return (bool)(Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT COUNT(*) FROM `'._DB_PREFIX_.'group`') > 3); } /** diff --git a/classes/GroupReduction.php b/classes/GroupReduction.php index e258d88fa..f42dcf705 100644 --- a/classes/GroupReduction.php +++ b/classes/GroupReduction.php @@ -132,6 +132,9 @@ class GroupReductionCore extends ObjectModel public static function getValueForProduct($id_product, $id_group) { + if (!Configuration::get('PS_GROUP_FEATURE_ACTIVE')) + return 0; + if (!isset(self::$reduction_cache[$id_product.'-'.$id_group])) self::$reduction_cache[$id_product.'-'.$id_group] = Db::getInstance()->getValue(' SELECT `reduction` diff --git a/classes/Manufacturer.php b/classes/Manufacturer.php index c40fa01c8..2916cd22a 100644 --- a/classes/Manufacturer.php +++ b/classes/Manufacturer.php @@ -155,11 +155,12 @@ class ManufacturerCore extends ObjectModel * @param boolean $get_nb_products [optional] return products numbers for each * @return array Manufacturers */ - public static function getManufacturers($get_nb_products = false, $id_lang = 0, $active = true, $p = false, - $n = false, $all_group = false) + public static function getManufacturers($get_nb_products = false, $id_lang = 0, $active = true, $p = false, $n = false, $all_group = false) { if (!$id_lang) $id_lang = (int)Configuration::get('PS_LANG_DEFAULT'); + if (!Configuration::get('PS_GROUP_FEATURE_ACTIVE')) + $all_group = true; $sql = 'SELECT m.*, ml.`description`, ml.`short_description` FROM `'._DB_PREFIX_.'manufacturer` m diff --git a/classes/Product.php b/classes/Product.php index 2fd34114c..08590f2cb 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -1988,8 +1988,7 @@ class ProductCore extends ObjectModel * @param integer $nbProducts Number of products to return (optional) * @return array New products */ - public static function getNewProducts($id_lang, $page_number = 0, $nb_products = 10, - $count = false, $order_by = null, $order_way = null, Context $context = null) + public static function getNewProducts($id_lang, $page_number = 0, $nb_products = 10, $count = false, $order_by = null, $order_way = null, Context $context = null) { if (!$context) $context = Context::getContext(); @@ -2009,14 +2008,25 @@ class ProductCore extends ObjectModel if (!Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way)) die(Tools::displayError()); - $groups = FrontController::getCurrentCustomerGroups(); - $sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1'); + $sql_groups = ''; + if (Configuration::get('PS_GROUP_FEATURE_ACTIVE')) + { + $groups = FrontController::getCurrentCustomerGroups(); + $sql_groups = 'AND p.`id_product` IN ( + SELECT cp.`id_product` + FROM `'._DB_PREFIX_.'category_group` cg + LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`) + WHERE cg.`id_group` '.(count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1').' + )'; + } + if (strpos($order_by, '.') > 0) { $order_by = explode('.', $order_by); $order_by_prefix = $order_by[0]; $order_by = $order_by[1]; } + if ($count) { $sql = 'SELECT COUNT(p.`id_product`) AS nb @@ -2025,12 +2035,7 @@ class ProductCore extends ObjectModel WHERE product_shop.`active` = 1 AND product_shop.`date_add` > "'.date('Y-m-d', strtotime('-'.(Configuration::get('PS_NB_DAYS_NEW_PRODUCT') ? (int)Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY')).'" '.($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').' - AND p.`id_product` IN ( - SELECT cp.`id_product` - FROM `'._DB_PREFIX_.'category_group` cg - LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`) - WHERE cg.`id_group` '.$sql_groups.' - )'; + '.$sql_groups; return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql); } @@ -2056,12 +2061,13 @@ class ProductCore extends ObjectModel if ($front) $sql->where('product_shop.`visibility` IN ("both", "catalog")'); $sql->where('product_shop.`date_add` > "'.date('Y-m-d', strtotime('-'.(Configuration::get('PS_NB_DAYS_NEW_PRODUCT') ? (int)Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY')).'"'); - $sql->where('p.`id_product` IN ( - SELECT cp.`id_product` - FROM `'._DB_PREFIX_.'category_group` cg - LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`) - WHERE cg.`id_group` '.$sql_groups.' - )'); + if (Configuration::get('PS_GROUP_FEATURE_ACTIVE')) + $sql->where('p.`id_product` IN ( + SELECT cp.`id_product` + FROM `'._DB_PREFIX_.'category_group` cg + LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`) + WHERE cg.`id_group` '.$sql_groups.' + )'); $sql->groupBy('product_shop.id_product'); $sql->orderBy((isset($order_by_prefix) ? pSQL($order_by_prefix).'.' : '').'`'.pSQL($order_by).'` '.pSQL($order_way)); @@ -2234,77 +2240,80 @@ class ProductCore extends ObjectModel if (!in_array($context->controller->controller_type, array('front', 'modulefront'))) $front = false; - $groups = FrontController::getCurrentCustomerGroups(); - $sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1'); + $sql_groups = ''; + if (Configuration::get('PS_GROUP_FEATURE_ACTIVE')) + { + $groups = FrontController::getCurrentCustomerGroups(); + $sql_groups = 'AND p.`id_product` IN ( + SELECT cp.`id_product` + FROM `'._DB_PREFIX_.'category_group` cg + LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`) + WHERE cg.`id_group` '.(count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1').' + )'; + } if ($count) { - $sql = 'SELECT COUNT(DISTINCT p.`id_product`) AS nb - FROM `'._DB_PREFIX_.'product` p - '.Shop::addSqlAssociation('product', 'p').' - WHERE product_shop.`active` = 1 - AND product_shop.`show_price` = 1 - '.($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').' - '.((!$beginning && !$ending) ? 'AND p.`id_product` IN('.((is_array($tab_id_product) && count($tab_id_product)) ? implode(', ', $tab_id_product) : 0).')' : '').' - AND p.`id_product` IN ( - SELECT cp.`id_product` - FROM `'._DB_PREFIX_.'category_group` cg - LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`) - WHERE cg.`id_group` '.$sql_groups.' - )'; - $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql); - return (int)$result['nb']; + return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' + SELECT COUNT(DISTINCT p.`id_product`) + FROM `'._DB_PREFIX_.'product` p + '.Shop::addSqlAssociation('product', 'p').' + WHERE product_shop.`active` = 1 + AND product_shop.`show_price` = 1 + '.($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').' + '.((!$beginning && !$ending) ? 'AND p.`id_product` IN('.((is_array($tab_id_product) && count($tab_id_product)) ? implode(', ', $tab_id_product) : 0).')' : '').' + '.$sql_groups); } + if (strpos($order_by, '.') > 0) { $order_by = explode('.', $order_by); $order_by = pSQL($order_by[0]).'.`'.pSQL($order_by[1]).'`'; } - $sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pl.`description`, pl.`description_short`, MAX(product_attribute_shop.id_product_attribute) id_product_attribute, - pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, - pl.`name`, MAX(image_shop.`id_image`) id_image, il.`legend`, m.`name` AS manufacturer_name, - DATEDIFF( - p.`date_add`, - DATE_SUB( - NOW(), - INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY - ) - ) > 0 AS new - FROM `'._DB_PREFIX_.'product` p - '.Shop::addSqlAssociation('product', 'p').' - LEFT JOIN '._DB_PREFIX_.'product_attribute pa ON (pa.id_product = p.id_product) - '.Shop::addSqlAssociation('product_attribute', 'pa', false, 'product_attribute_shop.default_on=1').' - '.Product::sqlStock('p', 0, false, $context->shop).' - LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON ( - p.`id_product` = pl.`id_product` - AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').' + + $sql = ' + SELECT + p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pl.`description`, pl.`description_short`, + MAX(product_attribute_shop.id_product_attribute) id_product_attribute, + pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, + pl.`name`, MAX(image_shop.`id_image`) id_image, il.`legend`, m.`name` AS manufacturer_name, + DATEDIFF( + p.`date_add`, + DATE_SUB( + NOW(), + INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY ) - LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product`)'. - Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').' - LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.') - LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`) - WHERE product_shop.`active` = 1 - AND product_shop.`show_price` = 1 - '.($front ? ' AND p.`visibility` IN ("both", "catalog")' : '').' - '.((!$beginning && !$ending) ? ' AND p.`id_product` IN ('.((is_array($tab_id_product) && count($tab_id_product)) ? implode(', ', $tab_id_product) : 0).')' : '').' - AND p.`id_product` IN ( - SELECT cp.`id_product` - FROM `'._DB_PREFIX_.'category_group` cg - LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`) - WHERE cg.`id_group` '.$sql_groups.' - ) - GROUP BY product_shop.id_product - ORDER BY '.(isset($order_by_prefix) ? pSQL($order_by_prefix).'.' : '').pSQL($order_by).' '.pSQL($order_way).' - LIMIT '.(int)($page_number * $nb_products).', '.(int)$nb_products; + ) > 0 AS new + FROM `'._DB_PREFIX_.'product` p + '.Shop::addSqlAssociation('product', 'p').' + LEFT JOIN '._DB_PREFIX_.'product_attribute pa ON (pa.id_product = p.id_product) + '.Shop::addSqlAssociation('product_attribute', 'pa', false, 'product_attribute_shop.default_on=1').' + '.Product::sqlStock('p', 0, false, $context->shop).' + LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON ( + p.`id_product` = pl.`id_product` + AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').' + ) + LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product`)'. + Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').' + LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.') + LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`) + WHERE product_shop.`active` = 1 + AND product_shop.`show_price` = 1 + '.($front ? ' AND p.`visibility` IN ("both", "catalog")' : '').' + '.((!$beginning && !$ending) ? ' AND p.`id_product` IN ('.((is_array($tab_id_product) && count($tab_id_product)) ? implode(', ', $tab_id_product) : 0).')' : '').' + '.$sql_groups.' + GROUP BY product_shop.id_product + ORDER BY '.(isset($order_by_prefix) ? pSQL($order_by_prefix).'.' : '').pSQL($order_by).' '.pSQL($order_way).' + LIMIT '.(int)($page_number * $nb_products).', '.(int)$nb_products; $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); - if ($order_by == 'price') - Tools::orderbyPrice($result, $order_way); - if (!$result) return false; + if ($order_by == 'price') + Tools::orderbyPrice($result, $order_way); + return Product::getProductsProperties($id_lang, $result); } @@ -4333,6 +4342,9 @@ class ProductCore extends ObjectModel public function checkAccess($id_customer) { + if (!Configuration::get('PS_GROUP_FEATURE_ACTIVE')) + return true; + if (!$id_customer) return (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' SELECT ctg.`id_group` diff --git a/classes/ProductSale.php b/classes/ProductSale.php index 1bc24f88e..4df788477 100644 --- a/classes/ProductSale.php +++ b/classes/ProductSale.php @@ -71,16 +71,22 @@ class ProductSaleCore if ($order_by == 'date_add' || $order_by == 'date_upd') $order_table = 'product_shop'; if (is_null($order_way) || $order_by == 'sales') $order_way = 'DESC'; - $groups = FrontController::getCurrentCustomerGroups(); - $sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1'); + + $sql_groups = ''; + if (Configuration::get('PS_GROUP_FEATURE_ACTIVE')) + { + $groups = FrontController::getCurrentCustomerGroups(); + $sql_groups = 'WHERE cg.`id_group` '.(count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1'); + } $interval = Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20; - //Subquery: get product ids in a separate query to (greatly!) improve performances and RAM usage - $sql = 'SELECT cp.`id_product` - FROM `'._DB_PREFIX_.'category_group` cg - LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`) - WHERE cg.`id_group` '.$sql_groups; - $products = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); + // Subquery: get product ids in a separate query to (greatly!) improve performances and RAM usage + $products = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' + SELECT cp.`id_product` + FROM `'._DB_PREFIX_.'category_group` cg + LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`) + '.$sql_groups); + $ids = array(); foreach ($products as $product) $ids[$product['id_product']] = 1; @@ -88,37 +94,38 @@ class ProductSaleCore sort($ids); $ids = count($ids) > 0 ? implode(',', $ids) : 'NULL'; - //Main query + // Main query if ($order_by == 'date_add') - $sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, - pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, - pl.`meta_keywords`, pl.`meta_title`, pl.`name`, - m.`name` AS manufacturer_name, p.`id_manufacturer` as id_manufacturer, - MAX(image_shop.`id_image`) id_image, il.`legend`, - ps.`quantity` AS sales, t.`rate`, pl.`meta_keywords`, pl.`meta_title`, pl.`meta_description`, - DATEDIFF(p.`date_add`, DATE_SUB(NOW(), - INTERVAL '.$interval.' DAY)) > 0 AS new - FROM `'._DB_PREFIX_.'product_sale` ps - LEFT JOIN `'._DB_PREFIX_.'product` p ON ps.`id_product` = p.`id_product` - '.Shop::addSqlAssociation('product', 'p', false).' - LEFT JOIN `'._DB_PREFIX_.'product_lang` pl - ON p.`id_product` = pl.`id_product` - AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').' - LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product`)'. - Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').' - LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.') - LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`) - LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (product_shop.`id_tax_rules_group` = tr.`id_tax_rules_group`) - AND tr.`id_country` = '.(int)Context::getContext()->country->id.' - AND tr.`id_state` = 0 - LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`) - '.Product::sqlStock('p').' - WHERE product_shop.`active` = 1 - AND p.`visibility` != \'none\' - AND p.`id_product` IN ('.$ids.') - GROUP BY product_shop.id_product - ORDER BY '.(!empty($order_table) ? '`'.pSQL($order_table).'`.' : '').'`'.pSQL($order_by).'` '.pSQL($order_way).' - LIMIT '.(int)($page_number * $nb_products).', '.(int)$nb_products; + $sql = ' + SELECT + p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, + pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, + pl.`meta_keywords`, pl.`meta_title`, pl.`name`, + m.`name` AS manufacturer_name, p.`id_manufacturer` as id_manufacturer, + MAX(image_shop.`id_image`) id_image, il.`legend`, + ps.`quantity` AS sales, t.`rate`, pl.`meta_keywords`, pl.`meta_title`, pl.`meta_description`, + DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL '.$interval.' DAY)) > 0 AS new + FROM `'._DB_PREFIX_.'product_sale` ps + LEFT JOIN `'._DB_PREFIX_.'product` p ON ps.`id_product` = p.`id_product` + '.Shop::addSqlAssociation('product', 'p', false).' + LEFT JOIN `'._DB_PREFIX_.'product_lang` pl + ON p.`id_product` = pl.`id_product` + AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').' + LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product`)'. + Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').' + LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.') + LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`) + LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (product_shop.`id_tax_rules_group` = tr.`id_tax_rules_group`) + AND tr.`id_country` = '.(int)Context::getContext()->country->id.' + AND tr.`id_state` = 0 + LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`) + '.Product::sqlStock('p').' + WHERE product_shop.`active` = 1 + AND p.`visibility` != \'none\' + AND p.`id_product` IN ('.$ids.') + GROUP BY product_shop.id_product + ORDER BY '.(!empty($order_table) ? '`'.pSQL($order_table).'`.' : '').'`'.pSQL($order_by).'` '.pSQL($order_way).' + LIMIT '.(int)($page_number * $nb_products).', '.(int)$nb_products; $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); @@ -144,15 +151,20 @@ class ProductSaleCore if ($page_number < 0) $page_number = 0; if ($nb_products < 1) $nb_products = 10; - $groups = FrontController::getCurrentCustomerGroups(); - $sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1'); + $sql_groups = ''; + if (Configuration::get('PS_GROUP_FEATURE_ACTIVE')) + { + $groups = FrontController::getCurrentCustomerGroups(); + $sql_groups = 'AND cg.`id_group` '.(count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1'); + } //Subquery: get product ids in a separate query to (greatly!) improve performances and RAM usage - $sql = 'SELECT cp.`id_product` - FROM `'._DB_PREFIX_.'category_group` cg - LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`) - WHERE cg.`id_group` '.$sql_groups.' AND cp.`id_product` IS NOT NULL'; - $products = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); + $products = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' + SELECT cp.`id_product` + FROM `'._DB_PREFIX_.'category_group` cg + LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`) + WHERE cp.`id_product` IS NOT NULL + '.$sql_groups); $ids = array(); foreach ($products as $product) $ids[$product['id_product']] = 1; @@ -161,31 +173,34 @@ class ProductSaleCore $ids = count($ids) > 0 ? implode(',', $ids) : 'NULL'; //Main query - $sql = 'SELECT p.id_product, MAX(product_attribute_shop.id_product_attribute) id_product_attribute, pl.`link_rewrite`, pl.`name`, pl.`description_short`, MAX(image_shop.`id_image`) id_image, il.`legend`, - ps.`quantity` AS sales, p.`ean13`, p.`upc`, cl.`link_rewrite` AS category, p.show_price, p.available_for_order, IFNULL(stock.quantity, 0) as quantity, p.customizable, - IFNULL(pa.minimal_quantity, p.minimal_quantity) as minimal_quantity, stock.out_of_stock - FROM `'._DB_PREFIX_.'product_sale` ps - LEFT JOIN `'._DB_PREFIX_.'product` p ON ps.`id_product` = p.`id_product` - '.Shop::addSqlAssociation('product', 'p').' - LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa - ON (p.`id_product` = pa.`id_product`) - '.Shop::addSqlAssociation('product_attribute', 'pa', false, 'product_attribute_shop.`default_on` = 1').' - '.Product::sqlStock('p', 'product_attribute_shop', false, $context->shop).' - LEFT JOIN `'._DB_PREFIX_.'product_lang` pl - ON p.`id_product` = pl.`id_product` - AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').' - LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product`)'. - Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').' - LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.') - LEFT JOIN `'._DB_PREFIX_.'category_lang` cl - ON cl.`id_category` = product_shop.`id_category_default` - AND cl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').' - WHERE product_shop.`active` = 1 - AND p.`visibility` != \'none\' - AND p.`id_product` IN ('.$ids.') - GROUP BY product_shop.id_product - ORDER BY sales DESC - LIMIT '.(int)($page_number * $nb_products).', '.(int)$nb_products; + $sql = ' + SELECT + p.id_product, MAX(product_attribute_shop.id_product_attribute) id_product_attribute, pl.`link_rewrite`, pl.`name`, pl.`description_short`, + MAX(image_shop.`id_image`) id_image, il.`legend`, + ps.`quantity` AS sales, p.`ean13`, p.`upc`, cl.`link_rewrite` AS category, p.show_price, p.available_for_order, IFNULL(stock.quantity, 0) as quantity, p.customizable, + IFNULL(pa.minimal_quantity, p.minimal_quantity) as minimal_quantity, stock.out_of_stock + FROM `'._DB_PREFIX_.'product_sale` ps + LEFT JOIN `'._DB_PREFIX_.'product` p ON ps.`id_product` = p.`id_product` + '.Shop::addSqlAssociation('product', 'p').' + LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa + ON (p.`id_product` = pa.`id_product`) + '.Shop::addSqlAssociation('product_attribute', 'pa', false, 'product_attribute_shop.`default_on` = 1').' + '.Product::sqlStock('p', 'product_attribute_shop', false, $context->shop).' + LEFT JOIN `'._DB_PREFIX_.'product_lang` pl + ON p.`id_product` = pl.`id_product` + AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').' + LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product`)'. + Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').' + LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.') + LEFT JOIN `'._DB_PREFIX_.'category_lang` cl + ON cl.`id_category` = product_shop.`id_category_default` + AND cl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').' + WHERE product_shop.`active` = 1 + AND p.`visibility` != \'none\' + AND p.`id_product` IN ('.$ids.') + GROUP BY product_shop.id_product + ORDER BY sales DESC + LIMIT '.(int)($page_number * $nb_products).', '.(int)$nb_products; if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql)) return false; @@ -196,11 +211,11 @@ class ProductSaleCore $row['id_image'] = Product::defineProductImage($row, $id_lang); $row['allow_oosp'] = Product::isAvailableWhenOutOfStock($row['out_of_stock']); $row['price_tax_exc'] = Product::getPriceStatic( - (int)$row['id_product'], - false, - ((isset($row['id_product_attribute']) && !empty($row['id_product_attribute'])) ? (int)$row['id_product_attribute'] : null), - (Product::$_taxCalculationMethod == PS_TAX_EXC ? 2 : 6) - ); + (int)$row['id_product'], + false, + ((isset($row['id_product_attribute']) && !empty($row['id_product_attribute'])) ? (int)$row['id_product_attribute'] : null), + (Product::$_taxCalculationMethod == PS_TAX_EXC ? 2 : 6) + ); } return $result; } diff --git a/controllers/admin/AdminPerformanceController.php b/controllers/admin/AdminPerformanceController.php index 1e4cb39cb..494031e49 100644 --- a/controllers/admin/AdminPerformanceController.php +++ b/controllers/admin/AdminPerformanceController.php @@ -239,12 +239,33 @@ class AdminPerformanceControllerCore extends AdminController ) ), 'hint' => $this->l('These features will be disabled') + ), + array( + 'type' => 'switch', + 'label' => $this->l('Customer Groups'), + 'name' => 'customer_group', + 'is_bool' => true, + 'disabled' => Group::isCurrentlyUsed(), + 'values' => array( + array( + 'id' => 'group_1', + 'value' => 1, + 'label' => $this->l('Yes'), + ), + array( + 'id' => 'group_0', + 'value' => 0, + 'label' => $this->l('No') + ) + ), + 'hint' => $this->l('These features will be disabled') ) ) ); $this->fields_value['combination'] = Combination::isFeatureActive(); $this->fields_value['feature'] = Feature::isFeatureActive(); + $this->fields_value['customer_group'] = Group::isFeatureActive(); } public function initFieldsetCCC() @@ -646,8 +667,10 @@ class AdminPerformanceControllerCore extends AdminController { if ($this->tabAccess['edit'] === '1') { - if (!Combination::isCurrentlyUsed()) + if (Tools::getValue('combination') || !Combination::isCurrentlyUsed()) Configuration::updateValue('PS_COMBINATION_FEATURE_ACTIVE', Tools::getValue('combination')); + if (Tools::getValue('group') || !Group::isCurrentlyUsed()) + Configuration::updateValue('PS_GROUP_FEATURE_ACTIVE', Tools::getValue('group')); Configuration::updateValue('PS_FEATURE_FEATURE_ACTIVE', Tools::getValue('feature')); $redirectAdmin = true; }