From 726a53c490157f5d1c0c8e80b86f08321cd114bc Mon Sep 17 00:00:00 2001 From: bMancone Date: Mon, 14 Nov 2011 15:44:26 +0000 Subject: [PATCH] // Deleted carriers are now properly removed from the table warehouse_carrier git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@10107 b9a71923-0436-4b27-9f14-aed3839534dd --- classes/stock/Warehouse.php | 18 +++++++++++++++++- controllers/admin/AdminCarriersController.php | 10 +++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/classes/stock/Warehouse.php b/classes/stock/Warehouse.php index f34a5f3c0..a94409eaf 100644 --- a/classes/stock/Warehouse.php +++ b/classes/stock/Warehouse.php @@ -182,6 +182,20 @@ class WarehouseCore extends ObjectModel Db::getInstance()->autoExecute(_DB_PREFIX_.'warehouse_carrier', $row_to_insert, 'INSERT'); } + /** + * For a given carrier, removes it from the warehouse/carrier association + * If $id_warehouse is set, it only removes the carrier for this warehouse + * @param int $id_carrier + * @param int $id_warehouse optional + */ + public static function removeCarrier($id_carrier, $id_warehouse = null) + { + Db::getInstance()->execute(' + DELETE FROM '._DB_PREFIX_.'warehouse_carrier + WHERE id_carrier = '.(int)$id_carrier. + ($id_warehouse ? ' AND id_warehouse = '.(int)$id_warehouse : '')); + } + /** * Checks if a warehouse is empty - i.e. holds no stock * @@ -315,7 +329,9 @@ class WarehouseCore extends ObjectModel FROM '._DB_PREFIX_.'stock s WHERE s.id_warehouse = '.(int)$this->id; - return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query); + $res = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query); + + return ($res ? $res : 0); } /** diff --git a/controllers/admin/AdminCarriersController.php b/controllers/admin/AdminCarriersController.php index 76e730530..ff8767355 100644 --- a/controllers/admin/AdminCarriersController.php +++ b/controllers/admin/AdminCarriersController.php @@ -491,13 +491,21 @@ class AdminCarriersControllerCore extends AdminController || (isset($_GET['delete'.$this->table]) && Tools::getValue('id_carrier') == Configuration::get('PS_CARRIER_DEFAULT'))) $this->_errors[] = $this->l('Please set another carrier as default before deleting'); else + { + // if deletion : removes the carrier from the warehouse/carrier association + if (Tools::isSubmit('delete'.$this->table)) + { + $id = (int)Tools::getValue('id_'.$this->table); + Warehouse::removeCarrier($id); + } parent::postProcess(); + } } } /** * Overload the property $fields_value - * + * * @param object $obj */ public function getFieldsValues($obj)