[-] BO : fixed bug #PSCFV-3352

This commit is contained in:
vAugagneur
2012-07-26 13:03:54 +00:00
parent a97e9530a2
commit 4e62d9d463
3 changed files with 11 additions and 25 deletions
+2 -11
View File
@@ -762,24 +762,15 @@ class ProductCore extends ObjectModel
if (empty($categories))
return false;
// take the first selected category to get the category tree (nleft and nright)
$category = new Category($categories[0]);
// get max position in each categories
$and = '';
if (Shop::isFeatureActive())
$and = '
AND (c.`nleft` < '.(int)$category->nleft.'
AND c.`nright` > '.(int)$category->nright.'
AND c.`level_depth` = 1)';
$result = Db::getInstance()->executeS('
SELECT c.`id_category`
FROM `'._DB_PREFIX_.'category_product` cp
LEFT JOIN `'._DB_PREFIX_.'category` c
ON (c.`id_category` = cp.`id_category`)
WHERE cp.`id_category` NOT IN('.implode(',', array_map('intval', $categories)).')
'.$and.'
AND cp.id_product = '.$this->id
AND cp.id_product = '.$this->id
);
foreach ($result as $categ_to_delete)
$this->deleteCategory($categ_to_delete['id_category']);
// if none are found, it's an error