[-] 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
+3 -1
View File
@@ -1132,8 +1132,10 @@ class CategoryCore extends ObjectModel
* @param mixed $id_category_parent
* @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;
$id = Context::getContext()->shop->id;
+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
@@ -530,7 +530,8 @@ class AdminCategoriesControllerCore extends AdminController
foreach (Tools::getValue($this->table.'Box') as $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())
@@ -546,13 +547,13 @@ class AdminCategoriesControllerCore extends AdminController
public function processDelete()
{
$category = $this->loadObject();
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.');
else if (parent::processDelete())
{
$category = $this->loadObject();
$this->setDeleteMode();
$this->processFatherlessProducts((int)$category->id_parent);
return true;
@@ -574,7 +575,6 @@ class AdminCategoriesControllerCore extends AdminController
/* Delete or link products which were not in others categories */
$fatherless_products = new Collection('Product', Context::getContext()->language->id);
$fatherless_products->where('id_product', 'notin', $all_product_asso);
foreach ($fatherless_products as $poor_product)
{
if (Validate::isLoadedObject($poor_product))
@@ -585,19 +585,12 @@ class AdminCategoriesControllerCore extends AdminController
{
if ($this->disable_products)
$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();
}
}
}
/* 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()