[*] FO : Added the possibility to deactivate customer groups management (for performances) [part 1]

This commit is contained in:
Damien Metzger
2013-11-21 12:32:51 +01:00
parent 794f729c5d
commit 9f1c39a7d6
8 changed files with 227 additions and 178 deletions
@@ -198,7 +198,7 @@
$('#smarty_up').val(1); $('#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'); $('#features_detachables_up').val('true');
}); });
+19 -20
View File
@@ -547,31 +547,30 @@ class CategoryCore extends ObjectModel
*/ */
public function getSubCategories($id_lang, $active = true) public function getSubCategories($id_lang, $active = true)
{ {
if (!Validate::isBool($active)) $sql_groups_where = '';
die(Tools::displayError()); $sql_groups_join = '';
if (Configuration::get('PS_GROUP_FEATURE_ACTIVE'))
$groups = FrontController::getCurrentCustomerGroups(); {
$sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '='.(int)Group::getCurrent()->id); $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(' $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 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 FROM `'._DB_PREFIX_.'category` c
'.Shop::addSqlAssociation('category', 'c').' '.Shop::addSqlAssociation('category', 'c').'
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = '.(int)$id_lang.' '.Shop::addSqlRestrictionOnLang('cl').')
ON (c.`id_category` = cl.`id_category` '.$sql_groups_join.'
AND `id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').') WHERE `id_parent` = '.(int)$this->id.'
LEFT JOIN `'._DB_PREFIX_.'category_group` cg '.($active ? 'AND `active` = 1' : '').'
ON (cg.`id_category` = c.`id_category`) '.$sql_groups_where.'
WHERE `id_parent` = '.(int)$this->id.' GROUP BY c.`id_category`
'.($active ? 'AND `active` = 1' : '').' ORDER BY `level_depth` ASC, category_shop.`position` ASC');
AND cg.`id_group` '.$sql_groups.'
GROUP BY c.`id_category`
ORDER BY `level_depth` ASC, category_shop.`position` ASC
');
foreach ($result as &$row) 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'; $row['legend'] = 'no picture';
} }
return $result; return $result;
+4 -8
View File
@@ -178,7 +178,8 @@ class GroupCore extends ObjectModel
$this->truncateModulesRestrictions($this->id); $this->truncateModulesRestrictions($this->id);
// Refresh cache of feature detachable // 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 // Add default group (id 3) to customers without groups
Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'customer_group` ( 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 * @since 1.5.0.1
* @param $table * @param $table
* @param $has_active_column * @param $has_active_column
@@ -221,12 +222,7 @@ class GroupCore extends ObjectModel
*/ */
public static function isCurrentlyUsed($table = null, $has_active_column = false) 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 COUNT(*) FROM `'._DB_PREFIX_.'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').'
');
} }
/** /**
+3
View File
@@ -132,6 +132,9 @@ class GroupReductionCore extends ObjectModel
public static function getValueForProduct($id_product, $id_group) 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])) if (!isset(self::$reduction_cache[$id_product.'-'.$id_group]))
self::$reduction_cache[$id_product.'-'.$id_group] = Db::getInstance()->getValue(' self::$reduction_cache[$id_product.'-'.$id_group] = Db::getInstance()->getValue('
SELECT `reduction` SELECT `reduction`
+3 -2
View File
@@ -155,11 +155,12 @@ class ManufacturerCore extends ObjectModel
* @param boolean $get_nb_products [optional] return products numbers for each * @param boolean $get_nb_products [optional] return products numbers for each
* @return array Manufacturers * @return array Manufacturers
*/ */
public static function getManufacturers($get_nb_products = false, $id_lang = 0, $active = true, $p = false, public static function getManufacturers($get_nb_products = false, $id_lang = 0, $active = true, $p = false, $n = false, $all_group = false)
$n = false, $all_group = false)
{ {
if (!$id_lang) if (!$id_lang)
$id_lang = (int)Configuration::get('PS_LANG_DEFAULT'); $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` $sql = 'SELECT m.*, ml.`description`, ml.`short_description`
FROM `'._DB_PREFIX_.'manufacturer` m FROM `'._DB_PREFIX_.'manufacturer` m
+83 -71
View File
@@ -1988,8 +1988,7 @@ class ProductCore extends ObjectModel
* @param integer $nbProducts Number of products to return (optional) * @param integer $nbProducts Number of products to return (optional)
* @return array New products * @return array New products
*/ */
public static function getNewProducts($id_lang, $page_number = 0, $nb_products = 10, public static function getNewProducts($id_lang, $page_number = 0, $nb_products = 10, $count = false, $order_by = null, $order_way = null, Context $context = null)
$count = false, $order_by = null, $order_way = null, Context $context = null)
{ {
if (!$context) if (!$context)
$context = Context::getContext(); $context = Context::getContext();
@@ -2009,14 +2008,25 @@ class ProductCore extends ObjectModel
if (!Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way)) if (!Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way))
die(Tools::displayError()); die(Tools::displayError());
$groups = FrontController::getCurrentCustomerGroups(); $sql_groups = '';
$sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1'); 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) if (strpos($order_by, '.') > 0)
{ {
$order_by = explode('.', $order_by); $order_by = explode('.', $order_by);
$order_by_prefix = $order_by[0]; $order_by_prefix = $order_by[0];
$order_by = $order_by[1]; $order_by = $order_by[1];
} }
if ($count) if ($count)
{ {
$sql = 'SELECT COUNT(p.`id_product`) AS nb $sql = 'SELECT COUNT(p.`id_product`) AS nb
@@ -2025,12 +2035,7 @@ class ProductCore extends ObjectModel
WHERE product_shop.`active` = 1 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')).'" 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")' : '').' '.($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').'
AND p.`id_product` IN ( '.$sql_groups;
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.'
)';
return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql); return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
} }
@@ -2056,12 +2061,13 @@ class ProductCore extends ObjectModel
if ($front) if ($front)
$sql->where('product_shop.`visibility` IN ("both", "catalog")'); $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('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 ( if (Configuration::get('PS_GROUP_FEATURE_ACTIVE'))
SELECT cp.`id_product` $sql->where('p.`id_product` IN (
FROM `'._DB_PREFIX_.'category_group` cg SELECT cp.`id_product`
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`) FROM `'._DB_PREFIX_.'category_group` cg
WHERE cg.`id_group` '.$sql_groups.' 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->groupBy('product_shop.id_product');
$sql->orderBy((isset($order_by_prefix) ? pSQL($order_by_prefix).'.' : '').'`'.pSQL($order_by).'` '.pSQL($order_way)); $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'))) if (!in_array($context->controller->controller_type, array('front', 'modulefront')))
$front = false; $front = false;
$groups = FrontController::getCurrentCustomerGroups(); $sql_groups = '';
$sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1'); 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) if ($count)
{ {
$sql = 'SELECT COUNT(DISTINCT p.`id_product`) AS nb return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
FROM `'._DB_PREFIX_.'product` p SELECT COUNT(DISTINCT p.`id_product`)
'.Shop::addSqlAssociation('product', 'p').' FROM `'._DB_PREFIX_.'product` p
WHERE product_shop.`active` = 1 '.Shop::addSqlAssociation('product', 'p').'
AND product_shop.`show_price` = 1 WHERE product_shop.`active` = 1
'.($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').' AND product_shop.`show_price` = 1
'.((!$beginning && !$ending) ? 'AND p.`id_product` IN('.((is_array($tab_id_product) && count($tab_id_product)) ? implode(', ', $tab_id_product) : 0).')' : '').' '.($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').'
AND p.`id_product` IN ( '.((!$beginning && !$ending) ? 'AND p.`id_product` IN('.((is_array($tab_id_product) && count($tab_id_product)) ? implode(', ', $tab_id_product) : 0).')' : '').'
SELECT cp.`id_product` '.$sql_groups);
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'];
} }
if (strpos($order_by, '.') > 0) if (strpos($order_by, '.') > 0)
{ {
$order_by = explode('.', $order_by); $order_by = explode('.', $order_by);
$order_by = pSQL($order_by[0]).'.`'.pSQL($order_by[1]).'`'; $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`, $sql = '
pl.`name`, MAX(image_shop.`id_image`) id_image, il.`legend`, m.`name` AS manufacturer_name, SELECT
DATEDIFF( p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pl.`description`, pl.`description_short`,
p.`date_add`, MAX(product_attribute_shop.id_product_attribute) id_product_attribute,
DATE_SUB( pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`,
NOW(), pl.`name`, MAX(image_shop.`id_image`) id_image, il.`legend`, m.`name` AS manufacturer_name,
INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY DATEDIFF(
) p.`date_add`,
) > 0 AS new DATE_SUB(
FROM `'._DB_PREFIX_.'product` p NOW(),
'.Shop::addSqlAssociation('product', 'p').' INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY
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`)'. ) > 0 AS new
Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').' FROM `'._DB_PREFIX_.'product` p
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.') '.Shop::addSqlAssociation('product', 'p').'
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`) LEFT JOIN '._DB_PREFIX_.'product_attribute pa ON (pa.id_product = p.id_product)
WHERE product_shop.`active` = 1 '.Shop::addSqlAssociation('product_attribute', 'pa', false, 'product_attribute_shop.default_on=1').'
AND product_shop.`show_price` = 1 '.Product::sqlStock('p', 0, false, $context->shop).'
'.($front ? ' AND p.`visibility` IN ("both", "catalog")' : '').' LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (
'.((!$beginning && !$ending) ? ' AND p.`id_product` IN ('.((is_array($tab_id_product) && count($tab_id_product)) ? implode(', ', $tab_id_product) : 0).')' : '').' p.`id_product` = pl.`id_product`
AND p.`id_product` IN ( AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').'
SELECT cp.`id_product` )
FROM `'._DB_PREFIX_.'category_group` cg LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product`)'.
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`) Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').'
WHERE cg.`id_group` '.$sql_groups.' 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`)
GROUP BY product_shop.id_product WHERE product_shop.`active` = 1
ORDER BY '.(isset($order_by_prefix) ? pSQL($order_by_prefix).'.' : '').pSQL($order_by).' '.pSQL($order_way).' AND product_shop.`show_price` = 1
LIMIT '.(int)($page_number * $nb_products).', '.(int)$nb_products; '.($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); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
if ($order_by == 'price')
Tools::orderbyPrice($result, $order_way);
if (!$result) if (!$result)
return false; return false;
if ($order_by == 'price')
Tools::orderbyPrice($result, $order_way);
return Product::getProductsProperties($id_lang, $result); return Product::getProductsProperties($id_lang, $result);
} }
@@ -4333,6 +4342,9 @@ class ProductCore extends ObjectModel
public function checkAccess($id_customer) public function checkAccess($id_customer)
{ {
if (!Configuration::get('PS_GROUP_FEATURE_ACTIVE'))
return true;
if (!$id_customer) if (!$id_customer)
return (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' return (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
SELECT ctg.`id_group` SELECT ctg.`id_group`
+90 -75
View File
@@ -71,16 +71,22 @@ class ProductSaleCore
if ($order_by == 'date_add' || $order_by == 'date_upd') if ($order_by == 'date_add' || $order_by == 'date_upd')
$order_table = 'product_shop'; $order_table = 'product_shop';
if (is_null($order_way) || $order_by == 'sales') $order_way = 'DESC'; 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; $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 // Subquery: get product ids in a separate query to (greatly!) improve performances and RAM usage
$sql = 'SELECT cp.`id_product` $products = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
FROM `'._DB_PREFIX_.'category_group` cg SELECT cp.`id_product`
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`) FROM `'._DB_PREFIX_.'category_group` cg
WHERE cg.`id_group` '.$sql_groups; LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)
$products = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); '.$sql_groups);
$ids = array(); $ids = array();
foreach ($products as $product) foreach ($products as $product)
$ids[$product['id_product']] = 1; $ids[$product['id_product']] = 1;
@@ -88,37 +94,38 @@ class ProductSaleCore
sort($ids); sort($ids);
$ids = count($ids) > 0 ? implode(',', $ids) : 'NULL'; $ids = count($ids) > 0 ? implode(',', $ids) : 'NULL';
//Main query // Main query
if ($order_by == 'date_add') if ($order_by == 'date_add')
$sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, $sql = '
pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, SELECT
pl.`meta_keywords`, pl.`meta_title`, pl.`name`, p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity,
m.`name` AS manufacturer_name, p.`id_manufacturer` as id_manufacturer, pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`,
MAX(image_shop.`id_image`) id_image, il.`legend`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`,
ps.`quantity` AS sales, t.`rate`, pl.`meta_keywords`, pl.`meta_title`, pl.`meta_description`, m.`name` AS manufacturer_name, p.`id_manufacturer` as id_manufacturer,
DATEDIFF(p.`date_add`, DATE_SUB(NOW(), MAX(image_shop.`id_image`) id_image, il.`legend`,
INTERVAL '.$interval.' DAY)) > 0 AS new ps.`quantity` AS sales, t.`rate`, pl.`meta_keywords`, pl.`meta_title`, pl.`meta_description`,
FROM `'._DB_PREFIX_.'product_sale` ps DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL '.$interval.' DAY)) > 0 AS new
LEFT JOIN `'._DB_PREFIX_.'product` p ON ps.`id_product` = p.`id_product` FROM `'._DB_PREFIX_.'product_sale` ps
'.Shop::addSqlAssociation('product', 'p', false).' LEFT JOIN `'._DB_PREFIX_.'product` p ON ps.`id_product` = p.`id_product`
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl '.Shop::addSqlAssociation('product', 'p', false).'
ON p.`id_product` = pl.`id_product` LEFT JOIN `'._DB_PREFIX_.'product_lang` pl
AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').' ON p.`id_product` = pl.`id_product`
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product`)'. AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').'
Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').' LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product`)'.
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.') Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').'
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`) 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_.'tax_rule` tr ON (product_shop.`id_tax_rules_group` = tr.`id_tax_rules_group`) LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)
AND tr.`id_country` = '.(int)Context::getContext()->country->id.' LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (product_shop.`id_tax_rules_group` = tr.`id_tax_rules_group`)
AND tr.`id_state` = 0 AND tr.`id_country` = '.(int)Context::getContext()->country->id.'
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`) AND tr.`id_state` = 0
'.Product::sqlStock('p').' LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)
WHERE product_shop.`active` = 1 '.Product::sqlStock('p').'
AND p.`visibility` != \'none\' WHERE product_shop.`active` = 1
AND p.`id_product` IN ('.$ids.') AND p.`visibility` != \'none\'
GROUP BY product_shop.id_product AND p.`id_product` IN ('.$ids.')
ORDER BY '.(!empty($order_table) ? '`'.pSQL($order_table).'`.' : '').'`'.pSQL($order_by).'` '.pSQL($order_way).' GROUP BY product_shop.id_product
LIMIT '.(int)($page_number * $nb_products).', '.(int)$nb_products; 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); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
@@ -144,15 +151,20 @@ class ProductSaleCore
if ($page_number < 0) $page_number = 0; if ($page_number < 0) $page_number = 0;
if ($nb_products < 1) $nb_products = 10; if ($nb_products < 1) $nb_products = 10;
$groups = FrontController::getCurrentCustomerGroups(); $sql_groups = '';
$sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1'); 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 //Subquery: get product ids in a separate query to (greatly!) improve performances and RAM usage
$sql = 'SELECT cp.`id_product` $products = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
FROM `'._DB_PREFIX_.'category_group` cg SELECT cp.`id_product`
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`) FROM `'._DB_PREFIX_.'category_group` cg
WHERE cg.`id_group` '.$sql_groups.' AND cp.`id_product` IS NOT NULL'; LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)
$products = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); WHERE cp.`id_product` IS NOT NULL
'.$sql_groups);
$ids = array(); $ids = array();
foreach ($products as $product) foreach ($products as $product)
$ids[$product['id_product']] = 1; $ids[$product['id_product']] = 1;
@@ -161,31 +173,34 @@ class ProductSaleCore
$ids = count($ids) > 0 ? implode(',', $ids) : 'NULL'; $ids = count($ids) > 0 ? implode(',', $ids) : 'NULL';
//Main query //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`, $sql = '
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, SELECT
IFNULL(pa.minimal_quantity, p.minimal_quantity) as minimal_quantity, stock.out_of_stock p.id_product, MAX(product_attribute_shop.id_product_attribute) id_product_attribute, pl.`link_rewrite`, pl.`name`, pl.`description_short`,
FROM `'._DB_PREFIX_.'product_sale` ps MAX(image_shop.`id_image`) id_image, il.`legend`,
LEFT JOIN `'._DB_PREFIX_.'product` p ON ps.`id_product` = p.`id_product` 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,
'.Shop::addSqlAssociation('product', 'p').' IFNULL(pa.minimal_quantity, p.minimal_quantity) as minimal_quantity, stock.out_of_stock
LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa FROM `'._DB_PREFIX_.'product_sale` ps
ON (p.`id_product` = pa.`id_product`) LEFT JOIN `'._DB_PREFIX_.'product` p ON ps.`id_product` = p.`id_product`
'.Shop::addSqlAssociation('product_attribute', 'pa', false, 'product_attribute_shop.`default_on` = 1').' '.Shop::addSqlAssociation('product', 'p').'
'.Product::sqlStock('p', 'product_attribute_shop', false, $context->shop).' LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pa.`id_product`)
ON p.`id_product` = pl.`id_product` '.Shop::addSqlAssociation('product_attribute', 'pa', false, 'product_attribute_shop.`default_on` = 1').'
AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').' '.Product::sqlStock('p', 'product_attribute_shop', false, $context->shop).'
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product`)'. LEFT JOIN `'._DB_PREFIX_.'product_lang` pl
Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').' ON p.`id_product` = pl.`id_product`
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.') AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').'
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product`)'.
ON cl.`id_category` = product_shop.`id_category_default` Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').'
AND cl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').' LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
WHERE product_shop.`active` = 1 LEFT JOIN `'._DB_PREFIX_.'category_lang` cl
AND p.`visibility` != \'none\' ON cl.`id_category` = product_shop.`id_category_default`
AND p.`id_product` IN ('.$ids.') AND cl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').'
GROUP BY product_shop.id_product WHERE product_shop.`active` = 1
ORDER BY sales DESC AND p.`visibility` != \'none\'
LIMIT '.(int)($page_number * $nb_products).', '.(int)$nb_products; 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)) if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql))
return false; return false;
@@ -196,11 +211,11 @@ class ProductSaleCore
$row['id_image'] = Product::defineProductImage($row, $id_lang); $row['id_image'] = Product::defineProductImage($row, $id_lang);
$row['allow_oosp'] = Product::isAvailableWhenOutOfStock($row['out_of_stock']); $row['allow_oosp'] = Product::isAvailableWhenOutOfStock($row['out_of_stock']);
$row['price_tax_exc'] = Product::getPriceStatic( $row['price_tax_exc'] = Product::getPriceStatic(
(int)$row['id_product'], (int)$row['id_product'],
false, false,
((isset($row['id_product_attribute']) && !empty($row['id_product_attribute'])) ? (int)$row['id_product_attribute'] : null), ((isset($row['id_product_attribute']) && !empty($row['id_product_attribute'])) ? (int)$row['id_product_attribute'] : null),
(Product::$_taxCalculationMethod == PS_TAX_EXC ? 2 : 6) (Product::$_taxCalculationMethod == PS_TAX_EXC ? 2 : 6)
); );
} }
return $result; return $result;
} }
@@ -239,12 +239,33 @@ class AdminPerformanceControllerCore extends AdminController
) )
), ),
'hint' => $this->l('These features will be disabled') '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['combination'] = Combination::isFeatureActive();
$this->fields_value['feature'] = Feature::isFeatureActive(); $this->fields_value['feature'] = Feature::isFeatureActive();
$this->fields_value['customer_group'] = Group::isFeatureActive();
} }
public function initFieldsetCCC() public function initFieldsetCCC()
@@ -646,8 +667,10 @@ class AdminPerformanceControllerCore extends AdminController
{ {
if ($this->tabAccess['edit'] === '1') if ($this->tabAccess['edit'] === '1')
{ {
if (!Combination::isCurrentlyUsed()) if (Tools::getValue('combination') || !Combination::isCurrentlyUsed())
Configuration::updateValue('PS_COMBINATION_FEATURE_ACTIVE', Tools::getValue('combination')); 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')); Configuration::updateValue('PS_FEATURE_FEATURE_ACTIVE', Tools::getValue('feature'));
$redirectAdmin = true; $redirectAdmin = true;
} }