From ff81f714498d2e1a7917551db88b546b9b5ce0fe Mon Sep 17 00:00:00 2001 From: rMalie Date: Tue, 19 Jul 2011 09:23:10 +0000 Subject: [PATCH] // Context in modules + Shop::sql* methods --- admin-dev/tabs/AdminReferrers.php | 11 ++- classes/AdminTab.php | 31 ++++---- classes/Category.php | 4 +- classes/Module.php | 45 +++-------- classes/Product.php | 4 +- classes/Shop.php | 37 +++++---- modules/blockcategories/blockcategories.php | 15 ++-- modules/blockcurrencies/blockcurrencies.php | 12 +-- modules/blocklanguages/blocklanguages.php | 9 +-- modules/blocklayered/blocklayered.php | 2 +- .../blockmanufacturer/blockmanufacturer.php | 2 +- modules/blocknewsletter/blocknewsletter.php | 15 ++-- modules/blockspecials/blockspecials.php | 10 +-- modules/pagesnotfound/pagesnotfound.php | 2 +- modules/referralprogram/referralprogram.php | 4 +- modules/sekeywords/sekeywords.php | 2 +- .../statsbestcategories.php | 4 +- .../statsbestproducts/statsbestproducts.php | 15 +--- modules/statscatalog/statscatalog.php | 10 +-- modules/statscheckup/statscheckup.php | 42 ++-------- modules/statsforecast/statsforecast.php | 79 +++++-------------- modules/statsproduct/statsproduct.php | 15 +--- modules/statssearch/statssearch.php | 2 +- modules/statsstock/statsstock.php | 16 +--- modules/treepodia/treepodia.php | 2 +- 25 files changed, 127 insertions(+), 263 deletions(-) diff --git a/admin-dev/tabs/AdminReferrers.php b/admin-dev/tabs/AdminReferrers.php index 3bfd9bb06..06172057b 100644 --- a/admin-dev/tabs/AdminReferrers.php +++ b/admin-dev/tabs/AdminReferrers.php @@ -59,12 +59,11 @@ class AdminReferrers extends AdminTab $this->edit = true; $this->delete = true; - $this->_select = 'SUM(rs.cache_visitors) AS cache_visitors, SUM(rs.cache_visits) AS cache_visits, SUM(rs.cache_pages) AS cache_pages, - SUM(rs.cache_registrations) AS cache_registrations, SUM(rs.cache_orders) AS cache_orders, SUM(rs.cache_sales) AS cache_sales, - IF(rs.cache_orders > 0, ROUND(rs.cache_sales/rs.cache_orders, 2), 0) as cart, (rs.cache_visits*click_fee) as fee0, - (rs.cache_orders*base_fee) as fee1, (rs.cache_sales*percent_fee/100) as fee2'; - $this->_join = 'LEFT JOIN '._DB_PREFIX_.'referrer_shop rs ON a.id_referrer = rs.id_referrer '.Shop::sqlRestriction(false, 'rs'); - $this->_group = 'GROUP BY rs.id_referrer'; + $this->_select = 'SUM(sa.cache_visitors) AS cache_visitors, SUM(sa.cache_visits) AS cache_visits, SUM(sa.cache_pages) AS cache_pages, + SUM(sa.cache_registrations) AS cache_registrations, SUM(sa.cache_orders) AS cache_orders, SUM(sa.cache_sales) AS cache_sales, + IF(sa.cache_orders > 0, ROUND(sa.cache_sales/sa.cache_orders, 2), 0) as cart, (sa.cache_visits*click_fee) as fee0, + (sa.cache_orders*base_fee) as fee1, (sa.cache_sales*percent_fee/100) as fee2'; + $this->_group = 'GROUP BY sa.id_referrer'; $this->fieldsDisplay = array( 'id_referrer' => array('title' => $this->l('ID'), 'width' => 25, 'align' => 'center'), 'name' => array('title' => $this->l('Name'), 'width' => 80), diff --git a/classes/AdminTab.php b/classes/AdminTab.php index 760081b4f..4de023c31 100644 --- a/classes/AdminTab.php +++ b/classes/AdminTab.php @@ -1171,28 +1171,25 @@ abstract class AdminTabCore $whereShop = Shop::sqlRestriction($this->shopShareDatas, 'a', null, null, $this->shopLinkType); } - $filterShop = ''; - if (Context::shop() != Shop::CONTEXT_ALL) + $assos = Shop::getAssoTables(); + if (isset($assos[$this->table]) && $assos[$this->table]['type'] == 'shop') { - $assos = Shop::getAssoTables(); - if (isset($assos[$this->table]) && $assos[$this->table]['type'] == 'shop') + $filterKey = $assos[$this->table]['type']; + $idenfierShop = Shop::getListFromContext(); + } + else if (Context::shop() == Shop::CONTEXT_GROUP) + { + $assos = GroupShop::getAssoTables(); + if (isset($assos[$this->table]) AND $assos[$this->table]['type'] == 'group_shop') { $filterKey = $assos[$this->table]['type']; - $idenfierShop = Shop::getListFromContext(); + $idenfierShop = array($context->shop->getGroupID()); } - else if (Context::shop() == Shop::CONTEXT_GROUP) - { - $assos = GroupShop::getAssoTables(); - if (isset($assos[$this->table]) AND $assos[$this->table]['type'] == 'group_shop') - { - $filterKey = $assos[$this->table]['type']; - $idenfierShop = array($context->shop->getGroupID()); - } - } - - if (isset($filterKey)) - $filterShop = 'JOIN `'._DB_PREFIX_.$this->table.'_'.$filterKey.'` sa ON (sa.'.$this->identifier.' = a.'.$this->identifier.' AND sa.id_'.$filterKey.' IN ('.implode(', ', $idenfierShop).'))'; } + + $filterShop = ''; + if (isset($filterKey)) + $filterShop = 'JOIN `'._DB_PREFIX_.$this->table.'_'.$filterKey.'` sa ON (sa.'.$this->identifier.' = a.'.$this->identifier.' AND sa.id_'.$filterKey.' IN ('.implode(', ', $idenfierShop).'))'; /* Query in order to get results with all fields */ $sql = 'SELECT SQL_CALC_FOUND_ROWS diff --git a/classes/Category.php b/classes/Category.php index 3335ea7b3..32b4f629d 100644 --- a/classes/Category.php +++ b/classes/Category.php @@ -493,7 +493,7 @@ class CategoryCore extends ObjectModel { $sql = 'SELECT COUNT(cp.`id_product`) AS total FROM `'._DB_PREFIX_.'product` p - '.Shop::sqlAsso('product', 'p', $context).' + '.Shop::sqlAsso('product', 'p', true, $context).' LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON p.`id_product` = cp.`id_product` WHERE cp.`id_category` = '.(int)($this->id). ($active ? ' AND p.`active` = 1' : ''). @@ -506,7 +506,7 @@ class CategoryCore extends ObjectModel FROM `'._DB_PREFIX_.'category_product` cp LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = cp.`id_product` LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product` AND default_on = 1) - '.Shop::sqlAsso('product', 'p', $context).' + '.Shop::sqlAsso('product', 'p', true, $context).' '.Product::sqlStock('p', 'pa', false, $context).' LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (p.`id_category_default` = cl.`id_category` AND cl.`id_lang` = '.(int)$id_lang.Shop::sqlLang('cl', $context).') LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.Shop::sqlLang('pl', $context).') diff --git a/classes/Module.php b/classes/Module.php index 8d36ab544..6e9718902 100644 --- a/classes/Module.php +++ b/classes/Module.php @@ -90,24 +90,19 @@ abstract class ModuleCore * @var array used by AdminTab to determine which lang file to use (admin.php or module lang file) */ public static $classInModule = array(); - - /** @var int */ - protected $shopID; - - /** @var int */ - protected $shopGroupID; + + /** @var Context */ + protected $context; /** * Constructor * * @param string $name Module unique name + * @param Context $context */ - public function __construct($name = null) + public function __construct($name = null, Context $context = null) { - // Search the module shop context - list($shopID, $shopGroupID) = Shop::getContext(); - $this->setShopID($shopID); - $this->setShopGroupID($shopGroupID); + $this->context = ($context) ? $context : Context::getContext(); if ($this->name == NULL) $this->name = $this->id; @@ -115,7 +110,7 @@ abstract class ModuleCore { if (self::$modulesCache == NULL AND !is_array(self::$modulesCache)) { - $list = Shop::getListOfID($this->shopID, $this->shopGroupID); + $list = Shop::getListOfID($this->context); // Join clause is done to check if the module is activated in current shop context $sql = 'SELECT m.id_module, m.name, ( @@ -142,26 +137,10 @@ abstract class ModuleCore } } } - - /** - * @param int $id Set shopID property - */ - public function setShopID($id) - { - $this->shopID = (int)$id; - } - - /** - * @param int $id Set shopGroupID property - */ - public function setShopGroupID($id) - { - $this->shopGroupID = (int)$id; - } - + protected function sqlShopRestriction($share = false, $alias = null) { - return Shop::sqlRestriction($share, $alias, $this->shopID, $this->shopGroupID, 'shop'); + return Shop::sqlRestriction($share, $alias, $this->context, 'shop'); } /** @@ -240,7 +219,7 @@ abstract class ModuleCore */ public function enable($forceAll = false) { - $list = Shop::getListOfID($this->shopID, $this->shopGroupID); + $list = Shop::getListOfID($this->context); $sql = 'SELECT id_shop FROM '._DB_PREFIX_.'module_shop WHERE id_module = '.$this->id.' @@ -288,7 +267,7 @@ abstract class ModuleCore { $sql = 'DELETE FROM '._DB_PREFIX_.'module_shop WHERE id_module = '.$this->id.' - '.((!$forceAll) ? ' AND id_shop IN('.implode(', ', Shop::getListOfID($this->shopID, $this->shopGroupID)).')' : ''); + '.((!$forceAll) ? ' AND id_shop IN('.implode(', ', Shop::getListOfID($this->context)).')' : ''); Db::getInstance()->execute($sql); } @@ -916,7 +895,7 @@ abstract class ModuleCore */ public function updatePosition($id_hook, $way, $position = NULL) { - $list = ShopCore::getListOfID($this->shopID, $this->shopGroupID); + $list = ShopCore::getListOfID($this->context); foreach ($list as $shopID) { $sql = 'SELECT hm.`id_module`, hm.`position`, hm.`id_hook` diff --git a/classes/Product.php b/classes/Product.php index 719d72645..6aabb588c 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -1517,7 +1517,7 @@ class ProductCore extends ObjectModel { $sql = 'SELECT COUNT(DISTINCT p.`id_product`) AS nb FROM `'._DB_PREFIX_.'product` p - '.Shop::sqlAsso('product', 'p', $context).' + '.Shop::sqlAsso('product', 'p', true, $context).' WHERE p.`active` = 1 AND p.`show_price` = 1 '.((!$beginning AND !$ending) ? ' AND p.`id_product` IN('.((is_array($ids_product) AND sizeof($ids_product)) ? implode(', ', $ids_product) : 0).')' : '').' @@ -1535,7 +1535,7 @@ class ProductCore extends ObjectModel pl.`name`, i.`id_image`, il.`legend`, t.`rate`, 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::sqlAsso('product', 'p', $context).' + '.Shop::sqlAsso('product', 'p', true, $context).' '.Product::sqlStock('p', 0, false, $context).' LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.Shop::sqlLang('pl', $context).') LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1) diff --git a/classes/Shop.php b/classes/Shop.php index 963797ac6..ef123b750 100644 --- a/classes/Shop.php +++ b/classes/Shop.php @@ -449,8 +449,11 @@ class ShopCore extends ObjectModel * @param bool $share If true and if $shopID is set, list shops with share data too * @return array */ - public static function getListOfID($shopID, $shopGroupID, $share = false) + public static function getListOfID(Context $context, $share = false) { + $shopID = $context->shop->getID(); + $shopGroupID = $context->shop->getGroupID(); + if ($shopID) $list = (!$share) ? array($shopID) : Shop::getSharedShops($shopID); else if ($shopGroupID) @@ -531,14 +534,11 @@ class ShopCore extends ObjectModel /** * Get a list of ID concerned by the shop context (E.g. if context is shop group, get list of children shop ID) * - * @param Context $context * @return array */ - public static function getListFromContext(Context $context = null) + public static function getListFromContext() { - if (!$context) - $context = Context::getContext(); - return Shop::getListOfID($context->shop->getID(), $context->shop->getGroupID()); + return Shop::getListOfID(Context::getContext()); } /** @@ -556,7 +556,7 @@ class ShopCore extends ObjectModel return Shop::CONTEXT_ALL; } - public static function sqlRestriction($share = false, $alias = null, $shopID = null, $shopGroupID = null, $type = 'shop') + public static function sqlRestriction($share = false, $alias = null, Context $context = null, $type = 'shop') { if ($type != 'shop' && $type != 'group_shop') $type = 'shop'; @@ -565,10 +565,10 @@ class ShopCore extends ObjectModel $alias .= '.'; $restriction = ''; - if (is_null($shopID)) - $shopID = Shop::getContext('shop'); - if (is_null($shopGroupID)) - $shopGroupID = Shop::getContext('group'); + if (!$context) + $context = Context::getContext(); + $shopID = $context->shop->getID(); + $shopGroupID = $context->shop->getGroupID(); if ($type == 'group_shop') { @@ -580,7 +580,7 @@ class ShopCore extends ObjectModel else { if ($shopID || $shopGroupID) - $restriction = ' AND '.$alias.'id_shop IN ('.implode(', ', Shop::getListOfID($shopID, $shopGroupID, $share)).')'; + $restriction = ' AND '.$alias.'id_shop IN ('.implode(', ', Shop::getListOfID($context, $share)).')'; } return $restriction; @@ -610,21 +610,26 @@ class ShopCore extends ObjectModel * * @param string $table Table name (E.g. product, module, etc.) * @param string $alias Alias of table + * @param bool $innerJoin Use or not INNER JOIN * @param Context $context * @return string */ - public static function sqlAsso($table, $alias, Context $context = null) + public static function sqlAsso($table, $alias, $innerJoin = false, Context $context = null) { if (!$context) $context = Context::getContext(); + $tableAlias = ' asso_shop_'.$table; + if (strpos($table, '.') !== false) + list($tableAlias, $table) = explode('.', $table); + $assoTables = Shop::getAssoTables(); if (!isset($assoTables[$table]) || $assoTables[$table]['type'] != 'shop') return ; - $sql = ' LEFT JOIN '._DB_PREFIX_.$table.'_shop asso_shop_'.$table.' - ON asso_shop_'.$table.'.id_'.$table.' = '.$alias.'.id_'.$table.' - AND asso_shop_'.$table.'.id_shop IN('.implode(', ', Shop::getListFromContext($context)).') '; + $sql = (($innerJoin) ? ' INNER' : ' LEFT').' JOIN '._DB_PREFIX_.$table.'_shop '.$tableAlias.' + ON '.$tableAlias.'.id_'.$table.' = '.$alias.'.id_'.$table.' + AND '.$tableAlias.'.id_shop IN('.implode(', ', Shop::getListFromContext($context)).') '; return $sql; } diff --git a/modules/blockcategories/blockcategories.php b/modules/blockcategories/blockcategories.php index 624d4b837..e3b2e3011 100644 --- a/modules/blockcategories/blockcategories.php +++ b/modules/blockcategories/blockcategories.php @@ -124,15 +124,13 @@ class BlockCategories extends Module public function getTree($resultParents, $resultIds, $maxDepth, $id_category = 1, $currentDepth = 0) { - $context = Context::getContext(); - $children = array(); if (isset($resultParents[$id_category]) AND sizeof($resultParents[$id_category]) AND ($maxDepth == 0 OR $currentDepth < $maxDepth)) foreach ($resultParents[$id_category] as $subcat) $children[] = $this->getTree($resultParents, $resultIds, $maxDepth, $subcat['id_category'], $currentDepth + 1); if (!isset($resultIds[$id_category])) return false; - $return = array('id' => $id_category, 'link' => $context->link->getCategoryLink($id_category, $resultIds[$id_category]['link_rewrite']), + $return = array('id' => $id_category, 'link' => $this->context->link->getCategoryLink($id_category, $resultIds[$id_category]['link_rewrite']), 'name' => $resultIds[$id_category]['name'], 'desc'=> $resultIds[$id_category]['description'], 'children' => $children); return $return; @@ -141,7 +139,7 @@ class BlockCategories extends Module public function hookLeftColumn($params) { $context = Context::getContext(); - $id_current_shop = $this->shopID; + $id_current_shop = $context->shop->getID(); $id_customer = (int)($params['cookie']->id_customer); // Get all groups for this customer and concatenate them as a string: "1,2,3..." @@ -220,8 +218,8 @@ class BlockCategories extends Module public function hookFooter($params) { - $context = Context::getContext(); - $id_current_shop = $this->shopID; + $context = $this->context; + $id_current_shop = $context->shop->getID(); $id_customer = (int)($params['cookie']->id_customer); // Get all groups for this customer and concatenate them as a string: "1,2,3..." @@ -321,9 +319,8 @@ class BlockCategories extends Module public function hookHeader() { - $context = Context::getContext(); - $context->controller->addJS(_THEME_JS_DIR_.'tools/treeManagement.js'); - $context->controller->addCSS(($this->_path).'blockcategories.css', 'all'); + $this->context->controller->addJS(_THEME_JS_DIR_.'tools/treeManagement.js'); + $this->context->controller->addCSS(($this->_path).'blockcategories.css', 'all'); } private function _clearBlockcategoriesCache() diff --git a/modules/blockcurrencies/blockcurrencies.php b/modules/blockcurrencies/blockcurrencies.php index 8bf2aca30..0983b1e18 100644 --- a/modules/blockcurrencies/blockcurrencies.php +++ b/modules/blockcurrencies/blockcurrencies.php @@ -59,14 +59,11 @@ class BlockCurrencies extends Module { if (Configuration::get('PS_CATALOG_MODE')) return ; - - $context = Context::getContext(); - - $id_current_shop = $this->shopID; - $currencies = Currency::getCurrencies(false, 1, $id_current_shop); + + $currencies = Currency::getCurrencies(false, 1, $this->context->shop->getID()); if (!sizeof($currencies)) return ''; - $context->controller->smarty->assign('currencies', $currencies); + $this->context->controller->smarty->assign('currencies', $currencies); return $this->display(__FILE__, 'blockcurrencies.tpl'); } @@ -74,8 +71,7 @@ class BlockCurrencies extends Module { if (Configuration::get('PS_CATALOG_MODE')) return ; - $context = Context::getContext(); - $context->controller->addCSS(($this->_path).'blockcurrencies.css', 'all'); + $this->context->controller->addCSS(($this->_path).'blockcurrencies.css', 'all'); } } diff --git a/modules/blocklanguages/blocklanguages.php b/modules/blocklanguages/blocklanguages.php index 5603deefe..3821d75fd 100644 --- a/modules/blocklanguages/blocklanguages.php +++ b/modules/blocklanguages/blocklanguages.php @@ -57,19 +57,16 @@ class BlockLanguages extends Module */ function hookTop($params) { - $context = Context::getContext(); - - $languages = Language::getLanguages(true, $this->shopID); + $languages = Language::getLanguages(true, $this->context->shop->getID()); if (!sizeof($languages)) return ''; - $context->controller->smarty->assign('languages', $languages); + $this->context->controller->smarty->assign('languages', $languages); return $this->display(__FILE__, 'blocklanguages.tpl'); } function hookHeader($params) { - $context = Context::getContext(); - $context->controller->addCSS(($this->_path).'blocklanguages.css', 'all'); + $this->context->controller->addCSS(($this->_path).'blocklanguages.css', 'all'); } } diff --git a/modules/blocklayered/blocklayered.php b/modules/blocklayered/blocklayered.php index 060d24fe6..ff26abdf4 100644 --- a/modules/blocklayered/blocklayered.php +++ b/modules/blocklayered/blocklayered.php @@ -387,7 +387,7 @@ class BlockLayered extends Module p.ean13, pl.available_later, pl.description_short, pl.link_rewrite, pl.name, i.id_image, il.legend, m.name manufacturer_name, p.condition, p.id_manufacturer, stock.quantity, 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::sqlAsso('product', 'p', $context).' + '.Shop::sqlAsso('product', 'p', true, $context).' LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = p.id_product'.Shop::sqlLang('pl', $context).') '.Product::sqlStock('p', 0).' LEFT JOIN '._DB_PREFIX_.'image i ON (i.id_product = p.id_product AND i.cover = 1) diff --git a/modules/blockmanufacturer/blockmanufacturer.php b/modules/blockmanufacturer/blockmanufacturer.php index 449a16415..0d1d4399f 100644 --- a/modules/blockmanufacturer/blockmanufacturer.php +++ b/modules/blockmanufacturer/blockmanufacturer.php @@ -57,7 +57,7 @@ class BlockManufacturer extends Module $context = Context::getContext(); //$getNbProducts = false, $id_lang = 0, $active = true, $p = false, $n = false, $all_group = false, $id_shop = false $context->controller->smarty->assign(array( - 'manufacturers' => Manufacturer::getManufacturers(false, 0, true, false, false, false, $this->shopGroupID), + 'manufacturers' => Manufacturer::getManufacturers(false, 0, true, false, false, false, $this->context->shop->getGroupID()), 'link' => $context->link, 'text_list' => Configuration::get('MANUFACTURER_DISPLAY_TEXT'), 'text_list_nb' => Configuration::get('MANUFACTURER_DISPLAY_TEXT_NB'), diff --git a/modules/blocknewsletter/blocknewsletter.php b/modules/blocknewsletter/blocknewsletter.php index fd5dfbc34..9909d5847 100644 --- a/modules/blocknewsletter/blocknewsletter.php +++ b/modules/blocknewsletter/blocknewsletter.php @@ -140,13 +140,13 @@ class Blocknewsletter extends Module { $sql = 'SELECT `email` FROM '._DB_PREFIX_.'newsletter WHERE `email` = \''.pSQL($customerEmail).'\' - AND id_shop = '.$this->shopID; + AND id_shop = '.$this->context->shop->getID(); if (Db::getInstance()->getRow($sql)) return 1; $sql = 'SELECT `newsletter` FROM '._DB_PREFIX_.'customer WHERE `email` = \''.pSQL($customerEmail).'\' - AND id_shop = '.$this->shopID; + AND id_shop = '.$this->context->shop->getID(); if (!$registered = Db::getInstance()->getRow($sql)) return -1; @@ -160,7 +160,6 @@ class Blocknewsletter extends Module */ private function newsletterRegistration() { - $context = Context::getContext(); if (empty($_POST['email']) OR !Validate::isEmail($_POST['email'])) return $this->error = $this->l('Invalid e-mail address'); @@ -173,14 +172,14 @@ class Blocknewsletter extends Module /* If the user ins't a customer */ elseif ($registerStatus == 1) { - if (!Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'newsletter WHERE `email` = \''.pSQL($_POST['email']).'\' AND id_shop = '.$this->shopID)) + if (!Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'newsletter WHERE `email` = \''.pSQL($_POST['email']).'\' AND id_shop = '.$this->context->shop->getID())) return $this->error = $this->l('Error during unsubscription'); return $this->valid = $this->l('Unsubscription successful'); } /* If the user is a customer */ elseif ($registerStatus == 2) { - if (!Db::getInstance()->Execute('UPDATE '._DB_PREFIX_.'customer SET `newsletter` = 0 WHERE `email` = \''.pSQL($_POST['email']).'\' AND id_shop = '.$this->shopID)) + if (!Db::getInstance()->Execute('UPDATE '._DB_PREFIX_.'customer SET `newsletter` = 0 WHERE `email` = \''.pSQL($_POST['email']).'\' AND id_shop = '.$this->context->shop->getID())) return $this->error = $this->l('Error during unsubscription'); return $this->valid = $this->l('Unsubscription successful'); } @@ -196,8 +195,8 @@ class Blocknewsletter extends Module elseif ($registerStatus == -1) { $sql = 'INSERT INTO '._DB_PREFIX_.'newsletter (id_shop, id_group_shop, email, newsletter_date_add, ip_registration_newsletter, http_referer) - VALUES ('.$this->shopID.', '.$this->shopGroupID.', \''.pSQL($_POST['email']).'\', NOW(), \''.pSQL(Tools::getRemoteAddr()).'\', - (SELECT c.http_referer FROM '._DB_PREFIX_.'connections c WHERE c.id_guest = '.(int)$context->customer->id.' ORDER BY c.date_add DESC LIMIT 1) + VALUES ('.$this->context->shop->getID().', '.$this->context->shop->getGroupID().', \''.pSQL($_POST['email']).'\', NOW(), \''.pSQL(Tools::getRemoteAddr()).'\', + (SELECT c.http_referer FROM '._DB_PREFIX_.'connections c WHERE c.id_guest = '.(int)$this->context->customer->id.' ORDER BY c.date_add DESC LIMIT 1) )'; if (!Db::getInstance()->Execute($sql)) return $this->error = $this->l('Error during subscription'); @@ -211,7 +210,7 @@ class Blocknewsletter extends Module $sql = 'UPDATE '._DB_PREFIX_.'customer SET `newsletter` = 1, newsletter_date_add = NOW(), `ip_registration_newsletter` = \''.pSQL(Tools::getRemoteAddr()).'\' WHERE `email` = \''.pSQL($_POST['email']).'\' - AND id_shop = '.$this->shopID; + AND id_shop = '.$this->context->shop->getID(); if (!Db::getInstance()->Execute($sql)) return $this->error = $this->l('Error during subscription'); $this->sendVoucher(pSQL($_POST['email'])); diff --git a/modules/blockspecials/blockspecials.php b/modules/blockspecials/blockspecials.php index ca4b242a3..9ffa4ad5f 100644 --- a/modules/blockspecials/blockspecials.php +++ b/modules/blockspecials/blockspecials.php @@ -85,11 +85,10 @@ class BlockSpecials extends Module { if (Configuration::get('PS_CATALOG_MODE')) return ; - - $context = Context::getContext(); - if (!$special = Product::getRandomSpecial((int)($params['cookie']->id_lang), false, false, $this->shopID) AND !Configuration::get('PS_BLOCK_SPECIALS_DISPLAY')) + + if (!$special = Product::getRandomSpecial((int)($params['cookie']->id_lang), false, false, $this->context->shop->getID()) AND !Configuration::get('PS_BLOCK_SPECIALS_DISPLAY')) return; - $context->controller->smarty->assign(array( + $this->context->controller->smarty->assign(array( 'special' => $special, 'priceWithoutReduction_tax_excl' => Tools::ps_round($special['price_without_reduction'], 2), 'mediumSize' => Image::getSize('medium') @@ -107,8 +106,7 @@ class BlockSpecials extends Module { if (Configuration::get('PS_CATALOG_MODE')) return ; - $context = Context::getContext(); - $context->controller->addCSS(($this->_path).'blockspecials.css', 'all'); + $this->context->controller->addCSS(($this->_path).'blockspecials.css', 'all'); } } diff --git a/modules/pagesnotfound/pagesnotfound.php b/modules/pagesnotfound/pagesnotfound.php index 45b28c7e9..531fead24 100644 --- a/modules/pagesnotfound/pagesnotfound.php +++ b/modules/pagesnotfound/pagesnotfound.php @@ -156,7 +156,7 @@ class Pagesnotfound extends Module { $http_referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; if (empty($http_referer) OR Validate::isAbsoluteUrl($http_referer)) - Db::getInstance()->Execute('INSERT INTO `'._DB_PREFIX_.'pagenotfound` (`request_uri`, `http_referer`, `date_add`, `id_shop`, `id_group_shop`) VALUES (\''.pSQL($request_uri).'\', \''.pSQL($http_referer).'\', NOW(), '.$this->shopID.', '.$this->shopGroupID.')'); + Db::getInstance()->Execute('INSERT INTO `'._DB_PREFIX_.'pagenotfound` (`request_uri`, `http_referer`, `date_add`, `id_shop`, `id_group_shop`) VALUES (\''.pSQL($request_uri).'\', \''.pSQL($http_referer).'\', NOW(), '.$this->context->shop->getID().', '.$this->context->shop->getGroupID().')'); } } } diff --git a/modules/referralprogram/referralprogram.php b/modules/referralprogram/referralprogram.php index e8c0ffeb3..ccd8128d5 100644 --- a/modules/referralprogram/referralprogram.php +++ b/modules/referralprogram/referralprogram.php @@ -362,7 +362,7 @@ class ReferralProgram extends Module if (!Validate::isLoadedObject($discount)) return false; - if ($params['cart']->checkDiscountValidity($discount, $params['cart']->getDiscounts(), $params['cart']->getOrderTotal(true, Cart::ONLY_PRODUCTS), $params['cart']->getProducts(), false, $this->shopID, $this->shopGroupID)===false) + if ($params['cart']->checkDiscountValidity($discount, $params['cart']->getDiscounts(), $params['cart']->getOrderTotal(true, Cart::ONLY_PRODUCTS), $params['cart']->getProducts(), false, $this->context->shop->getID(), $this->context->shop->getGroupID())===false) { global $smarty; $smarty->assign(array('discount_display' => Discount::display($discount->value, $discount->id_discount_type, new Currency($params['cookie']->id_currency)), 'discount' => $discount)); @@ -438,7 +438,7 @@ class ReferralProgram extends Module return false; $sponsor = new Customer(); - if ($sponsor = $sponsor->getByEmail($sponsorEmail, NULL, $this->shopGroupID, $this->shopID)) + if ($sponsor = $sponsor->getByEmail($sponsorEmail, NULL, $this->context->shop->getGroupID(), $this->context->shop->getID())) { include_once(dirname(__FILE__).'/ReferralProgramModule.php'); diff --git a/modules/sekeywords/sekeywords.php b/modules/sekeywords/sekeywords.php index b54d7bfcf..0bcb06df9 100644 --- a/modules/sekeywords/sekeywords.php +++ b/modules/sekeywords/sekeywords.php @@ -89,7 +89,7 @@ class SEKeywords extends ModuleGraph if ($keywords = $this->getKeywords($_SERVER['HTTP_REFERER'])) Db::getInstance()->Execute('INSERT INTO `'._DB_PREFIX_.'sekeyword` (`keyword`, `date_add`, `id_shop`, `id_group_shop`) - VALUES (\''.pSQL(Tools::strtolower(trim($keywords))).'\', NOW(), '.$this->shopID.', '.$this->shopGroupID.')'); + VALUES (\''.pSQL(Tools::strtolower(trim($keywords))).'\', NOW(), '.$this->context->shop->getID().', '.$this->context->shop->getGroupID().')'); } public function hookAdminStatsModules() diff --git a/modules/statsbestcategories/statsbestcategories.php b/modules/statsbestcategories/statsbestcategories.php index b0323c41a..fce2c0bc0 100644 --- a/modules/statsbestcategories/statsbestcategories.php +++ b/modules/statsbestcategories/statsbestcategories.php @@ -123,14 +123,14 @@ class StatsBestCategories extends ModuleGrid // If a shop is selected, get all children categories for the shop $categories = array(); - if ($this->shopID || $this->shopGroupID) + if ($this->context->shop->getContextType() != Shop::CONTEXT_ALL) { $sql = 'SELECT c.nleft, c.nright FROM '._DB_PREFIX_.'category c WHERE c.id_category IN ( SELECT s.id_category FROM '._DB_PREFIX_.'shop s - WHERE s.id_shop IN ('.(($this->shopID) ? $this->shopID : 'SELECT id_shop FROM '._DB_PREFIX_.'shop WHERE id_group_shop = '.$this->shopGroupID).') + WHERE s.id_shop IN ('.implode(', ', Shop::getListOfID($this->context)).') )'; if ($result = Db::getInstance()->executeS($sql)) { diff --git a/modules/statsbestproducts/statsbestproducts.php b/modules/statsbestproducts/statsbestproducts.php index 0ffba44a0..38475614f 100644 --- a/modules/statsbestproducts/statsbestproducts.php +++ b/modules/statsbestproducts/statsbestproducts.php @@ -149,16 +149,6 @@ class StatsBestProducts extends ModuleGrid $dateBetween = $this->getDate(); $arrayDateBetween = explode(' AND ', $dateBetween); - $joinShop = $whereShop = ''; - if ($this->shopID || $this->shopGroupID) - { - $joinShop = ' LEFT JOIN '._DB_PREFIX_.'product_shop ps ON ps.id_product = p.id_product '; - if ($this->shopID) - $whereShop = ' ps.id_shop = '.$this->shopID.' AND '; - else if ($this->shopGroupID) - $whereShop = 'ps.id_shop IN (SELECT id_shop FROM '._DB_PREFIX_.'shop WHERE id_group_shop = '.$this->shopGroupID.') AND'; - } - $this->_query = 'SELECT SQL_CALC_FOUND_ROWS p.reference, p.id_product, pl.name, ROUND(AVG(od.product_price / o.conversion_rate), 2) as avgPriceSold, IFNULL((SELECT SUM(pa.quantity) FROM '._DB_PREFIX_.'product_attribute pa WHERE pa.id_product = p.id_product GROUP BY pa.id_product), p.quantity) as quantity, IFNULL(SUM(od.product_quantity), 0) AS totalQuantitySold, @@ -174,12 +164,11 @@ class StatsBestProducts extends ModuleGrid AND dr.time_end BETWEEN '.$dateBetween.' ) AS totalPageViewed FROM '._DB_PREFIX_.'product p - '.$joinShop.' + '.Shop::sqlAsso('product', 'p', true, $this->context).' LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (p.id_product = pl.id_product AND pl.id_lang = '.(int)($this->getLang()).') LEFT JOIN '._DB_PREFIX_.'order_detail od ON od.product_id = p.id_product LEFT JOIN '._DB_PREFIX_.'orders o ON od.id_order = o.id_order - WHERE '.$whereShop.' - p.active = 1 + WHERE p.active = 1 AND o.valid = 1 AND o.invoice_date BETWEEN '.$dateBetween.' GROUP BY od.product_id'; diff --git a/modules/statscatalog/statscatalog.php b/modules/statscatalog/statscatalog.php index 2ee20eb18..f0969fb8c 100644 --- a/modules/statscatalog/statscatalog.php +++ b/modules/statscatalog/statscatalog.php @@ -147,15 +147,7 @@ class StatsCatalog extends Module $this->_join = ' LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_product` = p.`id_product`)'; $this->_where = ' AND cp.`id_category` = '.$id_category; } - - if ($this->shopID || $this->shopGroupID) - { - $this->_join .= ' LEFT JOIN '._DB_PREFIX_.'product_shop ps ON ps.id_product = p.id_product'; - if ($this->shopID) - $this->_where .= ' AND ps.id_shop = ' . $this->shopID; - else if ($this->shopGroupID) - $this->_where .= ' AND ps.id_shop IN (SELECT id_shop FROM '._DB_PREFIX_.'shop WHERE id_group_shop = '.$this->shopGroupID.')'; - } + $this->_join .= Shop::sqlAsso('product', 'p', true, $this->context); $result1 = $this->getQuery1(true); $total = $result1['total']; diff --git a/modules/statscheckup/statscheckup.php b/modules/statscheckup/statscheckup.php index 3ce88406f..a9305e961 100644 --- a/modules/statscheckup/statscheckup.php +++ b/modules/statscheckup/statscheckup.php @@ -75,18 +75,14 @@ class StatsCheckUp extends Module $db = Db::getInstance(_PS_USE_SQL_SLAVE_); $employee = new Employee((int)($cookie->id_employee)); $prop30 = ((strtotime($employee->stats_date_to.' 23:59:59') - strtotime($employee->stats_date_from.' 00:00:00')) / 60 / 60 / 24) / 30; + + $shopID = $this->context->shop->getID(); + $shopGroupID = $this->context->shop->getGroupID(); // Get languages $sql = 'SELECT l.* - FROM '._DB_PREFIX_.'lang l'; - if ($this->shopID || $this->shopGroupID) - { - $sql .= ' LEFT JOIN '._DB_PREFIX_.'lang_shop ls ON ls.id_lang = l.id_lang'; - if ($this->shopID) - $sql .= ' WHERE ls.id_shop = ' . $this->shopID; - else if ($this->shopGroupID) - $sql .= ' WHERE ls.id_shop IN (SELECT id_shop FROM '._DB_PREFIX_.'shop WHERE id_group_shop = '.$this->shopGroupID.')'; - } + FROM '._DB_PREFIX_.'lang l' + .Shop::sqlAsso('lang', 'l', true, $this->context); $languages = $db->ExecuteS($sql); $arrayColors = array( @@ -109,40 +105,19 @@ class StatsCheckUp extends Module elseif ($cookie->checkup_order == 3) $orderBy = 'nbSales DESC'; - // Generate SQL restrictions for products stats per shop - $joinProduct = $joinImage = $whereProduct = $whereImage = $whereOrder = ''; - if ($this->shopID || $this->shopGroupID) - { - $joinProduct = ' LEFT JOIN '._DB_PREFIX_.'product_shop ps ON ps.id_product = p.id_product '; - $joinImage = ' LEFT JOIN '._DB_PREFIX_.'image_shop ishop ON ishop.id_image = i.id_image '; - if ($this->shopID) - { - $whereProduct = ' WHERE ps.id_shop = '.$this->shopID; - $whereImage = ' AND ishop.id_shop = '.$this->shopID; - $whereOrder = ' AND o.id_shop = '.$this->shopID; - } - else if ($this->shopGroupID) - { - $whereProduct = ' WHERE ps.id_shop IN (SELECT id_shop FROM '._DB_PREFIX_.'shop WHERE id_group_shop = '.$this->shopGroupID.')'; - $whereImage = ' AND ishop.id_shop IN (SELECT id_shop FROM '._DB_PREFIX_.'shop WHERE id_group_shop = '.$this->shopGroupID.')'; - $whereOrder = ' AND o.id_group_shop = '.$this->shopGroupID; - } - } - // Get products stats $sql = 'SELECT p.id_product, p.active, pl.name, ( SELECT COUNT(*) FROM '._DB_PREFIX_.'image i - '.$joinImage.' + '.Shop::sqlAsso('image', 'i', true, $this->context).' WHERE i.id_product = p.id_product - '.$whereImage.' ) as nbImages, ( SELECT SUM(od.product_quantity) FROM '._DB_PREFIX_.'orders o LEFT JOIN '._DB_PREFIX_.'order_detail od ON o.id_order = od.id_order WHERE od.product_id = p.id_product AND o.invoice_date BETWEEN '.ModuleGraph::getDateBetween().' - '.$whereOrder.' + '.$this->sqlShopRestriction().' ) as nbSales, IFNULL(( SELECT SUM(pa.quantity) FROM '._DB_PREFIX_.'product_attribute pa @@ -150,8 +125,7 @@ class StatsCheckUp extends Module ), p.quantity) as stock FROM '._DB_PREFIX_.'product p LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (p.id_product = pl.id_product AND pl.id_lang = '.(int)$cookie->id_lang.') - '.$joinProduct.' - '.$whereProduct.' + '.Shop::sqlAsso('product', 'p', true, $this->context).' ORDER BY '.$orderBy; $result = $db->ExecuteS($sql); diff --git a/modules/statsforecast/statsforecast.php b/modules/statsforecast/statsforecast.php index f2895a44c..429fd21dc 100644 --- a/modules/statsforecast/statsforecast.php +++ b/modules/statsforecast/statsforecast.php @@ -79,27 +79,7 @@ class StatsForecast extends Module $currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); $employee = new Employee((int)($cookie->id_employee)); - - // Prepare SQL clause to filter per shop - $whereOrder = $whereConnection = $whereCustomer = $whereCart = ''; - if ($this->shopID || $this->shopGroupID) - { - if ($this->shopID) - { - $whereOrder = ' AND o.id_shop = '.$this->shopID; - $whereConnection = ' AND c.id_shop = '.$this->shopID; - $whereCustomer = ' AND id_shop = '.$this->shopID; - $whereCart = ' AND id_shop = '.$this->shopID; - } - else if ($this->shopGroupID) - { - $whereOrder = ' AND o.id_group_shop = '.$this->shopGroupID; - $whereConnection = ' AND c.id_group_shop = '.$this->shopGroupID; - $whereCustomer = ' AND id_group_shop = '.$this->shopGroupID; - $whereCart = ' AND id_group_shop = '.$this->shopGroupID; - } - } - + // @todo use PHP functions to get timestamp ... $result = $db->getRow('SELECT UNIX_TIMESTAMP(\'2009-06-05 00:00:00\') as t1, UNIX_TIMESTAMP(\''.$employee->stats_date_from.' 00:00:00\') as t2'); $from = max($result['t1'], $result['t2']); @@ -141,7 +121,7 @@ class StatsForecast extends Module LEFT JOIN '._DB_PREFIX_.'product p ON od.product_id = p.id_product WHERE o.valid = 1 AND o.invoice_date BETWEEN '.ModuleGraph::getDateBetween().' - '.$whereOrder.' + '.$this->sqlShopRestriction(false, 'o').' GROUP BY '.$dateFromGInvoice.' ORDER BY fix_date'; $result = $db->ExecuteS($sql, false); @@ -188,7 +168,7 @@ class StatsForecast extends Module $sql = 'SELECT '.$dateFromGAdd.' as fix_date, COUNT(*) as visits FROM '._DB_PREFIX_.'connections c WHERE c.date_add BETWEEN '.ModuleGraph::getDateBetween().' - '.$whereConnection.' + '.$this->sqlShopRestriction(false, 'c').' GROUP BY '.$dateFromGAdd; $visits = Db::getInstance()->ExecuteS($sql, false); while ($row = $db->nextRow($visits)) @@ -201,7 +181,7 @@ class StatsForecast extends Module WHERE o.valid = 1 AND o.total_paid_real > 0 AND o.invoice_date BETWEEN '.ModuleGraph::getDateBetween() - .$whereOrder.' + .$this->sqlShopRestriction(false, 'o').' GROUP BY '.$dateFromGInvoice; $discounts = Db::getInstance()->ExecuteS($sql, false); while ($row = $db->nextRow($discounts)) @@ -219,7 +199,7 @@ class StatsForecast extends Module $sql = 'SELECT COUNT(*) FROM '._DB_PREFIX_.'customer WHERE date_add BETWEEN '.ModuleGraph::getDateBetween().' AND date_add '.$dateFromGReg - .$whereCustomer; + .$this->sqlShopRestriction(true); $row['registrations'] = Db::getInstance()->getValue($sql); $totalHT = $row['totalProducts'] - $discountToday; @@ -297,7 +277,7 @@ class StatsForecast extends Module $sql = 'SELECT COUNT(DISTINCT c.id_guest) FROM '._DB_PREFIX_.'connections c WHERE c.date_add BETWEEN '.ModuleGraph::getDateBetween() - .$whereConnection; + .$this->sqlShopRestriction(false, 'c'); $visitors = Db::getInstance()->getValue($sql); $sql = 'SELECT COUNT(DISTINCT id_customer) @@ -305,7 +285,7 @@ class StatsForecast extends Module INNER JOIN '._DB_PREFIX_.'guest g ON c.id_guest = g.id_guest WHERE c.id_customer != 0 AND c.date_add BETWEEN '.ModuleGraph::getDateBetween() - .$whereConnection; + .$this->sqlShopRestriction(false, 'c'); $customers = Db::getInstance()->getValue($sql); $sql = 'SELECT COUNT(*) @@ -314,7 +294,7 @@ class StatsForecast extends Module SELECT id_cart FROM '._DB_PREFIX_.'cart_product ) AND ( date_add BETWEEN '.ModuleGraph::getDateBetween().' OR date_upd BETWEEN '.ModuleGraph::getDateBetween().' - )'.$whereCart; + )'.$this->sqlShopRestriction(); $carts = Db::getInstance()->getValue($sql); $sql = 'SELECT COUNT(*) @@ -324,14 +304,14 @@ class StatsForecast extends Module ) AND id_address_invoice != 0 AND ( date_add BETWEEN '.ModuleGraph::getDateBetween().' OR date_upd BETWEEN '.ModuleGraph::getDateBetween().' - )'.$whereCart; + )'.$this->sqlShopRestriction(); $fullcarts = Db::getInstance()->getValue($sql); $sql = 'SELECT COUNT(*) FROM '._DB_PREFIX_.'orders o WHERE o.valid = 1 AND o.date_add BETWEEN '.ModuleGraph::getDateBetween() - .$whereOrder; + .$this->sqlShopRestriction(false, 'o'); $orders = Db::getInstance()->getValue($sql); $this->_html .= '
 
@@ -508,23 +488,7 @@ class StatsForecast extends Module $employee = new Employee($cookie->id_employee); $ca = array(); - // Prepare SQL clause to filter per shop - $whereOrder = $where = $join = $joinLang = $whereLang = ''; - if ($this->shopID || $this->shopGroupID) - { - $joinLang = ' LEFT JOIN '._DB_PREFIX_.'lang_shop ls ON ls.id_lang = l.id_lang '; - if ($this->shopID) - { - $whereOrder = ' AND o.id_shop = '.$this->shopID; - $whereLang = ' AND ls.id_shop = '.$this->shopID; - } - else if ($this->shopGroupID) - { - $whereOrder = ' AND o.id_group_shop = '.$this->shopGroupID; - $whereLang = ' AND ls.id_shop IN (SELECT id_shop FROM '._DB_PREFIX_.'shop WHERE id_group_shop = '.$this->shopGroupID.')'; - } - } - + $where = $join = ''; if ((int)$cookie->stats_id_zone) { $join = ' LEFT JOIN `'._DB_PREFIX_.'address` a ON o.id_address_invoice = a.id_address LEFT JOIN `'._DB_PREFIX_.'country` co ON co.id_country = a.id_country'; @@ -540,7 +504,7 @@ class StatsForecast extends Module WHERE o.valid = 1 AND o.`invoice_date` BETWEEN '.ModuleGraph::getDateBetween().' '.$where.' - '.$whereOrder.' + '.$this->sqlShopRestriction(false, 'o').' GROUP BY p.id_category_default'; $ca['cat'] = Db::getInstance()->ExecuteS($sql); uasort($ca['cat'], 'statsforecast_sort'); @@ -548,9 +512,8 @@ class StatsForecast extends Module $langValues = ''; $sql = 'SELECT l.id_lang, l.iso_code FROM `'._DB_PREFIX_.'lang` l - '.$joinLang.' - WHERE l.active = 1 - '.$whereLang; + '.Shop::sqlAsso('lang', 'l', true, $this->context).' + WHERE l.active = 1'; $languages = Db::getInstance()->ExecuteS($sql); foreach ($languages as $language) $langValues .= 'SUM(IF(o.id_lang = '.(int)$language['id_lang'].', total_products / o.conversion_rate, 0)) as '.pSQL($language['iso_code']).','; @@ -562,7 +525,7 @@ class StatsForecast extends Module FROM `'._DB_PREFIX_.'orders` o WHERE o.valid = 1 AND o.`invoice_date` BETWEEN '.ModuleGraph::getDateBetween().' - '.$whereOrder; + '.$this->sqlShopRestriction(false, 'o'); $ca['lang'] = Db::getInstance()->getRow($sql); arsort($ca['lang']); @@ -570,7 +533,7 @@ class StatsForecast extends Module FROM `'._DB_PREFIX_.'orders` o WHERE o.valid = 1 AND ADDDATE(o.`invoice_date`, interval 30 day) BETWEEN \''.$employee->stats_date_from.' 00:00:00\' AND \''.min(date('Y-m-d H:i:s'), $employee->stats_date_to.' 23:59:59').'\' - '.$whereOrder; + '.$this->sqlShopRestriction(false, 'o'); $ca['langprev'] = Db::getInstance()->getRow($sql); } else @@ -585,7 +548,7 @@ class StatsForecast extends Module WHERE o.valid = 1 AND o.`invoice_date` BETWEEN '.ModuleGraph::getDateBetween().' '.$where.' - '.$whereOrder.' + '.$this->sqlShopRestriction(false, 'o').' GROUP BY o.module ORDER BY total DESC'; $ca['payment'] = Db::getInstance()->ExecuteS($sql); @@ -597,7 +560,7 @@ class StatsForecast extends Module LEFT JOIN `'._DB_PREFIX_.'zone` z ON z.id_zone = c.id_zone WHERE o.valid = 1 AND o.`invoice_date` BETWEEN '.ModuleGraph::getDateBetween().' - '.$whereOrder.' + '.$this->sqlShopRestriction(false, 'o').' GROUP BY c.id_zone ORDER BY total DESC'; $ca['zones'] = Db::getInstance()->ExecuteS($sql); @@ -609,7 +572,7 @@ class StatsForecast extends Module WHERE o.valid = 1 AND o.`invoice_date` BETWEEN '.ModuleGraph::getDateBetween().' '.$where.' - '.$whereOrder.' + '.$this->sqlShopRestriction(false, 'o').' GROUP BY o.id_currency ORDER BY total DESC'; $ca['currencies'] = Db::getInstance()->ExecuteS($sql); @@ -618,7 +581,7 @@ class StatsForecast extends Module FROM `'._DB_PREFIX_.'orders` o WHERE o.valid = 1 AND o.`invoice_date` BETWEEN '.ModuleGraph::getDateBetween().' - '.$whereOrder; + '.$this->sqlShopRestriction(false, 'o'); $ca['ventil'] = Db::getInstance()->getRow($sql); $sql = 'SELECT /*pac.id_attribute,*/ agl.name as gname, al.name as aname, COUNT(*) as total @@ -630,7 +593,7 @@ class StatsForecast extends Module INNER JOIN '._DB_PREFIX_.'attribute_lang al ON (a.id_attribute = al.id_attribute AND al.id_lang = '.(int)($cookie->id_lang).') WHERE o.valid = 1 AND o.`invoice_date` BETWEEN '.ModuleGraph::getDateBetween().' - '.$whereOrder.' + '.$this->sqlShopRestriction(false, 'o').' GROUP BY pac.id_attribute'; $ca['attributes'] = Db::getInstance()->ExecuteS($sql); diff --git a/modules/statsproduct/statsproduct.php b/modules/statsproduct/statsproduct.php index ff5b67db1..940ec581e 100644 --- a/modules/statsproduct/statsproduct.php +++ b/modules/statsproduct/statsproduct.php @@ -99,24 +99,13 @@ class StatsProduct extends ModuleGraph private function getProducts($id_lang) { - $joinShop = $whereShop = ''; - if ($this->shopID || $this->shopGroupID) - { - $joinShop = ' LEFT JOIN '._DB_PREFIX_.'product_shop ps ON ps.id_product = p.id_product '; - if ($this->shopID) - $whereShop = ' ps.id_shop = '.$this->shopID.' AND '; - else if ($this->shopGroupID) - $whereShop = 'ps.id_shop IN (SELECT id_shop FROM '._DB_PREFIX_.'shop WHERE id_group_shop = '.$this->shopGroupID.') AND'; - } - $sql = 'SELECT p.`id_product`, p.reference, pl.`name`, IFNULL( (SELECT SUM(pa.quantity) FROM '._DB_PREFIX_.'product_attribute pa WHERE pa.id_product = p.id_product), p.quantity) as quantity FROM `'._DB_PREFIX_.'product` p LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON p.`id_product` = pl.`id_product` - '.$joinShop.' + '.Shop::sqlAsso('product', 'p', true, $this->context).' '.(Tools::getValue('id_category') ? 'LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON p.`id_product` = cp.`id_product`' : '').' - WHERE '.$whereShop.' - pl.`id_lang` = '.(int)($id_lang).' + WHERE pl.`id_lang` = '.(int)($id_lang).' '.(Tools::getValue('id_category') ? 'AND cp.id_category = '.(int)(Tools::getValue('id_category')) : '').' ORDER BY pl.`name`'; return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql); diff --git a/modules/statssearch/statssearch.php b/modules/statssearch/statssearch.php index a9c27a343..d63a1cd16 100644 --- a/modules/statssearch/statssearch.php +++ b/modules/statssearch/statssearch.php @@ -87,7 +87,7 @@ class StatsSearch extends ModuleGraph function hookSearch($params) { $sql = 'INSERT INTO `'._DB_PREFIX_.'statssearch` (`id_shop`, `id_group_shop`, `keywords`, `results`, `date_add`) - VALUES ('.$this->shopID.', '.$this->shopGroupID.', \''.pSQL($params['expr']).'\', '.(int)($params['total']).', NOW())'; + VALUES ('.$this->context->shop->getID().', '.$this->context->shop->getGroupID().', \''.pSQL($params['expr']).'\', '.(int)($params['total']).', NOW())'; Db::getInstance()->Execute($sql); } diff --git a/modules/statsstock/statsstock.php b/modules/statsstock/statsstock.php index adbd290a1..59ba6809e 100644 --- a/modules/statsstock/statsstock.php +++ b/modules/statsstock/statsstock.php @@ -59,17 +59,7 @@ class StatsStock extends Module $ru = $currentIndex.'&module='.$this->name.'&token='.Tools::getValue('token'); $currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); $filter = ((int)$cookie->statsstock_id_category ? ' AND p.id_product IN (SELECT cp.id_product FROM '._DB_PREFIX_.'category_product cp WHERE cp.id_category = '.(int)$cookie->statsstock_id_category.')' : ''); - - $joinProduct = $whereProduct = ''; - if ($this->shopID || $this->shopGroupID) - { - $joinProduct = ' LEFT JOIN '._DB_PREFIX_.'product_shop ps ON ps.id_product = p.id_product '; - if ($this->shopID) - $whereProduct = ' AND ps.id_shop = '.$this->shopID; - else if ($this->shopGroupID) - $whereProduct = ' AND ps.id_shop IN (SELECT id_shop FROM '._DB_PREFIX_.'shop WHERE id_group_shop = '.$this->shopGroupID.')'; - } - + $sql = 'SELECT p.id_product, p.reference, pl.name, IFNULL(( SELECT AVG(pa.wholesale_price) @@ -85,10 +75,10 @@ class StatsStock extends Module FROM '._DB_PREFIX_.'product_attribute pa WHERE p.id_product = pa.id_product ), p.wholesale_price * p.quantity) as stockvalue FROM '._DB_PREFIX_.'product p - '.$joinProduct.' + '.Shop::sqlAsso('product', 'p', true, $this->context).' INNER JOIN '._DB_PREFIX_.'product_lang pl ON (p.id_product = pl.id_product AND pl.id_lang = '.(int)$cookie->id_lang.') WHERE 1 = 1 - '.$filter.$whereProduct; + '.$filter; $products = Db::getInstance()->ExecuteS($sql); echo ' diff --git a/modules/treepodia/treepodia.php b/modules/treepodia/treepodia.php index f0ea898ed..a743002be 100644 --- a/modules/treepodia/treepodia.php +++ b/modules/treepodia/treepodia.php @@ -253,7 +253,7 @@ XML; } } - $quantityDiscounts = SpecificPrice::getQuantityDiscounts((int)$sqlProduct['id_product'], $this->shopID, 0, 0, 0); + $quantityDiscounts = SpecificPrice::getQuantityDiscounts((int)$sqlProduct['id_product'], $this->context->shop->getGroupID(), 0, 0, 0); foreach ($quantityDiscounts AS $quantityDiscount) {