From cff9554dda73cbc1eaa6276fc875d4c4129421e7 Mon Sep 17 00:00:00 2001 From: hAitmansour Date: Fri, 28 Oct 2011 14:19:13 +0000 Subject: [PATCH] [+] MO : multi-shop allow the removal of a shop if it has no order and no customer git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@9722 b9a71923-0436-4b27-9f14-aed3839534dd --- admin-dev/tabs/AdminShop.php | 16 +++++++++++++++- classes/shop/Shop.php | 23 ++++++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/admin-dev/tabs/AdminShop.php b/admin-dev/tabs/AdminShop.php index b6eac9e43..aeb4faffb 100755 --- a/admin-dev/tabs/AdminShop.php +++ b/admin-dev/tabs/AdminShop.php @@ -34,7 +34,7 @@ class AdminShop extends AdminTab $this->table = 'shop'; $this->className = 'Shop'; $this->edit = true; - $this->delete = false; + $this->delete = true; $this->deleted = false; $this->_select = 'gs.name group_shop_name, cl.name category_name'; @@ -73,6 +73,20 @@ class AdminShop extends AdminTab $newShop->copyShopData((int)Tools::getValue('importFromShop'), $importData); } + public function getList($id_lang, $orderBy = NULL, $orderWay = NULL, $start = 0, $limit = NULL, $id_lang_shop = false) + { + parent::getList($id_lang, $orderBy, $orderWay, $start, $limit, $id_lang_shop); + $shop_delete_list = array(); + + // test store authorized to remove + foreach($this->_list as $shop) + { + if(Shop::has_dependency($shop['id_shop'])) + $shop_delete_list[] = $shop['id_shop']; + } + $this->_listSkipDelete = $shop_delete_list; + } + public function postProcess() { if ((Tools::isSubmit('status') || Tools::isSubmit('status'.$this->table) || (Tools::isSubmit('submitAdd'.$this->table) && Tools::getValue($this->identifier) && !Tools::getValue('active'))) && $this->loadObject() && $this->loadObject()->active) diff --git a/classes/shop/Shop.php b/classes/shop/Shop.php index 396d90769..94ed3d506 100644 --- a/classes/shop/Shop.php +++ b/classes/shop/Shop.php @@ -155,7 +155,7 @@ class ShopCore extends ObjectModel public function delete() { - if (!$res = parent::delete()) + if (self::has_dependency($this->id) || !$res = parent::delete()) return false; foreach (Shop::getAssoTables() as $table_name => $row) @@ -173,6 +173,27 @@ class ShopCore extends ObjectModel return $res; } + /** + * Detect dependency with customer or orders + * + * @return bool + */ + public static function has_dependency($id_shop) + { + $has_dependency = false; + $nbr_customer = (int)Db::getInstance()->getValue('SELECT `id_customer` FROM `'._DB_PREFIX_.'customer` WHERE `id_shop`='.(int)$id_shop); + if($nbr_customer) + $has_dependency = true; + else + { + $nbr_order= (int)Db::getInstance()->getValue('SELECT `id_order` FROM `'._DB_PREFIX_.'orders` WHERE `id_shop`='.(int)$id_shop); + if($nbr_order) + $has_dependency = true; + } + + return $has_dependency; + } + /** * Get a new instance of a shop *