[-] BO : fixed bug #PSCFV-3352
This commit is contained in:
@@ -1132,8 +1132,10 @@ class CategoryCore extends ObjectModel
|
|||||||
* @param mixed $id_category_parent
|
* @param mixed $id_category_parent
|
||||||
* @return boolean true if succeed
|
* @return boolean true if succeed
|
||||||
*/
|
*/
|
||||||
public static function cleanPositions($id_category_parent)
|
public static function cleanPositions($id_category_parent = null)
|
||||||
{
|
{
|
||||||
|
if ($id_category_parent === null)
|
||||||
|
return;
|
||||||
$return = true;
|
$return = true;
|
||||||
|
|
||||||
$id = Context::getContext()->shop->id;
|
$id = Context::getContext()->shop->id;
|
||||||
|
|||||||
+2
-11
@@ -762,24 +762,15 @@ 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
|
|
||||||
$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('
|
$result = Db::getInstance()->executeS('
|
||||||
SELECT c.`id_category`
|
SELECT c.`id_category`
|
||||||
FROM `'._DB_PREFIX_.'category_product` cp
|
FROM `'._DB_PREFIX_.'category_product` cp
|
||||||
LEFT JOIN `'._DB_PREFIX_.'category` c
|
LEFT JOIN `'._DB_PREFIX_.'category` c
|
||||||
ON (c.`id_category` = cp.`id_category`)
|
ON (c.`id_category` = cp.`id_category`)
|
||||||
WHERE cp.`id_category` NOT IN('.implode(',', array_map('intval', $categories)).')
|
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)
|
foreach ($result as $categ_to_delete)
|
||||||
$this->deleteCategory($categ_to_delete['id_category']);
|
$this->deleteCategory($categ_to_delete['id_category']);
|
||||||
// if none are found, it's an error
|
// if none are found, it's an error
|
||||||
|
|||||||
@@ -530,7 +530,8 @@ class AdminCategoriesControllerCore extends AdminController
|
|||||||
foreach (Tools::getValue($this->table.'Box') as $id_category)
|
foreach (Tools::getValue($this->table.'Box') as $id_category)
|
||||||
{
|
{
|
||||||
$category = new Category((int)$id_category);
|
$category = new Category((int)$id_category);
|
||||||
$cats_ids[$category->id] = $category->id_parent;
|
if (!$category->isRootCategoryForAShop())
|
||||||
|
$cats_ids[$category->id] = $category->id_parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parent::processBulkDelete())
|
if (parent::processBulkDelete())
|
||||||
@@ -546,13 +547,13 @@ class AdminCategoriesControllerCore extends AdminController
|
|||||||
|
|
||||||
public function processDelete()
|
public function processDelete()
|
||||||
{
|
{
|
||||||
|
$category = $this->loadObject();
|
||||||
if ($this->tabAccess['delete'] === '1')
|
if ($this->tabAccess['delete'] === '1')
|
||||||
{
|
{
|
||||||
if ($this->isRootCategoryForAShop())
|
if ($category->isRootCategoryForAShop())
|
||||||
$this->errors[] = Tools::displayError('You cannot remove this category because a shop uses this category as a root category.');
|
$this->errors[] = Tools::displayError('You cannot remove this category because a shop uses this category as a root category.');
|
||||||
else if (parent::processDelete())
|
else if (parent::processDelete())
|
||||||
{
|
{
|
||||||
$category = $this->loadObject();
|
|
||||||
$this->setDeleteMode();
|
$this->setDeleteMode();
|
||||||
$this->processFatherlessProducts((int)$category->id_parent);
|
$this->processFatherlessProducts((int)$category->id_parent);
|
||||||
return true;
|
return true;
|
||||||
@@ -574,7 +575,6 @@ class AdminCategoriesControllerCore extends AdminController
|
|||||||
/* Delete or link products which were not in others categories */
|
/* Delete or link products which were not in others categories */
|
||||||
$fatherless_products = new Collection('Product', Context::getContext()->language->id);
|
$fatherless_products = new Collection('Product', Context::getContext()->language->id);
|
||||||
$fatherless_products->where('id_product', 'notin', $all_product_asso);
|
$fatherless_products->where('id_product', 'notin', $all_product_asso);
|
||||||
|
|
||||||
foreach ($fatherless_products as $poor_product)
|
foreach ($fatherless_products as $poor_product)
|
||||||
{
|
{
|
||||||
if (Validate::isLoadedObject($poor_product))
|
if (Validate::isLoadedObject($poor_product))
|
||||||
@@ -585,19 +585,12 @@ class AdminCategoriesControllerCore extends AdminController
|
|||||||
{
|
{
|
||||||
if ($this->disable_products)
|
if ($this->disable_products)
|
||||||
$poor_product->active = 0;
|
$poor_product->active = 0;
|
||||||
$poor_product->addToCategories($id_parent);
|
$poor_product->id_category_default = (int)$id_parent;
|
||||||
|
$poor_product->addToCategories((int)$id_parent);
|
||||||
$poor_product->save();
|
$poor_product->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set category default to Home category where categorie no more exists */
|
|
||||||
Db::getInstance()->execute('
|
|
||||||
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`)
|
|
||||||
');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function processPosition()
|
public function processPosition()
|
||||||
|
|||||||
Reference in New Issue
Block a user