// Context

This commit is contained in:
rMalie committed 2011-07-12 13:50:15 +00:00
1 parent 89920e17fd
commit 286a374353
20 files changed
+319 -264

No files matched your search

+6 -12
View File
@@ -50,7 +50,7 @@ class AdminCatalog extends AdminTab
{ {
/* Get current category */ /* Get current category */
$id_category = abs(Tools::getValue('id_category')); $id_category = abs(Tools::getValue('id_category'));
$shop = new Shop(Shop::getCurrentShop(true)); $shop = Context::getContext()->shop;
if (!$id_category) if (!$id_category)
$id_category = $shop->id_category; $id_category = $shop->id_category;
else if ($id_category != $shop->id_category) else if ($id_category != $shop->id_category)
@@ -58,18 +58,18 @@ class AdminCatalog extends AdminTab
// Check if current category is "inside" shop default category // Check if current category is "inside" shop default category
$sql = 'SELECT nleft, nright FROM '._DB_PREFIX_.'category $sql = 'SELECT nleft, nright FROM '._DB_PREFIX_.'category
WHERE id_category = '.$shop->id_category; WHERE id_category = '.$shop->id_category;
if ($result = Db::getInstance()->getRow($sql)) if ($interval = Category::getInterval($shop->id_category))
{ {
$sql = 'SELECT id_category FROM '._DB_PREFIX_.'category $sql = 'SELECT id_category FROM '._DB_PREFIX_.'category
WHERE id_category = '.(int)$id_category.' WHERE id_category = '.(int)$id_category.'
AND nleft >= '.$result['nleft'].' AND nleft >= '.$interval['nleft'].'
AND nright <= '.$result['nright']; AND nright <= '.$interval['nright'];
if (!Db::getInstance()->getValue($sql)) if (!Db::getInstance()->getValue($sql))
$id_category = $shop->id_category; $id_category = $shop->id_category;
} }
} }
self::$_category = new Category($id_category, NULL, Shop::getCurrentShop(true)); self::$_category = new Category($id_category);
if (!Validate::isLoadedObject(self::$_category)) if (!Validate::isLoadedObject(self::$_category))
die('Category cannot be loaded'); die('Category cannot be loaded');
@@ -176,13 +176,7 @@ class AdminCatalog extends AdminTab
if (!$id_category) if (!$id_category)
{ {
$home = true; $home = true;
if (Shop::getContextType() == Shop::CONTEXT_SHOP) $id_category = Context::getContext()->shop->id_category1;
{
$shop = new Shop((int)Shop::getCurrentShop());
$id_category = $shop->id_category;
}
else
$id_category = 1;
} }
$catalog_tabs = array('category', 'product'); $catalog_tabs = array('category', 'product');
// Cleaning links // Cleaning links
+15 -19
View File
@@ -34,8 +34,6 @@ class AdminCategories extends AdminTab
public function __construct() public function __construct()
{ {
global $cookie;
$this->table = 'category'; $this->table = 'category';
$this->className = 'Category'; $this->className = 'Category';
$this->lang = true; $this->lang = true;
@@ -61,8 +59,6 @@ class AdminCategories extends AdminTab
public function displayList($token = NULL) public function displayList($token = NULL)
{ {
global $currentIndex;
/* Display list header (filtering, pagination and column names) */ /* Display list header (filtering, pagination and column names) */
$this->displayListHeader($token); $this->displayListHeader($token);
if (!sizeof($this->_list)) if (!sizeof($this->_list))
@@ -77,8 +73,9 @@ class AdminCategories extends AdminTab
public function display($token = NULL) public function display($token = NULL)
{ {
global $currentIndex, $cookie; $context = Context::getContext();
$this->getList((int)($cookie->id_lang), !$cookie->__get($this->table.'Orderby') ? 'position' : NULL, !$cookie->__get($this->table.'Orderway') ? 'ASC' : NULL, 0, NULL, (int)Shop::getCurrentShop(true));
$this->getList((int)($context->language->id), !$context->cookie->__get($this->table.'Orderby') ? 'position' : NULL, !$context->cookie->__get($this->table.'Orderway') ? 'ASC' : NULL, 0, NULL, $context->shop->getID());
echo '<h3>'.(!$this->_listTotal ? ($this->l('There are no subcategories')) : ($this->_listTotal.' '.($this->_listTotal > 1 ? $this->l('subcategories') : $this->l('subcategory')))).' '.$this->l('in category').' "'.stripslashes($this->_category->getName()).'"</h3>'; echo '<h3>'.(!$this->_listTotal ? ($this->l('There are no subcategories')) : ($this->_listTotal.' '.($this->_listTotal > 1 ? $this->l('subcategories') : $this->l('subcategory')))).' '.$this->l('in category').' "'.stripslashes($this->_category->getName()).'"</h3>';
if ($this->tabAccess['add'] === '1') if ($this->tabAccess['add'] === '1')
echo '<a href="'.__PS_BASE_URI__.substr($_SERVER['PHP_SELF'], strlen(__PS_BASE_URI__)).'?tab=AdminCatalog&add'.$this->table.'&id_parent='.$this->_category->id.'&token='.($token!=NULL ? $token : $this->token).'"><img src="../img/admin/add.gif" border="0" /> '.$this->l('Add a new subcategory').'</a>'; echo '<a href="'.__PS_BASE_URI__.substr($_SERVER['PHP_SELF'], strlen(__PS_BASE_URI__)).'?tab=AdminCatalog&add'.$this->table.'&id_parent='.$this->_category->id.'&token='.($token!=NULL ? $token : $this->token).'"><img src="../img/admin/add.gif" border="0" /> '.$this->l('Add a new subcategory').'</a>';
@@ -89,9 +86,8 @@ class AdminCategories extends AdminTab
public function postProcess($token = NULL) public function postProcess($token = NULL)
{ {
global $cookie, $currentIndex; $context = Context::getContext();
$this->tabAccess = Profile::getProfileAccess($context->employee->id_profile, $this->id);
$this->tabAccess = Profile::getProfileAccess($cookie->profile, $this->id);
if (Tools::isSubmit('submitAdd'.$this->table)) if (Tools::isSubmit('submitAdd'.$this->table))
{ {
@@ -123,7 +119,7 @@ class AdminCategories extends AdminTab
$target = '&id_category='.(int)($matches[1]); $target = '&id_category='.(int)($matches[1]);
} }
Module::hookExec('categoryUpdate'); Module::hookExec('categoryUpdate');
Tools::redirectAdmin($currentIndex.'&conf=5'.$target.'&token='.Tools::getValue('token')); Tools::redirectAdmin($this->currentIndex.'&conf=5'.$target.'&token='.Tools::getValue('token'));
} }
else else
$this->_errors[] = Tools::displayError('An error occurred while updating status.'); $this->_errors[] = Tools::displayError('An error occurred while updating status.');
@@ -151,10 +147,10 @@ class AdminCategories extends AdminTab
$object->deleteImage(); $object->deleteImage();
$object->deleted = 1; $object->deleted = 1;
if ($object->update()) if ($object->update())
Tools::redirectAdmin($currentIndex.'&conf=1&token='.Tools::getValue('token').'&id_category='.(int)($object->id_parent)); Tools::redirectAdmin($this->currentIndex.'&conf=1&token='.Tools::getValue('token').'&id_category='.(int)($object->id_parent));
} }
elseif ($object->delete()) elseif ($object->delete())
Tools::redirectAdmin($currentIndex.'&conf=1&token='.Tools::getValue('token').'&id_category='.(int)($object->id_parent)); Tools::redirectAdmin($this->currentIndex.'&conf=1&token='.Tools::getValue('token').'&id_category='.(int)($object->id_parent));
$this->_errors[] = Tools::displayError('An error occurred during deletion.'); $this->_errors[] = Tools::displayError('An error occurred during deletion.');
} }
} }
@@ -173,7 +169,7 @@ class AdminCategories extends AdminTab
if (!$object->updatePosition((int)(Tools::getValue('way')), (int)(Tools::getValue('position')))) if (!$object->updatePosition((int)(Tools::getValue('way')), (int)(Tools::getValue('position'))))
$this->_errors[] = Tools::displayError('Failed to update the position.'); $this->_errors[] = Tools::displayError('Failed to update the position.');
else else
Tools::redirectAdmin($currentIndex.'&'.$this->table.'Orderby=position&'.$this->table.'Orderway=asc&conf=5'.(($id_category = (int)(Tools::getValue($this->identifier, Tools::getValue('id_category_parent', 1)))) ? ('&'.$this->identifier.'='.$id_category) : '').'&token='.Tools::getAdminTokenLite('AdminCatalog')); Tools::redirectAdmin($this->currentIndex.'&'.$this->table.'Orderby=position&'.$this->table.'Orderway=asc&conf=5'.(($id_category = (int)(Tools::getValue($this->identifier, Tools::getValue('id_category_parent', 1)))) ? ('&'.$this->identifier.'='.$id_category) : '').'&token='.Tools::getAdminTokenLite('AdminCatalog'));
} }
/* Delete multiple objects */ /* Delete multiple objects */
elseif (Tools::getValue('submitDel'.$this->table)) elseif (Tools::getValue('submitDel'.$this->table))
@@ -188,7 +184,7 @@ class AdminCategories extends AdminTab
if ($result) if ($result)
{ {
$category->cleanPositions((int)(Tools::getValue('id_category'))); $category->cleanPositions((int)(Tools::getValue('id_category')));
Tools::redirectAdmin($currentIndex.'&conf=2&token='.Tools::getAdminTokenLite('AdminCatalog').'&id_category='.(int)(Tools::getValue('id_category'))); Tools::redirectAdmin($this->currentIndex.'&conf=2&token='.Tools::getAdminTokenLite('AdminCatalog').'&id_category='.(int)(Tools::getValue('id_category')));
} }
$this->_errors[] = Tools::displayError('An error occurred while deleting selection.'); $this->_errors[] = Tools::displayError('An error occurred while deleting selection.');
@@ -217,9 +213,9 @@ class AdminCategories extends AdminTab
public function displayForm($token = NULL) public function displayForm($token = NULL)
{ {
global $currentIndex, $cookie;
parent::displayForm(); parent::displayForm();
$context = Context::getContext();
if (!($obj = $this->loadObject(true))) if (!($obj = $this->loadObject(true)))
return; return;
$active = $this->getFieldValue($obj, 'active'); $active = $this->getFieldValue($obj, 'active');
@@ -233,7 +229,7 @@ class AdminCategories extends AdminTab
$id_category = (int)Tools::getValue('id_parent'); $id_category = (int)Tools::getValue('id_parent');
echo ' echo '
<form action="'.$currentIndex.'&submitAdd'.$this->table.'=1&token='.($token!=NULL ? $token : $this->token).'" method="post" enctype="multipart/form-data"> <form action="'.$this->currentIndex.'&submitAdd'.$this->table.'=1&token='.($token!=NULL ? $token : $this->token).'" method="post" enctype="multipart/form-data">
'.($obj->id ? '<input type="hidden" name="id_'.$this->table.'" value="'.$obj->id.'" />' : '').' '.($obj->id ? '<input type="hidden" name="id_'.$this->table.'" value="'.$obj->id.'" />' : '').'
<fieldset><legend><img src="../img/admin/tab-categories.gif" />'.$this->l('Category').'</legend> <fieldset><legend><img src="../img/admin/tab-categories.gif" />'.$this->l('Category').'</legend>
<label>'.$this->l('Name:').' </label> <label>'.$this->l('Name:').' </label>
@@ -256,7 +252,7 @@ class AdminCategories extends AdminTab
<label>'.$this->l('Parent category:').' </label> <label>'.$this->l('Parent category:').' </label>
<div class="margin-form"> <div class="margin-form">
<select name="id_parent">'; <select name="id_parent">';
$categories = Category::getCategories((int)$cookie->id_lang, false); $categories = Category::getCategories((int)$context->language->id, false);
Category::recurseCategory($categories, $categories[0][1], 1, ($obj->id ? $this->getFieldValue($obj, 'id_parent') : $id_category)); Category::recurseCategory($categories, $categories[0][1], 1, ($obj->id ? $this->getFieldValue($obj, 'id_parent') : $id_category));
echo ' echo '
</select> </select>
@@ -272,7 +268,7 @@ class AdminCategories extends AdminTab
</div> </div>
<label>'.$this->l('Image:').' </label> <label>'.$this->l('Image:').' </label>
<div class="margin-form">'; <div class="margin-form">';
echo $this->displayImage($obj->id, _PS_IMG_DIR_.'c/'.$obj->id.'.jpg', 350, NULL, Tools::getAdminToken('AdminCatalog'.(int)(Tab::getIdFromClassName('AdminCatalog')).(int)($cookie->id_employee)), true); echo $this->displayImage($obj->id, _PS_IMG_DIR_.'c/'.$obj->id.'.jpg', 350, NULL, Tools::getAdminToken('AdminCatalog'.(int)(Tab::getIdFromClassName('AdminCatalog')).$context->employee->id), true);
echo ' <br /><input type="file" name="image" /> echo ' <br /><input type="file" name="image" />
<p>'.$this->l('Upload category logo from your computer').'</p> <p>'.$this->l('Upload category logo from your computer').'</p>
</div> </div>
@@ -317,7 +313,7 @@ class AdminCategories extends AdminTab
</div> </div>
<label>'.$this->l('Groups access:').' </label> <label>'.$this->l('Groups access:').' </label>
<div class="margin-form">'; <div class="margin-form">';
$groups = Group::getGroups((int)($cookie->id_lang)); $groups = Group::getGroups((int)($context->language->id));
if (sizeof($groups)) if (sizeof($groups))
{ {
echo ' echo '
+1 -1
View File
@@ -188,7 +188,7 @@ class AdminMeta extends AdminTab
public function getList($id_lang, $orderBy = NULL, $orderWay = NULL, $start = 0, $limit = NULL, $id_lang_shop = false) 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, Shop::getCurrentShop(true)); parent::getList($id_lang, $orderBy, $orderWay, $start, $limit, Context::getContext()->shop->getID());
} }
} }
+1 -1
View File
@@ -262,7 +262,7 @@ class AdminModulesPositions extends AdminTab
else else
echo '<p>'.$this->l('By clicking here you will be redirected to the front office of your shop to move and delete modules directly.').'</p> echo '<p>'.$this->l('By clicking here you will be redirected to the front office of your shop to move and delete modules directly.').'</p>
<br> <br>
<a href="'.$link->getPageLink('index').'&live_edit&ad='.$admin_dir.'&liveToken='.sha1($admin_dir._COOKIE_KEY_).((Tools::isMultiShopActivated()) ? '&id_shop='.Shop::getCurrentShop() : '').'" target="_blank" class="button">'.$this->l('Run LiveEdit').'</a>'; <a href="'.$link->getPageLink('index').'&live_edit&ad='.$admin_dir.'&liveToken='.sha1($admin_dir._COOKIE_KEY_).((Tools::isMultiShopActivated()) ? '&id_shop='.Context::getContext()->shop->getID() : '').'" target="_blank" class="button">'.$this->l('Run LiveEdit').'</a>';
echo '</fieldset>'; echo '</fieldset>';
// Print hook list // Print hook list
+9 -8
View File
@@ -31,9 +31,9 @@ class AdminPayment extends AdminTab
public function __construct() public function __construct()
{ {
global $cookie; $shopID = Context::getContext()->shop->getID();
/* Get all modules then select only payment ones*/
/* Get all modules then select only payment ones*/
$modules = Module::getModulesOnDisk(); $modules = Module::getModulesOnDisk();
foreach ($modules AS $module) foreach ($modules AS $module)
@@ -43,19 +43,19 @@ class AdminPayment extends AdminTab
{ {
if(!get_class($module) == 'SimpleXMLElement') if(!get_class($module) == 'SimpleXMLElement')
$module->country = array(); $module->country = array();
$countries = DB::getInstance()->ExecuteS('SELECT id_country FROM '._DB_PREFIX_.'module_country WHERE id_module = '.(int)$module->id.' AND `id_shop`='.Shop::getCurrentShop(true)); $countries = DB::getInstance()->ExecuteS('SELECT id_country FROM '._DB_PREFIX_.'module_country WHERE id_module = '.(int)$module->id.' AND `id_shop`='.$shopID);
foreach ($countries as $country) foreach ($countries as $country)
$module->country[] = $country['id_country']; $module->country[] = $country['id_country'];
if(!get_class($module) == 'SimpleXMLElement') if(!get_class($module) == 'SimpleXMLElement')
$module->currency = array(); $module->currency = array();
$currencies = DB::getInstance()->ExecuteS('SELECT id_currency FROM '._DB_PREFIX_.'module_currency WHERE id_module = '.(int)$module->id.' AND `id_shop`='.Shop::getCurrentShop(true)); $currencies = DB::getInstance()->ExecuteS('SELECT id_currency FROM '._DB_PREFIX_.'module_currency WHERE id_module = '.(int)$module->id.' AND `id_shop`='.$shopID);
foreach ($currencies as $currency) foreach ($currencies as $currency)
$module->currency[] = $currency['id_currency']; $module->currency[] = $currency['id_currency'];
if(!get_class($module) == 'SimpleXMLElement') if(!get_class($module) == 'SimpleXMLElement')
$module->group = array(); $module->group = array();
$groups = DB::getInstance()->ExecuteS('SELECT id_group FROM '._DB_PREFIX_.'module_group WHERE id_module = '.(int)$module->id.' AND `id_shop`='.Shop::getCurrentShop(true)); $groups = DB::getInstance()->ExecuteS('SELECT id_group FROM '._DB_PREFIX_.'module_group WHERE id_module = '.(int)$module->id.' AND `id_shop`='.$shopID);
foreach ($groups as $group) foreach ($groups as $group)
$module->group[] = $group['id_group']; $module->group[] = $group['id_group'];
} }
@@ -84,12 +84,13 @@ class AdminPayment extends AdminTab
private function saveRestrictions($type) private function saveRestrictions($type)
{ {
global $currentIndex, $cookie; global $currentIndex;
Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'module_'.$type.' WHERE id_shop='.Shop::getCurrentShop(true));
Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'module_'.$type.' WHERE id_shop='.Context::getContext()->shop->getID());
foreach ($this->paymentModules as $module) foreach ($this->paymentModules as $module)
if ($module->active AND isset($_POST[$module->name.'_'.$type.''])) if ($module->active AND isset($_POST[$module->name.'_'.$type.'']))
foreach ($_POST[$module->name.'_'.$type.''] as $selected) foreach ($_POST[$module->name.'_'.$type.''] as $selected)
$values[] = '('.(int)$module->id.', '.Shop::getCurrentShop(true).', '.(int)$selected.')'; $values[] = '('.(int)$module->id.', '.Context::getContext()->shop->getID().', '.(int)$selected.')';
if (sizeof($values)) if (sizeof($values))
Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'module_'.$type.' (`id_module`, `id_shop`, `id_'.$type.'`) VALUES '.implode(',', $values)); Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'module_'.$type.' (`id_module`, `id_shop`, `id_'.$type.'`) VALUES '.implode(',', $values));
Tools::redirectAdmin($currentIndex.'&conf=4'.'&token='.$this->token); Tools::redirectAdmin($currentIndex.'&conf=4'.'&token='.$this->token);
+2 -2
View File
@@ -222,7 +222,7 @@ class AdminPreferences extends AdminTab
{ {
if (Tools::isSubmit('submitAppearanceconfiguration')) if (Tools::isSubmit('submitAppearanceconfiguration'))
{ {
$id_shop = Shop::getCurrentShop(true); $id_shop = Context::getContext()->shop->getID();
if (isset($_FILES['PS_LOGO']['tmp_name']) AND $_FILES['PS_LOGO']['tmp_name']) if (isset($_FILES['PS_LOGO']['tmp_name']) AND $_FILES['PS_LOGO']['tmp_name'])
{ {
if ($error = checkImage($_FILES['PS_LOGO'], 300000)) if ($error = checkImage($_FILES['PS_LOGO'], 300000))
@@ -242,7 +242,7 @@ class AdminPreferences extends AdminTab
$this->_errors[] = $error; $this->_errors[] = $error;
if (!$tmpName == tempnam(_PS_TMP_IMG_DIR_, 'PS_MAIL') OR !move_uploaded_file($_FILES['PS_LOGO_MAIL']['tmp_name'], $tmpName)) if (!$tmpName == tempnam(_PS_TMP_IMG_DIR_, 'PS_MAIL') OR !move_uploaded_file($_FILES['PS_LOGO_MAIL']['tmp_name'], $tmpName))
return false; return false;
if ($id_shop = Configuration::get('PS_SHOP_DEFAULT') && !@imageResize($tmpName, _PS_IMG_DIR_.'logo_mail.jpg')) if ($id_shop == Configuration::get('PS_SHOP_DEFAULT') && !@imageResize($tmpName, _PS_IMG_DIR_.'logo_mail.jpg'))
$this->_errors[] = 'an error occurred during logo copy'; $this->_errors[] = 'an error occurred during logo copy';
if (!@imageResize($tmpName, _PS_IMG_DIR_.'logo_mail-'.(int)$id_shop.'.jpg')) if (!@imageResize($tmpName, _PS_IMG_DIR_.'logo_mail-'.(int)$id_shop.'.jpg'))
$this->_errors[] = 'an error occurred during logo copy'; $this->_errors[] = 'an error occurred during logo copy';
+1 -1
View File
@@ -95,7 +95,7 @@ class AdminThemes extends AdminPreferences
{ {
$this->className = 'Configuration'; $this->className = 'Configuration';
$this->table = 'configuration'; $this->table = 'configuration';
$id_shop = (int)Shop::getCurrentShop(true); $id_shop = Context::getContext()->shop->getID();
$this->_fieldsAppearance = array( $this->_fieldsAppearance = array(
'PS_LOGO' => array('title' => $this->l('Header logo:'), 'desc' => $this->l('Will appear on main page'), 'type' => 'file', 'thumb' => array('file' => _PS_IMG_.'logo-'.(int)$id_shop.'.jpg?date='.time(), 'pos' => 'before')), 'PS_LOGO' => array('title' => $this->l('Header logo:'), 'desc' => $this->l('Will appear on main page'), 'type' => 'file', 'thumb' => array('file' => _PS_IMG_.'logo-'.(int)$id_shop.'.jpg?date='.time(), 'pos' => 'before')),
'PS_LOGO_MAIL' => array('title' => $this->l('Mail logo:'), 'desc' => $this->l('Will appear on e-mail headers, if undefined the Header logo will be used'), 'type' => 'file', 'thumb' => array('file' => ((file_exists(_PS_IMG_DIR_.'logo_mail-'.(int)$id_shop.'.jpg')) ? _PS_IMG_.'logo_mail-'.(int)$id_shop.'.jpg?date='.time() : _PS_IMG_.'logo-'.(int)$id_shop.'.jpg?date='.time()), 'pos' => 'before')), 'PS_LOGO_MAIL' => array('title' => $this->l('Mail logo:'), 'desc' => $this->l('Will appear on e-mail headers, if undefined the Header logo will be used'), 'type' => 'file', 'thumb' => array('file' => ((file_exists(_PS_IMG_DIR_.'logo_mail-'.(int)$id_shop.'.jpg')) ? _PS_IMG_.'logo_mail-'.(int)$id_shop.'.jpg?date='.time() : _PS_IMG_.'logo-'.(int)$id_shop.'.jpg?date='.time()), 'pos' => 'before')),
+17 -17
View File
@@ -1127,22 +1127,22 @@ abstract class AdminTabCore
*/ */
public function getList($id_lang, $orderBy = NULL, $orderWay = NULL, $start = 0, $limit = NULL, $id_lang_shop = false) 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 */ /* Manage default params values */
if (empty($limit)) 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)) if (!Validate::isTableOrIdentifier($this->table))
die (Tools::displayError('Table name is invalid:').' "'.$this->table.'"'); die (Tools::displayError('Table name is invalid:').' "'.$this->table.'"');
if (empty($orderBy)) 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)) 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)); $limit = (int)(Tools::getValue('pagination', $limit));
$cookie->{$this->table.'_pagination'} = $limit; $context->cookie->{$this->table.'_pagination'} = $limit;
/* Check params validity */ /* Check params validity */
if (!Validate::isOrderBy($orderBy) OR !Validate::isOrderWay($orderWay) 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); $whereShop = Shop::sqlRestriction($this->shopShareDatas, 'a', null, null, $this->shopLinkType);
} }
$filterShop = ''; $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(); $assos = Shop::getAssoTables();
if (isset($assos[$this->table]) AND $assos[$this->table]['type'] == 'shop') if (isset($assos[$this->table]) AND $assos[$this->table]['type'] == 'shop')
$filterKey = $assos[$this->table]['type']; $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(); $assos = GroupShop::getAssoTables();
if (isset($assos[$this->table]) AND $assos[$this->table]['type'] == 'group_shop') if (isset($assos[$this->table]) AND $assos[$this->table]['type'] == 'group_shop')
$filterKey = $assos[$this->table]['type']; $filterKey = $assos[$this->table]['type'];
$idenfierShop = Shop::getCurrentGroupShop(); $idenfierShop = $context->shop->getGroup();
} }
if (isset($filterKey)) if (isset($filterKey))
$filterShop = 'JOIN `'._DB_PREFIX_.$this->table.'_'.$filterKey.'` sa ON (sa.'.$this->identifier.' = a.'.$this->identifier.' AND sa.id_'.$filterKey.'='.(int)$idenfierShop.')'; $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) * @param integer $id_lang Language id (optional)
* @return string * @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()) if (!$id_shop AND $obj->isLangMultishop())
$id_shop = Shop::getCurrentShop(true); $id_shop = $context->shop->getID();
if ($id_lang) if ($id_lang)
$defaultValue = ($obj->id AND isset($obj->{$key}[$id_lang])) ? $obj->{$key}[$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()) if (!Tools::isMultiShopActivated())
return; return;
if (!$id_shop = Shop::getCurrentShop())
$id_shop = Configuration::get('PS_SHOP_DEFAULT'); return $this->l('This field will be changed for the shop:').' '.Context::getContext()->shop->name;
$shop = new Shop((int)$id_shop);
return $this->l('This field will be changed for the shop:').' '.$shop->name;
} }
protected function displayAssoGroupShop($field_name = 'name') protected function displayAssoGroupShop($field_name = 'name')
+1 -1
View File
@@ -276,7 +276,7 @@ class CustomerCore extends ObjectModel
$sql = 'SELECT `id_customer` $sql = 'SELECT `id_customer`
FROM `'._DB_PREFIX_.'customer` FROM `'._DB_PREFIX_.'customer`
WHERE `email` = \''.pSQL($email).'\' WHERE `email` = \''.pSQL($email).'\'
'.Shop::sqlRestriction(true, null, $id_shop, $id_group_shop). '.Shop::sqlRestriction(true).
($ignoreGuest ? 'AND `is_guest` = 0' : ''); ($ignoreGuest ? 'AND `is_guest` = 0' : '');
$result = Db::getInstance()->getRow($sql); $result = Db::getInstance()->getRow($sql);
+2 -2
View File
@@ -118,7 +118,7 @@ abstract class ObjectModelCore
die(Tools::displayError()); die(Tools::displayError());
if ($this->langMultiShop AND $id_shop == NULL) 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) if ($id_shop AND $this->langMultiShop)
$this->id_shop = $id_shop; $this->id_shop = $id_shop;
/* Connect to database and check SQL table/identifier */ /* 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.')'; $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; $class_name = WebserviceRequest::$ws_current_classname;
$vars = get_class_vars($classname); $vars = get_class_vars($class_name);
foreach ($vars['shopIDs'] as $id_shop) foreach ($vars['shopIDs'] as $id_shop)
$OR[] = ' multi_shop_'.$this->table.'.id_shop = '.$id_shop.' '; $OR[] = ' multi_shop_'.$this->table.'.id_shop = '.$id_shop.' ';
$multi_shop_filter = ' AND ('.implode('OR', $OR).') '; $multi_shop_filter = ' AND ('.implode('OR', $OR).') ';
+4 -3
View File
@@ -108,13 +108,14 @@ class PageCore extends ObjectModel
public static function setPageViewed($id_page) public static function setPageViewed($id_page)
{ {
$id_date_range = DateRange::getCurrentRange(); $id_date_range = DateRange::getCurrentRange();
$context = Context::getContext();
// Try to increment the visits counter // Try to increment the visits counter
$sql = 'UPDATE `'._DB_PREFIX_.'page_viewed` $sql = 'UPDATE `'._DB_PREFIX_.'page_viewed`
SET `counter` = `counter` + 1 SET `counter` = `counter` + 1
WHERE `id_date_range` = '.(int)$id_date_range.' WHERE `id_date_range` = '.(int)$id_date_range.'
AND `id_page` = '.(int)$id_page.' AND `id_page` = '.(int)$id_page.'
AND `id_shop` = ' . Shop::getCurrentShop(); AND `id_shop` = ' . $context->shop->getID();
Db::getInstance()->Execute($sql); Db::getInstance()->Execute($sql);
// If no one has seen the page in this date range, it is added // 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_date_range' => (int)$id_date_range,
'id_page' => (int)$id_page, 'id_page' => (int)$id_page,
'counter' => 1, 'counter' => 1,
'id_shop' => Shop::getCurrentShop(), 'id_shop' => $context->shop->getID(),
'id_group_shop' => Shop::getCurrentGroupShop(), 'id_group_shop' => $context->shop->getGroup(),
), 'INSERT'); ), 'INSERT');
} }
} }
+1 -1
View File
@@ -2089,7 +2089,7 @@ class ProductCore extends ObjectModel
// For retrocompatibility // For retrocompatibility
$id_product_attribute = (int)$id_product_attribute; $id_product_attribute = (int)$id_product_attribute;
$quantity = (int)$quantity; $quantity = (int)$quantity;
if (Shop::isDefaultShop($shop)) if (Shop::getInstance($shop)->isDefaultShop())
{ {
if ($id_product_attribute) if ($id_product_attribute)
{ {
-1
View File
@@ -71,7 +71,6 @@ class ReferrerCore extends ObjectModel
{ {
parent::validateFields(); parent::validateFields();
$fields['id_shop'] = (!$this->id_shop) ? Shop::getCurrentShop(true) : (int)$this->id_shop;
$fields['name'] = pSQL($this->name); $fields['name'] = pSQL($this->name);
$fields['passwd'] = pSQL($this->passwd); $fields['passwd'] = pSQL($this->passwd);
$fields['http_referer_regexp'] = pSQL($this->http_referer_regexp, true); $fields['http_referer_regexp'] = pSQL($this->http_referer_regexp, true);
+47 -41
View File
@@ -405,8 +405,8 @@ class SearchCore
// Every indexed words are cached into a PHP array // Every indexed words are cached into a PHP array
$wordIdsByWord = array(); $wordIdsByWord = array();
$wordIds = Db::getInstance()->ExecuteS(' $wordIds = Db::getInstance()->ExecuteS('
SELECT sw.id_word, sw.word, id_lang, id_shop SELECT id_word, word, id_lang, id_shop
FROM '._DB_PREFIX_.'search_word sw', false); FROM '._DB_PREFIX_.'search_word', false);
$wordIdsByWord = array(); $wordIdsByWord = array();
while ($wordId = $db->nextRow($wordIds)) while ($wordId = $db->nextRow($wordIds))
{ {
@@ -533,10 +533,15 @@ class SearchCore
$queryArray3 = array(); $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) if (!$context)
$context = Context::getContext(); $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 // Only use cookie if id_customer is not present
if ($useCookie) if ($useCookie)
$id_customer = (int)$context->customer->id; $id_customer = (int)$context->customer->id;
@@ -552,45 +557,46 @@ class SearchCore
if ($count) if ($count)
{ {
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' $sql = 'SELECT COUNT(DISTINCT pt.`id_product`) nb
SELECT COUNT(DISTINCT pt.`id_product`) nb FROM `'._DB_PREFIX_.'product` p
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_.'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_.'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_product` cp ON (cp.`id_product` = p.`id_product`)
LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = cp.`id_category`) LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = cp.`id_category`)
WHERE p.`active` = 1 WHERE p.`active` = 1
AND cg.`id_group` '.(!$id_customer ? '= 1' : 'IN ( AND cg.`id_group` '.(!$id_customer ? '= 1' : 'IN (
SELECT id_group FROM '._DB_PREFIX_.'customer_group SELECT id_group FROM '._DB_PREFIX_.'customer_group
WHERE id_customer = '.(int)$id_customer.')').' WHERE id_customer = '.(int)$id_customer.')').'
AND t.`name` LIKE \'%'.pSQL($tag).'%\''); AND t.`name` LIKE \'%'.pSQL($tag).'%\'';
return isset($result['nb']) ? $result['nb'] : 0; return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
} }
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' $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,
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
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
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_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.') 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` 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_.'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` 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_country` = '.(int)$context->country->id.'
AND tr.`id_state` = 0) AND tr.`id_state` = 0)
LEFT JOIN `'._DB_PREFIX_.'tax` tax ON (tax.`id_tax` = tr.`id_tax`) 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_.'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_.'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_.'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_product` cp ON (cp.`id_product` = p.`id_product`)
LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = cp.`id_category`) LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = cp.`id_category`)
WHERE p.`active` = 1 WHERE p.`active` = 1
AND cg.`id_group` '.(!$id_customer ? '= 1' : 'IN ( AND cg.`id_group` '.(!$id_customer ? '= 1' : 'IN (
SELECT id_group FROM '._DB_PREFIX_.'customer_group SELECT id_group FROM '._DB_PREFIX_.'customer_group
WHERE id_customer = '.(int)$id_customer.')').' WHERE id_customer = '.(int)$id_customer.')').'
AND t.`name` LIKE \'%'.pSQL($tag).'%\' AND t.`name` LIKE \'%'.pSQL($tag).'%\'
ORDER BY position DESC'.($orderBy ? ', '.$orderBy : '').($orderWay ? ' '.$orderWay : '').' ORDER BY position DESC'.($orderBy ? ', '.$orderBy : '').($orderWay ? ' '.$orderWay : '').'
LIMIT '.(int)(($pageNumber - 1) * $pageSize).','.(int)$pageSize); LIMIT '.(int)(($pageNumber - 1) * $pageSize).','.(int)$pageSize;
if (!$result) return false; if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql))
return false;
return Product::getProductsProperties((int)$id_lang, $result); return Product::getProductsProperties((int)$id_lang, $result);
} }
+195 -138
View File
@@ -36,16 +36,26 @@ class ShopCore extends ObjectModel
public $active; public $active;
public $id_category; public $id_category;
public $deleted; public $deleted;
private static $current_base_uri; protected $base_uri;
private static $current_theme_name; 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_shop;
private static $id_current_group_shop; private static $id_current_group_shop;
private static $id_current_root_category; private static $id_current_root_category;
protected $fieldsSize = array('name' => 64); protected $fieldsSize = array('name' => 64);
protected $fieldsValidate = array('active' => 'isBool', protected $fieldsValidate = array(
'name' => 'isGenericName'); 'active' => 'isBool',
'name' => 'isGenericName',
);
protected $table = 'shop'; protected $table = 'shop';
protected $identifier = 'id_shop'; protected $identifier = 'id_shop';
@@ -75,7 +85,7 @@ class ShopCore extends ObjectModel
'store' => array('type' => 'shop'), 'store' => array('type' => 'shop'),
'webservice_account' => array('type' => 'shop'), 'webservice_account' => array('type' => 'shop'),
); );
protected $webserviceParameters = array( protected $webserviceParameters = array(
'fields' => array( 'fields' => array(
'id_group_shop' => array('xlink_resource' => 'shop_groups'), 'id_group_shop' => array('xlink_resource' => 'shop_groups'),
@@ -83,14 +93,14 @@ class ShopCore extends ObjectModel
'id_theme' => array(), 'id_theme' => array(),
), ),
); );
/** /**
* There are 3 kinds of shop context : shop, group shop and general * There are 3 kinds of shop context : shop, group shop and general
*/ */
const CONTEXT_SHOP = 1; const CONTEXT_SHOP = 1;
const CONTEXT_GROUP = 2; const CONTEXT_GROUP = 2;
const CONTEXT_ALL = 3; const CONTEXT_ALL = 3;
public function getFields() public function getFields()
{ {
parent::validateFields(); parent::validateFields();
@@ -103,30 +113,14 @@ class ShopCore extends ObjectModel
$fields['deleted'] = (int)$this->deleted; $fields['deleted'] = (int)$this->deleted;
return $fields; 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) public function add($autodate = true, $nullValues = false)
{ {
$res = parent::add(); $res = parent::add();
Shop::loadShops(true); Shop::cacheShops(true);
return $res; return $res;
} }
public function delete() public function delete()
{ {
if (!$res = parent::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); $res &= Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.$table_name.'` WHERE `'.$id.'`='.(int)$this->id);
} }
Shop::loadShops(true); Shop::cacheShops(true);
return $res; 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 * @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 * @param bool $refresh
*/ */
public static function loadShops($refresh = false) public static function cacheShops($refresh = false)
{ {
if (self::$shops && !$refresh) if (self::$shops && !$refresh)
return; 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 * return self::$assoTables;
FROM '._DB_PREFIX.'shop_url
WHERE active=1 AND id_shop='.(int)$this->id);
} }
/** /**
@@ -224,7 +374,7 @@ class ShopCore extends ObjectModel
*/ */
public static function getShops($active = true, $id_group_shop = null, $getAsListID = false) public static function getShops($active = true, $id_group_shop = null, $getAsListID = false)
{ {
Shop::loadShops(); Shop::cacheShops();
$results = array(); $results = array();
foreach (self::$shops as $groupID => $groupData) foreach (self::$shops as $groupID => $groupData)
foreach ($groupData['shops'] as $id => $shopData) foreach ($groupData['shops'] as $id => $shopData)
@@ -246,7 +396,7 @@ class ShopCore extends ObjectModel
*/ */
public static function getIdByName($name) public static function getIdByName($name)
{ {
Shop::loadShops(); Shop::cacheShops();
foreach (self::$shops as $groupData) foreach (self::$shops as $groupData)
foreach ($groupData['shops'] as $shopID => $shopData) foreach ($groupData['shops'] as $shopID => $shopData)
if (Tools::strtolower($shopData['name']) == Tools::strtolower($name)) if (Tools::strtolower($shopData['name']) == Tools::strtolower($name))
@@ -262,99 +412,6 @@ class ShopCore extends ObjectModel
return count(Shop::getShops($active)); 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 * Retrieve group ID of a shop
* *
@@ -363,7 +420,7 @@ class ShopCore extends ObjectModel
*/ */
public static function getGroupFromShop($shopID, $asID = true) public static function getGroupFromShop($shopID, $asID = true)
{ {
Shop::loadShops(); Shop::cacheShops();
foreach (self::$shops as $groupID => $groupData) foreach (self::$shops as $groupID => $groupData)
if (array_key_exists($shopID, $groupData['shops'])) if (array_key_exists($shopID, $groupData['shops']))
return ($asID) ? $groupID : $groupData; 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 * @param int $shopID
* @return array * @return array
*/ */
public static function getSharedShops($shopID) public static function getSharedShops($shopID)
{ {
Shop::loadShops(); Shop::cacheShops();
foreach (self::$shops as $groupData) foreach (self::$shops as $groupData)
if (array_key_exists($shopID, $groupData['shops']) && $groupData['share_datas']) if (array_key_exists($shopID, $groupData['shops']) && $groupData['share_datas'])
return array_keys($groupData['shops']); return array_keys($groupData['shops']);
@@ -519,7 +576,7 @@ class ShopCore extends ObjectModel
if (!$shopID) if (!$shopID)
return ($shopGroupID) ? ' AND '.$alias.'id_group_shop = '.(int)$shopGroupID : ''; return ($shopGroupID) ? ' AND '.$alias.'id_group_shop = '.(int)$shopGroupID : '';
Shop::loadShops(); Shop::cacheShops();
foreach (self::$shops as $groupID => $groupData) foreach (self::$shops as $groupID => $groupData)
if (array_key_exists($shopID, $groupData['shops']) && $groupData['share_stock']) if (array_key_exists($shopID, $groupData['shops']) && $groupData['share_stock'])
return ' AND '.$alias.'id_group_shop = '.$groupID; return ' AND '.$alias.'id_group_shop = '.$groupID;
@@ -533,7 +590,7 @@ class ShopCore extends ObjectModel
*/ */
public static function getTree() public static function getTree()
{ {
Shop::loadShops(); Shop::cacheShops();
return self::$shops; return self::$shops;
} }
+4 -3
View File
@@ -92,10 +92,11 @@ function ppp($var) {
function ddd($var) { function ddd($var) {
Tools::d($var); Tools::d($var);
} }
/* Set the current Shop */ /* Set the current Shop */
Shop::setCurrentShop(); Context::getContext()->shop = Shop::initialize();
define('_THEME_NAME_', Shop::getCurrentTheme()); define('_THEME_NAME_', Context::getContext()->shop->getTheme());
define('__PS_BASE_URI__', Shop::getCurrentBaseURI()); define('__PS_BASE_URI__', Context::getContext()->shop->getBaseURI());
/* Include all defines */ /* Include all defines */
require_once(dirname(__FILE__).'/defines.inc.php'); require_once(dirname(__FILE__).'/defines.inc.php');
+1 -1
View File
@@ -205,7 +205,7 @@ class ProductControllerCore extends FrontController
$ecotaxTaxAmount = Tools::ps_round($ecotaxTaxAmount * (1 + $ecotax_rate / 100), 2); $ecotaxTaxAmount = Tools::ps_round($ecotaxTaxAmount * (1 + $ecotax_rate / 100), 2);
$this->smarty->assign(array( $this->smarty->assign(array(
'quantity_discounts' => $this->formatQuantityDiscounts(SpecificPrice::getQuantityDiscounts((int)($this->product->id), (int)(Shop::getCurrentShop()), (int)(self::$cookie->id_currency), $id_country, $id_group), $this->product->getPrice(Product::$_taxCalculationMethod == PS_TAX_INC, false), (float)($tax)), 'quantity_discounts' => $this->formatQuantityDiscounts(SpecificPrice::getQuantityDiscounts((int)($this->product->id), $this->id_current_shop, (int)(self::$cookie->id_currency), $id_country, $id_group), $this->product->getPrice(Product::$_taxCalculationMethod == PS_TAX_INC, false), (float)($tax)),
'product' => $this->product, 'product' => $this->product,
'ecotax_tax_inc' => $ecotaxTaxAmount, 'ecotax_tax_inc' => $ecotaxTaxAmount,
'ecotax_tax_exc' => Tools::ps_round($this->product->ecotax, 2), 'ecotax_tax_exc' => Tools::ps_round($this->product->ecotax, 2),
+1 -2
View File
@@ -179,13 +179,12 @@ class BlockCms extends Module
if (!$context) if (!$context)
$context = Context::getContext(); $context = Context::getContext();
$id_current_shop = Shop::getCurrentShop();
$cmsCategories = Db::getInstance()->ExecuteS(' $cmsCategories = Db::getInstance()->ExecuteS('
SELECT bc.`id_cms_block`, bc.`id_cms_category`, bc.`display_store`, ccl.`link_rewrite`, ccl.`name` category_name, bcl.`name` block_name SELECT bc.`id_cms_block`, bc.`id_cms_category`, bc.`display_store`, ccl.`link_rewrite`, ccl.`name` category_name, bcl.`name` block_name
FROM `'._DB_PREFIX_.'cms_block` bc FROM `'._DB_PREFIX_.'cms_block` bc
INNER JOIN `'._DB_PREFIX_.'cms_category_lang` ccl ON (bc.`id_cms_category` = ccl.`id_cms_category`) INNER JOIN `'._DB_PREFIX_.'cms_category_lang` ccl ON (bc.`id_cms_category` = ccl.`id_cms_category`)
INNER JOIN `'._DB_PREFIX_.'cms_block_lang` bcl ON (bc.`id_cms_block` = bcl.`id_cms_block`) INNER JOIN `'._DB_PREFIX_.'cms_block_lang` bcl ON (bc.`id_cms_block` = bcl.`id_cms_block`)
WHERE bc.`location` = '.(int)($location).' AND ccl.`id_lang` = '.(int)$context->language->id.' AND bcl.`id_lang` = '.(int)$context->language->id.' AND bc.id_shop='.(int)$id_current_shop.' WHERE bc.`location` = '.(int)($location).' AND ccl.`id_lang` = '.(int)$context->language->id.' AND bcl.`id_lang` = '.(int)$context->language->id.' AND bc.id_shop='.$context->shop->getID().'
ORDER BY `position`'); ORDER BY `position`');
$content = array(); $content = array();
@@ -186,8 +186,8 @@ class ReferralProgramModule extends ObjectModel
{ {
if (empty($email) OR !Validate::isEmail($email)) if (empty($email) OR !Validate::isEmail($email))
die (Tools::displayError('Email invalid.')); die (Tools::displayError('Email invalid.'));
// $return_id = false, $ignoreGuest = true, $id_group_shop = false, $id_shop = false
if ($checkCustomer === true AND Customer::customerExists($email, false, true, (int)Shop::getCurrentGroupShop(), (int)Shop::getCurrentShop())) if ($checkCustomer === true AND Customer::customerExists($email))
return false; return false;
$result = Db::getInstance()->getRow(' $result = Db::getInstance()->getRow('
SELECT s.`id_referralprogram` SELECT s.`id_referralprogram`
@@ -426,6 +426,7 @@ class ThemeInstallator extends Module
$hookedModule = array(); $hookedModule = array();
$position = array(); $position = array();
$msg = ''; $msg = '';
$shopID = Context::getContext()->shop->getID();
foreach ($this->xml->modules->hooks->hook as $row) foreach ($this->xml->modules->hooks->hook as $row)
{ {
@@ -455,17 +456,17 @@ class ThemeInstallator extends Module
WHERE `name` = \''.pSQL($row).'\''); WHERE `name` = \''.pSQL($row).'\'');
else if (!$obj OR !$obj->install()) else if (!$obj OR !$obj->install())
continue; continue;
Db::getInstance()->Execute('INSERT IGNORE INTO '._DB_PREFIX_.'module_shop (id_module, id_shop) VALUES('.(int)$obj->id.', '.(int)Shop::getCurrentShop().')'); Db::getInstance()->Execute('INSERT IGNORE INTO '._DB_PREFIX_.'module_shop (id_module, id_shop) VALUES('.(int)$obj->id.', '.$shopID.')');
$msg .= '<i>- '.pSQL($row).'</i><br />'; $msg .= '<i>- '.pSQL($row).'</i><br />';
Db::getInstance()->Execute(' Db::getInstance()->Execute('
DELETE FROM `'._DB_PREFIX_.'hook_module` DELETE FROM `'._DB_PREFIX_.'hook_module`
WHERE `id_module` = '.pSQL($obj->id).' AND id_shop='.(int)Shop::getCurrentShop()); WHERE `id_module` = '.pSQL($obj->id).' AND id_shop='.$shopID);
$count = -1; $count = -1;
while (isset($hookedModule[++$count])) while (isset($hookedModule[++$count]))
if ($hookedModule[$count] == $row) if ($hookedModule[$count] == $row)
Db::getInstance()->Execute(' Db::getInstance()->Execute('
INSERT INTO `'._DB_PREFIX_.'hook_module` (`id_module`, `id_shop`, `id_hook`, `position`) INSERT INTO `'._DB_PREFIX_.'hook_module` (`id_module`, `id_shop`, `id_hook`, `position`)
VALUES ('.(int)$obj->id.', '.(int)Shop::getCurrentShop().', '.(int)Hook::get($hook[$count]).', '.(int)$position[$count].')'); VALUES ('.(int)$obj->id.', '.$shopID.', '.(int)Hook::get($hook[$count]).', '.(int)$position[$count].')');
} }
if (($val = (int)(Tools::getValue('nativeModules'))) != 1) if (($val = (int)(Tools::getValue('nativeModules'))) != 1)
{ {
@@ -482,7 +483,7 @@ class ThemeInstallator extends Module
$msg .= '<i>- '.pSQL($row).'</i><br />'; $msg .= '<i>- '.pSQL($row).'</i><br />';
Db::getInstance()->Execute(' Db::getInstance()->Execute('
DELETE FROM `'._DB_PREFIX_.'module_shop` DELETE FROM `'._DB_PREFIX_.'module_shop`
WHERE `id_module` = '.pSQL($obj->id).' AND id_shop='.(int)Shop::getCurrentShop(true)); WHERE `id_module` = '.pSQL($obj->id).' AND id_shop='.$shopID);
} }
} }
$flag = 0; $flag = 0;
@@ -496,7 +497,7 @@ class ThemeInstallator extends Module
UPDATE `'._DB_PREFIX_.'module` UPDATE `'._DB_PREFIX_.'module`
SET `active`= 1 SET `active`= 1
WHERE `name` = \''.pSQL($row).'\''); WHERE `name` = \''.pSQL($row).'\'');
Db::getInstance()->Execute('INSERT IGNORE INTO '._DB_PREFIX_.'module_shop (id_module, id_shop) VALUES('.(int)$obj->id.', '.(int)Shop::getCurrentShop(true).')'); Db::getInstance()->Execute('INSERT IGNORE INTO '._DB_PREFIX_.'module_shop (id_module, id_shop) VALUES('.(int)$obj->id.', '.$shopID.')');
} }
else if (!is_object($obj) OR !$obj->install()) else if (!is_object($obj) OR !$obj->install())
continue ; continue ;
@@ -505,19 +506,19 @@ class ThemeInstallator extends Module
$msg .= '<i>- '.pSQL($row).'</i><br />'; $msg .= '<i>- '.pSQL($row).'</i><br />';
Db::getInstance()->Execute(' Db::getInstance()->Execute('
DELETE FROM `'._DB_PREFIX_.'hook_module` DELETE FROM `'._DB_PREFIX_.'hook_module`
WHERE `id_module` = '.pSQL($obj->id).' AND id_shop='.(int)Shop::getCurrentShop(true)); WHERE `id_module` = '.pSQL($obj->id).' AND id_shop='.$shopID);
$count = -1; $count = -1;
while (isset($hookedModule[++$count])) while (isset($hookedModule[++$count]))
if ($hookedModule[$count] == $row) if ($hookedModule[$count] == $row)
{ {
Db::getInstance()->Execute(' Db::getInstance()->Execute('
INSERT INTO `'._DB_PREFIX_.'hook_module` (`id_module`, `id_shop`, `id_hook`, `position`) INSERT INTO `'._DB_PREFIX_.'hook_module` (`id_module`, `id_shop`, `id_hook`, `position`)
VALUES ('.(int)$obj->id.', '.(int)Shop::getCurrentShop(true).', '.(int)Hook::get($hook[$count]).', '.(int)$position[$count].')'); VALUES ('.(int)$obj->id.', '.$shopID.', '.(int)Hook::get($hook[$count]).', '.(int)$position[$count].')');
foreach ($exceptions[$count] as $filename) foreach ($exceptions[$count] as $filename)
if (!empty($filename)) if (!empty($filename))
Db::getInstance()->Execute(' Db::getInstance()->Execute('
INSERT INTO `'._DB_PREFIX_.'hook_module_exceptions` (`id_module`, id_shop, `id_hook`, `file_name`) INSERT INTO `'._DB_PREFIX_.'hook_module_exceptions` (`id_module`, id_shop, `id_hook`, `file_name`)
VALUES ('.(int)$obj->id.', '.(int)Shop::getCurrentShop(true).', '.(int)Hook::get($hook[$count]).', "'.pSQL($filename).'")'); VALUES ('.(int)$obj->id.', '.$shopID.', '.(int)Hook::get($hook[$count]).', "'.pSQL($filename).'")');
} }
} }
} }