From c1290cebaec00cd93bb06b065cc90cf91d778af9 Mon Sep 17 00:00:00 2001 From: vChabot Date: Tue, 15 May 2012 09:46:04 +0000 Subject: [PATCH] // little fix sql categories and product --- classes/Category.php | 23 ++++++++++++++++--- classes/controller/AdminController.php | 2 +- .../admin/AdminCategoriesController.php | 2 +- controllers/admin/AdminProductsController.php | 3 +-- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/classes/Category.php b/classes/Category.php index cc06b3091..c5371778a 100644 --- a/classes/Category.php +++ b/classes/Category.php @@ -1444,15 +1444,32 @@ class CategoryCore extends ObjectModel public function addPosition($position, $id_shop = null) { + $return = true; if (is_null($id_shop)) { - $id = Context::getContext()->shop->id; - $id_shop = $id ? $id : Configuration::get('PS_SHOP_DEFAULT'); + if (Shop::getContext() != Shop::CONTEXT_SHOP) + foreach (Shop::getContextListShopID() as $id_shop) + $return &= Db::getInstance()->execute(' + INSERT INTO `'._DB_PREFIX_.'category_shop` (`id_category`, `id_shop`, `position`) VALUES + ('.(int)$this->id.', '.(int)$id_shop.', '.(int)$position.') + ON DUPLICATE KEY UPDATE `position` = '.(int)$position); + else + { + $id = Context::getContext()->shop->id; + $id_shop = $id ? $id : Configuration::get('PS_SHOP_DEFAULT'); + $return &= Db::getInstance()->execute(' + INSERT INTO `'._DB_PREFIX_.'category_shop` (`id_category`, `id_shop`, `position`) VALUES + ('.(int)$this->id.', '.(int)$id_shop.', '.(int)$position.') + ON DUPLICATE KEY UPDATE `position` = '.(int)$position); + } } - return Db::getInstance()->execute(' + else + $return &= Db::getInstance()->execute(' INSERT INTO `'._DB_PREFIX_.'category_shop` (`id_category`, `id_shop`, `position`) VALUES ('.(int)$this->id.', '.(int)$id_shop.', '.(int)$position.') ON DUPLICATE KEY UPDATE `position` = '.(int)$position); + + return $return; } public static function getShopsByCategory($id_category) diff --git a/classes/controller/AdminController.php b/classes/controller/AdminController.php index 6cc756b5c..8076016fe 100644 --- a/classes/controller/AdminController.php +++ b/classes/controller/AdminController.php @@ -1986,7 +1986,7 @@ class AdminControllerCore extends Controller $this->_group .= ', a.'.pSQL($this->identifier); $test_join = !preg_match('#`?'.preg_quote(_DB_PREFIX_.$this->table.'_shop').'`? *sa#', $this->_join); - if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_ALL && $test_join) + if (Shop::isFeatureActive() && $test_join) { $filter_shop = ' JOIN `'._DB_PREFIX_.$this->table.'_shop` sa '; $filter_shop .= 'ON (sa.'.$this->identifier.' = a.'.$this->identifier.' AND sa.id_shop IN ('.implode(', ', $idenfier_shop).'))'; diff --git a/controllers/admin/AdminCategoriesController.php b/controllers/admin/AdminCategoriesController.php index 749720279..a93bc7fb1 100644 --- a/controllers/admin/AdminCategoriesController.php +++ b/controllers/admin/AdminCategoriesController.php @@ -158,7 +158,7 @@ class AdminCategoriesControllerCore extends AdminController $this->_join = Shop::addSqlAssociation('category', 'a'); // we add restriction for shop if (Shop::getContext() == Shop::CONTEXT_SHOP && $is_multishop) - $this->_where = ' AND cs.`id_shop` = '.(int)Context::getContext()->shop->id; + $this->_where = ' AND category_shop.`id_shop` = '.(int)Context::getContext()->shop->id; $categories_tree = $this->_category->getParentsCategories(); if (empty($categories_tree) diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index 493c5e4f3..275690118 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -271,8 +271,7 @@ class AdminProductsControllerCore extends AdminController $orderWay = 'ASC'; } - $alias = (Shop::getContext() != Shop::CONTEXT_SHOP) ? 'product_shop': 'sa'; - $this->_select .= ', '.$alias.'.`active`'; + $this->_select .= ', sa.`active`'; if (!Tools::isSubmit('productFilter_active')) $this->_filter = ''; parent::getList($id_lang, $orderBy, $orderWay, $start, $limit, $this->context->shop->id);