[-] BO: Fix #PSCFV-4889 don't delete product if physical stock > 0

This commit is contained in:
Rémi Gaillard committed 2012-12-04 11:38:47 +01:00
1 parent e5ec07f95a
commit 7d05a6d8e9
1 file changed
+5 -3
@@ -536,15 +536,19 @@ class AdminProductsControllerCore extends AdminController
$this->errors[] = Tools::displayError('You cannot delete the product because there is physical stock left or supply orders in progress.'); $this->errors[] = Tools::displayError('You cannot delete the product because there is physical stock left or supply orders in progress.');
} }
if (!count($this->errors))
{
if ($object->delete()) if ($object->delete())
{ {
$id_category = (int)Tools::getValue('id_category'); $id_category = (int)Tools::getValue('id_category');
$category_url = empty($id_category) ? '' : '&id_category='.(int)$id_category; $category_url = empty($id_category) ? '' : '&id_category='.(int)$id_category;
$this->redirect_after = self::$currentIndex.'&conf=1&token='.$this->token.$category_url; $this->redirect_after = self::$currentIndex.'&conf=1&token='.$this->token.$category_url;
} }
else
$this->errors[] = Tools::displayError('An error occurred during deletion.'); $this->errors[] = Tools::displayError('An error occurred during deletion.');
} }
} }
}
else else
$this->errors[] = Tools::displayError('An error occurred while deleting object.').' <b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)'); $this->errors[] = Tools::displayError('An error occurred while deleting object.').' <b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)');
} }
@@ -632,10 +636,8 @@ class AdminProductsControllerCore extends AdminController
$real_quantity = $stock_manager->getProductRealQuantities($product->id, 0); $real_quantity = $stock_manager->getProductRealQuantities($product->id, 0);
if ($physical_quantity > 0 || $real_quantity > $physical_quantity) if ($physical_quantity > 0 || $real_quantity > $physical_quantity)
$this->errors[] = sprintf(Tools::displayError('You cannot delete the product #%d because there is physical stock left or supply orders in progress.'), $product->id); $this->errors[] = sprintf(Tools::displayError('You cannot delete the product #%d because there is physical stock left or supply orders in progress.'), $product->id);
else
$success &= $product->delete();
} }
else if (!count($this->errors))
$success &= $product->delete(); $success &= $product->delete();
} }
} }