[*] FO : Added the possibility to deactivate customer groups management (for performances) [part 2]
This commit is contained in:
+8
-8
@@ -151,19 +151,23 @@ class GroupCore extends ObjectModel
|
||||
|
||||
public function add($autodate = true, $null_values = false)
|
||||
{
|
||||
Configuration::updateGlobalValue('PS_GROUP_FEATURE_ACTIVE', '1');
|
||||
if (parent::add($autodate, $null_values))
|
||||
{
|
||||
Category::setNewGroupForHome((int)$this->id);
|
||||
|
||||
Carrier::assignGroupToAllCarriers((int)$this->id);
|
||||
|
||||
// Set cache of feature detachable to true
|
||||
Configuration::updateGlobalValue('PS_GROUP_FEATURE_ACTIVE', '1');
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function update($autodate = true, $null_values = false)
|
||||
{
|
||||
if (!Configuration::getGlobalValue('PS_GROUP_FEATURE_ACTIVE') && $this->reduction > 0)
|
||||
Configuration::updateGlobalValue('PS_GROUP_FEATURE_ACTIVE', 1);
|
||||
return parent::update($autodate, $null_values);
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
if ($this->id == (int)Configuration::get('PS_CUSTOMER_GROUP'))
|
||||
@@ -177,10 +181,6 @@ class GroupCore extends ObjectModel
|
||||
Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'product_group_reduction_cache` WHERE `id_group` = '.(int)$this->id);
|
||||
$this->truncateModulesRestrictions($this->id);
|
||||
|
||||
// Refresh cache of feature detachable
|
||||
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` (
|
||||
SELECT c.id_customer, '.(int)Configuration::get('PS_CUSTOMER_GROUP').' FROM `'._DB_PREFIX_.'customer` c
|
||||
|
||||
+42
-40
@@ -181,12 +181,6 @@ class SearchCore
|
||||
$context = Context::getContext();
|
||||
$db = Db::getInstance(_PS_USE_SQL_SLAVE_);
|
||||
|
||||
// Only use cookie if id_customer is not present
|
||||
if ($use_cookie)
|
||||
$id_customer = $context->customer->id;
|
||||
else
|
||||
$id_customer = 0;
|
||||
|
||||
// TODO : smart page management
|
||||
if ($page_number < 1) $page_number = 1;
|
||||
if ($page_size < 1) $page_size = 1;
|
||||
@@ -235,21 +229,25 @@ class SearchCore
|
||||
AND ('.implode(' OR ', $score_array).')
|
||||
) position';
|
||||
|
||||
$sql = 'SELECT cp.`id_product`
|
||||
FROM `'._DB_PREFIX_.'category_group` cg
|
||||
INNER JOIN `'._DB_PREFIX_.'category_product` cp ON cp.`id_category` = cg.`id_category`
|
||||
INNER JOIN `'._DB_PREFIX_.'category` c ON cp.`id_category` = c.`id_category`
|
||||
INNER JOIN `'._DB_PREFIX_.'product` p ON cp.`id_product` = p.`id_product`
|
||||
'.Shop::addSqlAssociation('product', 'p', false).'
|
||||
WHERE c.`active` = 1
|
||||
AND product_shop.`active` = 1
|
||||
AND product_shop.`visibility` IN ("both", "search")
|
||||
AND product_shop.indexed = 1
|
||||
AND cg.`id_group` '.(!$id_customer ? '= '.(int)Configuration::get('PS_UNIDENTIFIED_GROUP') : 'IN (
|
||||
SELECT id_group FROM '._DB_PREFIX_.'customer_group
|
||||
WHERE id_customer = '.(int)$id_customer.'
|
||||
)');
|
||||
$results = $db->executeS($sql);
|
||||
$sql_groups = '';
|
||||
if (Configuration::get('PS_GROUP_FEATURE_ACTIVE'))
|
||||
{
|
||||
$groups = FrontController::getCurrentCustomerGroups();
|
||||
$sql_groups = 'AND cg.`id_group` '.(count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1');
|
||||
}
|
||||
|
||||
$results = $db->executeS('
|
||||
SELECT cp.`id_product`
|
||||
FROM `'._DB_PREFIX_.'category_product` cp
|
||||
'.(Configuration::get('PS_GROUP_FEATURE_ACTIVE') ? 'INNER JOIN `'._DB_PREFIX_.'category_group` cg ON cp.`id_category` = cg.`id_category`' : '').'
|
||||
INNER JOIN `'._DB_PREFIX_.'category` c ON cp.`id_category` = c.`id_category`
|
||||
INNER JOIN `'._DB_PREFIX_.'product` p ON cp.`id_product` = p.`id_product`
|
||||
'.Shop::addSqlAssociation('product', 'p', false).'
|
||||
WHERE c.`active` = 1
|
||||
AND product_shop.`active` = 1
|
||||
AND product_shop.`visibility` IN ("both", "search")
|
||||
AND product_shop.indexed = 1
|
||||
'.$sql_groups);
|
||||
|
||||
$eligible_products = array();
|
||||
foreach ($results as $row)
|
||||
@@ -641,23 +639,29 @@ class SearchCore
|
||||
|
||||
$id = Context::getContext()->shop->id;
|
||||
$id_shop = $id ? $id : Configuration::get('PS_SHOP_DEFAULT');
|
||||
|
||||
$sql_groups = '';
|
||||
if (Configuration::get('PS_GROUP_FEATURE_ACTIVE'))
|
||||
{
|
||||
$groups = FrontController::getCurrentCustomerGroups();
|
||||
$sql_groups = 'AND cg.`id_group` '.(count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1');
|
||||
}
|
||||
|
||||
if ($count)
|
||||
{
|
||||
$sql = 'SELECT COUNT(DISTINCT pt.`id_product`) nb
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
'.Shop::addSqlAssociation('product', 'p').'
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_tag` pt ON (p.`id_product` = pt.`id_product`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tag` t ON (pt.`id_tag` = t.`id_tag` AND t.`id_lang` = '.(int)$id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_product` = p.`id_product`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_shop` cs ON (cp.`id_category` = cs.`id_category` AND cs.`id_shop` = '.(int)$id_shop.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = cp.`id_category`)
|
||||
WHERE product_shop.`active` = 1
|
||||
AND cs.`id_shop` = '.(int)Context::getContext()->shop->id.'
|
||||
AND cg.`id_group` '.(!$id_customer ? '= '.(int)Configuration::get('PS_UNIDENTIFIED_GROUP') : 'IN (
|
||||
SELECT id_group FROM '._DB_PREFIX_.'customer_group
|
||||
WHERE id_customer = '.(int)$id_customer.')').'
|
||||
AND t.`name` LIKE \'%'.pSQL($tag).'%\'';
|
||||
return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
|
||||
return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(
|
||||
'SELECT COUNT(DISTINCT pt.`id_product`) nb
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
'.Shop::addSqlAssociation('product', 'p').'
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_tag` pt ON (p.`id_product` = pt.`id_product`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tag` t ON (pt.`id_tag` = t.`id_tag` AND t.`id_lang` = '.(int)$id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_product` = p.`id_product`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_shop` cs ON (cp.`id_category` = cs.`id_category` AND cs.`id_shop` = '.(int)$id_shop.')
|
||||
'.(Configuration::get('PS_GROUP_FEATURE_ACTIVE') ? 'LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = cp.`id_category`)' : '').'
|
||||
WHERE product_shop.`active` = 1
|
||||
AND cs.`id_shop` = '.(int)Context::getContext()->shop->id.'
|
||||
'.$sql_groups.'
|
||||
AND t.`name` LIKE \'%'.pSQL($tag).'%\'');
|
||||
}
|
||||
|
||||
$sql = 'SELECT DISTINCT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pl.`description_short`, pl.`link_rewrite`, pl.`name`,
|
||||
@@ -682,14 +686,12 @@ class SearchCore
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_tag` pt ON (p.`id_product` = pt.`id_product`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tag` t ON (pt.`id_tag` = t.`id_tag` AND t.`id_lang` = '.(int)$id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_product` = p.`id_product`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = cp.`id_category`)
|
||||
'.(Configuration::get('PS_GROUP_FEATURE_ACTIVE') ? 'LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = cp.`id_category`)' : '').'
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_shop` cs ON (cg.`id_category` = cs.`id_category` AND cs.`id_shop` = '.(int)$id_shop.')
|
||||
'.Product::sqlStock('p', 0).'
|
||||
WHERE product_shop.`active` = 1
|
||||
AND cs.`id_shop` = '.(int)Context::getContext()->shop->id.'
|
||||
AND cg.`id_group` '.(!$id_customer ? '= '.(int)Configuration::get('PS_UNIDENTIFIED_GROUP') : 'IN (
|
||||
SELECT id_group FROM '._DB_PREFIX_.'customer_group
|
||||
WHERE id_customer = '.(int)$id_customer.')').'
|
||||
'.$sql_groups.'
|
||||
AND t.`name` LIKE \'%'.pSQL($tag).'%\'
|
||||
GROUP BY product_shop.id_product
|
||||
ORDER BY position DESC'.($orderBy ? ', '.$orderBy : '').($orderWay ? ' '.$orderWay : '').'
|
||||
|
||||
+31
-28
@@ -107,6 +107,8 @@ class SupplierCore extends ObjectModel
|
||||
{
|
||||
if (!$id_lang)
|
||||
$id_lang = Configuration::get('PS_LANG_DEFAULT');
|
||||
if (!Configuration::get('PS_GROUP_FEATURE_ACTIVE'))
|
||||
$all_groups = true;
|
||||
|
||||
$query = new DbQuery();
|
||||
$query->select('s.*, sl.`description`');
|
||||
@@ -130,6 +132,7 @@ class SupplierCore extends ObjectModel
|
||||
$groups = FrontController::getCurrentCustomerGroups();
|
||||
$sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1');
|
||||
}
|
||||
|
||||
foreach ($suppliers as $key => $supplier)
|
||||
{
|
||||
$sql = '
|
||||
@@ -206,31 +209,31 @@ class SupplierCore 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 = 'WHERE cg.`id_group` '.(count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1');
|
||||
}
|
||||
|
||||
/* Return only the number of products */
|
||||
if ($get_total)
|
||||
{
|
||||
$sql = '
|
||||
SELECT DISTINCT(ps.`id_product`)
|
||||
FROM `'._DB_PREFIX_.'product_supplier` ps
|
||||
JOIN `'._DB_PREFIX_.'product` p ON (ps.`id_product`= p.`id_product`)
|
||||
'.Shop::addSqlAssociation('product', 'p').'
|
||||
WHERE ps.`id_supplier` = '.(int)$id_supplier.'
|
||||
AND ps.id_product_attribute = 0'.
|
||||
($active ? ' AND product_shop.`active` = 1' : '').'
|
||||
'.($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`)'.
|
||||
($active_category ? ' INNER JOIN `'._DB_PREFIX_.'category` ca ON cp.`id_category` = ca.`id_category` AND ca.`active` = 1' : '').'
|
||||
WHERE cg.`id_group` '.$sql_groups.'
|
||||
)';
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
||||
return (int)count($result);
|
||||
}
|
||||
return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT COUNT(DISTINCT ps.`id_product`)
|
||||
FROM `'._DB_PREFIX_.'product_supplier` ps
|
||||
JOIN `'._DB_PREFIX_.'product` p ON (ps.`id_product`= p.`id_product`)
|
||||
'.Shop::addSqlAssociation('product', 'p').'
|
||||
WHERE ps.`id_supplier` = '.(int)$id_supplier.'
|
||||
AND ps.id_product_attribute = 0
|
||||
'.($active ? ' AND product_shop.`active` = 1' : '').'
|
||||
'.($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').'
|
||||
AND p.`id_product` IN (
|
||||
SELECT cp.`id_product`
|
||||
FROM `'._DB_PREFIX_.'category_product` cp
|
||||
'.(Configuration::get('PS_GROUP_FEATURE_ACTIVE') ? 'LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cp.`id_category` = cg.`id_category`)' : '').'
|
||||
'.($active_category ? ' INNER JOIN `'._DB_PREFIX_.'category` ca ON cp.`id_category` = ca.`id_category` AND ca.`active` = 1' : '').'
|
||||
'.$sql_groups.'
|
||||
)');
|
||||
|
||||
$nb_days_new_product = Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20;
|
||||
|
||||
@@ -277,15 +280,15 @@ class SupplierCore extends ObjectModel
|
||||
LEFT JOIN `'._DB_PREFIX_.'supplier` s ON s.`id_supplier` = p.`id_supplier`
|
||||
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer`
|
||||
'.Product::sqlStock('p').'
|
||||
WHERE ps.`id_supplier` = '.(int)$id_supplier.
|
||||
($active ? ' AND product_shop.`active` = 1' : '').'
|
||||
WHERE ps.`id_supplier` = '.(int)$id_supplier.'
|
||||
'.($active ? ' AND product_shop.`active` = 1' : '').'
|
||||
'.($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`)'.
|
||||
($active_category ? ' INNER JOIN `'._DB_PREFIX_.'category` ca ON cp.`id_category` = ca.`id_category` AND ca.`active` = 1' : '').'
|
||||
WHERE cg.`id_group` '.$sql_groups.'
|
||||
FROM `'._DB_PREFIX_.'category_product` cp
|
||||
'.(Configuration::get('PS_GROUP_FEATURE_ACTIVE') ? 'LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cp.`id_category` = cg.`id_category`)' : '').'
|
||||
'.($active_category ? ' INNER JOIN `'._DB_PREFIX_.'category` ca ON cp.`id_category` = ca.`id_category` AND ca.`active` = 1' : '').'
|
||||
'.$sql_groups.'
|
||||
)
|
||||
GROUP BY product_shop.id_product
|
||||
ORDER BY '.$alias.pSQL($order_by).' '.pSQL($order_way).'
|
||||
|
||||
+14
-9
@@ -130,8 +130,18 @@ class TagCore extends ObjectModel
|
||||
|
||||
public static function getMainTags($id_lang, $nb = 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 p.`id_product` IN (
|
||||
SELECT cp.`id_product`
|
||||
FROM `'._DB_PREFIX_.'category_product` cp
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cp.`id_category` = cg.`id_category`)
|
||||
WHERE cg.`id_group` '.(count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1').'
|
||||
)';
|
||||
}
|
||||
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||
SELECT t.name, COUNT(pt.id_tag) AS times
|
||||
@@ -141,15 +151,10 @@ class TagCore extends ObjectModel
|
||||
'.Shop::addSqlAssociation('product', 'p').'
|
||||
WHERE t.`id_lang` = '.(int)$id_lang.'
|
||||
AND product_shop.`active` = 1
|
||||
AND product_shop.`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.'
|
||||
GROUP BY t.id_tag
|
||||
ORDER BY times DESC
|
||||
LIMIT 0, '.(int)$nb);
|
||||
LIMIT '.(int)$nb);
|
||||
}
|
||||
|
||||
public static function getProductTags($id_product)
|
||||
|
||||
@@ -484,8 +484,10 @@ class AdminGroupsControllerCore extends AdminController
|
||||
DELETE FROM `'._DB_PREFIX_.'product_group_reduction_cache`
|
||||
WHERE `id_group` = '.(int)Tools::getValue('id_group')
|
||||
);
|
||||
if (is_array($category_reduction))
|
||||
if (is_array($category_reduction) && count($category_reduction))
|
||||
{
|
||||
if (!Configuration::getGlobalValue('PS_GROUP_FEATURE_ACTIVE'))
|
||||
Configuration::updateGlobalValue('PS_GROUP_FEATURE_ACTIVE', 1);
|
||||
foreach ($category_reduction as $cat => $reduction)
|
||||
{
|
||||
if (!Validate::isUnsignedId($cat) || !$this->validateDiscount($reduction))
|
||||
|
||||
Reference in New Issue
Block a user