[+] 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
This commit is contained in:
hAitmansour
2011-10-28 14:19:13 +00:00
parent c5dd56aa5f
commit cff9554dda
2 changed files with 37 additions and 2 deletions
+15 -1
View File
@@ -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)
+22 -1
View File
@@ -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
*