diff --git a/admin-dev/functions.php b/admin-dev/functions.php
index 894834909..07c29ca4b 100644
--- a/admin-dev/functions.php
+++ b/admin-dev/functions.php
@@ -152,6 +152,7 @@ function getPath($urlBase, $id_category, $path = '', $highlight = '', $categoryT
AND c.nright >= '.(int)$category['nright'].'
AND cl.id_lang = '.(int)$context->language->id.
($home ? ' AND c.id_category='.$id_category : '').'
+ AND c.id_category != '.(int)Category::getTopCategory()->id.'
GROUP BY c.id_category
ORDER BY c.level_depth ASC
LIMIT '.(!$home ? (int)($category['level_depth'] + 1) : 1);
diff --git a/admin-dev/themes/default/template/controllers/products/associations.tpl b/admin-dev/themes/default/template/controllers/products/associations.tpl
index e1c07817a..822e2ffaf 100644
--- a/admin-dev/themes/default/template/controllers/products/associations.tpl
+++ b/admin-dev/themes/default/template/controllers/products/associations.tpl
@@ -58,10 +58,10 @@
- {l s='The default category is the category who is displayed by default.'}
+ {l s='The default category is the category who is displayed by default.'}
|
diff --git a/classes/Cart.php b/classes/Cart.php
index f52ac2007..5a60870c7 100644
--- a/classes/Cart.php
+++ b/classes/Cart.php
@@ -376,7 +376,7 @@ class CartCore extends ObjectModel
// Build SELECT
$sql->select('cp.`id_product_attribute`, cp.`id_product`, cp.`quantity` AS cart_quantity, cp.id_shop, pl.`name`, p.`is_virtual`,
- pl.`description_short`, pl.`available_now`, pl.`available_later`, p.`id_product`, p.`id_category_default`, p.`id_supplier`,
+ pl.`description_short`, pl.`available_now`, pl.`available_later`, p.`id_product`, ps.`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`,
stock.`quantity` quantity_available, p.`width`, p.`height`, p.`depth`, stock.`out_of_stock`, p.`active`, p.`date_add`,
p.`date_upd`, t.`id_tax`, tl.`name` AS tax, t.`rate`, IFNULL(stock.quantity, 0) as quantity, pl.`link_rewrite`, cl.`link_rewrite` AS category,
@@ -406,8 +406,12 @@ class CartCore extends ObjectModel
t.`id_tax` = tl.`id_tax`
AND tl.`id_lang` = '.(int)$this->id_lang
);
+ $sql->leftJoin('product_shop', 'ps', '
+ ps.`id_product` = p.`id_product`
+ AND ps.`id_shop` = '.(int)Context::getContext()->shop->id
+ );
$sql->leftJoin('category_lang', 'cl', '
- p.`id_category_default` = cl.`id_category`
+ ps.`id_category_default` = cl.`id_category`
AND cl.`id_lang` = '.(int)$this->id_lang.Shop::addSqlRestrictionOnLang('cl')
);
@@ -419,6 +423,7 @@ class CartCore extends ObjectModel
if ($id_product)
$sql->where('cp.`id_product` = '.(int)$id_product);
$sql->where('p.`id_product` IS NOT NULL');
+ $sql->where('ps.`id_shop` = '.(int)Context::getContext()->shop->id);
// Build GROUP BY
$sql->groupBy('unique_id');
diff --git a/classes/Category.php b/classes/Category.php
index 073b5cbd6..33338e903 100644
--- a/classes/Category.php
+++ b/classes/Category.php
@@ -353,10 +353,10 @@ class CategoryCore extends ObjectModel
}
}
- /* Set category default to 1 where categorie no more exists */
+ /* Set category default to Home category where categorie no more exists */
$result = Db::getInstance()->execute('
- UPDATE `'._DB_PREFIX_.'product`
- SET `id_category_default` = 1
+ UPDATE `'._DB_PREFIX_.'product_shop`
+ SET `id_category_default` = '.(int)Configuration::get('PS_HOME_CATEGORY').'
WHERE `id_category_default`
NOT IN (SELECT `id_category` FROM `'._DB_PREFIX_.'category`)
');
@@ -638,7 +638,7 @@ class CategoryCore extends ObjectModel
'.Shop::addSqlAssociation('product', 'p').'
'.Product::sqlStock('p', 'pa', false, $context->shop).'
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl
- ON (p.`id_category_default` = cl.`id_category`
+ ON (asso_shop_product.`id_category_default` = cl.`id_category`
AND cl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').')
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl
ON (p.`id_product` = pl.`id_product`
@@ -663,7 +663,8 @@ class CategoryCore extends ObjectModel
AND tl.`id_lang` = '.(int)$id_lang.')
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m
ON m.`id_manufacturer` = p.`id_manufacturer`
- WHERE cp.`id_category` = '.(int)$this->id
+ WHERE asso_shop_product.`id_shop` = '.(int)Context::getContext()->shop->id.'
+ AND cp.`id_category` = '.(int)$this->id
.($active ? ' AND p.`active` = 1' : '')
.($id_supplier ? ' AND p.id_supplier = '.(int)$id_supplier : '');
@@ -696,7 +697,7 @@ class CategoryCore extends ObjectModel
*/
public static function getHomeCategories($id_lang, $active = true)
{
- return self::getChildren(1, $id_lang, $active);
+ return self::getChildren(Configuration::get('PS_HOME_CATEGORY'), $id_lang, $active);
}
public static function getRootCategory($id_lang = null, Shop $shop = null)
@@ -844,7 +845,7 @@ class CategoryCore extends ObjectModel
public static function checkBeforeMove($id_category, $id_parent)
{
if ($id_category == $id_parent) return false;
- if ($id_parent == 1) return true;
+ if ($id_parent == Configuration::get('PS_HOME_CATEGORY')) return true;
$i = (int)$id_parent;
while (42)
@@ -852,7 +853,7 @@ class CategoryCore extends ObjectModel
$result = Db::getInstance()->getRow('SELECT `id_parent` FROM `'._DB_PREFIX_.'category` WHERE `id_category` = '.(int)$i);
if (!isset($result['id_parent'])) return false;
if ($result['id_parent'] == $id_category) return false;
- if ($result['id_parent'] == 1) return true;
+ if ($result['id_parent'] == Configuration::get('PS_HOME_CATEGORY')) return true;
$i = $result['id_parent'];
}
}
@@ -920,8 +921,8 @@ class CategoryCore extends ObjectModel
ON (c.`id_category` = cl.`id_category`
AND `id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').')
WHERE `name` LIKE \'%'.pSQL($query).'%\'
- AND c.`id_category` != 1
- ');
+ AND c.`id_category` != '.(int)Configuration::get('PS_HOME_CATEGORY')
+ );
}
/**
@@ -941,7 +942,7 @@ class CategoryCore extends ObjectModel
ON (c.`id_category` = cl.`id_category`
AND `id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').')
WHERE `name` LIKE \''.pSQL($category_name).'\'
- AND c.`id_category` != 1
+ AND c.`id_category` != '.(int)Configuration::get('PS_HOME_CATEGORY').'
AND c.`id_parent` = '.(int)$id_parent_category
);
}
diff --git a/classes/GroupReduction.php b/classes/GroupReduction.php
index 2d489158e..c74aff1db 100644
--- a/classes/GroupReduction.php
+++ b/classes/GroupReduction.php
@@ -59,9 +59,9 @@ class GroupReductionCore extends ObjectModel
public function delete()
{
$products = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
- SELECT p.`id_product`
- FROM `'._DB_PREFIX_.'product` p
- WHERE p.`id_category_default` = '.(int)$this->id_category
+ SELECT ps.`id_product`
+ FROM `'._DB_PREFIX_.'product_shop` ps
+ WHERE ps.`id_category_default` = '.(int)$this->id_category
);
$ids = array();
@@ -81,9 +81,9 @@ class GroupReductionCore extends ObjectModel
protected function _setCache()
{
$products = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
- SELECT p.`id_product`
- FROM `'._DB_PREFIX_.'product` p
- WHERE p.`id_category_default` = '.(int)$this->id_category
+ SELECT ps.`id_product`
+ FROM `'._DB_PREFIX_.'product_shop` ps
+ WHERE ps.`id_category_default` = '.(int)$this->id_category
);
$query = 'INSERT INTO `'._DB_PREFIX_.'product_group_reduction_cache` (`id_product`, `id_group`, `reduction`) VALUES ';
@@ -102,9 +102,9 @@ class GroupReductionCore extends ObjectModel
protected function _updateCache()
{
$products = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
- SELECT p.`id_product`
- FROM `'._DB_PREFIX_.'product` p
- WHERE p.`id_category_default` = '.(int)$this->id_category,
+ SELECT ps.`id_product`
+ FROM `'._DB_PREFIX_.'product_shop` ps
+ WHERE ps.`id_category_default` = '.(int)$this->id_category,
false);
$ids = array();
diff --git a/classes/Pack.php b/classes/Pack.php
index a7cad7df3..51b003eb3 100644
--- a/classes/Pack.php
+++ b/classes/Pack.php
@@ -109,7 +109,7 @@ class PackCore extends Product
if (!Pack::isFeatureActive())
return array();
- $sql = 'SELECT p.*, pl.*, i.`id_image`, il.`legend`, t.`rate`, cl.`name` AS category_default, a.quantity AS pack_quantity
+ $sql = 'SELECT p.*, pl.*, i.`id_image`, il.`legend`, t.`rate`, cl.`name` AS category_default, a.quantity AS pack_quantity, asso_shop_product.`id_category_default`
FROM `'._DB_PREFIX_.'pack` a
LEFT JOIN `'._DB_PREFIX_.'product` p ON p.id_product = a.id_product_item
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl
@@ -117,17 +117,19 @@ class PackCore extends Product
AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').'
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.')
+ '.Shop::addSqlAssociation('product', 'p').'
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl
- ON p.`id_category_default` = cl.`id_category`
+ ON asso_shop_product.`id_category_default` = cl.`id_category`
AND cl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').'
LEFT JOIN `'._DB_PREFIX_.'product_tax_rules_group_shop` ptrgs ON (p.`id_product` = ptrgs.`id_product`
AND ptrgs.id_shop='.(int)Context::getContext()->shop->id.')
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (ptrgs.`id_tax_rules_group` = tr.`id_tax_rules_group`
AND tr.`id_country` = '.(int)Context::getContext()->country->id.'
AND tr.`id_state` = 0)
- LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)
+ LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)
LEFT JOIN `'._DB_PREFIX_.'tax_lang` tl ON (t.`id_tax` = tl.`id_tax` AND tl.`id_lang` = '.(int)$id_lang.')
- WHERE a.`id_product_pack` = '.(int)$id_product;
+ WHERE asso_shop_product.`id_shop` = '.(int)Context::getContext()->shop->id.'
+ AND a.`id_product_pack` = '.(int)$id_product;
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
if (!$full)
return $result;
diff --git a/classes/Product.php b/classes/Product.php
index 5e8bac2be..922ccfdae 100644
--- a/classes/Product.php
+++ b/classes/Product.php
@@ -422,6 +422,10 @@ class ProductCore extends ObjectModel
$this->loadStockData();
}
+ // update id_category_default
+ if ($this->id && !is_null($id_shop))
+ $this->id_category_default = $this->getDefaultCategory($id_shop);
+
if ($this->id_category_default)
$this->category = Category::getLinkRewrite((int)$this->id_category_default, (int)$id_lang);
}
@@ -442,6 +446,8 @@ class ProductCore extends ObjectModel
{
if (!parent::add($autodate, $null_values))
return false;
+ // add id_category_default to product_shop
+ $this->updateCategoryDefault();
Hook::exec('actionProductSave', array('id_product' => $this->id));
return true;
}
@@ -449,6 +455,8 @@ class ProductCore extends ObjectModel
public function update($null_values = false)
{
$return = parent::update($null_values);
+ // add id_category_default to product_shop
+ $this->updateCategoryDefault(Context::getContext()->shop);
Hook::exec('actionProductSave', array('id_product' => $this->id));
return $return;
}
@@ -1941,12 +1949,13 @@ class ProductCore extends ObjectModel
$sql = 'SELECT p.*, stock.`out_of_stock` out_of_stock, pl.`description`, pl.`description_short`,
pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`,
- p.`ean13`, p.`upc`, i.`id_image`, il.`legend`, t.`rate`
+ p.`ean13`, p.`upc`, i.`id_image`, il.`legend`, t.`rate`, asso_shop_product.`id_category_default`
FROM `'._DB_PREFIX_.'product` p
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (
p.`id_product` = pl.`id_product`
AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').'
)
+ '.Shop::addSqlAssociation('product', 'p').'
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_.'product_tax_rules_group_shop` ptrgs ON (p.`id_product` = ptrgs.`id_product`
@@ -2931,7 +2940,7 @@ class ProductCore extends ObjectModel
AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').'
)
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (
- p.`id_category_default` = cl.`id_category`
+ asso_shop_product.`id_category_default` = cl.`id_category`
AND cl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').'
)
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
@@ -2940,11 +2949,12 @@ class ProductCore extends ObjectModel
LEFT JOIN `'._DB_PREFIX_.'product_tax_rules_group_shop` ptrgs ON (p.`id_product` = ptrgs.`id_product`
AND ptrgs.id_shop='.(int)$context->shop->id.')
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (ptrgs.`id_tax_rules_group` = tr.`id_tax_rules_group`
- AND tr.`id_country` = '.(int)Context::getContext()->country->id.'
+ 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`)
'.Product::sqlStock('p', 0).'
- WHERE `id_product_1` = '.(int)$this->id.
+ WHERE asso_shop_product.`id_shop` = '.(int)$context->shop->id.'
+ AND `id_product_1` = '.(int)$this->id.
($active ? ' AND p.`active` = 1' : '');
if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql))
return false;
@@ -4035,8 +4045,9 @@ class ProductCore extends ObjectModel
SELECT pl.`id_lang`, pl.`link_rewrite`, p.`ean13`, cl.`link_rewrite` AS category_rewrite
FROM `'._DB_PREFIX_.'product` p
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product`'.Shop::addSqlRestrictionOnLang('pl').')
+ '.Shop::addSqlAssociation('product', 'p').'
LEFT JOIN `'._DB_PREFIX_.'lang` l ON (pl.`id_lang` = l.`id_lang`)
- LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (cl.`id_category` = p.`id_category_default` AND cl.`id_lang` = pl.`id_lang`'.Shop::addSqlRestrictionOnLang('cl').')
+ LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (cl.`id_category` = asso_shop_product.`id_category_default` AND cl.`id_lang` = pl.`id_lang`'.Shop::addSqlRestrictionOnLang('cl').')
WHERE p.`id_product` = '.(int)$id_product.'
AND l.`active` = 1
');
@@ -4794,4 +4805,39 @@ class ProductCore extends ObjectModel
$this->out_of_stock = StockAvailable::outOfStock($this->id);
$this->depends_on_stock = StockAvailable::dependsOnStock($this->id);
}
+
+ /**
+ * get the default category according to the shop
+ */
+ public function getDefaultCategory($id_shop = null)
+ {
+ $context = Context::getContext();
+ if (!$id_shop)
+ $id_shop = Shop::getContext() == Shop::CONTEXT_SHOP ? $context->shop->id : Configuration::get('PS_SHOP_DEFAULT');
+ return Db::getInstance()->getValue('
+ SELECT asso_shop_product.`id_category_default`
+ FROM `'._DB_PREFIX_.'product` p
+ '.Shop::addSqlAssociation('product', 'p').'
+ WHERE asso_shop_product.`id_shop` = '.(int)$id_shop);
+
+ }
+
+ public static function getShopsByProduct($id_product)
+ {
+ return Db::getInstance()->executeS('
+ SELECT `id_shop`
+ FROM `'._DB_PREFIX_.'product_shop`
+ WHERE `id_product` = '.(int)$id_product);
+ }
+
+ public function updateCategoryDefault($shop = null)
+ {
+ if (is_null($shop))
+ $shop = new Shop(Configuration::get('PS_SHOP_DEFAULT'));
+ return Db::getInstance()->execute('
+ UPDATE `'._DB_PREFIX_.'product_shop`
+ SET `id_category_default` = '.(int)$this->id_category_default.'
+ WHERE `id_shop` = '.(int)$shop->id.'
+ AND `id_product` = '.(int)$this->id);
+ }
}
diff --git a/classes/ProductSale.php b/classes/ProductSale.php
index a9f8ad463..eb8ad7c4b 100644
--- a/classes/ProductSale.php
+++ b/classes/ProductSale.php
@@ -145,7 +145,7 @@ class ProductSaleCore
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_.'category_lang` cl
- ON cl.`id_category` = p.`id_category_default`
+ ON cl.`id_category` = asso_shop_product.`id_category_default`
AND cl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').'
WHERE p.`active` = 1
AND p.`id_product` IN (
diff --git a/classes/Search.php b/classes/Search.php
index 2e0eeb06c..64d476338 100644
--- a/classes/Search.php
+++ b/classes/Search.php
@@ -254,8 +254,9 @@ class SearchCore
p.`id_product` = pl.`id_product`
AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').'
)
+ '.Shop::addSqlAssociation('product', 'p').'
INNER JOIN `'._DB_PREFIX_.'category_lang` cl ON (
- p.`id_category_default` = cl.`id_category`
+ asso_shop_product.`id_category_default` = cl.`id_category`
AND cl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').'
)
WHERE p.`id_product` '.$product_pool.'
@@ -374,8 +375,9 @@ class SearchCore
FROM '._DB_PREFIX_.'product p
LEFT JOIN '._DB_PREFIX_.'product_lang pl
ON p.id_product = pl.id_product
+ '.Shop::addSqlAssociation('product', 'p').'
LEFT JOIN '._DB_PREFIX_.'category_lang cl
- ON (cl.id_category = p.id_category_default AND pl.id_lang = cl.id_lang)
+ ON (cl.id_category = asso_shop_product.id_category_default AND pl.id_lang = cl.id_lang)
LEFT JOIN '._DB_PREFIX_.'manufacturer m
ON m.id_manufacturer = p.id_manufacturer
WHERE p.indexed = 0
diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php
index e7c4dce56..7a8748bdb 100644
--- a/controllers/admin/AdminProductsController.php
+++ b/controllers/admin/AdminProductsController.php
@@ -2549,6 +2549,7 @@ class AdminProductsControllerCore extends AdminController
$data->assign(array('default_category' => $default_category,
'selected_cat_ids' => implode(',', array_keys($selected_cat)),
'selected_cat' => $selected_cat,
+ 'id_category_default' => $product->getDefaultCategory(),
'category_tree' => $helper->renderCategoryTree(null, $selected_cat, 'categoryBox', false, true),
'product' => $product,
'link' => $this->context->link
@@ -3271,7 +3272,7 @@ class AdminProductsControllerCore extends AdminController
$data->assign(array(
'list' => $this->renderListAttributes($id_product_download, $product, $currency),
'product' => $product,
- 'id_category' => $product->id_category_default,
+ 'id_category' => $product->getDefaultCategory(),
'token_generator' => Tools::getAdminTokenLite('AdminAttributeGenerator')
));
}
@@ -3943,4 +3944,39 @@ class AdminProductsControllerCore extends AdminController
';
$this->tpl_form_vars['warning_unavailable_product'] = $content;
}
+
+ protected function updateAssoShop($id_object = false, $new_id_object = false)
+ {
+ $assos_data = $this->getAssoShop($this->table, $id_object);
+ $assos = $assos_data[0];
+ $type = $assos_data[1];
+
+ $product_shop = Product::getShopsByProduct($id_object);
+
+ if (!$type)
+ return;
+
+ $delete = $insert = '';
+ foreach ($assos as $asso)
+ {
+ $passed = false;
+ $delete .= (int)$asso['id_'.$type].',';
+ foreach ($product_shop as $product)
+ if ($product['id_shop'] == $asso['id_'.$type])
+ $passed = true;
+ if (!$passed)
+ $insert .= '('.($new_id_object ? (int)$new_id_object : (int)$asso['id_object']).', '.(int)$asso['id_'.$type].'),';
+ }
+ $delete = rtrim($delete, ',');
+ $insert = rtrim($insert, ',');
+
+ if (!empty($delete))
+ Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.$this->table.'_'.$type.
+ ($id_object ? ' WHERE `'.$this->identifier.'` = '.(int)$id_object.' AND `id_'.$type.'` NOT IN ('.$delete.')' : ''));
+
+ if (!empty($insert))
+ Db::getInstance()->execute('
+ INSERT INTO '._DB_PREFIX_.$this->table.'_'.$type.' (`'.pSQL($this->identifier).'`, `id_'.$type.'`)
+ VALUES '.pSQL($insert));
+ }
}
diff --git a/controllers/front/ProductController.php b/controllers/front/ProductController.php
index 26a6cff29..b0c1ff775 100644
--- a/controllers/front/ProductController.php
+++ b/controllers/front/ProductController.php
@@ -68,7 +68,7 @@ class ProductControllerCore extends FrontController
parent::init();
if ($id_product = (int)Tools::getValue('id_product'))
- $this->product = new Product($id_product, true, $this->context->language->id);
+ $this->product = new Product($id_product, true, $this->context->language->id, $this->context->shop->id);
if (!Validate::isLoadedObject($this->product))
{
@@ -429,8 +429,6 @@ class ProductControllerCore extends FrontController
*/
protected function assignCategory()
{
-
-
// Assign category to the template
if ($this->category !== false && Validate::isLoadedObject($this->category))
{
diff --git a/install-dev/data/db_structure.sql b/install-dev/data/db_structure.sql
index 069b25cee..61bb2d44b 100644
--- a/install-dev/data/db_structure.sql
+++ b/install-dev/data/db_structure.sql
@@ -2045,6 +2045,7 @@ PRIMARY KEY (`id_store`, `id_shop`),
CREATE TABLE `PREFIX_product_shop` (
`id_product` INT( 11 ) UNSIGNED NOT NULL,
`id_shop` INT( 11 ) UNSIGNED NOT NULL,
+`id_category_default` INT( 11 ) UNSIGNED DEFAULT NULL,
PRIMARY KEY ( `id_shop` , `id_product` ),
KEY `id_shop` (`id_shop`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
diff --git a/install-dev/data/xml/configuration.xml b/install-dev/data/xml/configuration.xml
index e3601ea9f..a317e0e0d 100644
--- a/install-dev/data/xml/configuration.xml
+++ b/install-dev/data/xml/configuration.xml
@@ -866,5 +866,11 @@
logo_stores.gif
+
+ 1
+
+
+ 2
+
diff --git a/install-dev/upgrade/php/generate_root_category_for_multishop.php b/install-dev/upgrade/php/generate_root_category_for_multishop.php
index 7a5b064d9..39bc322f4 100644
--- a/install-dev/upgrade/php/generate_root_category_for_multishop.php
+++ b/install-dev/upgrade/php/generate_root_category_for_multishop.php
@@ -13,6 +13,9 @@ function generate_root_category_for_multishop()
(0, 0, 1, NOW(), NOW(), 0)
');
$id = Db::getInstance()->insert_id();
+ // set vars config
+ Configuration::set('PS_ROOT_CATEGORY', $id);
+ Configuration::set('PS_HOME_CATEGORY', 1);
$langs = Db::getInstance()->executeS('
SELECT `id_lang`
diff --git a/install-dev/upgrade/sql/1.5.0.7.sql b/install-dev/upgrade/sql/1.5.0.7.sql
index 819835943..870d6964b 100644
--- a/install-dev/upgrade/sql/1.5.0.7.sql
+++ b/install-dev/upgrade/sql/1.5.0.7.sql
@@ -31,3 +31,5 @@ CREATE TABLE `PREFIX_carrier_tax_rules_group_shop` (
INSERT INTO `PREFIX_carrier_tax_rules_group_shop` (`id_carrier`, `id_tax_rules_group`, `id_shop`)
(SELECT `id_carrier`, `id_tax_rules_group`, `id_shop` FROM `PREFIX_carrier`, `PREFIX_shop`);
ALTER TABLE `PREFIX_carrier` DROP `id_tax_rules_group`;
+
+ALTER TABLE `PREFIX_product_shop` ADD `id_category_default` INT( 11 ) UNSIGNED DEFAULT NULL;
\ No newline at end of file
diff --git a/modules/blocklayered/blocklayered.php b/modules/blocklayered/blocklayered.php
index 032a3d320..51fdaa942 100644
--- a/modules/blocklayered/blocklayered.php
+++ b/modules/blocklayered/blocklayered.php
@@ -2324,14 +2324,22 @@ class BlockLayered extends Module
else
{
$n = (int)Tools::getValue('n', Configuration::get('PS_PRODUCTS_PER_PAGE'));
+ $join = '';
+ $alias = 'p';
+ if (version_compare(_PS_VERSION_,'1.5','>'))
+ {
+ $join = Shop::addSqlAssociation('product', 'p');
+ $alias = 'asso_shop_product';
+ }
$this->products = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
- SELECT p.id_product, p.on_sale, p.out_of_stock, p.available_for_order, p.quantity, p.minimal_quantity, p.id_category_default, p.customizable, p.show_price, p.`weight`,
+ SELECT p.id_product, p.on_sale, p.out_of_stock, p.available_for_order, p.quantity, p.minimal_quantity, '.$alias.'.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,
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_.'category_product` cp
LEFT JOIN '._DB_PREFIX_.'category c ON (c.id_category = cp.id_category)
LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = cp.`id_product`
+ '.$join.'
LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = p.id_product)
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)($cookie->id_lang).')
diff --git a/modules/blockviewed/blockviewed.php b/modules/blockviewed/blockviewed.php
index 624c3d19e..d7a4f6549 100644
--- a/modules/blockviewed/blockviewed.php
+++ b/modules/blockviewed/blockviewed.php
@@ -107,7 +107,8 @@ class BlockViewed extends Module
LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = p.id_product'.Shop::addSqlRestrictionOnLang('pl').')
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 (il.id_image = i.id_image)
- LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = p.id_category_default'.Shop::addSqlRestrictionOnLang('cl').')
+ '.Shop::addSqlAssociation('product', 'p').'
+ LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = asso_shop_product.id_category_default'.Shop::addSqlRestrictionOnLang('cl').')
WHERE p.id_product IN ('.$productIds.')
AND pl.id_lang = '.(int)($params['cookie']->id_lang).'
AND cl.id_lang = '.(int)($params['cookie']->id_lang)
diff --git a/modules/blockwishlist/WishList.php b/modules/blockwishlist/WishList.php
index 9f4c42d32..7e419f036 100644
--- a/modules/blockwishlist/WishList.php
+++ b/modules/blockwishlist/WishList.php
@@ -248,11 +248,12 @@ class WishList extends ObjectModel
die (Tools::displayError());
$products = Db::getInstance()->executeS('
SELECT wp.`id_product`, wp.`quantity`, p.`quantity` AS product_quantity, pl.`name`, wp.`id_product_attribute`, wp.`priority`, pl.link_rewrite, cl.link_rewrite AS category_rewrite
- FROM `'._DB_PREFIX_.'wishlist_product` wp
+ FROM `'._DB_PREFIX_.'wishlist_product` wp
JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = wp.`id_product`
+ '.Shop::addSqlAssociation('product', 'p').'
JOIN `'._DB_PREFIX_.'product_lang` pl ON pl.`id_product` = wp.`id_product`'.Shop::addSqlRestrictionOnLang('pl').'
JOIN `'._DB_PREFIX_.'wishlist` w ON w.`id_wishlist` = wp.`id_wishlist`
- LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON cl.`id_category` = p.`id_category_default` AND cl.id_lang='.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').'
+ LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON cl.`id_category` = asso_shop_product.`id_category_default` AND cl.id_lang='.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').'
WHERE w.`id_customer` = '.(int)($id_customer).'
AND pl.`id_lang` = '.(int)($id_lang).'
AND wp.`id_wishlist` = '.(int)($id_wishlist).
diff --git a/modules/crossselling/crossselling.php b/modules/crossselling/crossselling.php
index 9ca134193..b78e2c2bd 100755
--- a/modules/crossselling/crossselling.php
+++ b/modules/crossselling/crossselling.php
@@ -142,8 +142,9 @@ class CrossSelling extends Module
SELECT DISTINCT od.product_id, pl.name, pl.link_rewrite, p.reference, i.id_image, p.show_price, cl.link_rewrite category, p.ean13
FROM '._DB_PREFIX_.'order_detail od
LEFT JOIN '._DB_PREFIX_.'product p ON (p.id_product = od.product_id)
+ '.Shop::addSqlAssociation('product', 'p').'
LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = od.product_id'.Shop::addSqlRestrictionOnLang('pl').')
- LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = p.id_category_default'.Shop::addSqlRestrictionOnLang('cl').')
+ LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = asso_shop_product.id_category_default'.Shop::addSqlRestrictionOnLang('cl').')
LEFT JOIN '._DB_PREFIX_.'image i ON (i.id_product = od.product_id)
WHERE od.id_order IN ('.$list.') AND pl.id_lang = '.(int)$this->context->language->id.' AND cl.id_lang = '.(int)$this->context->language->id.'
AND od.product_id NOT IN ('.$list_product_ids.') AND i.cover = 1 AND p.active = 1
diff --git a/modules/gsitemap/gsitemap.php b/modules/gsitemap/gsitemap.php
index 97ef77c68..7151fab7f 100644
--- a/modules/gsitemap/gsitemap.php
+++ b/modules/gsitemap/gsitemap.php
@@ -172,7 +172,7 @@ XML;
FROM '._DB_PREFIX_.'product p
LEFT JOIN '._DB_PREFIX_.'product_shop ps ON ps.id_product = p.id_product
LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (p.id_product = pl.id_product AND pl.id_shop ='.$shopID.')
- LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (p.id_category_default = cl.id_category AND pl.id_lang = cl.id_lang AND cl.id_shop = '.$shopID.')
+ LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (ps.id_category_default = cl.id_category AND pl.id_lang = cl.id_lang AND cl.id_shop = '.$shopID.')
LEFT JOIN '._DB_PREFIX_.'image i ON p.id_product = i.id_product
LEFT JOIN '._DB_PREFIX_.'image_lang il ON (i.id_image = il.id_image)
LEFT JOIN '._DB_PREFIX_.'lang l ON (pl.id_lang = l.id_lang)
diff --git a/modules/productcomments/ProductCommentCriterion.php b/modules/productcomments/ProductCommentCriterion.php
index fb140c817..2d039d0e6 100644
--- a/modules/productcomments/ProductCommentCriterion.php
+++ b/modules/productcomments/ProductCommentCriterion.php
@@ -140,13 +140,21 @@ class ProductCommentCriterion extends ObjectModel
if (!Validate::isUnsignedId($id_product) ||
!Validate::isUnsignedId($id_lang))
die(Tools::displayError());
+ $alias = 'p';
+ $table = '';
+ // check if version > 1.5 to add shop association
+ if (version_compare(_PS_VERSION_, '1.5', '>'))
+ {
+ $table = '_shop';
+ $alias = 'ps';
+ }
return Db::getInstance()->executeS('
SELECT pcc.`id_product_comment_criterion`, pccl.`name`
FROM `'._DB_PREFIX_.'product_comment_criterion` pcc
LEFT JOIN `'._DB_PREFIX_.'product_comment_criterion_lang` pccl ON (pcc.id_product_comment_criterion = pccl.id_product_comment_criterion)
LEFT JOIN `'._DB_PREFIX_.'product_comment_criterion_product` pccp ON (pcc.`id_product_comment_criterion` = pccp.`id_product_comment_criterion` AND pccp.`id_product` = '.(int)$id_product.')
LEFT JOIN `'._DB_PREFIX_.'product_comment_criterion_category` pccc ON (pcc.`id_product_comment_criterion` = pccc.`id_product_comment_criterion`)
- LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.id_category_default = pccc.id_category AND p.id_product = '.(int)$id_product.')
+ LEFT JOIN `'._DB_PREFIX_.'product'.$table.'` '.$alias.' ON ('.$alias.'.id_category_default = pccc.id_category AND '.$alias.'.id_product = '.(int)$id_product.')
WHERE pccl.`id_lang` = '.(int)($id_lang).' AND (pccp.id_product IS NOT NULL OR p.id_product IS NOT NULL OR pcc.id_product_comment_criterion_type = 1) AND pcc.active = 1
GROUP BY pcc.id_product_comment_criterion');
}
diff --git a/modules/statsforecast/statsforecast.php b/modules/statsforecast/statsforecast.php
index 5d67f54d3..5eabeb5bf 100644
--- a/modules/statsforecast/statsforecast.php
+++ b/modules/statsforecast/statsforecast.php
@@ -499,13 +499,14 @@ class StatsForecast extends Module
FROM `'._DB_PREFIX_.'orders` o
LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON o.id_order = od.id_order
LEFT JOIN `'._DB_PREFIX_.'product` p ON p.id_product = od.product_id
- LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (p.id_category_default = cl.id_category AND cl.id_lang = '.(int)$this->context->language->id.Shop::addSqlRestrictionOnLang('cl').')
+ '.Shop::addSqlAssociation('product', 'p').'
+ LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (asso_shop_product.id_category_default = cl.id_category AND cl.id_lang = '.(int)$this->context->language->id.Shop::addSqlRestrictionOnLang('cl').')
'.$join.'
WHERE o.valid = 1
AND o.`invoice_date` BETWEEN '.ModuleGraph::getDateBetween().'
'.$where.'
'.Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o').'
- GROUP BY p.id_category_default';
+ GROUP BY asso_shop_product.id_category_default';
$ca['cat'] = Db::getInstance()->executeS($sql);
uasort($ca['cat'], 'statsforecast_sort');