[+] 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
+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
*