// notice id_shop
This commit is contained in:
+55
-55
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
* 2007-2011 PrestaShop
|
* 2007-2011 PrestaShop
|
||||||
*
|
*
|
||||||
* NOTICE OF LICENSE
|
* NOTICE OF LICENSE
|
||||||
*
|
*
|
||||||
@@ -99,7 +99,7 @@ class ShopCore extends ObjectModel
|
|||||||
const CONTEXT_SHOP = 1;
|
const CONTEXT_SHOP = 1;
|
||||||
const CONTEXT_GROUP = 2;
|
const CONTEXT_GROUP = 2;
|
||||||
const CONTEXT_ALL = 3;
|
const CONTEXT_ALL = 3;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Some data can be shared between shops, like customers or orders
|
* Some data can be shared between shops, like customers or orders
|
||||||
*/
|
*/
|
||||||
@@ -109,7 +109,7 @@ class ShopCore extends ObjectModel
|
|||||||
public function getFields()
|
public function getFields()
|
||||||
{
|
{
|
||||||
parent::validateFields();
|
parent::validateFields();
|
||||||
|
|
||||||
$fields['id_group_shop'] = (int)$this->id_group_shop;
|
$fields['id_group_shop'] = (int)$this->id_group_shop;
|
||||||
$fields['id_category'] = (int)$this->id_category;
|
$fields['id_category'] = (int)$this->id_category;
|
||||||
$fields['id_theme'] = (int)$this->id_theme;
|
$fields['id_theme'] = (int)$this->id_theme;
|
||||||
@@ -140,7 +140,7 @@ class ShopCore extends ObjectModel
|
|||||||
if ($group->share_stock && $group->getNbShops() > 1)
|
if ($group->share_stock && $group->getNbShops() > 1)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$id = 'id_'.$row['type'];
|
$id = 'id_'.$row['type'];
|
||||||
if ($row['type'] == 'fk_shop')
|
if ($row['type'] == 'fk_shop')
|
||||||
$id = 'id_shop';
|
$id = 'id_shop';
|
||||||
@@ -148,7 +148,7 @@ class ShopCore extends ObjectModel
|
|||||||
$table_name .= '_'.$row['type'];
|
$table_name .= '_'.$row['type'];
|
||||||
$res &= Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.$table_name.'` WHERE `'.$id.'`='.(int)$this->id);
|
$res &= Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.$table_name.'` WHERE `'.$id.'`='.(int)$this->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
Shop::cacheShops(true);
|
Shop::cacheShops(true);
|
||||||
|
|
||||||
return $res;
|
return $res;
|
||||||
@@ -167,7 +167,7 @@ class ShopCore extends ObjectModel
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Find the shop from current domain / uri and get an instance of this shop
|
* Find the shop from current domain / uri and get an instance of this shop
|
||||||
*
|
*
|
||||||
* @return Shop
|
* @return Shop
|
||||||
*/
|
*/
|
||||||
public static function initialize()
|
public static function initialize()
|
||||||
@@ -188,13 +188,17 @@ class ShopCore extends ObjectModel
|
|||||||
AND s.active = 1
|
AND s.active = 1
|
||||||
AND s.deleted = 0
|
AND s.deleted = 0
|
||||||
ORDER BY LENGTH(uri) DESC';
|
ORDER BY LENGTH(uri) DESC';
|
||||||
|
|
||||||
|
$id_shop = '';
|
||||||
if ($results = Db::getInstance()->executeS($sql))
|
if ($results = Db::getInstance()->executeS($sql))
|
||||||
foreach ($results as $row)
|
foreach ($results as $row)
|
||||||
|
{
|
||||||
if (preg_match('#^'.preg_quote($row['uri'], '#').'#', $_SERVER['REQUEST_URI']))
|
if (preg_match('#^'.preg_quote($row['uri'], '#').'#', $_SERVER['REQUEST_URI']))
|
||||||
{
|
{
|
||||||
$id_shop = $row['id_shop'];
|
$id_shop = $row['id_shop'];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!$id_shop)
|
if (!$id_shop)
|
||||||
die('Shop not found ... redirect me please !');
|
die('Shop not found ... redirect me please !');
|
||||||
@@ -205,10 +209,10 @@ class ShopCore extends ObjectModel
|
|||||||
die(Tools::displayError());
|
die(Tools::displayError());
|
||||||
return $shop;
|
return $shop;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load some additional data of current shop (theme name, shop uri)
|
* Load some additional data of current shop (theme name, shop uri)
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function loadShopInfos()
|
protected function loadShopInfos()
|
||||||
@@ -229,10 +233,10 @@ class ShopCore extends ObjectModel
|
|||||||
$this->virtual_uri = $row['virtual_uri'];
|
$this->virtual_uri = $row['virtual_uri'];
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get shop theme name
|
* Get shop theme name
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getTheme()
|
public function getTheme()
|
||||||
@@ -241,11 +245,11 @@ class ShopCore extends ObjectModel
|
|||||||
$this->loadShopInfos();
|
$this->loadShopInfos();
|
||||||
return $this->theme_name;
|
return $this->theme_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Get shop URI
|
* Get shop URI
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getBaseURI()
|
public function getBaseURI()
|
||||||
@@ -254,15 +258,15 @@ class ShopCore extends ObjectModel
|
|||||||
$this->loadShopInfos();
|
$this->loadShopInfos();
|
||||||
return $this->physical_uri.$this->virtual_uri.'/';
|
return $this->physical_uri.$this->virtual_uri.'/';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPhysicalURI()
|
public function getPhysicalURI()
|
||||||
{
|
{
|
||||||
return $this->physical_uri;
|
return $this->physical_uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get group of current shop
|
* Get group of current shop
|
||||||
*
|
*
|
||||||
* @return GroupShop
|
* @return GroupShop
|
||||||
*/
|
*/
|
||||||
public function getGroup($asObject = false)
|
public function getGroup($asObject = false)
|
||||||
@@ -296,7 +300,7 @@ class ShopCore extends ObjectModel
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get root category of current shop
|
* Get root category of current shop
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getCategory()
|
public function getCategory()
|
||||||
@@ -306,7 +310,7 @@ class ShopCore extends ObjectModel
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get list of shop's urls
|
* Get list of shop's urls
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getUrls()
|
public function getUrls()
|
||||||
@@ -320,7 +324,7 @@ class ShopCore extends ObjectModel
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if current shop ID is the same as default shop in configuration
|
* Check if current shop ID is the same as default shop in configuration
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isDefaultShop()
|
public function isDefaultShop()
|
||||||
@@ -340,14 +344,14 @@ class ShopCore extends ObjectModel
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Load list of groups and shops, and cache it
|
* Load list of groups and shops, and cache it
|
||||||
*
|
*
|
||||||
* @param bool $refresh
|
* @param bool $refresh
|
||||||
*/
|
*/
|
||||||
public static function cacheShops($refresh = false)
|
public static function cacheShops($refresh = false)
|
||||||
{
|
{
|
||||||
if (self::$shops && !$refresh)
|
if (self::$shops && !$refresh)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
$sql = 'SELECT gs.*, s.*, gs.name AS group_name, s.name AS shop_name, s.active, su.domain, su.domain_ssl, su.physical_uri, su.virtual_uri
|
$sql = 'SELECT gs.*, s.*, gs.name AS group_name, s.name AS shop_name, s.active, su.domain, su.domain_ssl, su.physical_uri, su.virtual_uri
|
||||||
FROM '._DB_PREFIX_.'group_shop gs
|
FROM '._DB_PREFIX_.'group_shop gs
|
||||||
LEFT JOIN '._DB_PREFIX_.'shop s
|
LEFT JOIN '._DB_PREFIX_.'shop s
|
||||||
@@ -365,8 +369,6 @@ class ShopCore extends ObjectModel
|
|||||||
self::$shops[$row['id_group_shop']] = array(
|
self::$shops[$row['id_group_shop']] = array(
|
||||||
'id' => $row['id_group_shop'],
|
'id' => $row['id_group_shop'],
|
||||||
'name' => $row['group_name'],
|
'name' => $row['group_name'],
|
||||||
'share_customer' => $row['share_customer'],
|
|
||||||
'share_order' => $row['share_order'],
|
|
||||||
'share_stock' => $row['share_stock'],
|
'share_stock' => $row['share_stock'],
|
||||||
'shops' => array(),
|
'shops' => array(),
|
||||||
);
|
);
|
||||||
@@ -408,7 +410,7 @@ class ShopCore extends ObjectModel
|
|||||||
}
|
}
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return some informations cached for one shop
|
* Return some informations cached for one shop
|
||||||
*
|
*
|
||||||
@@ -426,7 +428,7 @@ class ShopCore extends ObjectModel
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a shop ID from shop name
|
* Return a shop ID from shop name
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
@@ -450,7 +452,7 @@ class ShopCore extends ObjectModel
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve group ID of a shop
|
* Retrieve group ID of a shop
|
||||||
*
|
*
|
||||||
* @param int $shopID Shop ID
|
* @param int $shopID Shop ID
|
||||||
* @return int Group ID
|
* @return int Group ID
|
||||||
*/
|
*/
|
||||||
@@ -465,7 +467,7 @@ class ShopCore extends ObjectModel
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* If the shop group has the option $type activated, get all shops ID of this group, else get current shop ID
|
* If the shop group has the option $type activated, get all shops ID of this group, else get current shop ID
|
||||||
*
|
*
|
||||||
* @param int $shopID
|
* @param int $shopID
|
||||||
* @param int $type Shop::SHARE_CUSTOMER or Shop::SHARE_ORDER
|
* @param int $type Shop::SHARE_CUSTOMER or Shop::SHARE_ORDER
|
||||||
* @return array
|
* @return array
|
||||||
@@ -476,15 +478,12 @@ class ShopCore extends ObjectModel
|
|||||||
die('Wrong argument ($type) in Shop::getSharedShops() method');
|
die('Wrong argument ($type) in Shop::getSharedShops() method');
|
||||||
|
|
||||||
Shop::cacheShops();
|
Shop::cacheShops();
|
||||||
foreach (self::$shops as $groupData)
|
|
||||||
if (array_key_exists($shopID, $groupData['shops']) && $groupData[$type])
|
|
||||||
return array_keys($groupData['shops']);
|
|
||||||
return array($shopID);
|
return array($shopID);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of ID concerned by the shop context (E.g. if context is shop group, get list of children shop ID)
|
* Get a list of ID concerned by the shop context (E.g. if context is shop group, get list of children shop ID)
|
||||||
*
|
*
|
||||||
* @param int $share If false, dont check share datas from group. Else can take a Shop::SHARE_* constant value
|
* @param int $share If false, dont check share datas from group. Else can take a Shop::SHARE_* constant value
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
@@ -498,14 +497,14 @@ class ShopCore extends ObjectModel
|
|||||||
else if ($shopGroupID)
|
else if ($shopGroupID)
|
||||||
$list = Shop::getShops(true, $shopGroupID, true);
|
$list = Shop::getShops(true, $shopGroupID, true);
|
||||||
else
|
else
|
||||||
$list = Shop::getShops(true, null, true);
|
$list = Shop::getShops(true, null, true);
|
||||||
|
|
||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the current shop context in FO or BO
|
* Retrieve the current shop context in FO or BO
|
||||||
*
|
*
|
||||||
* @param string null|shop|group
|
* @param string null|shop|group
|
||||||
* @return array(id_shop, id_group_shop)|int
|
* @return array(id_shop, id_group_shop)|int
|
||||||
*/
|
*/
|
||||||
@@ -551,20 +550,20 @@ class ShopCore extends ObjectModel
|
|||||||
return $shopGroupID;
|
return $shopGroupID;
|
||||||
return array($shopID, $shopGroupID);
|
return array($shopID, $shopGroupID);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get ID shop from context
|
* Get ID shop from context
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public static function getContextID()
|
public static function getContextID()
|
||||||
{
|
{
|
||||||
return Shop::getContext('shop');
|
return Shop::getContext('shop');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get ID shop from context
|
* Get ID shop from context
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public static function getContextGroupID()
|
public static function getContextGroupID()
|
||||||
@@ -574,7 +573,7 @@ class ShopCore extends ObjectModel
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Check in which type of shop context we are
|
* Check in which type of shop context we are
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getContextType()
|
public function getContextType()
|
||||||
@@ -589,7 +588,7 @@ class ShopCore extends ObjectModel
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Add an sql restriction for shops fields
|
* Add an sql restriction for shops fields
|
||||||
*
|
*
|
||||||
* @param int $share If false, dont check share datas from group. Else can take a Shop::SHARE_* constant value
|
* @param int $share If false, dont check share datas from group. Else can take a Shop::SHARE_* constant value
|
||||||
* @param string $alias
|
* @param string $alias
|
||||||
* @param string $type shop|group_shop
|
* @param string $type shop|group_shop
|
||||||
@@ -598,7 +597,7 @@ class ShopCore extends ObjectModel
|
|||||||
{
|
{
|
||||||
if ($type != 'shop' && $type != 'group_shop')
|
if ($type != 'shop' && $type != 'group_shop')
|
||||||
$type = 'shop';
|
$type = 'shop';
|
||||||
|
|
||||||
if ($alias)
|
if ($alias)
|
||||||
$alias .= '.';
|
$alias .= '.';
|
||||||
|
|
||||||
@@ -618,10 +617,10 @@ class ShopCore extends ObjectModel
|
|||||||
if ($shopID || $shopGroupID)
|
if ($shopID || $shopGroupID)
|
||||||
$restriction = ' AND '.$alias.'id_shop IN ('.implode(', ', $this->getListOfID($share)).') ';
|
$restriction = ' AND '.$alias.'id_shop IN ('.implode(', ', $this->getListOfID($share)).') ';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $restriction;
|
return $restriction;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function sqlSharedStock($alias = null)
|
public function sqlSharedStock($alias = null)
|
||||||
{
|
{
|
||||||
if ($alias)
|
if ($alias)
|
||||||
@@ -653,7 +652,7 @@ class ShopCore extends ObjectModel
|
|||||||
$tableAlias = ' asso_shop_'.$table;
|
$tableAlias = ' asso_shop_'.$table;
|
||||||
if (strpos($table, '.') !== false)
|
if (strpos($table, '.') !== false)
|
||||||
list($tableAlias, $table) = explode('.', $table);
|
list($tableAlias, $table) = explode('.', $table);
|
||||||
|
|
||||||
$assoTables = Shop::getAssoTables();
|
$assoTables = Shop::getAssoTables();
|
||||||
if (!isset($assoTables[$table]) || $assoTables[$table]['type'] != 'shop')
|
if (!isset($assoTables[$table]) || $assoTables[$table]['type'] != 'shop')
|
||||||
return ;
|
return ;
|
||||||
@@ -675,10 +674,10 @@ class ShopCore extends ObjectModel
|
|||||||
{
|
{
|
||||||
return ' AND '.$alias.'.id_shop = '.$this->getID(true). ' ';
|
return ' AND '.$alias.'.id_shop = '.$this->getID(true). ' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all groups and associated shops as subarrays
|
* Get all groups and associated shops as subarrays
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function getTree()
|
public static function getTree()
|
||||||
@@ -686,7 +685,7 @@ class ShopCore extends ObjectModel
|
|||||||
Shop::cacheShops();
|
Shop::cacheShops();
|
||||||
return self::$shops;
|
return self::$shops;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool Return true if there is more than one shop
|
* @return bool Return true if there is more than one shop
|
||||||
*/
|
*/
|
||||||
@@ -698,14 +697,14 @@ class ShopCore extends ObjectModel
|
|||||||
$total = Shop::getTotalShops(true);
|
$total = Shop::getTotalShops(true);
|
||||||
return ($total > 1) ? true : false;
|
return ($total > 1) ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function copyShopData($old_id, $tables_import = false, $deleted = false)
|
public function copyShopData($old_id, $tables_import = false, $deleted = false)
|
||||||
{
|
{
|
||||||
foreach (Shop::getAssoTables() AS $table_name => $row)
|
foreach (Shop::getAssoTables() AS $table_name => $row)
|
||||||
{
|
{
|
||||||
if ($tables_import && !isset($tables_import[$table_name]))
|
if ($tables_import && !isset($tables_import[$table_name]))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Special case for stock if current shop is in a share stock group
|
// Special case for stock if current shop is in a share stock group
|
||||||
if ($table_name == 'stock')
|
if ($table_name == 'stock')
|
||||||
{
|
{
|
||||||
@@ -713,13 +712,13 @@ class ShopCore extends ObjectModel
|
|||||||
if ($group->share_stock && $group->haveShops())
|
if ($group->share_stock && $group->haveShops())
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$id = 'id_'.$row['type'];
|
$id = 'id_'.$row['type'];
|
||||||
if ($row['type'] == 'fk_shop')
|
if ($row['type'] == 'fk_shop')
|
||||||
$id = 'id_shop';
|
$id = 'id_shop';
|
||||||
else
|
else
|
||||||
$table_name .= '_'.$row['type'];
|
$table_name .= '_'.$row['type'];
|
||||||
|
|
||||||
if (!$deleted)
|
if (!$deleted)
|
||||||
{
|
{
|
||||||
$res = Db::getInstance()->getRow('SELECT * FROM `'._DB_PREFIX_.$table_name.'` WHERE `'.$id.'` = '.(int)$old_id);
|
$res = Db::getInstance()->getRow('SELECT * FROM `'._DB_PREFIX_.$table_name.'` WHERE `'.$id.'` = '.(int)$old_id);
|
||||||
@@ -728,7 +727,7 @@ class ShopCore extends ObjectModel
|
|||||||
unset($res[$id]);
|
unset($res[$id]);
|
||||||
if (isset($row['primary']))
|
if (isset($row['primary']))
|
||||||
unset($res[$row['primary']]);
|
unset($res[$row['primary']]);
|
||||||
|
|
||||||
$keys = implode(', ', array_keys($res));
|
$keys = implode(', ', array_keys($res));
|
||||||
$sql = 'INSERT INTO `'._DB_PREFIX_.$table_name.'` ('.$keys.', '.$id.')
|
$sql = 'INSERT INTO `'._DB_PREFIX_.$table_name.'` ('.$keys.', '.$id.')
|
||||||
(SELECT '.$keys.', '.(int)$this->id.' FROM '._DB_PREFIX_.$table_name.'
|
(SELECT '.$keys.', '.(int)$this->id.' FROM '._DB_PREFIX_.$table_name.'
|
||||||
@@ -737,9 +736,10 @@ class ShopCore extends ObjectModel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Db::getInstance()->Execute('UPDATE `'._DB_PREFIX_.$table_name.'` SET WHERE `'.$id.'`='.(int)$old_id);
|
Db::getInstance()->Execute('UPDATE `'._DB_PREFIX_.$table_name.'` SET WHERE `'.$id.'`='.(int)$old_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user