// Multishop interface reworked
This commit is contained in:
+22
-27
@@ -198,6 +198,7 @@ class ShopCore extends ObjectModel
|
||||
/**
|
||||
* Detect dependency with customer or orders
|
||||
*
|
||||
* @param int $id_shop
|
||||
* @return bool
|
||||
*/
|
||||
public static function hasDependency($id_shop)
|
||||
@@ -224,17 +225,6 @@ class ShopCore extends ObjectModel
|
||||
return $has_dependency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a new instance of a shop
|
||||
*
|
||||
* @param int $id shop ID
|
||||
* @return Shop
|
||||
*/
|
||||
public static function getInstance($id)
|
||||
{
|
||||
return new Shop($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the shop from current domain / uri and get an instance of this shop
|
||||
* if INSTALL_VERSION is defined, will return an empty shop object
|
||||
@@ -533,6 +523,25 @@ class ShopCore extends ObjectModel
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a collection of shops
|
||||
*
|
||||
* @param bool $active
|
||||
* @param int $id_shop_group
|
||||
* @return Collection
|
||||
*/
|
||||
public static function getShopsCollection($active = true, $id_shop_group = null)
|
||||
{
|
||||
$shops = new Collection('Shop');
|
||||
if ($active)
|
||||
$shops->where('active', '=', 1);
|
||||
|
||||
if ($id_shop_group)
|
||||
$shops->where('id_shop_group', '=', $id_shop_group);
|
||||
|
||||
return $shops;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return some informations cached for one shop
|
||||
*
|
||||
@@ -749,15 +758,11 @@ class ShopCore extends ObjectModel
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool Return true if there is more than one shop
|
||||
* @return bool Return true if multishop feature is activated
|
||||
*/
|
||||
public static function isFeatureActive()
|
||||
{
|
||||
static $total = null;
|
||||
|
||||
if (is_null($total))
|
||||
$total = Db::getInstance()->getValue('SELECT COUNT(*) FROM '._DB_PREFIX_.'shop');
|
||||
return ($total > 1) ? true : false;
|
||||
return Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE');
|
||||
}
|
||||
|
||||
public function copyShopData($old_id, $tables_import = false, $deleted = false)
|
||||
@@ -813,16 +818,6 @@ class ShopCore extends ObjectModel
|
||||
), $m['id_module']);
|
||||
}
|
||||
|
||||
public function checkIfShopExist($id)
|
||||
{
|
||||
return (int)Db::getInstance()->getValue('SELECT COUNT(*) FROM`'._DB_PREFIX_.'shop` WHERE `id_shop` = '.(int)$id);
|
||||
}
|
||||
|
||||
public function checkIfShopGroupExist($id)
|
||||
{
|
||||
return (int)Db::getInstance()->getValue('SELECT COUNT(*) FROM`'._DB_PREFIX_.'shop_group` WHERE `id_shop_group` = '.(int)$id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated 1.5.0 Use shop->id
|
||||
*/
|
||||
|
||||
@@ -108,4 +108,42 @@ class ShopGroupCore extends ObjectModel
|
||||
WHERE name = \''.pSQL($name).'\'';
|
||||
return (int)Db::getInstance()->getValue($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect dependency with customer or orders
|
||||
*
|
||||
* @param int $id_shop_group
|
||||
* @param string $check all|customer|order
|
||||
* @return bool
|
||||
*/
|
||||
public static function hasDependency($id_shop_group, $check = 'all')
|
||||
{
|
||||
$list_shops = Shop::getShops(false, $id_shop_group, true);
|
||||
if (!$list_shops)
|
||||
return false;
|
||||
|
||||
if ($check == 'all' || $check == 'customer')
|
||||
{
|
||||
$total_customer = (int)Db::getInstance()->getValue('
|
||||
SELECT count(*)
|
||||
FROM `'._DB_PREFIX_.'customer`
|
||||
WHERE `id_shop` IN ('.implode(', ', $list_shops).')'
|
||||
);
|
||||
if ($total_customer)
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($check == 'all' || $check == 'order')
|
||||
{
|
||||
$total_order = (int)Db::getInstance()->getValue('
|
||||
SELECT count(*)
|
||||
FROM `'._DB_PREFIX_.'orders`
|
||||
WHERE `id_shop` IN ('.implode(', ', $list_shops).')'
|
||||
);
|
||||
if ($total_order)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,41 +164,4 @@ class ShopUrlCore extends ObjectModel
|
||||
}
|
||||
return self::$main_domain_ssl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @param string $virtual_uri
|
||||
* @param int $id_shop_tested
|
||||
* @return bool
|
||||
*/
|
||||
public static function virtualUriExists($virtual_uri, $id_shop_tested)
|
||||
{
|
||||
Tools::displayAsDeprecated();
|
||||
$virtual_uri = trim($virtual_uri);
|
||||
if (substr($virtual_uri, -1) != '/')
|
||||
$virtual_uri .= '/';
|
||||
return (bool) Db::getInstance()->getValue('
|
||||
SELECT `virtual_uri`
|
||||
FROM `'._DB_PREFIX_.'shop_url`
|
||||
WHERE `id_shop` != '.(int)$id_shop_tested.'
|
||||
AND `virtual_uri` = "'.pSQL($virtual_uri).'"');
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @param string $domain
|
||||
* @param string $physical_uri
|
||||
* @param string $virtual_uri
|
||||
* @param int $id_shop_tested
|
||||
* @return bool
|
||||
*/
|
||||
public static function urlExists($domain, $physical_uri, $virtual_uri, $id_shop_tested)
|
||||
{
|
||||
$url = $domain.$physical_uri.$virtual_uri;
|
||||
return (bool)Db::getInstance()->getValue('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'shop_url`
|
||||
WHERE `id_shop` != '.(int)$id_shop_tested.'
|
||||
AND CONCAT(`domain`, `physical_uri`, `virtual_uri`) ="'.pSQL($url).'"');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user