// id_category_default is now for multishop

This commit is contained in:
vChabot
2012-02-27 13:53:52 +00:00
parent 7e0e9e2adb
commit 77774d0d94
22 changed files with 172 additions and 49 deletions
+1
View File
@@ -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);
@@ -58,10 +58,10 @@
<td class="col-right">
<select id="id_category_default" name="id_category_default">
{foreach from=$selected_cat item=cat}
<option value="{$cat.id_category}" {if $product->id_category_default == $cat.id_category}selected="selected"{/if} >{$cat.name}</option>
<option value="{$cat.id_category}" {if $id_category_default == $cat.id_category}selected="selected"{/if} >{$cat.name}</option>
{/foreach}
</select>
<div class="hint" style="display:block;">{l s='The default category is the category who is displayed by default.'}</div>
<div class="hint" style="display:block;">{l s='The default category is the category who is displayed by default.'}</div>
</td>
</tr>
</table>
+7 -2
View File
@@ -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');
+12 -11
View File
@@ -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
);
}
+9 -9
View File
@@ -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();
+6 -4
View File
@@ -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;
+51 -5
View File
@@ -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);
}
}
+1 -1
View File
@@ -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 (
+4 -2
View File
@@ -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
+37 -1
View File
@@ -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
</div>';
$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));
}
}
+1 -3
View File
@@ -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))
{
+1
View File
@@ -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;
+6
View File
@@ -866,5 +866,11 @@
<configuration id="PS_STORES_ICON" name="PS_STORES_ICON">
<value>logo_stores.gif</value>
</configuration>
<configuration id="PS_ROOT_CATEGORY" name="PS_ROOT_CATEGORY">
<value>1</value>
</configuration>
<configuration id="PS_HOME_CATEGORY" name="PS_HOME_CATEGORY">
<value>2</value>
</configuration>
</entities>
</entity_configuration>
@@ -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`
+2
View File
@@ -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;
+9 -1
View File
@@ -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).')
+2 -1
View File
@@ -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)
+3 -2
View File
@@ -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).
+2 -1
View File
@@ -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
+1 -1
View File
@@ -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)
@@ -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');
}
+3 -2
View File
@@ -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');