// product categories now handle the multiple category trees

This commit is contained in:
vChabot
2012-04-20 15:13:08 +00:00
parent 6e83883bfb
commit 02a35a960f
+11 -4
View File
@@ -754,12 +754,19 @@ class ProductCore extends ObjectModel
if (empty($categories)) if (empty($categories))
return false; 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 // get max position in each categories
$result = Db::getInstance()->executeS(' $result = Db::getInstance()->executeS('
SELECT `id_category` SELECT c.`id_category`
FROM `'._DB_PREFIX_.'category_product` FROM `'._DB_PREFIX_.'category_product` cp
WHERE `id_category` NOT IN('.implode(',', array_map('intval', $categories)).') LEFT JOIN `'._DB_PREFIX_.'category` c
AND id_product = '.$this->id ON (c.`id_category` = cp.`id_category`)
WHERE cp.`id_category` NOT IN('.implode(',', array_map('intval', $categories)).')
AND (c.`nleft` < '.(int)$category->nleft.'
AND c.`nright` > '.(int)$category->nright.'
AND c.`level_depth` = 1)
AND cp.id_product = '.$this->id
); );
foreach ($result as $categ_to_delete) foreach ($result as $categ_to_delete)
$this->deleteCategory($categ_to_delete['id_category']); $this->deleteCategory($categ_to_delete['id_category']);