// Multishop optimizations

This commit is contained in:
dMetzger
2012-08-22 16:17:13 +00:00
parent d6079f42ff
commit 12111a4ee3
6 changed files with 60 additions and 50 deletions
+19 -22
View File
@@ -1289,8 +1289,11 @@ abstract class ModuleCore
if (isset($context->cart))
$billing = new Address((int)$context->cart->id_address_invoice);
$frontend = true;
$groups = array();
if (isset($context->customer))
if (isset($context->employee))
$frontend = false;
elseif (isset($context->customer))
{
$groups = $context->customer->getGroups();
if (empty($groups))
@@ -1302,27 +1305,21 @@ abstract class ModuleCore
$hookPayment = 'displayPayment';
$list = Shop::getContextListShopID();
$sql = 'SELECT DISTINCT h.`id_hook`, m.`name`, hm.`position`
FROM `'._DB_PREFIX_.'module_country` mc
LEFT JOIN `'._DB_PREFIX_.'module` m ON m.`id_module` = mc.`id_module`
INNER JOIN `'._DB_PREFIX_.'module_group` mg ON (m.`id_module` = mg.`id_module`)
'.(isset($context->customer)
? 'INNER JOIN `'._DB_PREFIX_.'customer_group` cg on (cg.`id_group` = mg.`id_group`AND cg.`id_customer` = '.(int)$context->customer->id.')'
: '').'
LEFT JOIN `'._DB_PREFIX_.'hook_module` hm ON hm.`id_module` = m.`id_module`
LEFT JOIN `'._DB_PREFIX_.'hook` h ON hm.`id_hook` = h.`id_hook`
WHERE h.`name` = \''.pSQL($hookPayment).'\'
'.(isset($billing) ? 'AND mc.id_country = '.(int)$billing->id_country : '').'
AND mc.id_shop = '.(int)$context->shop->id.'
AND mg.id_shop = '.(int)$context->shop->id.'
AND (SELECT COUNT(*) FROM '._DB_PREFIX_.'module_shop ms WHERE ms.id_module = m.id_module AND ms.id_shop IN('.implode(', ', $list).')) = '.count($list).'
AND hm.id_shop IN('.implode(', ', $list).')
'.(count($groups) ? 'AND (mg.`id_group` IN('.implode(', ', $groups).'))' : '').'
GROUP BY hm.id_hook, hm.id_module
ORDER BY hm.`position`, m.`name` DESC';
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
return $result;
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT DISTINCT h.`id_hook`, m.`name`, hm.`position`
FROM `'._DB_PREFIX_.'module` m
'.($frontend ? 'LEFT JOIN `'._DB_PREFIX_.'module_country` mc ON (m.`id_module` = mc.`id_module` AND mc.id_shop = '.(int)$context->shop->id.')' : '').'
'.($frontend ? 'INNER JOIN `'._DB_PREFIX_.'module_group` mg ON (m.`id_module` = mg.`id_module` AND mg.id_shop = '.(int)$context->shop->id.')' : '').'
'.(isset($context->customer) ? 'INNER JOIN `'._DB_PREFIX_.'customer_group` cg on (cg.`id_group` = mg.`id_group`AND cg.`id_customer` = '.(int)$context->customer->id.')' : '').'
LEFT JOIN `'._DB_PREFIX_.'hook_module` hm ON hm.`id_module` = m.`id_module`
LEFT JOIN `'._DB_PREFIX_.'hook` h ON hm.`id_hook` = h.`id_hook`
WHERE h.`name` = \''.pSQL($hookPayment).'\'
'.(isset($billing) && $frontend ? 'AND mc.id_country = '.(int)$billing->id_country : '').'
AND (SELECT COUNT(*) FROM '._DB_PREFIX_.'module_shop ms WHERE ms.id_module = m.id_module AND ms.id_shop IN('.implode(', ', $list).')) = '.count($list).'
AND hm.id_shop IN('.implode(', ', $list).')
'.(count($groups) && $frontend ? 'AND (mg.`id_group` IN('.implode(', ', $groups).'))' : '').'
GROUP BY hm.id_hook, hm.id_module
ORDER BY hm.`position`, m.`name` DESC');
}
/**
+3 -3
View File
@@ -69,7 +69,7 @@ abstract class ModuleGridCore extends Module
{
if (!Validate::isModuleName($render))
die(Tools::displayError());
if (!Tools::file_exists_cache($file = dirname(__FILE__).'/../../modules/'.$render.'/'.$render.'.php'))
if (!Tools::file_exists_cache($file = _PS_ROOT_DIR_.'/modules/'.$render.'/'.$render.'.php'))
die(Tools::displayError());
require_once($file);
$this->_render = new $render($type);
@@ -99,7 +99,7 @@ abstract class ModuleGridCore extends Module
return Tools::displayError('No grid engine selected');
if (!Validate::isModuleName($render))
die(Tools::displayError());
if (!file_exists(dirname(__FILE__).'/../../modules/'.$render.'/'.$render.'.php'))
if (!file_exists(_PS_ROOT_DIR_.'/modules/'.$render.'/'.$render.'.php'))
return Tools::displayError('Grid engine selected is unavailable.');
$grider = 'grider.php?render='.$render.'&module='.Tools::safeOutput(Tools::getValue('module'));
@@ -132,7 +132,7 @@ abstract class ModuleGridCore extends Module
if (isset($params['dir']) && Validate::isSortDirection($params['dir']))
$grider .= '&dir='.$params['dir'];
require_once(dirname(__FILE__).'/../../modules/'.$render.'/'.$render.'.php');
require_once(_PS_ROOT_DIR_.'/modules/'.$render.'/'.$render.'.php');
return call_user_func(array($render, 'hookGridEngine'), $params, $grider);
}