// Context
This commit is contained in:
+17
-17
@@ -1127,22 +1127,22 @@ abstract class AdminTabCore
|
||||
*/
|
||||
public function getList($id_lang, $orderBy = NULL, $orderWay = NULL, $start = 0, $limit = NULL, $id_lang_shop = false)
|
||||
{
|
||||
global $cookie;
|
||||
$context = Context::getContext();
|
||||
|
||||
/* Manage default params values */
|
||||
if (empty($limit))
|
||||
$limit = ((!isset($cookie->{$this->table.'_pagination'})) ? $this->_pagination[1] : $limit = $cookie->{$this->table.'_pagination'});
|
||||
$limit = ((!isset($context->cookie->{$this->table.'_pagination'})) ? $this->_pagination[1] : $limit = $context->cookie->{$this->table.'_pagination'});
|
||||
|
||||
if (!Validate::isTableOrIdentifier($this->table))
|
||||
die (Tools::displayError('Table name is invalid:').' "'.$this->table.'"');
|
||||
|
||||
if (empty($orderBy))
|
||||
$orderBy = $cookie->__get($this->table.'Orderby') ? $cookie->__get($this->table.'Orderby') : $this->_defaultOrderBy;
|
||||
$orderBy = $context->cookie->__get($this->table.'Orderby') ? $context->cookie->__get($this->table.'Orderby') : $this->_defaultOrderBy;
|
||||
if (empty($orderWay))
|
||||
$orderWay = $cookie->__get($this->table.'Orderway') ? $cookie->__get($this->table.'Orderway') : 'ASC';
|
||||
$orderWay = $context->cookie->__get($this->table.'Orderway') ? $context->cookie->__get($this->table.'Orderway') : 'ASC';
|
||||
|
||||
$limit = (int)(Tools::getValue('pagination', $limit));
|
||||
$cookie->{$this->table.'_pagination'} = $limit;
|
||||
$context->cookie->{$this->table.'_pagination'} = $limit;
|
||||
|
||||
/* Check params validity */
|
||||
if (!Validate::isOrderBy($orderBy) OR !Validate::isOrderWay($orderWay)
|
||||
@@ -1176,21 +1176,21 @@ abstract class AdminTabCore
|
||||
$whereShop = Shop::sqlRestriction($this->shopShareDatas, 'a', null, null, $this->shopLinkType);
|
||||
}
|
||||
$filterShop = '';
|
||||
if (($context_type = Shop::getContextType()) != Shop::CONTEXT_ALL)
|
||||
if ($context->shop->getContextType() != Shop::CONTEXT_ALL)
|
||||
{
|
||||
if ($context_type == Shop::CONTEXT_SHOP)
|
||||
if ($context->shop->getContextType() == Shop::CONTEXT_SHOP)
|
||||
{
|
||||
$assos = Shop::getAssoTables();
|
||||
if (isset($assos[$this->table]) AND $assos[$this->table]['type'] == 'shop')
|
||||
$filterKey = $assos[$this->table]['type'];
|
||||
$idenfierShop = Shop::getCurrentShop();
|
||||
$idenfierShop = $context->shop->getID();
|
||||
}
|
||||
elseif ($context_type == Shop::CONTEXT_GROUP)
|
||||
elseif ($context->shop->getContextType() == Shop::CONTEXT_GROUP)
|
||||
{
|
||||
$assos = GroupShop::getAssoTables();
|
||||
if (isset($assos[$this->table]) AND $assos[$this->table]['type'] == 'group_shop')
|
||||
$filterKey = $assos[$this->table]['type'];
|
||||
$idenfierShop = Shop::getCurrentGroupShop();
|
||||
$idenfierShop = $context->shop->getGroup();
|
||||
}
|
||||
if (isset($filterKey))
|
||||
$filterShop = 'JOIN `'._DB_PREFIX_.$this->table.'_'.$filterKey.'` sa ON (sa.'.$this->identifier.' = a.'.$this->identifier.' AND sa.id_'.$filterKey.'='.(int)$idenfierShop.')';
|
||||
@@ -1833,12 +1833,14 @@ abstract class AdminTabCore
|
||||
* @param integer $id_lang Language id (optional)
|
||||
* @return string
|
||||
*/
|
||||
protected function getFieldValue($obj, $key, $id_lang = NULL, $id_shop = NULL)
|
||||
protected function getFieldValue($obj, $key, $id_lang = NULL, $context = NULL)
|
||||
{
|
||||
global $cookie;
|
||||
$id_shop = ($context) ? $context->shop->getID() : null;
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
|
||||
if (!$id_shop AND $obj->isLangMultishop())
|
||||
$id_shop = Shop::getCurrentShop(true);
|
||||
$id_shop = $context->shop->getID();
|
||||
|
||||
if ($id_lang)
|
||||
$defaultValue = ($obj->id AND isset($obj->{$key}[$id_lang])) ? $obj->{$key}[$id_lang] : '';
|
||||
@@ -2066,10 +2068,8 @@ abstract class AdminTabCore
|
||||
{
|
||||
if (!Tools::isMultiShopActivated())
|
||||
return;
|
||||
if (!$id_shop = Shop::getCurrentShop())
|
||||
$id_shop = Configuration::get('PS_SHOP_DEFAULT');
|
||||
$shop = new Shop((int)$id_shop);
|
||||
return $this->l('This field will be changed for the shop:').' '.$shop->name;
|
||||
|
||||
return $this->l('This field will be changed for the shop:').' '.Context::getContext()->shop->name;
|
||||
}
|
||||
|
||||
protected function displayAssoGroupShop($field_name = 'name')
|
||||
|
||||
@@ -276,7 +276,7 @@ class CustomerCore extends ObjectModel
|
||||
$sql = 'SELECT `id_customer`
|
||||
FROM `'._DB_PREFIX_.'customer`
|
||||
WHERE `email` = \''.pSQL($email).'\'
|
||||
'.Shop::sqlRestriction(true, null, $id_shop, $id_group_shop).
|
||||
'.Shop::sqlRestriction(true).
|
||||
($ignoreGuest ? 'AND `is_guest` = 0' : '');
|
||||
$result = Db::getInstance()->getRow($sql);
|
||||
|
||||
|
||||
@@ -118,7 +118,7 @@ abstract class ObjectModelCore
|
||||
die(Tools::displayError());
|
||||
|
||||
if ($this->langMultiShop AND $id_shop == NULL)
|
||||
$id_shop = (int)Shop::getCurrentShop(true);
|
||||
$id_shop = Context::getContext()->shop->getID();
|
||||
if ($id_shop AND $this->langMultiShop)
|
||||
$this->id_shop = $id_shop;
|
||||
/* Connect to database and check SQL table/identifier */
|
||||
@@ -683,7 +683,7 @@ abstract class ObjectModelCore
|
||||
{
|
||||
$multi_shop_join = ' LEFT JOIN `'._DB_PREFIX_.$this->table.'_'.$assoc[$this->table]['type'].'` AS multi_shop_'.$this->table.' ON (main.'.$this->identifier.' = '.'multi_shop_'.$this->table.'.'.$this->identifier.')';
|
||||
$class_name = WebserviceRequest::$ws_current_classname;
|
||||
$vars = get_class_vars($classname);
|
||||
$vars = get_class_vars($class_name);
|
||||
foreach ($vars['shopIDs'] as $id_shop)
|
||||
$OR[] = ' multi_shop_'.$this->table.'.id_shop = '.$id_shop.' ';
|
||||
$multi_shop_filter = ' AND ('.implode('OR', $OR).') ';
|
||||
|
||||
+4
-3
@@ -108,13 +108,14 @@ class PageCore extends ObjectModel
|
||||
public static function setPageViewed($id_page)
|
||||
{
|
||||
$id_date_range = DateRange::getCurrentRange();
|
||||
$context = Context::getContext();
|
||||
|
||||
// Try to increment the visits counter
|
||||
$sql = 'UPDATE `'._DB_PREFIX_.'page_viewed`
|
||||
SET `counter` = `counter` + 1
|
||||
WHERE `id_date_range` = '.(int)$id_date_range.'
|
||||
AND `id_page` = '.(int)$id_page.'
|
||||
AND `id_shop` = ' . Shop::getCurrentShop();
|
||||
AND `id_shop` = ' . $context->shop->getID();
|
||||
Db::getInstance()->Execute($sql);
|
||||
|
||||
// If no one has seen the page in this date range, it is added
|
||||
@@ -123,8 +124,8 @@ class PageCore extends ObjectModel
|
||||
'id_date_range' => (int)$id_date_range,
|
||||
'id_page' => (int)$id_page,
|
||||
'counter' => 1,
|
||||
'id_shop' => Shop::getCurrentShop(),
|
||||
'id_group_shop' => Shop::getCurrentGroupShop(),
|
||||
'id_shop' => $context->shop->getID(),
|
||||
'id_group_shop' => $context->shop->getGroup(),
|
||||
), 'INSERT');
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -2089,7 +2089,7 @@ class ProductCore extends ObjectModel
|
||||
// For retrocompatibility
|
||||
$id_product_attribute = (int)$id_product_attribute;
|
||||
$quantity = (int)$quantity;
|
||||
if (Shop::isDefaultShop($shop))
|
||||
if (Shop::getInstance($shop)->isDefaultShop())
|
||||
{
|
||||
if ($id_product_attribute)
|
||||
{
|
||||
|
||||
@@ -71,7 +71,6 @@ class ReferrerCore extends ObjectModel
|
||||
{
|
||||
parent::validateFields();
|
||||
|
||||
$fields['id_shop'] = (!$this->id_shop) ? Shop::getCurrentShop(true) : (int)$this->id_shop;
|
||||
$fields['name'] = pSQL($this->name);
|
||||
$fields['passwd'] = pSQL($this->passwd);
|
||||
$fields['http_referer_regexp'] = pSQL($this->http_referer_regexp, true);
|
||||
|
||||
+47
-41
@@ -405,8 +405,8 @@ class SearchCore
|
||||
// Every indexed words are cached into a PHP array
|
||||
$wordIdsByWord = array();
|
||||
$wordIds = Db::getInstance()->ExecuteS('
|
||||
SELECT sw.id_word, sw.word, id_lang, id_shop
|
||||
FROM '._DB_PREFIX_.'search_word sw', false);
|
||||
SELECT id_word, word, id_lang, id_shop
|
||||
FROM '._DB_PREFIX_.'search_word', false);
|
||||
$wordIdsByWord = array();
|
||||
while ($wordId = $db->nextRow($wordIds))
|
||||
{
|
||||
@@ -533,10 +533,15 @@ class SearchCore
|
||||
$queryArray3 = array();
|
||||
}
|
||||
|
||||
public static function searchTag($id_lang, $tag, $count = false, $pageNumber = 0, $pageSize = 10, $orderBy = false, $orderWay = false, $useCookie = true, $context = null)
|
||||
public static function searchTag($id_lang, $tag, $count = false, $pageNumber = 0, $pageSize = 10, $orderBy = false, $orderWay = false, $useCookie = true, $shops = null, $context = null)
|
||||
{
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
if (is_null($shops))
|
||||
$shops = array($context->shop->getID());
|
||||
if (!is_array($shops))
|
||||
$shops = array($shops);
|
||||
|
||||
// Only use cookie if id_customer is not present
|
||||
if ($useCookie)
|
||||
$id_customer = (int)$context->customer->id;
|
||||
@@ -552,45 +557,46 @@ class SearchCore
|
||||
|
||||
if ($count)
|
||||
{
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||
SELECT COUNT(DISTINCT pt.`id_product`) nb
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_tag` pt ON (p.`id_product` = pt.`id_product`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tag` t ON (pt.`id_tag` = t.`id_tag` AND t.`id_lang` = '.(int)$id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_product` = p.`id_product`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = cp.`id_category`)
|
||||
WHERE p.`active` = 1
|
||||
AND cg.`id_group` '.(!$id_customer ? '= 1' : 'IN (
|
||||
SELECT id_group FROM '._DB_PREFIX_.'customer_group
|
||||
WHERE id_customer = '.(int)$id_customer.')').'
|
||||
AND t.`name` LIKE \'%'.pSQL($tag).'%\'');
|
||||
return isset($result['nb']) ? $result['nb'] : 0;
|
||||
$sql = 'SELECT COUNT(DISTINCT pt.`id_product`) nb
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
INNER JOIN '._DB_PREFIX_.'product_shop ps ON p.id_product = ps.id_product AND ps.id_shop IN ('.implode(', ', $shops).')
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_tag` pt ON (p.`id_product` = pt.`id_product`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tag` t ON (pt.`id_tag` = t.`id_tag` AND t.`id_lang` = '.(int)$id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_product` = p.`id_product`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = cp.`id_category`)
|
||||
WHERE p.`active` = 1
|
||||
AND cg.`id_group` '.(!$id_customer ? '= 1' : 'IN (
|
||||
SELECT id_group FROM '._DB_PREFIX_.'customer_group
|
||||
WHERE id_customer = '.(int)$id_customer.')').'
|
||||
AND t.`name` LIKE \'%'.pSQL($tag).'%\'';
|
||||
return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
|
||||
}
|
||||
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT DISTINCT p.*, pl.`description_short`, pl.`link_rewrite`, pl.`name`, tax.`rate`, i.`id_image`, il.`legend`, m.`name` manufacturer_name, 1 position,
|
||||
DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0 new
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
INNER JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
|
||||
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group`
|
||||
AND tr.`id_country` = '.(int)$context->country->id.'
|
||||
AND tr.`id_state` = 0)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax` tax ON (tax.`id_tax` = tr.`id_tax`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_tag` pt ON (p.`id_product` = pt.`id_product`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tag` t ON (pt.`id_tag` = t.`id_tag` AND t.`id_lang` = '.(int)$id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_product` = p.`id_product`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = cp.`id_category`)
|
||||
WHERE p.`active` = 1
|
||||
AND cg.`id_group` '.(!$id_customer ? '= 1' : 'IN (
|
||||
SELECT id_group FROM '._DB_PREFIX_.'customer_group
|
||||
WHERE id_customer = '.(int)$id_customer.')').'
|
||||
AND t.`name` LIKE \'%'.pSQL($tag).'%\'
|
||||
ORDER BY position DESC'.($orderBy ? ', '.$orderBy : '').($orderWay ? ' '.$orderWay : '').'
|
||||
LIMIT '.(int)(($pageNumber - 1) * $pageSize).','.(int)$pageSize);
|
||||
if (!$result) return false;
|
||||
|
||||
$sql = 'SELECT DISTINCT p.*, pl.`description_short`, pl.`link_rewrite`, pl.`name`, tax.`rate`, i.`id_image`, il.`legend`, m.`name` manufacturer_name, 1 position,
|
||||
DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0 new
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
INNER JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.' AND pl.id_shop IN ('.implode(', ', $shops).'))
|
||||
INNER JOIN '._DB_PREFIX_.'product_shop ps ON p.id_product = ps.id_product AND ps.id_shop IN ('.implode(', ', $shops).')
|
||||
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
|
||||
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group`
|
||||
AND tr.`id_country` = '.(int)$context->country->id.'
|
||||
AND tr.`id_state` = 0)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax` tax ON (tax.`id_tax` = tr.`id_tax`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_tag` pt ON (p.`id_product` = pt.`id_product`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tag` t ON (pt.`id_tag` = t.`id_tag` AND t.`id_lang` = '.(int)$id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_product` = p.`id_product`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = cp.`id_category`)
|
||||
WHERE p.`active` = 1
|
||||
AND cg.`id_group` '.(!$id_customer ? '= 1' : 'IN (
|
||||
SELECT id_group FROM '._DB_PREFIX_.'customer_group
|
||||
WHERE id_customer = '.(int)$id_customer.')').'
|
||||
AND t.`name` LIKE \'%'.pSQL($tag).'%\'
|
||||
ORDER BY position DESC'.($orderBy ? ', '.$orderBy : '').($orderWay ? ' '.$orderWay : '').'
|
||||
LIMIT '.(int)(($pageNumber - 1) * $pageSize).','.(int)$pageSize;
|
||||
if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql))
|
||||
return false;
|
||||
|
||||
return Product::getProductsProperties((int)$id_lang, $result);
|
||||
}
|
||||
|
||||
+195
-138
@@ -36,16 +36,26 @@ class ShopCore extends ObjectModel
|
||||
public $active;
|
||||
public $id_category;
|
||||
public $deleted;
|
||||
|
||||
private static $current_base_uri;
|
||||
private static $current_theme_name;
|
||||
|
||||
protected $base_uri;
|
||||
protected $theme_name;
|
||||
|
||||
/**
|
||||
* @var GroupShop
|
||||
*/
|
||||
protected $group;
|
||||
|
||||
//private static $current_base_uri;
|
||||
//private static $current_theme_name;
|
||||
private static $id_current_shop;
|
||||
private static $id_current_group_shop;
|
||||
private static $id_current_root_category;
|
||||
|
||||
|
||||
protected $fieldsSize = array('name' => 64);
|
||||
protected $fieldsValidate = array('active' => 'isBool',
|
||||
'name' => 'isGenericName');
|
||||
protected $fieldsValidate = array(
|
||||
'active' => 'isBool',
|
||||
'name' => 'isGenericName',
|
||||
);
|
||||
protected $table = 'shop';
|
||||
protected $identifier = 'id_shop';
|
||||
|
||||
@@ -75,7 +85,7 @@ class ShopCore extends ObjectModel
|
||||
'store' => array('type' => 'shop'),
|
||||
'webservice_account' => array('type' => 'shop'),
|
||||
);
|
||||
|
||||
|
||||
protected $webserviceParameters = array(
|
||||
'fields' => array(
|
||||
'id_group_shop' => array('xlink_resource' => 'shop_groups'),
|
||||
@@ -83,14 +93,14 @@ class ShopCore extends ObjectModel
|
||||
'id_theme' => array(),
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* There are 3 kinds of shop context : shop, group shop and general
|
||||
*/
|
||||
const CONTEXT_SHOP = 1;
|
||||
const CONTEXT_GROUP = 2;
|
||||
const CONTEXT_ALL = 3;
|
||||
|
||||
|
||||
public function getFields()
|
||||
{
|
||||
parent::validateFields();
|
||||
@@ -103,30 +113,14 @@ class ShopCore extends ObjectModel
|
||||
$fields['deleted'] = (int)$this->deleted;
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an instance of a shop
|
||||
*
|
||||
* @param int $id shop ID
|
||||
* @return Shop
|
||||
*/
|
||||
public static function getInstance($id)
|
||||
{
|
||||
return new Shop($id);
|
||||
}
|
||||
|
||||
public static function getAssoTables()
|
||||
{
|
||||
return self::$assoTables;
|
||||
}
|
||||
|
||||
|
||||
public function add($autodate = true, $nullValues = false)
|
||||
{
|
||||
$res = parent::add();
|
||||
Shop::loadShops(true);
|
||||
Shop::cacheShops(true);
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
public function delete()
|
||||
{
|
||||
if (!$res = parent::delete())
|
||||
@@ -150,20 +144,173 @@ class ShopCore extends ObjectModel
|
||||
$res &= Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.$table_name.'` WHERE `'.$id.'`='.(int)$this->id);
|
||||
}
|
||||
|
||||
Shop::loadShops(true);
|
||||
Shop::cacheShops(true);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @return Shop
|
||||
*/
|
||||
public static function initialize()
|
||||
{
|
||||
// Get list of excluded uri
|
||||
$dirname = dirname(__FILE__);
|
||||
$directories = scandir($dirname.'/../');
|
||||
$excluded_uris = array();
|
||||
foreach ($directories AS $directory)
|
||||
if (is_dir($dirname.'/../'.$directory) AND (!preg_match ('/^\./', $directory)))
|
||||
$excluded_uris[] = $directory;
|
||||
|
||||
// Parse request_uri
|
||||
preg_match('/^'.Tools::pRegexp(_PS_DIRECTORY_, '/').'([a-z0-9]+)\/.*$/Ui', $_SERVER['REQUEST_URI'], $res);
|
||||
$uri = (isset($res[1]) AND !in_array($res[1], $excluded_uris)) ? $res[1] : '';
|
||||
|
||||
if (!$id_shop = Tools::getValue('id_shop'))
|
||||
{
|
||||
// Find current shop from URL
|
||||
$db = Db::getInstance();
|
||||
$sql = 'SELECT s.id_shop
|
||||
FROM '._DB_PREFIX_.'shop_url su
|
||||
LEFT JOIN '._DB_PREFIX_.'shop s ON (s.id_shop = su.id_shop)
|
||||
WHERE su.domain=\''.pSQL(Tools::getHttpHost()).'\'
|
||||
AND uri=\''.pSQL($uri).'\'
|
||||
AND s.active = 1
|
||||
AND s.deleted = 0';
|
||||
if (!$id_shop = $db->getValue($sql))
|
||||
$id_shop = Configuration::get('PS_SHOP_DEFAULT');
|
||||
}
|
||||
|
||||
// Get instance of found shop
|
||||
$shop = new Shop($id_shop);
|
||||
if (!Validate::isLoadedObject($shop))
|
||||
die(Tools::displayError());
|
||||
return $shop;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if shop is the same as default shop in configuration
|
||||
* Load some additional data of current shop (theme name, shop uri)
|
||||
*
|
||||
* @param int $shopID
|
||||
* @return bool
|
||||
*/
|
||||
public static function isDefaultShop($shopID)
|
||||
protected function loadShopInfos()
|
||||
{
|
||||
return ($shopID == Configuration::get('PS_SHOP_DEFAULT'));
|
||||
$sql = 'SELECT su.uri, t.name
|
||||
FROM '._DB_PREFIX_.'shop s
|
||||
LEFT JOIN '._DB_PREFIX_.'shop_url su ON (s.id_shop = su.id_shop)
|
||||
LEFT JOIN '._DB_PREFIX_.'theme t ON (t.id_theme = s.id_theme)
|
||||
WHERE s.id_shop = '.$this->id.'
|
||||
AND s.active = 1
|
||||
AND s.deleted = 0
|
||||
AND su.main = 1';
|
||||
if (!$row = Db::getInstance()->getRow($sql))
|
||||
return false;
|
||||
|
||||
$this->theme_name = $row['name'];
|
||||
$this->base_uri = $row['uri'];
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get shop theme name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTheme()
|
||||
{
|
||||
if (!$this->theme_name)
|
||||
$this->loadShopInfos();
|
||||
return $this->theme_name;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Get shop URI
|
||||
*
|
||||
* @param bool $with_base
|
||||
* @return string
|
||||
*/
|
||||
public function getBaseURI($with_base = true)
|
||||
{
|
||||
if (!$this->theme_name)
|
||||
$this->loadShopInfos();
|
||||
return ($with_base ? _PS_DIRECTORY_ : '').$this->base_uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get group of current shop
|
||||
*
|
||||
* @param bool $asObject If false, return only the ID of the group
|
||||
* @return GroupShop
|
||||
*/
|
||||
public function getGroup($asObject = false)
|
||||
{
|
||||
if (!$asObject)
|
||||
return $this->id_group_shop;
|
||||
|
||||
if (!$this->group)
|
||||
$this->group = new GroupShop($this->id_group_shop);
|
||||
return $this->group;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current shop ID.
|
||||
*
|
||||
* @param bool $forceContext If true and if no shop is selected in context, get default shop ID
|
||||
* @return int
|
||||
*/
|
||||
public static function getID($forceContext = false)
|
||||
{
|
||||
if (!$this->id && $forceContext)
|
||||
return (int)Configuration::get('PS_SHOP_DEFAULT');
|
||||
return (int)$this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get root category of current shop
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getRootCategory()
|
||||
{
|
||||
return $this->id_category;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of shop's urls
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getUrls()
|
||||
{
|
||||
$sql = 'SELECT *
|
||||
FROM '._DB_PREFIX.'shop_url
|
||||
WHERE active = 1
|
||||
AND id_shop='.(int)$this->id;
|
||||
return Db::getInstance()->ExecuteS($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if current shop ID is the same as default shop in configuration
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isDefaultShop()
|
||||
{
|
||||
return ($this->id == Configuration::get('PS_SHOP_DEFAULT'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -171,7 +318,7 @@ class ShopCore extends ObjectModel
|
||||
*
|
||||
* @param bool $refresh
|
||||
*/
|
||||
public static function loadShops($refresh = false)
|
||||
public static function cacheShops($refresh = false)
|
||||
{
|
||||
if (self::$shops && !$refresh)
|
||||
return;
|
||||
@@ -208,11 +355,14 @@ class ShopCore extends ObjectModel
|
||||
}
|
||||
}
|
||||
|
||||
public function getUrls()
|
||||
/**
|
||||
* Get list of associated tables to shop
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getAssoTables()
|
||||
{
|
||||
return Db::getInstance()->ExecuteS('SELECT *
|
||||
FROM '._DB_PREFIX.'shop_url
|
||||
WHERE active=1 AND id_shop='.(int)$this->id);
|
||||
return self::$assoTables;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -224,7 +374,7 @@ class ShopCore extends ObjectModel
|
||||
*/
|
||||
public static function getShops($active = true, $id_group_shop = null, $getAsListID = false)
|
||||
{
|
||||
Shop::loadShops();
|
||||
Shop::cacheShops();
|
||||
$results = array();
|
||||
foreach (self::$shops as $groupID => $groupData)
|
||||
foreach ($groupData['shops'] as $id => $shopData)
|
||||
@@ -246,7 +396,7 @@ class ShopCore extends ObjectModel
|
||||
*/
|
||||
public static function getIdByName($name)
|
||||
{
|
||||
Shop::loadShops();
|
||||
Shop::cacheShops();
|
||||
foreach (self::$shops as $groupData)
|
||||
foreach ($groupData['shops'] as $shopID => $shopData)
|
||||
if (Tools::strtolower($shopData['name']) == Tools::strtolower($name))
|
||||
@@ -262,99 +412,6 @@ class ShopCore extends ObjectModel
|
||||
return count(Shop::getShops($active));
|
||||
}
|
||||
|
||||
public static function setCurrentShop()
|
||||
{
|
||||
$excluded_uris = self::getExcludedUris();
|
||||
preg_match('/^'.Tools::pRegexp(_PS_DIRECTORY_, '/').'([a-z0-9]+)\/.*$/Ui', $_SERVER['REQUEST_URI'], $res);
|
||||
if (isset($res[1]) AND !in_array($res[1], $excluded_uris))
|
||||
$uri = $res[1];
|
||||
else
|
||||
$uri = '';
|
||||
|
||||
if (!$id_shop = (int)Tools::getValue('id_shop'))
|
||||
{
|
||||
$id_shop = Db::getInstance()->getValue('SELECT s.id_shop
|
||||
FROM '._DB_PREFIX_.'shop_url su
|
||||
LEFT JOIN '._DB_PREFIX_.'shop s ON (s.id_shop = su.id_shop)
|
||||
WHERE su.domain=\''.pSQL(Tools::getHttpHost()).'\' AND uri=\''.pSQL($uri).'\' AND s.active=1 AND s.deleted=0');
|
||||
if (!$id_shop)
|
||||
$id_shop = Configuration::get('PS_SHOP_DEFAULT');
|
||||
}
|
||||
|
||||
$res = Db::getInstance()->getRow('SELECT s.id_shop, s.id_group_shop, s.id_category, su.uri, t.name
|
||||
FROM '._DB_PREFIX_.'shop s
|
||||
LEFT JOIN '._DB_PREFIX_.'shop_url su ON (s.id_shop = su.id_shop)
|
||||
LEFT JOIN '._DB_PREFIX_.'theme t ON (t.id_theme = s.id_theme)
|
||||
WHERE s.id_shop='.(int)$id_shop.' AND s.active=1 AND s.deleted=0 AND su.main=1');
|
||||
|
||||
$id_shop = (int)$res['id_shop'];
|
||||
$id_group_shop = (int)$res['id_group_shop'];
|
||||
self::$id_current_shop = (int)$id_shop;
|
||||
self::$id_current_group_shop = (int)$id_group_shop;
|
||||
self::$id_current_root_category = (int)$res['id_category'];
|
||||
self::$current_base_uri = (!empty($res['uri']) ? $res['uri'].'/' : '' );
|
||||
self::$current_theme_name = $res['name'];
|
||||
}
|
||||
|
||||
public static function getExcludedUris()
|
||||
{
|
||||
$dirname = dirname(__FILE__);
|
||||
$directories = scandir($dirname.'/../');
|
||||
$not_uri = array();
|
||||
foreach ($directories AS $directory)
|
||||
if (is_dir($dirname.'/../'.$directory) AND (!preg_match ('/^\./', $directory)))
|
||||
$not_uri[] = $directory;
|
||||
return $not_uri;
|
||||
}
|
||||
|
||||
public static function getCurrentTheme()
|
||||
{
|
||||
return self::$current_theme_name;
|
||||
}
|
||||
|
||||
public static function getCurrentBaseURI($with_base = true)
|
||||
{
|
||||
return ($with_base ? _PS_DIRECTORY_ : '').self::$current_base_uri;
|
||||
}
|
||||
|
||||
public static function getCurrentGroupShop()
|
||||
{
|
||||
return Shop::retrieveContext('group');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current shop ID.
|
||||
*
|
||||
* @param bool $forceContext If true and if no shop is selected in context, get default shop ID
|
||||
* @return int
|
||||
*/
|
||||
public static function getCurrentShop($forceContext = false)
|
||||
{
|
||||
$shopID = Shop::retrieveContext('shop');
|
||||
if (!$shopID && $forceContext)
|
||||
$shopID = (int)Configuration::get('PS_SHOP_DEFAULT');
|
||||
return $shopID;
|
||||
}
|
||||
|
||||
public function getTheme($entity = false, $id = false)
|
||||
{
|
||||
return Db::getInstance()->getValue('SELECT t.name
|
||||
FROM '._DB_PREFIX_.'shop s
|
||||
LEFT JOIN '._DB_PREFIX_.'theme t ON (s.id_theme = t.id_theme)
|
||||
WHERE id_shop='.(int)$this->id);
|
||||
|
||||
}
|
||||
|
||||
public static function getCurrentRootCategory()
|
||||
{
|
||||
return self::$id_current_root_category;
|
||||
}
|
||||
|
||||
public function getRootCategory()
|
||||
{
|
||||
return $this->id_category;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve group ID of a shop
|
||||
*
|
||||
@@ -363,7 +420,7 @@ class ShopCore extends ObjectModel
|
||||
*/
|
||||
public static function getGroupFromShop($shopID, $asID = true)
|
||||
{
|
||||
Shop::loadShops();
|
||||
Shop::cacheShops();
|
||||
foreach (self::$shops as $groupID => $groupData)
|
||||
if (array_key_exists($shopID, $groupData['shops']))
|
||||
return ($asID) ? $groupID : $groupData;
|
||||
@@ -371,14 +428,14 @@ class ShopCore extends ObjectModel
|
||||
}
|
||||
|
||||
/**
|
||||
* If the shop group has a the option "share_datas" activated, get all shops ID of this group, else get current shop ID
|
||||
* If the shop group has the option "share_datas" activated, get all shops ID of this group, else get current shop ID
|
||||
*
|
||||
* @param int $shopID
|
||||
* @return array
|
||||
*/
|
||||
public static function getSharedShops($shopID)
|
||||
{
|
||||
Shop::loadShops();
|
||||
Shop::cacheShops();
|
||||
foreach (self::$shops as $groupData)
|
||||
if (array_key_exists($shopID, $groupData['shops']) && $groupData['share_datas'])
|
||||
return array_keys($groupData['shops']);
|
||||
@@ -519,7 +576,7 @@ class ShopCore extends ObjectModel
|
||||
if (!$shopID)
|
||||
return ($shopGroupID) ? ' AND '.$alias.'id_group_shop = '.(int)$shopGroupID : '';
|
||||
|
||||
Shop::loadShops();
|
||||
Shop::cacheShops();
|
||||
foreach (self::$shops as $groupID => $groupData)
|
||||
if (array_key_exists($shopID, $groupData['shops']) && $groupData['share_stock'])
|
||||
return ' AND '.$alias.'id_group_shop = '.$groupID;
|
||||
@@ -533,7 +590,7 @@ class ShopCore extends ObjectModel
|
||||
*/
|
||||
public static function getTree()
|
||||
{
|
||||
Shop::loadShops();
|
||||
Shop::cacheShops();
|
||||
return self::$shops;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user