// little fix sql categories and product

This commit is contained in:
vChabot
2012-05-15 09:46:04 +00:00
parent 7a0c98aa13
commit c1290cebae
4 changed files with 23 additions and 7 deletions
+20 -3
View File
@@ -1444,15 +1444,32 @@ class CategoryCore extends ObjectModel
public function addPosition($position, $id_shop = null) public function addPosition($position, $id_shop = null)
{ {
$return = true;
if (is_null($id_shop)) if (is_null($id_shop))
{ {
$id = Context::getContext()->shop->id; if (Shop::getContext() != Shop::CONTEXT_SHOP)
$id_shop = $id ? $id : Configuration::get('PS_SHOP_DEFAULT'); 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 INSERT INTO `'._DB_PREFIX_.'category_shop` (`id_category`, `id_shop`, `position`) VALUES
('.(int)$this->id.', '.(int)$id_shop.', '.(int)$position.') ('.(int)$this->id.', '.(int)$id_shop.', '.(int)$position.')
ON DUPLICATE KEY UPDATE `position` = '.(int)$position); ON DUPLICATE KEY UPDATE `position` = '.(int)$position);
return $return;
} }
public static function getShopsByCategory($id_category) public static function getShopsByCategory($id_category)
+1 -1
View File
@@ -1986,7 +1986,7 @@ class AdminControllerCore extends Controller
$this->_group .= ', a.'.pSQL($this->identifier); $this->_group .= ', a.'.pSQL($this->identifier);
$test_join = !preg_match('#`?'.preg_quote(_DB_PREFIX_.$this->table.'_shop').'`? *sa#', $this->_join); $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 = ' JOIN `'._DB_PREFIX_.$this->table.'_shop` sa ';
$filter_shop .= 'ON (sa.'.$this->identifier.' = a.'.$this->identifier.' AND sa.id_shop IN ('.implode(', ', $idenfier_shop).'))'; $filter_shop .= 'ON (sa.'.$this->identifier.' = a.'.$this->identifier.' AND sa.id_shop IN ('.implode(', ', $idenfier_shop).'))';
@@ -158,7 +158,7 @@ class AdminCategoriesControllerCore extends AdminController
$this->_join = Shop::addSqlAssociation('category', 'a'); $this->_join = Shop::addSqlAssociation('category', 'a');
// we add restriction for shop // we add restriction for shop
if (Shop::getContext() == Shop::CONTEXT_SHOP && $is_multishop) 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(); $categories_tree = $this->_category->getParentsCategories();
if (empty($categories_tree) if (empty($categories_tree)
@@ -271,8 +271,7 @@ class AdminProductsControllerCore extends AdminController
$orderWay = 'ASC'; $orderWay = 'ASC';
} }
$alias = (Shop::getContext() != Shop::CONTEXT_SHOP) ? 'product_shop': 'sa'; $this->_select .= ', sa.`active`';
$this->_select .= ', '.$alias.'.`active`';
if (!Tools::isSubmit('productFilter_active')) if (!Tools::isSubmit('productFilter_active'))
$this->_filter = ''; $this->_filter = '';
parent::getList($id_lang, $orderBy, $orderWay, $start, $limit, $this->context->shop->id); parent::getList($id_lang, $orderBy, $orderWay, $start, $limit, $this->context->shop->id);