From e16a8ab8d3ff1b5517c4c522b1140aa205f69db4 Mon Sep 17 00:00:00 2001 From: rMalie Date: Mon, 18 Jul 2011 15:27:32 +0000 Subject: [PATCH] // Context part 10 --- admin-dev/init.php | 3 +- admin-dev/tabs/AdminCatalog.php | 14 +- admin-dev/tabs/AdminCategories.php | 6 +- admin-dev/tabs/AdminPreferences.php | 2 +- admin-dev/tabs/AdminProducts.php | 25 +-- admin-dev/tabs/AdminStockMvt.php | 4 +- admin-dev/tabs/AdminTaxRulesGroup.php | 7 +- classes/AdminTab.php | 30 +-- classes/Cart.php | 35 ++-- classes/Category.php | 41 ++--- classes/Context.php | 116 +++++------- classes/Db.php | 2 +- classes/ObjectModel.php | 88 +++++---- classes/Product.php | 59 ++++-- classes/Shop.php | 191 +++++++++++++------- classes/Stock.php | 6 +- classes/StockMvt.php | 3 +- controllers/PricesDropController.php | 2 +- controllers/SitemapController.php | 2 +- modules/blockcategories/blockcategories.php | 6 +- modules/blocklayered/blocklayered.php | 14 +- modules/gsitemap/gsitemap.php | 2 +- modules/homefeatured/homefeatured.php | 2 +- modules/mailalerts/mailalerts.php | 19 +- 24 files changed, 375 insertions(+), 304 deletions(-) diff --git a/admin-dev/init.php b/admin-dev/init.php index b4452a3c5..1fe76574e 100644 --- a/admin-dev/init.php +++ b/admin-dev/init.php @@ -95,4 +95,5 @@ $context->link = $link; $context->language = $language; $context->currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); $context->country = $defaultCountry; -$context->shop = new Shop(Shop::getContext('shop', true)); \ No newline at end of file +$context->smarty = $smarty; +$context->shop = new Shop(Shop::getContextID()); \ No newline at end of file diff --git a/admin-dev/tabs/AdminCatalog.php b/admin-dev/tabs/AdminCatalog.php index 41d9d60e8..c436c335e 100644 --- a/admin-dev/tabs/AdminCatalog.php +++ b/admin-dev/tabs/AdminCatalog.php @@ -52,20 +52,20 @@ class AdminCatalog extends AdminTab $id_category = abs(Tools::getValue('id_category')); $shop = Context::getContext()->shop; if (!$id_category) - $id_category = $shop->id_category; - else if ($id_category != $shop->id_category) + $id_category = $shop->getCategory(); + else if ($id_category != $shop->getCategory()) { // Check if current category is "inside" shop default category $sql = 'SELECT nleft, nright FROM '._DB_PREFIX_.'category - WHERE id_category = '.$shop->id_category; - if ($interval = Category::getInterval($shop->id_category)) + WHERE id_category = '.$shop->getCategory(); + if ($interval = Category::getInterval($shop->getCategory())) { $sql = 'SELECT id_category FROM '._DB_PREFIX_.'category WHERE id_category = '.(int)$id_category.' AND nleft >= '.$interval['nleft'].' AND nright <= '.$interval['nright']; if (!Db::getInstance()->getValue($sql)) - $id_category = $shop->id_category; + $id_category = $shop->getCategory(); } } @@ -139,7 +139,7 @@ class AdminCatalog extends AdminTab if (((Tools::isSubmit('submitAddcategory') OR Tools::isSubmit('submitAddcategoryAndStay')) AND sizeof($this->adminCategories->_errors)) OR isset($_GET['updatecategory']) OR isset($_GET['addcategory'])) { $this->adminCategories->displayForm($this->token); - echo '

'.$this->l('Back to list').'
'; + echo '

'.$this->l('Back to list').'
'; } elseif (((Tools::isSubmit('submitAddproduct') OR Tools::isSubmit('submitAddproductAndPreview') OR Tools::isSubmit('submitAddproductAndStay') OR Tools::isSubmit('submitSpecificPricePriorities') OR Tools::isSubmit('submitPriceAddition') OR Tools::isSubmit('submitPricesModification')) AND sizeof($this->adminProducts->_errors)) OR Tools::isSubmit('updateproduct') OR Tools::isSubmit('addproduct')) { @@ -174,7 +174,7 @@ class AdminCatalog extends AdminTab if (!$id_category) { $home = true; - $id_category = Context::getContext()->shop->id_category; + $id_category = Context::getContext()->shop->getCategory(); } $catalog_tabs = array('category', 'product'); // Cleaning links diff --git a/admin-dev/tabs/AdminCategories.php b/admin-dev/tabs/AdminCategories.php index 9f588690c..c1cb2c704 100644 --- a/admin-dev/tabs/AdminCategories.php +++ b/admin-dev/tabs/AdminCategories.php @@ -75,7 +75,7 @@ class AdminCategories extends AdminTab { $context = Context::getContext(); - $this->getList((int)($context->language->id), !$context->cookie->__get($this->table.'Orderby') ? 'position' : NULL, !$context->cookie->__get($this->table.'Orderway') ? 'ASC' : NULL, 0, NULL, $context->shop->getID()); + $this->getList((int)($context->language->id), !$context->cookie->__get($this->table.'Orderby') ? 'position' : NULL, !$context->cookie->__get($this->table.'Orderway') ? 'ASC' : NULL, 0, NULL, $context->shop->getID(true)); echo '

'.(!$this->_listTotal ? ($this->l('There are no subcategories')) : ($this->_listTotal.' '.($this->_listTotal > 1 ? $this->l('subcategories') : $this->l('subcategory')))).' '.$this->l('in category').' "'.stripslashes($this->_category->getName()).'"

'; if ($this->tabAccess['add'] === '1') echo ' '.$this->l('Add a new subcategory').''; @@ -93,7 +93,7 @@ class AdminCategories extends AdminTab { if ($id_category = (int)(Tools::getValue('id_category'))) { - if (!Category::checkBeforeMove($id_category, $this->_category->id)) + if (!Category::checkBeforeMove($id_category, $this->_category->id_parent)) { $this->_errors[] = Tools::displayError('Category cannot be moved here'); return false; @@ -221,7 +221,7 @@ class AdminCategories extends AdminTab $active = $this->getFieldValue($obj, 'active'); $customer_groups = $obj->getGroups(); if ($context->shop->getContextType() == Shop::CONTEXT_SHOP) - $id_category = $context->shop->id_category; + $id_category = $context->shop->getCategory(); else $id_category = (int)Tools::getValue('id_parent'); diff --git a/admin-dev/tabs/AdminPreferences.php b/admin-dev/tabs/AdminPreferences.php index 0d0c4d09c..ef8625960 100644 --- a/admin-dev/tabs/AdminPreferences.php +++ b/admin-dev/tabs/AdminPreferences.php @@ -366,7 +366,7 @@ class AdminPreferences extends AdminTab echo '
'; } - $isDisabled = (isset($field['visibility']) && $field['visibility'] > $context->shop->getContextType()) ? true : false; + $isDisabled = (Tools::isMultiShopActivated() && isset($field['visibility']) && $field['visibility'] > $context->shop->getContextType()) ? true : false; /* Display the appropriate input type for each field */ switch ($field['type']) diff --git a/admin-dev/tabs/AdminProducts.php b/admin-dev/tabs/AdminProducts.php index 9d1192073..234ae0a17 100644 --- a/admin-dev/tabs/AdminProducts.php +++ b/admin-dev/tabs/AdminProducts.php @@ -59,14 +59,14 @@ class AdminProducts extends AdminTab /* Join categories table */ $this->_category = AdminCatalog::getCurrentCategory(); - $this->_join = ' - LEFT JOIN '._DB_PREFIX_.'stock stock ON stock.id_product = a.id_product AND stock.id_product_attribute = 0 '.Shop::sqlSharedStock('stock').' - LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = a.`id_product` AND i.`cover` = 1) - LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_product` = a.`id_product`) - LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (a.`id_tax_rules_group` = tr.`id_tax_rules_group` AND tr.`id_country` = '.(int)$context->country->id.' AND tr.`id_state` = 0) - LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)'; + $this->_join = Product::sqlStock('a').' + LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = a.`id_product` AND i.`cover` = 1) + LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_product` = a.`id_product`) + LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (a.`id_tax_rules_group` = tr.`id_tax_rules_group` AND tr.`id_country` = '.(int)$context->country->id.' AND tr.`id_state` = 0) + LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)'; $this->_filter = 'AND cp.`id_category` = '.(int)($this->_category->id); - $this->_select = 'cp.`position`, i.`id_image`, (a.`price` * ((100 + (t.`rate`))/100)) AS price_final, stock.quantity AS quantity'; + $this->_select = 'cp.`position`, i.`id_image`, (a.`price` * ((100 + (t.`rate`))/100)) AS price_final, SUM(stock.quantity) AS quantity'; + $this->_group = 'GROUP BY stock.id_product'; parent::__construct(); } @@ -1395,11 +1395,12 @@ class AdminProducts extends AdminTab public function display($token = NULL) { $context = Context::getContext(); - $id_shop = $context->shop->getID(); - if (($id_category = (int)Tools::getValue('id_category'))) - $currentIndex .= '&id_category='.$id_category; - $this->getList($context->language->id, !$context->cookie->__get($this->table.'Orderby') ? 'position' : NULL, !$context->cookie->__get($this->table.'Orderway') ? 'ASC' : NULL, 0, NULL, $id_shop); - $id_category = (Tools::getValue('id_category',1)); + + if ($id_category = (int)Tools::getValue('id_category')) + AdminTab::$currentIndex .= '&id_category='.$id_category; + $this->getList($context->language->id, !$context->cookie->__get($this->table.'Orderby') ? 'position' : NULL, !$context->cookie->__get($this->table.'Orderway') ? 'ASC' : NULL, 0, NULL, $context->shop->getID(true)); + + $id_category = Tools::getValue('id_category', 1); if (!$id_category) $id_category = 1; echo '

'.(!$this->_listTotal ? ($this->l('No products found')) : ($this->_listTotal.' '.($this->_listTotal > 1 ? $this->l('products') : $this->l('product')))).' '. diff --git a/admin-dev/tabs/AdminStockMvt.php b/admin-dev/tabs/AdminStockMvt.php index 946c1ffcc..23d84940f 100755 --- a/admin-dev/tabs/AdminStockMvt.php +++ b/admin-dev/tabs/AdminStockMvt.php @@ -47,8 +47,8 @@ class AdminStockMvt extends AdminTab $context = Context::getContext(); $this->_select = 'CONCAT(pl.name, \' \', GROUP_CONCAT(IFNULL(al.name, \'\'), \'\')) product_name, CONCAT(e.lastname, \' \', e.firstname) employee, mrl.name reason'; - $this->_join = 'INNER JOIN '._DB_PREFIX_.'stock stock ON a.id_stock = stock.id_stock '.Shop::sqlSharedStock('stock', Shop::getCurrentShop(), Shop::getCurrentGroupShop()).' - LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (stock.id_product = pl.id_product AND pl.id_lang = '.(int)$context->language->id.') + $this->_join = 'INNER JOIN '._DB_PREFIX_.'stock stock ON a.id_stock = stock.id_stock '.Shop::sqlSharedStock('stock').' + LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (stock.id_product = pl.id_product AND pl.id_lang = '.(int)$context->language->id.' AND pl.id_shop = '.$context->shop->getID(true).') LEFT JOIN `'._DB_PREFIX_.'stock_mvt_reason_lang` mrl ON (a.id_stock_mvt_reason = mrl.id_stock_mvt_reason AND mrl.id_lang = '.(int)$context->language->id.') LEFT JOIN `'._DB_PREFIX_.'employee` e ON (e.id_employee = a.id_employee) LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON (pac.id_product_attribute = stock.id_product_attribute) diff --git a/admin-dev/tabs/AdminTaxRulesGroup.php b/admin-dev/tabs/AdminTaxRulesGroup.php index 3aa2b0bb1..356f6009d 100755 --- a/admin-dev/tabs/AdminTaxRulesGroup.php +++ b/admin-dev/tabs/AdminTaxRulesGroup.php @@ -102,7 +102,7 @@ class AdminTaxRulesGroup extends AdminTab if (Tools::isMultiShopActivated()) { echo '
'; - $this->displayAssoShop(); + $this->displayAssoGroupShop(); echo '
'; } echo ' @@ -507,6 +507,9 @@ class AdminTaxRulesGroup extends AdminTab $result = $object->update(); $this->afterUpdate($object); } + + if ($object->id) + $this->updateAssoGroupShop($object->id); if (!$result) $this->_errors[] = Tools::displayError('An error occurred while updating object.').' '.$this->table.' ('.Db::getInstance()->getMsgError().')'; elseif ($this->postImage($object->id) AND !sizeof($this->_errors)) @@ -549,7 +552,7 @@ class AdminTaxRulesGroup extends AdminTab if (Tools::isSubmit('submitAdd'.$this->table.'AndStay')) Tools::redirectAdmin(self::$currentIndex.'&'.$this->identifier.'='.$object->id.'&conf=3&update'.$this->table.'&token='.$token); - + $this->updateAssoGroupShop($object->id); $id_product = (int)Tools::getValue('id_product'); if ($id_product) Tools::redirectAdmin('?tab=AdminCatalog&id_product='.$id_product.'&updateproduct&token='.Tools::getAdminToken('AdminCatalog'.(int)(Tab::getIdFromClassName('AdminCatalog')).(int)($cookie->id_employee))); diff --git a/classes/AdminTab.php b/classes/AdminTab.php index 30324a04e..760081b4f 100644 --- a/classes/AdminTab.php +++ b/classes/AdminTab.php @@ -861,7 +861,7 @@ abstract class AdminTabCore } if (!sizeof($assos)) return; - Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.$this->table.'_group_shop'.($id_object ? ' WHERE id_object='.(int)$id_object : '')); + Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.$this->table.'_group_shop'.($id_object ? ' WHERE `'.$this->identifier.'`='.(int)$id_object : '')); foreach ($assos AS $asso) Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.$this->table.'_group_shop(`'.pSQL($this->identifier).'`, id_group_shop) VALUES('.(int)$asso['id_object'].', '.(int)$asso['id_group_shop'].')'); @@ -1170,25 +1170,28 @@ abstract class AdminTabCore ON a.id_'.$this->shopLinkType.' = shop.id_'.$this->shopLinkType; $whereShop = Shop::sqlRestriction($this->shopShareDatas, 'a', null, null, $this->shopLinkType); } + $filterShop = ''; - if ($context->shop->getContextType() != Shop::CONTEXT_ALL) + if (Context::shop() != Shop::CONTEXT_ALL) { - if ($context->shop->getContextType() == Shop::CONTEXT_SHOP) + $assos = Shop::getAssoTables(); + if (isset($assos[$this->table]) && $assos[$this->table]['type'] == 'shop') { - $assos = Shop::getAssoTables(); - if (isset($assos[$this->table]) AND $assos[$this->table]['type'] == 'shop') - $filterKey = $assos[$this->table]['type']; - $idenfierShop = $context->shop->getID(); + $filterKey = $assos[$this->table]['type']; + $idenfierShop = Shop::getListFromContext(); } - elseif ($context->shop->getContextType() == Shop::CONTEXT_GROUP) + 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 = $context->shop->getGroupID(); + $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.'='.(int)$idenfierShop.')'; + $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 */ @@ -1206,7 +1209,6 @@ abstract class AdminTabCore ORDER BY '.(($orderBy == $this->identifier) ? 'a.' : '').'`'.pSQL($orderBy).'` '.pSQL($orderWay). ($this->_tmpTableFilter ? ') tmpTable WHERE 1'.$this->_tmpTableFilter : '').' LIMIT '.(int)($start).','.(int)($limit); - //p($sql); $this->_list = Db::getInstance()->ExecuteS($sql); $this->_listTotal = Db::getInstance()->getValue('SELECT FOUND_ROWS() AS `'._DB_PREFIX_.$this->table.'`'); @@ -1691,7 +1693,7 @@ abstract class AdminTabCore if (!Validate::isCleanHtml($val)) $val = Configuration::get($key); - $isDisabled = (isset($field['visibility']) && $field['visibility'] > $context->shop->getContextType()) ? true : false; + $isDisabled = (Tools::isMultiShopActivated() && isset($field['visibility']) && $field['visibility'] > $context->shop->getContextType()) ? true : false; echo $this->getHtmlDefaultConfigurationValue($key, $this->_languages); echo ' @@ -2021,7 +2023,7 @@ abstract class AdminTabCore $html = ''; foreach ($shops AS $shop) - $html .= ''; + $html .= ''; $html .= '
'.$this->l('Shop').''.$this->l('Association').'
'.$shop['name'].'_object->id, $assos[$shop['id_shop']])) || !$this->_object->id) ? 'checked="checked"' : '').'>
'.$shop['name'].'_object->id, $assos[$shop['id_shop']])) || !$this->_object->id) ? 'checked="checked"' : '').'>
'; } echo $html; @@ -2081,7 +2083,7 @@ abstract class AdminTabCore $html = ''; foreach ($groups_shop as $group_shop) - $html .= ''; + $html .= ''; $html .= '
'.$this->l('Shop').''.$this->l('Association').'
'.$group_shop['name'].'id, $assos[$group_shop['id_group_shop']])) ? 'checked="checked"' : '').'>
'.$group_shop['name'].'_object->id, $assos[$group_shop['id_group_shop']])) || !$this->_object->id) ? 'checked="checked"' : '').'>
'; } echo $html; diff --git a/classes/Cart.php b/classes/Cart.php index 8b443d58b..e51dec766 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -348,7 +348,7 @@ class CartCore extends ObjectModel SELECT cp.`id_product_attribute`, cp.`id_product`, cu.`id_customization`, cp.`quantity` AS cart_quantity, cu.`quantity` AS customization_quantity, pl.`name`, pl.`description_short`, pl.`available_now`, pl.`available_later`, p.`id_product`, p.`id_category_default`, p.`id_supplier`, p.`id_manufacturer`, p.`on_sale`, p.`ecotax`, p.`additional_shipping_cost`, p.`available_for_order`, p.`price`, p.`weight`, p.`width`, p.`height`, p.`depth`, p.`out_of_stock`, p.`active`, p.`date_add`, p.`date_upd`, IFNULL(pa.`minimal_quantity`, p.`minimal_quantity`) as minimal_quantity, - t.`id_tax`, tl.`name` AS tax, t.`rate`, pa.`price` AS price_attribute, s.quantity, + t.`id_tax`, tl.`name` AS tax, t.`rate`, pa.`price` AS price_attribute, stock.quantity, pa.`ecotax` AS ecotax_attr, i.`id_image`, il.`legend`, pl.`link_rewrite`, cl.`link_rewrite` AS category, CONCAT(cp.`id_product`, cp.`id_product_attribute`) AS unique_id, IF (IFNULL(pa.`reference`, \'\') = \'\', p.`reference`, pa.`reference`) AS reference, IF (IFNULL(pa.`supplier_reference`, \'\') = \'\', p.`supplier_reference`, pa.`supplier_reference`) AS supplier_reference, @@ -378,7 +378,7 @@ class CartCore extends ObjectModel ) LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$this->id_lang.') LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (p.`id_category_default` = cl.`id_category` AND cl.`id_lang` = '.(int)$this->id_lang.') - LEFT JOIN '._DB_PREFIX_.'stock s ON cp.id_product = s.id_product AND cp.id_product_attribute = s.id_product_attribute '.Shop::sqlSharedStock('s').' + '.Product::sqlStock('cp', 'cp').' WHERE cp.`id_cart` = '.(int)$this->id.' '.($id_product ? ' AND cp.`id_product` = '.(int)$id_product : '').' AND p.`id_product` IS NOT NULL @@ -533,13 +533,15 @@ class CartCore extends ObjectModel * @param integer $id_product_attribute Attribute ID if needed * @param string $operator Indicate if quantity must be increased or decreased */ - public function updateQty($quantity, $id_product, $id_product_attribute = NULL, $id_customization = false, $operator = 'up', $id_shop = NULL, $id_group_shop = NULL) + public function updateQty($quantity, $id_product, $id_product_attribute = NULL, $id_customization = false, $operator = 'up', Context $context = null) { - if (is_null($id_shop)) $id_shop = Context::getContext()->shop->getID(); + if (!$context) + $context = Context::getContext(); + $quantity = (int)$quantity; $id_product = (int)$id_product; $id_product_attribute = (int)$id_product_attribute; - $product = new Product($id_product, false, Configuration::get('PS_LANG_DEFAULT'), $id_shop); + $product = new Product($id_product, false, Configuration::get('PS_LANG_DEFAULT'), $context->shop->getID()); /* If we have a product combination, the minimal quantity is set with the one of this combination */ if (!empty($id_product_attribute)) @@ -568,12 +570,10 @@ class CartCore extends ObjectModel { if ($operator == 'up') { - $sql = 'SELECT p.out_of_stock, s.quantity + $sql = 'SELECT p.out_of_stock, stock.quantity FROM '._DB_PREFIX_.'product p - LEFT JOIN '._DB_PREFIX_.'stock s ON s.id_product = p.id_product - WHERE s.id_product = '.$id_product.' - AND s.id_product_attribute = '.$id_product_attribute - .Shop::sqlSharedStock('s', $id_shop, $id_group_shop); + '.Product::sqlStock('p', $id_product_attribute, true, $context).' + WHERE p.id_product = '.$id_product; $result2 = Db::getInstance()->getRow($sql); $productQty = (int)$result2['quantity']; $newQty = (int)$result['quantity'] + (int)$quantity; @@ -611,12 +611,10 @@ class CartCore extends ObjectModel /* Add product to the cart */ else { - $sql = 'SELECT p.out_of_stock, s.quantity + $sql = 'SELECT p.out_of_stock, stock.quantity FROM '._DB_PREFIX_.'product p - LEFT JOIN '._DB_PREFIX_.'stock s ON s.id_product = p.id_product - WHERE s.id_product = '.$id_product.' - AND s.id_product_attribute = '.$id_product_attribute - .Shop::sqlSharedStock('s', $id_shop, $id_group_shop); + '.Product::sqlStock('p', $id_product_attribute, true, $context).' + WHERE p.id_product = '.$id_product; $result2 = Db::getInstance()->getRow($sql); if (!Product::isAvailableWhenOutOfStock((int)$result2['out_of_stock'])) if ((int)$quantity > $result2['quantity']) @@ -1602,9 +1600,12 @@ class CartCore extends ObjectModel return false; $success = true; $products = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('SELECT * FROM `'._DB_PREFIX_.'cart_product` WHERE `id_cart` = '.(int)$this->id); + + $newContext = Context::cloneContext(); + $newContext->shop = new Shop($cart->id_shop); foreach ($products AS $product) - $success &= $cart->updateQty($product['quantity'], (int)$product['id_product'], (int)$product['id_product_attribute'], NULL, 'up', (int)$cart->id_shop, (int)$cart->id_group_shop); - + $success &= $cart->updateQty($product['quantity'], (int)$product['id_product'], (int)$product['id_product_attribute'], NULL, 'up', $newContext); + // Customized products $customs = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT * diff --git a/classes/Category.php b/classes/Category.php index 1197f85af..3335ea7b3 100644 --- a/classes/Category.php +++ b/classes/Category.php @@ -451,18 +451,13 @@ class CategoryCore extends ObjectModel * @param boolean $checkAccess set to false to return all products (even if customer hasn't access) * @return mixed Products or number of products */ - public function getProducts($id_lang, $p, $n, $orderBy = NULL, $orderWay = NULL, $getTotal = false, $active = true, $random = false, $randomNumberProducts = 1, $checkAccess = true, $id_shop = null, $context = null) + public function getProducts($id_lang, $p, $n, $orderBy = NULL, $orderWay = NULL, $getTotal = false, $active = true, $random = false, $randomNumberProducts = 1, $checkAccess = true, $context = null) { if (!$context) $context = Context::getContext(); if (!$checkAccess OR !$this->checkAccess($context->customer->id)) return false; - - if (!$id_shop) - $id_shop_lang = (int)Configuration::get('PS_SHOP_DEFAULT'); - else - $id_shop_lang = (int)$id_shop; - + if ($p < 1) $p = 1; if (empty($orderBy)) @@ -498,24 +493,23 @@ class CategoryCore extends ObjectModel { $sql = 'SELECT COUNT(cp.`id_product`) AS total FROM `'._DB_PREFIX_.'product` p - '.($id_shop ? 'LEFT JOIN '._DB_PREFIX_.'product_shop ps ON (ps.id_product = p.id_product)' : '').' + '.Shop::sqlAsso('product', 'p', $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' : ''). - ($id_shop ? ' AND ps.id_shop='.(int)$id_shop : ''). ($id_supplier ? 'AND p.id_supplier = '.(int)($id_supplier) : ''); return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql); } - $sql = 'SELECT p.*, s.quantity, pa.`id_product_attribute`, pl.`description`, pl.`description_short`, pl.`available_now`, pl.`available_later`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, i.`id_image`, il.`legend`, m.`name` AS manufacturer_name, tl.`name` AS tax_name, t.`rate`, cl.`name` AS category_default, 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, + $sql = 'SELECT p.*, stock.quantity, pa.`id_product_attribute`, pl.`description`, pl.`description_short`, pl.`available_now`, pl.`available_later`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, i.`id_image`, il.`legend`, m.`name` AS manufacturer_name, tl.`name` AS tax_name, t.`rate`, cl.`name` AS category_default, 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, (p.`price` * IF(t.`rate`,((100 + (t.`rate`))/100),1)) AS orderprice FROM `'._DB_PREFIX_.'category_product` cp LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = cp.`id_product` - '.($id_shop ? 'LEFT JOIN '._DB_PREFIX_.'product_shop ps ON (ps.id_product = p.id_product)' : '').' LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product` AND default_on = 1) - LEFT JOIN '._DB_PREFIX_.'stock s ON s.id_product = p.id_product AND s.id_product_attribute = IFNULL(pa.id_product_attribute, 0) '.Shop::sqlSharedStock('s', $id_shop).' - LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (p.`id_category_default` = cl.`id_category` AND cl.`id_lang` = '.(int)$id_lang.' AND cl.`id_shop` = '.(int)$id_shop_lang.') - LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.' AND pl.`id_shop` = '.(int)$id_shop_lang.') + '.Shop::sqlAsso('product', 'p', $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).') LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1) LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.') LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group` @@ -526,8 +520,7 @@ class CategoryCore extends ObjectModel LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer` WHERE cp.`id_category` = '.(int)($this->id) .($active ? ' AND p.`active` = 1' : '') - .($id_supplier ? ' AND p.id_supplier = '.(int)$id_supplier : '') - .($id_shop ? ' AND ps.id_shop='.(int)$id_shop : ''); + .($id_supplier ? ' AND p.id_supplier = '.(int)$id_supplier : ''); if ($random === true) { $sql .= ' ORDER BY RAND()'; @@ -576,11 +569,11 @@ class CategoryCore extends ObjectModel static public function getRootCategory($id_lang = NULL, $id_shop = false, $context = null) { - if (!$id_shop) - $id_shop = Configuration::get('PS_SHOP_DEFAULT'); - $shop = new Shop($id_shop); + if (!$context) + $context = Context::getContext(); + $shop = new Shop($context->shop->getID(true)); - return new Category ($shop->id_category, is_null($id_lang) ? $context->language->id : $id_lang); + return new Category($shop->getCategory(), is_null($id_lang) ? $context->language->id : $id_lang); } /** @@ -724,21 +717,19 @@ class CategoryCore extends ObjectModel return $context->link->getCategoryLink($this->id, $this->link_rewrite); } - public function getName($id_lang = NULL, $id_shop = false, $context = null) + public function getName($id_lang = NULL, $context = null) { - if (!$id_shop) - $id_shop = Context::getContext()->shop->getID(); if (!$id_lang) { if (!$context) $context = Context::getContext(); - if (isset($this->name[(int)$id_shop][$context->language->id])) + if (isset($this->name[$context->language->id])) $id_lang = $context->language->id; else $id_lang = (int)(Configuration::get('PS_LANG_DEFAULT')); } - return isset($this->name[(int)$id_shop][$id_lang]) ? $this->name[(int)$id_shop][$id_lang] : ''; + return isset($this->name[$id_lang]) ? $this->name[$id_lang] : ''; } /** diff --git a/classes/Context.php b/classes/Context.php index 6b2f8ecd8..3273d67b3 100644 --- a/classes/Context.php +++ b/classes/Context.php @@ -30,90 +30,42 @@ */ class ContextCore { - /** - * @var Context - */ + /** @var Context */ protected static $instance; - /** - * @var Cart - */ + /** @var Cart */ public $cart; - - /** - * @var Customer - */ + + /** @var Customer */ public $customer; - - /** - * @var Cookie - */ + + /** @var Cookie */ public $cookie; - - /** - * @var Link - */ + + /** @var Link */ public $link; - - /** - * @var Country - */ + + /** @var Country */ public $country; - - /** - * @var Employee - */ + + /** @var Employee */ public $employee; - - /** - * @var Controller - */ + + /** @var Controller */ public $controller; - - /** - * @var Language - */ + + /** @var Language */ public $language; - - /** - * @var Currency - */ + + /** @var Currency */ public $currency; - - /** - * @var AdminTab - */ + + /** @var AdminTab */ public $tab; - - /** - * @var Shop - */ + + /** @var Shop */ public $shop; - - /** - * Create a context without singleton constraint - */ - public function __construct($cart = null, - $customer = null, - $cookie = null, - $link = null, - $country = null, - $employee = null, - $language = null, - $currency = null, - $tab = null) - { - $this->cart = $cart; - $this->customer = $customer; - $this->cookie = $cookie; - $this->link = $link; - $this->country = $country; - $this->employee = $employee; - $this->language = $language; - $this->currency = $currency; - $this->tab = $tab; - } - + /** * Get a singleton context * @@ -122,7 +74,27 @@ class ContextCore public static function getContext() { if (!isset(self::$instance)) - self::$instance = new self(); + self::$instance = new Context(); return self::$instance; } + + /** + * Clone current context ( + * + * @return Context + */ + public function cloneContext() + { + return clone($this); + } + + /** + * @return int Shop context type (Shop::CONTEXT_ALL, etc.) + */ + public static function shop() + { + if (!self::$instance->shop->getContextType()) + return Shop::CONTEXT_ALL; + return self::$instance->shop->getContextType(); + } } \ No newline at end of file diff --git a/classes/Db.php b/classes/Db.php index e20efe3e2..048379dde 100644 --- a/classes/Db.php +++ b/classes/Db.php @@ -75,7 +75,7 @@ abstract class DbCore * Get Db object instance (Singleton) * * @param boolean $master Decides wether the connection to be returned by the master server or the slave server - * @return object Db instance + * @return Db instance */ public static function getInstance($master = 1) { diff --git a/classes/ObjectModel.php b/classes/ObjectModel.php index 697ab5f38..c26986efc 100644 --- a/classes/ObjectModel.php +++ b/classes/ObjectModel.php @@ -35,6 +35,8 @@ abstract class ObjectModelCore protected $id_shop = NULL; + private $getShopFromContext = true; + /** @var string SQL Table name */ protected $table = NULL; @@ -116,11 +118,16 @@ abstract class ObjectModelCore $this->id_lang = $id_lang; elseif ($id_lang != NULL) die(Tools::displayError()); - - if ($this->langMultiShop AND $id_shop == NULL) - $id_shop = Context::getContext()->shop->getID(); - if ($id_shop AND $this->langMultiShop) - $this->id_shop = $id_shop; + + if ($id_shop && $this->langMultiShop) + { + $this->id_shop = (int)$id_shop; + $this->getShopFromContext = false; + } + + if ($this->langMultiShop && !$this->id_shop) + $this->id_shop = Context::getContext()->shop->getID(true); + /* Connect to database and check SQL table/identifier */ if (!Validate::isTableOrIdentifier($this->identifier) OR !Validate::isTableOrIdentifier($this->table)) die(Tools::displayError()); @@ -130,12 +137,15 @@ abstract class ObjectModelCore if ($id) { if (!isset(self::$_cache[$this->table][(int)$id][(int)$id_shop][(int)$id_lang])) - self::$_cache[$this->table][(int)($id)][(int)$id_shop][(int)$id_lang] = $db->getRow(' - SELECT * - FROM `'._DB_PREFIX_.$this->table.'` a '. - ($id_lang ? ('LEFT JOIN `'.pSQL(_DB_PREFIX_.$this->table).'_lang` b ON (a.`'.$this->identifier.'` = b.`'.$this->identifier).'` AND `id_lang` = '.(int)($id_lang).')' : '') - .' WHERE 1 AND a.`'.$this->identifier.'` = '.(int)$id. - (($this->langMultiShop AND $id_shop AND $id_lang) ? ' AND b.id_shop='.(int)$id_shop : '')); + { + $sql = 'SELECT * + FROM `'._DB_PREFIX_.$this->table.'` a '. + ($id_lang ? ('LEFT JOIN `'.pSQL(_DB_PREFIX_.$this->table).'_lang` b ON (a.`'.$this->identifier.'` = b.`'.$this->identifier).'` AND `id_lang` = '.(int)($id_lang).')' : '') + .' WHERE 1 AND a.`'.$this->identifier.'` = '.(int)$id. + (($this->id_shop AND $id_lang) ? ' AND b.id_shop='.$this->id_shop : ''); + self::$_cache[$this->table][(int)($id)][(int)$id_shop][(int)$id_lang] = $db->getRow($sql); + } + $result = self::$_cache[$this->table][(int)$id][(int)$id_shop][(int)$id_lang]; if ($result) { @@ -146,9 +156,10 @@ abstract class ObjectModelCore if (!$id_lang AND method_exists($this, 'getTranslationsFieldsChild')) { - $result = $db->ExecuteS('SELECT * FROM `'.pSQL(_DB_PREFIX_.$this->table).'_lang` - WHERE `'.$this->identifier.'` = '.(int)$id - .(($this->langMultiShop AND $id_shop) ? ' AND `id_shop`='.(int)$id_shop : '')); + $sql = 'SELECT * FROM `'.pSQL(_DB_PREFIX_.$this->table).'_lang` + WHERE `'.$this->identifier.'` = '.(int)$id + .(($this->id_shop) ? ' AND `id_shop` = '.$this->id_shop : ''); + $result = $db->ExecuteS($sql); if ($result) foreach ($result as $row) foreach ($row AS $key => $value) @@ -157,8 +168,7 @@ abstract class ObjectModelCore { if (!is_array($this->{$key})) $this->{$key} = array(); - else - $this->{$key}[$row['id_lang']] = stripslashes($value); + $this->{$key}[$row['id_lang']] = stripslashes($value); } } } @@ -224,17 +234,17 @@ abstract class ObjectModelCore if (!Validate::isTableOrIdentifier($key)) die(Tools::displayError()); $field[$this->identifier] = (int)$this->id; - $result = Db::getInstance()->AutoExecute(_DB_PREFIX_.$this->table.'_lang', $field, 'INSERT') && $result; + if (isset($assos[$this->table.'_lang']) && $assos[$this->table.'_lang']['type'] == 'fk_shop') { foreach ($shops as $id_shop) { - if ($this->id_shop == (int)$id_shop) - continue; $field['id_shop'] = (int)$id_shop; - $result = Db::getInstance()->AutoExecute(_DB_PREFIX_.$this->table.'_lang', $field, 'INSERT') && $result; + $result &= Db::getInstance()->AutoExecute(_DB_PREFIX_.$this->table.'_lang', $field, 'INSERT'); } } + else + $result &= Db::getInstance()->AutoExecute(_DB_PREFIX_.$this->table.'_lang', $field, 'INSERT'); } } @@ -252,7 +262,7 @@ abstract class ObjectModelCore /** * Update current object to database * - * return boolean Update result + * @return boolean Update result */ public function update($nullValues = false) { @@ -283,20 +293,34 @@ abstract class ObjectModelCore foreach ($field as $key => $value) if (!Validate::isTableOrIdentifier($key)) die(Tools::displayError()); - + + // If this table is linked to multishop system, update / insert for all shops from context if ($this->langMultiShop) - $field['id_shop'] = ($this->id_shop ? $this->id_shop : Context::getContext()->shop->getID()); + { + $listShops = ($this->id_shop && !$this->getShopFromContext) ? array($this->id_shop) : Shop::getListFromContext(); + foreach ($listShops as $shop) + { + $field['id_shop'] = $shop; + $where = pSQL($this->identifier).' = '.(int)$this->id + .' AND id_lang = '.(int)$field['id_lang'] + .' AND id_shop = '.$field['id_shop']; - // used to insert missing lang entries - $where_lang = '`'.pSQL($this->identifier).'` = '.(int)$this->id. - ' AND `id_lang` = '.(int)$field['id_lang']. - (($this->langMultiShop AND $this->id_shop) ? ' AND `id_shop`='.$this->id_shop : ''); - - $lang_found = Db::getInstance()->getValue('SELECT COUNT(*) FROM `'.pSQL(_DB_PREFIX_.$this->table).'_lang` WHERE '. $where_lang); - if (!$lang_found) - $result &= Db::getInstance()->AutoExecute(_DB_PREFIX_.$this->table.'_lang', $field, 'INSERT'); + if (Db::getInstance()->getValue('SELECT COUNT(*) FROM '.pSQL(_DB_PREFIX_.$this->table).'_lang WHERE '.$where)) + $result &= Db::getInstance()->AutoExecute(_DB_PREFIX_.$this->table.'_lang', $field, 'UPDATE', $where); + else + $result &= Db::getInstance()->AutoExecute(_DB_PREFIX_.$this->table.'_lang', $field, 'INSERT'); + } + } + // If this table is not linked to multishop system ... else - $result &= Db::getInstance()->AutoExecute(_DB_PREFIX_.$this->table.'_lang', $field, 'UPDATE', $where_lang); + { + $where = pSQL($this->identifier).' = '.(int)$this->id + .' AND id_lang = '.(int)$field['id_lang']; + if (Db::getInstance()->getValue('SELECT COUNT(*) FROM '.pSQL(_DB_PREFIX_.$this->table).'_lang WHERE '.$where)) + $result &= Db::getInstance()->AutoExecute(_DB_PREFIX_.$this->table.'_lang', $field, 'UPDATE', $where); + else + $result &= Db::getInstance()->AutoExecute(_DB_PREFIX_.$this->table.'_lang', $field, 'INSERT'); + } } } } diff --git a/classes/Product.php b/classes/Product.php index 3da67ff1e..25d8685fe 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -390,7 +390,7 @@ class ProductCore extends ObjectModel { $fields[$language['id_lang']]['id_lang'] = $language['id_lang']; $fields[$language['id_lang']][$this->identifier] = (int)($this->id); - $fields[$language['id_lang']]['id_shop'] = (int)$this->id_shop; + $fields[$language['id_lang']]['id_shop'] = (int)$this->id_shop; // @todo ID shop in product ??? $fields[$language['id_lang']]['description'] = (isset($this->description[$language['id_lang']])) ? pSQL($this->description[$language['id_lang']], true) : ''; $fields[$language['id_lang']]['description_short'] = (isset($this->description_short[$language['id_lang']])) ? pSQL($this->description_short[$language['id_lang']], true) : ''; foreach ($fieldsArray as $field) @@ -507,9 +507,9 @@ class ProductCore extends ObjectModel { $sql = 'SELECT pa.id_product_attribute FROM '._DB_PREFIX_.'product_attribute pa' - .($minimumQuantity > 0 ? ' LEFT JOIN '._DB_PREFIX_.'stock s ON s.id_product = pa.id_product AND pa.id_product_attribute = s.id_product_attribute '.Shop::sqlSharedStock('s') : ''). + .($minimumQuantity > 0 ? Product::sqlStock('pa', 'pa') : ''). ' WHERE pa.default_on = 1 ' - .($minimumQuantity > 0 ? ' AND s.quantity >= '.(int)$minimumQuantity : ''). + .($minimumQuantity > 0 ? ' AND stock.quantity >= '.(int)$minimumQuantity : ''). ' AND pa.id_product = '.(int)$id_product; $result = Db::getInstance()->getRow($sql); @@ -517,7 +517,7 @@ class ProductCore extends ObjectModel { $sql = 'SELECT pa.id_product_attribute FROM '._DB_PREFIX_.'product_attribute pa' - .($minimumQuantity > 0 ? ' LEFT JOIN '._DB_PREFIX_.'stock s ON s.id_product = pa.id_product AND pa.id_product_attribute = s.id_product_attribute '.Shop::sqlSharedStock('s') : ''). + .($minimumQuantity > 0 ? Product::sqlStock('pa', 'pa') : ''). ' WHERE pa.id_product = '.(int)$id_product .($minimumQuantity > 0 ? ' AND s.quantity >= '.(int)$minimumQuantity : ''); $result = Db::getInstance()->getRow($sql); @@ -1490,12 +1490,12 @@ class ProductCore extends ObjectModel * @param boolean $count Only in order to get total number (optional) * @return array Prices drop */ - public static function getPricesDrop($id_lang, $pageNumber = 0, $nbProducts = 10, $count = false, $orderBy = NULL, $orderWay = NULL, $beginning = false, $ending = false, $id_shop = null) + public static function getPricesDrop($id_lang, $pageNumber = 0, $nbProducts = 10, $count = false, $orderBy = NULL, $orderWay = NULL, $beginning = false, $ending = false, Context $context = null) { if (!Validate::isBool($count)) die(Tools::displayError()); - if (is_null($id_shop)) $id_shop = Context::getContext()->shop->getID(); + if (is_null($context)) $context = Context::getContext(); if ($pageNumber < 0) $pageNumber = 0; if ($nbProducts < 1) $nbProducts = 10; if (empty($orderBy) || $orderBy == 'position') $orderBy = 'price'; @@ -1516,9 +1516,8 @@ class ProductCore extends ObjectModel { $sql = 'SELECT COUNT(DISTINCT p.`id_product`) AS nb FROM `'._DB_PREFIX_.'product` p - LEFT JOIN '._DB_PREFIX_.'product_shop ps ON (ps.id_product = p.id_product) + '.Shop::sqlAsso('product', 'p', $context).' WHERE p.`active` = 1 - AND ps.id_shop='.(int)$id_shop.' 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).')' : '').' AND p.`id_product` IN ( @@ -1536,8 +1535,8 @@ class ProductCore extends ObjectModel 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 LEFT JOIN '._DB_PREFIX_.'product_shop ps ON (ps.id_product = p.id_product) - LEFT JOIN '._DB_PREFIX_.'stock s ON p.id_product = s.id_product AND s.id_product_attribute = 0 '.Shop::sqlSharedStock('s', $id_shop).' - LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.' AND pl.id_shop = '.(int)$id_shop.') + '.Shop::sqlAsso('product', 'p', $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) 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 (p.`id_tax_rules_group` = tr.`id_tax_rules_group` @@ -1546,7 +1545,6 @@ class ProductCore extends ObjectModel LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`) LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`) WHERE p.`active` = 1 - AND ps.id_shop = '.(int)$id_shop.' 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).')' : '').' AND p.`id_product` IN ( @@ -2046,6 +2044,33 @@ class ProductCore extends ObjectModel return $product->getStock($id_product_attribute); } + /** + * Create JOIN query with 'stock' table + * + * @param string $productAlias Alias of product table + * @param string|int $productAttribute If string : alias of PA table ; if int : value of PA ; if null : nothing about PA + * @param bool $innerJoin LEFT JOIN or INNER JOIN + * @param Context $context + * @return string + */ + public static function sqlStock($productAlias, $productAttribute = 0, $innerJoin = false, Context $context = null) + { + if (!$context) + $context = Context::getContext(); + + $sql = (($innerJoin) ? ' INNER ' : ' LEFT ').'JOIN '._DB_PREFIX_.'stock stock ON stock.id_product = '.pSQL($productAlias).'.id_product'; + if (!is_null($productAttribute)) + { + if (is_numeric($productAttribute)) + $sql .= ' AND stock.id_product_attribute = '.$productAttribute; + else if (is_string($productAttribute)) + $sql .= ' AND stock.id_product_attribute = '.pSQL($productAttribute).'.id_product_attribute'; + } + $sql .= Shop::sqlSharedStock('stock', $context) . ' '; + + return $sql; + } + /** * Set the stock quantity of current product * @@ -2088,7 +2113,7 @@ class ProductCore extends ObjectModel // Change stock quantity on product attribute if ($id_product_attribute) { - if ($id_stock = Stock::getStockId($this->id, $id_product_attribute, $shop->getID())) + if ($id_stock = Stock::getStockId($this->id, $id_product_attribute, $shop->getID(true))) { $sql = 'UPDATE '._DB_PREFIX_.'stock SET quantity = '.(($update) ? 'quantity + '. $quantity : $quantity).' @@ -2106,7 +2131,7 @@ class ProductCore extends ObjectModel } // Change stock quantity on product - if ($id_stock = Stock::getStockId($this->id, $id_product_attribute, $shop->getID())) + if ($id_stock = Stock::getStockId($this->id, $id_product_attribute, $shop->getID(true))) { $sql = 'UPDATE '._DB_PREFIX_.'stock SET quantity = '.(($update) ? 'quantity + '. $quantity : $quantity).' @@ -2142,7 +2167,7 @@ class ProductCore extends ObjectModel FROM '._DB_PREFIX_.'stock WHERE id_product = '.$this->id.' AND id_product_attribute = '.(int)$id_product_attribute - .Shop::sqlSharedStock(); + .Shop::sqlSharedStock('', $context); return (int)Db::getInstance()->getValue($sql); } @@ -2260,9 +2285,9 @@ class ProductCore extends ObjectModel public function getAttributesGroups($id_lang) { $sql = 'SELECT ag.`id_attribute_group`, ag.`is_color_group`, agl.`name` AS group_name, agl.`public_name` AS public_group_name, a.`id_attribute`, al.`name` AS attribute_name, - a.`color` AS attribute_color, pa.`id_product_attribute`, s.quantity, pa.`price`, pa.`ecotax`, pa.`weight`, pa.`default_on`, pa.`reference`, pa.`unit_price_impact`, pa.`minimal_quantity` + a.`color` AS attribute_color, pa.`id_product_attribute`, stock.quantity, pa.`price`, pa.`ecotax`, pa.`weight`, pa.`default_on`, pa.`reference`, pa.`unit_price_impact`, pa.`minimal_quantity` FROM `'._DB_PREFIX_.'product_attribute` pa - LEFT JOIN '._DB_PREFIX_.'stock s ON s.id_product = pa.id_product AND s.id_product_attribute = pa.id_product_attribute '.Shop::sqlSharedStock('s').' + '.Product::sqlStock('pa', 'pa').' LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON pac.`id_product_attribute` = pa.`id_product_attribute` LEFT JOIN `'._DB_PREFIX_.'attribute` a ON a.`id_attribute` = pac.`id_attribute` LEFT JOIN `'._DB_PREFIX_.'attribute_group` ag ON ag.`id_attribute_group` = a.`id_attribute_group` @@ -3154,7 +3179,7 @@ class ProductCore extends ObjectModel // Add a new stock movement $stockMvt = new StockMvt(); - $stockMvt->id_stock = Stock::getStockId($this->id, $id_product_attribute, $this->id_shop); + $stockMvt->id_stock = Stock::getStockId($this->id, $id_product_attribute, Context::getContext()->shop->getID(true)); $stockMvt->id_product = $this->id; $stockMvt->id_product_attribute = (int)$id_product_attribute; $stockMvt->id_order = (int)$id_order; diff --git a/classes/Shop.php b/classes/Shop.php index 6b0238019..963797ac6 100644 --- a/classes/Shop.php +++ b/classes/Shop.php @@ -252,7 +252,7 @@ class ShopCore extends ObjectModel public function getGroup($asObject = false) { if (!$this->group) - $this->group = new GroupShop($this->id_group_shop); + $this->group = new GroupShop($this->getGroupID()); return $this->group; } @@ -261,11 +261,11 @@ class ShopCore extends ObjectModel * * @return int */ - public function getID() + public function getID($useDefault = false) { - return (int)$this->id; + return (!$this->id && $useDefault) ? (int)Configuration::get('PS_SHOP_DEFAULT') : (int)$this->id; } - + /** * Get current shop group ID * @@ -273,6 +273,8 @@ class ShopCore extends ObjectModel */ public function getGroupID() { + if (defined('PS_ADMIN_DIR')) + return Shop::getContextGroupID(); return (int)$this->id_group_shop; } @@ -281,9 +283,9 @@ class ShopCore extends ObjectModel * * @return int */ - public function getRootCategory() + public function getCategory() { - return $this->id_category; + return ($this->id_category) ? $this->id_category : 1; } /** @@ -296,10 +298,10 @@ class ShopCore extends ObjectModel $sql = 'SELECT * FROM '._DB_PREFIX.'shop_url WHERE active = 1 - AND id_shop='.(int)$this->id; + AND id_shop = '.(int)$this->id; return Db::getInstance()->ExecuteS($sql); } - + /** * Check if current shop ID is the same as default shop in configuration * @@ -438,60 +440,6 @@ class ShopCore extends ObjectModel return array_keys($groupData['shops']); return array($shopID); } - - /** - * Retrieve the current shop context in FO or BO - * - * @param string null|shop|group - * @param bool If true, this method will return default shop ID if no shop was found in context (for BO) - * @return array(id_shop, id_group_shop)|int - */ - public static function getContext($type = null, $useDefault = false) - { - static $executed = false, $shopID = 0, $shopGroupID = 0; - - if (!$executed) - { - $context = Context::getContext(); - if (defined('PS_ADMIN_DIR')) - { - // While cookie is not instancied in admin, we wait ... - if (!isset($context->cookie)) - return ($type == 'shop' || $type == 'group') ? '' : array('', ''); - - // Parse shopContext cookie value (E.g. s-2, g-4) - $split = explode('-', Context::getContext()->cookie->shopContext); - $shopID = $shopGroupID = ''; - if (count($split) == 2) - { - if ($split[0] == 's') - $shopID = (int)$split[1]; - else if ($split[0] == 'g') - $shopGroupID = (int)$split[1]; - - if ($shopID && !$shopGroupID) - $shopGroupID = Shop::getGroupFromShop($shopID); - } - } - else - { - $shopID = $context->shop->getID(); - $shopGroupID = $context->shop->getGroupID(); - } - $executed = true; - } - - if ($useDefault && !$shopID) - $shopID = Configuration::get('PS_SHOP_DEFAULT'); - if ($useDefault && !$shopGroupID) - $shopID = Shop::getGroupFromShop(Configuration::get('PS_SHOP_DEFAULT')); - - if ($type == 'shop') - return $shopID; - else if ($type == 'group') - return $shopGroupID; - return array($shopID, $shopGroupID); - } /** * Get a list of ID concerned by the shop context (E.g. if context is shop group, get list of children shop ID) @@ -513,15 +461,84 @@ class ShopCore extends ObjectModel return $list; } + /** + * Retrieve the current shop context in FO or BO + * + * @param string null|shop|group + * @return array(id_shop, id_group_shop)|int + */ + public static function getContext($type = null) + { + static $executed = false, $shopID = 0, $shopGroupID = 0; + + if (!$executed) + { + $context = Context::getContext(); + if (defined('PS_ADMIN_DIR')) + { + // While cookie is not instancied in admin, we wait ... + if (!isset($context->cookie)) + return ($type == 'shop' || $type == 'group') ? '' : array('', ''); + + // Parse shopContext cookie value (E.g. s-2, g-4) + $split = explode('-', Context::getContext()->cookie->shopContext); + if (count($split) == 2) + { + if ($split[0] == 's') + $shopID = (int)$split[1]; + else if ($split[0] == 'g') + $shopGroupID = (int)$split[1]; + + if ($shopID && !$shopGroupID) + $shopGroupID = Shop::getGroupFromShop($shopID); + } + } + else + { + $shopID = (int)$context->shop->id_shop; + $shopGroupID = (int)$context->shop->id_group_shop; + } + $executed = true; + } + + if ($type == 'shop') + return $shopID; + else if ($type == 'group') + return $shopGroupID; + return array($shopID, $shopGroupID); + } + + /** + * Get ID shop from context + * + * @return int + */ + public static function getContextID() + { + return Shop::getContext('shop'); + } + + /** + * Get ID shop from context + * + * @return int + */ + public static function getContextGroupID() + { + return Shop::getContext('group'); + } + /** * 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() + public static function getListFromContext(Context $context = null) { - list($shopID, $shopGroupID) = Shop::getContext(); - return Shop::getListOfID($shopID, $shopGroupID); + if (!$context) + $context = Context::getContext(); + return Shop::getListOfID($context->shop->getID(), $context->shop->getGroupID()); } /** @@ -569,14 +586,15 @@ class ShopCore extends ObjectModel return $restriction; } - public static function sqlSharedStock($alias = null, $shopID = null, $shopGroupID = null) + public static function sqlSharedStock($alias = null, Context $context = null) { if ($alias) $alias .= '.'; + if (!$context) + $context = Context::getContext(); - if (is_null($shopID)) - $shopID = Context::getContext()->shop->getID(); - + $shopID = $context->shop->getID(); + $shopGroupID = $context->shop->getGroupID(); if (!$shopID) return ($shopGroupID) ? ' AND '.$alias.'id_group_shop = '.(int)$shopGroupID : ''; @@ -586,6 +604,41 @@ class ShopCore extends ObjectModel return ' AND '.$alias.'id_group_shop = '.$groupID; return ' AND '.$alias.'id_shop = '.$shopID; } + + /** + * Add an SQL JOIN in query between a table and its associated table in multishop + * + * @param string $table Table name (E.g. product, module, etc.) + * @param string $alias Alias of table + * @param Context $context + * @return string + */ + public static function sqlAsso($table, $alias, Context $context = null) + { + if (!$context) + $context = Context::getContext(); + + $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)).') '; + return $sql; + } + + /** + * Add a restriction on id_shop for multishop lang table + * + * @param string $alias + * @param Context $context + * @return string + */ + public static function sqlLang($alias, Context $context = null) + { + return ' AND '.$alias.'.id_shop = '.$context->shop->getID(true). ' '; + } /** * Get all groups and associated shops as subarrays diff --git a/classes/Stock.php b/classes/Stock.php index 34b504d40..577b87cd1 100755 --- a/classes/Stock.php +++ b/classes/Stock.php @@ -54,13 +54,13 @@ class Stock extends ObjectModel return $fields; } - public static function getStockId($id_product, $id_product_attribute, $shopID = null) + public static function getStockId($id_product, $id_product_attribute, $shopID) { $sql = 'SELECT id_stock FROM '._DB_PREFIX_.'stock WHERE id_product = '.(int)$id_product.' - AND id_product_attribute = '.(int)$id_product_attribute - .Shop::sqlSharedStock('', $shopID); + AND id_product_attribute = '.(int)$id_product_attribute.' + AND id_shop = '.(int)$shopID; return (int)Db::getInstance()->getValue($sql); } } \ No newline at end of file diff --git a/classes/StockMvt.php b/classes/StockMvt.php index 4da2a3738..0956aaeda 100755 --- a/classes/StockMvt.php +++ b/classes/StockMvt.php @@ -90,14 +90,13 @@ class StockMvtCore extends ObjectModel // Search missing stock movement on products without attributes $sql = 'SELECT s.id_stock, (s.quantity - SUM(IFNULL(sm.quantity, 0))) AS qty FROM '._DB_PREFIX_.'product p - INNER JOIN '._DB_PREFIX_.'stock s ON s.id_product = p.id_product + '.Product::sqlStock('p', null, true).' LEFT JOIN '._DB_PREFIX_.'stock_mvt sm ON s.id_stock = sm.id_stock WHERE ( SELECT COUNT(*) FROM '._DB_PREFIX_.'stock s2 WHERE s2.id_product = p.id_product AND s2.id_product_attribute > 0 ) = 0 - '.Shop::sqlSharedStock('s').' GROUP BY s.id_product, s.id_shop HAVING qty <> 0'; $products_without_attributes = Db::getInstance()->ExecuteS($sql); diff --git a/controllers/PricesDropController.php b/controllers/PricesDropController.php index 7324c1b4b..2622bb808 100644 --- a/controllers/PricesDropController.php +++ b/controllers/PricesDropController.php @@ -49,7 +49,7 @@ class PricesDropControllerCore extends FrontController $this->pagination($nbProducts); $this->smarty->assign(array( - 'products' => Product::getPricesDrop((int)self::$cookie->id_lang, (int)$this->p - 1, (int)$this->n, false, $this->orderBy, $this->orderWay, false, false, (int)$this->id_current_shop), + 'products' => Product::getPricesDrop((int)self::$cookie->id_lang, (int)$this->p - 1, (int)$this->n, false, $this->orderBy, $this->orderWay), 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'nbProducts' => $nbProducts, 'homeSize' => Image::getSize('home') diff --git a/controllers/SitemapController.php b/controllers/SitemapController.php index 8e961fd73..fe4d08689 100644 --- a/controllers/SitemapController.php +++ b/controllers/SitemapController.php @@ -44,7 +44,7 @@ class SitemapControllerCore extends FrontController public function process() { parent::process(); - $this->smarty->assign('categoriesTree', Category::getRootCategory(NULL, $this->id_current_shop)->recurseLiteCategTree(0)); + $this->smarty->assign('categoriesTree', Category::getRootCategory()->recurseLiteCategTree(0)); $this->smarty->assign('categoriescmsTree', CMSCategory::getRecurseCategory(Context::getContext()->language->id, 1, 1, 1, $this->id_current_shop)); $this->smarty->assign('voucherAllowed', (int)Configuration::get('PS_VOUCHERS')); $blockmanufacturer = Module::getInstanceByName('blockmanufacturer'); diff --git a/modules/blockcategories/blockcategories.php b/modules/blockcategories/blockcategories.php index b3768b4ec..b5b4b8669 100644 --- a/modules/blockcategories/blockcategories.php +++ b/modules/blockcategories/blockcategories.php @@ -184,7 +184,7 @@ class BlockCategories extends Module unset($resultIds); //TODO clean that $res = $blockCategTree; - $shopcurrentroot = $context->shop->id_category; + $shopcurrentroot = $context->shop->getCategory(); if ($blockCategTree['id'] != $shopcurrentroot) $blockCategTree = $this->cleanTree($blockCategTree['children']); $isDhtml = (Configuration::get('BLOCK_CATEG_DHTML') == 1 ? true : false); @@ -268,7 +268,7 @@ class BlockCategories extends Module unset($resultIds); //TODO clean that $res = $blockCategTree; - if($blockCategTree['id'] != $context->shop->id_category) + if($blockCategTree['id'] != $context->shop->getCategory()) $blockCategTree = $this->cleanTree($blockCategTree['children']); $isDhtml = (Configuration::get('BLOCK_CATEG_DHTML') == 1 ? true : false); $isDhtml = (Configuration::get('BLOCK_CATEG_DHTML') == 1 ? true : false); @@ -304,7 +304,7 @@ class BlockCategories extends Module public function cleanTree($categories) { - $id_category_root = Context::getContext()->shop->id_category; + $id_category_root = Context::getContext()->shop->getCategory(); foreach ($categories AS $row) { if ($row['id'] == $id_category_root) diff --git a/modules/blocklayered/blocklayered.php b/modules/blocklayered/blocklayered.php index c64189395..3f5e94533 100644 --- a/modules/blocklayered/blocklayered.php +++ b/modules/blocklayered/blocklayered.php @@ -384,12 +384,12 @@ class BlockLayered extends Module $n = (int)Tools::getValue('n', Configuration::get('PS_PRODUCTS_PER_PAGE')); $sql = 'SELECT p.id_product, p.out_of_stock, p.available_for_order, p.minimal_quantity, p.id_category_default, p.customizable, p.show_price, p.`weight`, - 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, s.quantity, + 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 - LEFT JOIN '._DB_PREFIX_.'product_shop ps ON ps.id_product = p.id_product AND ps.id_shop = '.$this->shopID.' - LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = p.id_product AND pl.id_shop = '.$this->shopID.') - LEFT JOIN '._DB_PREFIX_.'stock s ON s.id_product = p.id_product AND s.id_product_attribute = 0 '.Shop::sqlSharedStock('s').' + '.Shop::sqlAsso('product', 'p', $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) LEFT JOIN '._DB_PREFIX_.'image_lang il ON (i.id_image = il.id_image AND il.id_lang = '.(int)$context->language->id.') LEFT JOIN '._DB_PREFIX_.'manufacturer m ON (m.id_manufacturer = p.id_manufacturer) @@ -427,7 +427,7 @@ class BlockLayered extends Module foreach ($subCategories AS $subcategory) $whereC .= ' cp.`id_category` = '.(int)$subcategory['id_category'].' OR '; - $whereC = rtrim($whereC, 'OR ').')'; + $whereC = rtrim($whereC, 'OR ')''; $productsSQL = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT p.`id_product`, p.`condition`, p.`id_manufacturer`, p.`weight`, s.quantity, (SELECT GROUP_CONCAT(`id_category`) FROM `'._DB_PREFIX_.'category_product` cp WHERE cp.`id_product` = p.`id_product`) as ids_cat, @@ -437,8 +437,8 @@ class BlockLayered extends Module LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (pa.`id_product_attribute` = pac.`id_product_attribute`) WHERE pa.`id_product` = p.`id_product` ) as ids_attr FROM '._DB_PREFIX_.'product p - LEFT JOIN '._DB_PREFIX_.'stock s ON s.id_product = p.id_product AND s.id_product_attribute = 0 '.Shop::sqlSharedStock('s').' - WHERE p.`active` = 1 AND p.`id_product` IN ( SELECT id_product FROM `'._DB_PREFIX_.'category_product` cp WHERE'.$whereC, false); + '.Product::sqlStock('p', 0).' + WHERE p.`active` = 1 AND p.`id_product` IN ( SELECT id_product FROM `'._DB_PREFIX_.'category_product` cp WHERE'.$whereC.')', false); $products = array(); $db = Db::getInstance(); diff --git a/modules/gsitemap/gsitemap.php b/modules/gsitemap/gsitemap.php index 034633c30..4497bcffc 100644 --- a/modules/gsitemap/gsitemap.php +++ b/modules/gsitemap/gsitemap.php @@ -191,7 +191,7 @@ XML; } /* Categories Generator */ - $limits = Category::getInterval($shop->id_category); + $limits = Category::getInterval($shop->getCategory()); if (Configuration::get('PS_REWRITING_SETTINGS')) { $sql = 'SELECT c.id_category, c.level_depth, link_rewrite, DATE_FORMAT(IF(date_upd,date_upd,date_add), \'%Y-%m-%d\') AS date_upd, cl.id_lang diff --git a/modules/homefeatured/homefeatured.php b/modules/homefeatured/homefeatured.php index 6d84ae79f..691c694a5 100644 --- a/modules/homefeatured/homefeatured.php +++ b/modules/homefeatured/homefeatured.php @@ -96,7 +96,7 @@ class HomeFeatured extends Module $category = new Category(1, Configuration::get('PS_LANG_DEFAULT')); $nb = (int)(Configuration::get('HOME_FEATURED_NBR')); - $products = $category->getProducts((int)$params['cookie']->id_lang, 1, ($nb ? $nb : 10), NULL, NULL, false, true, false, 1, true, $this->shopID); + $products = $category->getProducts((int)$params['cookie']->id_lang, 1, ($nb ? $nb : 10)); $smarty->assign(array( 'products' => $products, 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), diff --git a/modules/mailalerts/mailalerts.php b/modules/mailalerts/mailalerts.php index f57cffc6c..7f4eb8704 100644 --- a/modules/mailalerts/mailalerts.php +++ b/modules/mailalerts/mailalerts.php @@ -480,13 +480,12 @@ class MailAlerts extends Module ) die (Tools::displayError()); - $sql = 'SELECT ma.`id_product`, s.quantity AS product_quantity, pl.`name`, ma.`id_product_attribute` + $sql = 'SELECT ma.`id_product`, stock.quantity AS product_quantity, pl.`name`, ma.`id_product_attribute` FROM `'._DB_PREFIX_.'mailalert_customer_oos` ma JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = ma.`id_product` - JOIN `'._DB_PREFIX_.'product_lang` pl ON pl.`id_product` = ma.`id_product` - LEFT JOIN '._DB_PREFIX_.'stock s ON s.id_product = p.id_product AND s.id_product_attribute = 0 '.Shop::sqlSharedStock('s').' - WHERE ma.`id_customer` = '.$id_customer.' - AND pl.`id_lang` = '.(int)$id_lang; + JOIN `'._DB_PREFIX_.'product_lang` pl ON pl.`id_product` = ma.`id_product` AND pl.`id_lang` = '.$id_lang.Shop::sqlLang('pl').' + '.Product::sqlStock('p', 0).' + WHERE ma.`id_customer` = '.$id_customer; $products = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql); if (empty($products) === true OR !sizeof($products)) return array(); @@ -504,8 +503,8 @@ class MailAlerts extends Module FROM `'._DB_PREFIX_.'product_attribute_combination` pac LEFT JOIN `'._DB_PREFIX_.'attribute` a ON (a.`id_attribute` = pac.`id_attribute`) LEFT JOIN `'._DB_PREFIX_.'attribute_group` ag ON (ag.`id_attribute_group` = a.`id_attribute_group`) - LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = '.(int)($id_lang).') - LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl ON (ag.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = '.(int)($id_lang).') + LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = '.$id_lang.') + LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl ON (ag.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = '.$id_lang.') LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (pac.`id_product_attribute` = pa.`id_product_attribute`) WHERE pac.`id_product_attribute` = '.(int)($products[$i]['id_product_attribute'])); $products[$i]['attributes_small'] = ''; @@ -515,9 +514,9 @@ class MailAlerts extends Module $products[$i]['attributes_small'] = rtrim($products[$i]['attributes_small'], ', '); // cover - $attrgrps = $obj->getAttributesGroups((int)($id_lang)); + $attrgrps = $obj->getAttributesGroups($id_lang); foreach ($attrgrps AS $attrgrp) - if ($attrgrp['id_product_attribute'] == (int)($products[$i]['id_product_attribute']) AND $images = Product::_getAttributeImageAssociations((int)($attrgrp['id_product_attribute']))) + if ($attrgrp['id_product_attribute'] == $products[$i]['id_product_attribute'] AND $images = Product::_getAttributeImageAssociations((int)($attrgrp['id_product_attribute']))) { $products[$i]['cover'] = $obj->id.'-'.array_pop($images); break; @@ -525,7 +524,7 @@ class MailAlerts extends Module } if (!isset($products[$i]['cover']) OR !$products[$i]['cover']) { - $images = $obj->getImages((int)($id_lang)); + $images = $obj->getImages($id_lang); foreach ($images AS $k => $image) if ($image['cover']) {