// Refactoring of shop class with new context

This commit is contained in:
rMalie
2011-07-12 16:28:20 +00:00
parent e7ea230525
commit 2d77925e7d
28 changed files with 216 additions and 185 deletions

View File

@@ -78,18 +78,12 @@ if (empty($tab) and !sizeof($_POST))
{
echo '
<span style="float:right">'.translate('You are currently view/configure your store for').' <b>';
if (Shop::getContextType() == Shop::CONTEXT_ALL)
if (Context::getContext()->shop->getContextType() == Shop::CONTEXT_ALL)
echo 'all shops';
elseif (Shop::getContextType() == Shop::CONTEXT_GROUP)
{
$group_shop = new GroupShop((int)Shop::getCurrentGroupShop());
echo 'all shops of group shop <b>'.$group_shop->name.'</b>';
}
elseif (Shop::getContextType() == Shop::CONTEXT_SHOP)
{
$shop = new Shop((int)Shop::getCurrentShop());
echo 'shop <b>'.$shop->name.'</b>';
}
elseif (Context::getContext()->shop->getContextType() == Shop::CONTEXT_GROUP)
echo 'all shops of group shop <b>'.Context::getContext()->shop->getGroup()->name.'</b>';
elseif (Context::getContext()->shop->getContextType() == Shop::CONTEXT_SHOP)
echo 'shop <b>'.Context::getContext()->shop->name.'</b>';
echo '</b>
</span>&nbsp;';
}

View File

@@ -176,7 +176,7 @@ class AdminCatalog extends AdminTab
if (!$id_category)
{
$home = true;
$id_category = Context::getContext()->shop->id_category1;
$id_category = Context::getContext()->shop->id_category;
}
$catalog_tabs = array('category', 'product');
// Cleaning links

View File

@@ -220,11 +220,8 @@ class AdminCategories extends AdminTab
return;
$active = $this->getFieldValue($obj, 'active');
$customer_groups = $obj->getGroups();
if (Shop::getContextType() == Shop::CONTEXT_SHOP)
{
$shop = new Shop(Shop::getCurrentShop());
$id_category = $shop->id_category;
}
if ($context->shop->getContextType() == Shop::CONTEXT_SHOP)
$id_category = $context->shop->id_category;
else
$id_category = (int)Tools::getValue('id_parent');

View File

@@ -589,7 +589,6 @@ class AdminImport extends AdminTab
public function productImport()
{
global $cookie;
$this->receiveTab();
$handle = $this->openCsvFile();
$defaultLanguageId = (int)(Configuration::get('PS_LANG_DEFAULT'));
@@ -788,7 +787,8 @@ class AdminImport extends AdminTab
{
$specificPrice = new SpecificPrice();
$specificPrice->id_product = (int)($product->id);
$specificPrice->id_shop = (int)(Shop::getCurrentShop());
// @todo multishop specific price import
$specificPrice->id_shop = $context->shop->getID();
$specificPrice->id_currency = 0;
$specificPrice->id_country = 0;
$specificPrice->id_group = 0;
@@ -849,7 +849,7 @@ class AdminImport extends AdminTab
if (isset($product->image) AND is_array($product->image) and sizeof($product->image))
{
$productHasImages = (bool)Image::getImages((int)($cookie->id_lang), (int)($product->id));
$productHasImages = (bool)Image::getImages($context->language->id, (int)($product->id));
foreach ($product->image AS $key => $url)
if (!empty($url))
{
@@ -1239,9 +1239,9 @@ class AdminImport extends AdminTab
public function displayForm($isMainTab = true)
{
global $currentIndex, $cookie;
parent::displayForm();
$context = Context::getContext();
if ((Tools::getValue('import')) AND (isset($this->_warnings) AND !sizeof($this->_warnings)))
echo '<div class="module_confirmation conf confirm"><img src="../img/admin/ok.gif" alt="" title="" style="margin-right:5px; float:left;" />'.$this->l('The .CSV file has been imported into your shop.').'</div>';
@@ -1270,7 +1270,7 @@ class AdminImport extends AdminTab
echo '
<fieldset class="width3">
<legend><img src="../img/admin/import.gif" />'.$this->l('Upload').'</legend>
<form action="'.$currentIndex.'&token='.$this->token.'" method="POST" enctype="multipart/form-data">
<form action="'.$this->currentIndex.'&token='.$this->token.'" method="POST" enctype="multipart/form-data">
<label class="clear">'.$this->l('Select a file').' </label>
<div class="margin-form">
<input name="file" type="file" /><br />'.$this->l('You can also upload your file by FTP and put it in').' '.realpath(dirname(__FILE__).'/../import/').'.
@@ -1295,7 +1295,7 @@ class AdminImport extends AdminTab
{
echo '
<div class="space">
<form id="preview_import" action="'.$currentIndex.'&token='.$this->token.'" method="post" style="display:inline" enctype="multipart/form-data" class="clear" onsubmit="if ($(\'#truncate\').get(0).checked) {if (confirm(\''.$this->l('Are you sure you want to delete', __CLASS__, true, false).'\' + \' \' + $(\'#entity > option:selected\').text().toLowerCase() + \''.$this->l('?', __CLASS__, true, false).'\')){this.submit();} else {return false;}}">
<form id="preview_import" action="'.$this->currentIndex.'&token='.$this->token.'" method="post" style="display:inline" enctype="multipart/form-data" class="clear" onsubmit="if ($(\'#truncate\').get(0).checked) {if (confirm(\''.$this->l('Are you sure you want to delete', __CLASS__, true, false).'\' + \' \' + $(\'#entity > option:selected\').text().toLowerCase() + \''.$this->l('?', __CLASS__, true, false).'\')){this.submit();} else {return false;}}">
<fieldset style="float: left; width: 550px">
<legend><img src="../img/admin/import.gif" />'.$this->l('Import').'</legend>
<label class="clear">'.$this->l('Select which entity to import:').' </label>
@@ -1321,7 +1321,7 @@ class AdminImport extends AdminTab
<div class="margin-form">
<select name="iso_lang">';
foreach ($this->_languages AS $lang)
echo '<option value="'.$lang['iso_code'].'" '.($lang['id_lang'] == $cookie->id_lang ? 'selected="selected"' : '').'>'.$lang['name'].'</option>';
echo '<option value="'.$lang['iso_code'].'" '.($lang['id_lang'] == $context->language->id ? 'selected="selected"' : '').'>'.$lang['name'].'</option>';
echo '</select></div><label for="convert" class="clear">'.$this->l('iso-8859-1 encoded file').' </label>
<div class="margin-form">
<input name="convert" id="convert" type="checkbox" style="margin-top: 6px;"/>
@@ -1360,7 +1360,7 @@ class AdminImport extends AdminTab
<script type="text/javascript">
$("select#entity").change( function() {
$("#entitie").html($("#entity > option:selected").text().toLowerCase());
$.getJSON("'.dirname($currentIndex).'/ajax.php",
$.getJSON("'.dirname($this->currentIndex).'/ajax.php",
{
getAvailableFields:1,
entity: $("#entity").val()},
@@ -1473,7 +1473,6 @@ class AdminImport extends AdminTab
public function displayCSV()
{
global $currentIndex;
$importMatchs = Db::getInstance()->ExecuteS('SELECT * FROM '._DB_PREFIX_.'import_match');
echo '
@@ -1512,7 +1511,7 @@ class AdminImport extends AdminTab
$res[] = '\''.$elem.'\'';
echo '
<form action="'.$currentIndex.'&token='.$this->token.'" method="post" id="import_form" name="import_form">
<form action="'.$this->currentIndex.'&token='.$this->token.'" method="post" id="import_form" name="import_form">
'.$this->l('Skip').' <input type="text" size="2" name="skip" value="0" /> '.$this->l('lines').'.
<input type="hidden" name="csv" value="'.Tools::getValue('csv').'" />
<input type="hidden" name="convert" value="'.Tools::getValue('convert').'" />
@@ -1626,8 +1625,6 @@ class AdminImport extends AdminTab
public function postProcess()
{
global $currentIndex;
if (Tools::isSubmit('submitFileUpload'))
{
if (isset($_FILES['file']) AND !empty($_FILES['file']['error']))
@@ -1662,7 +1659,7 @@ class AdminImport extends AdminTab
elseif (!file_exists($_FILES['file']['tmp_name']) OR !@move_uploaded_file($_FILES['file']['tmp_name'], dirname(__FILE__).'/../import/'.$_FILES['file']['name'].'.'.date('Ymdhis')))
$this->_errors[] = $this->l('an error occurred while uploading and copying file');
else
Tools::redirectAdmin($currentIndex.'&token='.Tools::getValue('token').'&conf=18');
Tools::redirectAdmin($this->currentIndex.'&token='.Tools::getValue('token').'&conf=18');
}
elseif (Tools::isSubmit('submitImportFile'))
$this->displayCSV();

View File

@@ -286,17 +286,12 @@ class AdminModules extends AdminTab
$toolbar .= '<tr>
<th colspan="4">
<input type="checkbox" name="activateModule" value="1" '.(($module->active) ? 'checked="checked"' : '').' '.$activateOnclick.' /> '.$this->l('Activate module for').' ';
if (Shop::getContextType() == Shop::CONTEXT_SHOP)
{
$shop = new Shop((int)Shop::getCurrentShop());
$toolbar .= 'shop <b>'.$shop->name.'</b>';
}
elseif (Shop::getContextType() == Shop::CONTEXT_GROUP)
{
$group_shop = new GroupShop((int)Shop::getCurrentGroupShop());
$toolbar .= 'all shops of group shop <b>'.$group_shop->name.'</b>';
}
elseif (Shop::getContextType() == Shop::CONTEXT_ALL)
$context = Context::getContext();
if ($context->shop->getContextType() == Shop::CONTEXT_SHOP)
$toolbar .= 'shop <b>'.$context->shop->name.'</b>';
elseif ($context->shop->getContextType() == Shop::CONTEXT_GROUP)
$toolbar .= 'all shops of group shop <b>'.$context->shop->getGroup()->name.'</b>';
else
$toolbar .= 'all shops';
$toolbar .= '</th>
</tr>';

View File

@@ -1169,7 +1169,7 @@ class AdminProducts extends AdminTab
/* Update an existing product */
if (isset($id) AND !empty($id))
{
$object = new $this->className($id, false, NULL, Shop::getCurrentShop(true));
$object = new $this->className($id);
if (Validate::isLoadedObject($object))
{
$this->_removeTaxFromEcotax();
@@ -1402,7 +1402,7 @@ class AdminProducts extends AdminTab
{
global $currentIndex, $cookie;
$id_shop = Shop::getCurrentShop(true);
$id_shop = Context::getContext()->shop->getID();
if (($id_category = (int)Tools::getValue('id_category')))
$currentIndex .= '&id_category='.$id_category;
@@ -3816,7 +3816,7 @@ class AdminProducts extends AdminTab
if ($id = (int)(Tools::getValue($this->identifier)) AND Validate::isUnsignedId($id))
{
if (!$this->_object)
$this->_object = new $this->className($id, false, NULL, (int)Shop::getCurrentShop(true));
$this->_object = new $this->className($id);
if (Validate::isLoadedObject($this->_object))
return $this->_object;
$this->_errors[] = Tools::displayError('Object cannot be loaded (not found)');

View File

@@ -44,36 +44,34 @@ class AdminStockMvt extends AdminTab
'employee' => array('title' => $this->l('Employee'), 'width' => 100, 'havingFilter' => true),
);
global $cookie;
$context = Context::getContext();
$this->_select = 'CONCAT(pl.name, \' \', GROUP_CONCAT(IFNULL(al.name, \'\'), \'\')) product_name, CONCAT(e.lastname, \' \', e.firstname) employee, mrl.name reason';
$this->_join = 'INNER JOIN '._DB_PREFIX_.'stock stock ON a.id_stock = stock.id_stock '.Shop::sqlSharedStock('stock', Shop::getCurrentShop(), Shop::getCurrentGroupShop()).'
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (stock.id_product = pl.id_product AND pl.id_lang = '.(int)$cookie->id_lang.')
LEFT JOIN `'._DB_PREFIX_.'stock_mvt_reason_lang` mrl ON (a.id_stock_mvt_reason = mrl.id_stock_mvt_reason AND mrl.id_lang = '.(int)$cookie->id_lang.')
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (stock.id_product = pl.id_product AND pl.id_lang = '.(int)$context->language->id.')
LEFT JOIN `'._DB_PREFIX_.'stock_mvt_reason_lang` mrl ON (a.id_stock_mvt_reason = mrl.id_stock_mvt_reason AND mrl.id_lang = '.(int)$context->language->id.')
LEFT JOIN `'._DB_PREFIX_.'employee` e ON (e.id_employee = a.id_employee)
LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON (pac.id_product_attribute = stock.id_product_attribute)
LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (al.id_attribute = pac.id_attribute AND al.id_lang = '.(int)$cookie->id_lang.')';
LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (al.id_attribute = pac.id_attribute AND al.id_lang = '.(int)$context->language->id.')';
$this->_group = 'GROUP BY a.id_stock_mvt';
parent::__construct();
}
public function postProcess()
{
global $cookie;
if (Tools::isSubmit('rebuildStock'))
StockMvt::addMissingMvt((int)$cookie->id_employee, false);
StockMvt::addMissingMvt($context->employee->id, false);
return parent::postProcess();
}
public function displayForm($isMainTab = true)
{
global $currentIndex, $cookie;
parent::displayForm();
if (!($obj = $this->loadObject(true)))
return;
$dl = 'name';
echo '<form action="'.$currentIndex.'&submitAdd'.$this->table.'=1&token='.$this->token.'&addstock_mvt_reason" method="post">
echo '<form action="'.$this->currentIndex.'&submitAdd'.$this->table.'=1&token='.$this->token.'&addstock_mvt_reason" method="post">
'.($obj->id ? '<input type="hidden" name="id_'.$this->table.'" value="'.$obj->id.'" />' : '').'
<fieldset><legend><img src="../img/admin/search.gif" />'.$this->l('Stock Movement').'</legend>
<label>'.$this->l('Name:').'</label>
@@ -102,11 +100,10 @@ class AdminStockMvt extends AdminTab
public function viewstock_mvt()
{
global $cookie;
$context = Context::getContext();
$stockMvt = new StockMvt((int)Tools::getValue('id_stock_mvt'));
$product = new Product((int)$stockMvt->id_product, true, (int)$cookie->id_lang);
$movements = $product->getStockMvts((int)$cookie->id_lang);
$product = new Product((int)$stockMvt->id_product, true, $context->language->id);
$movements = $product->getStockMvts($context->language->id);
echo '<h2>'.$this->l('Stock Movements for').' '.$product->name.'</h2>
<table cellspacing="0" cellpadding="0" class="table widthfull">
@@ -130,7 +127,7 @@ class AdminStockMvt extends AdminTab
<td>'.$mvt['reason'].'</td>
<td>'.$mvt['employee'].'</td>
<td>#'.$mvt['id_order'].'</td>
<td>'.Tools::displayDate($mvt['date_add'], (int)($cookie->id_lang)).'</td>
<td>'.Tools::displayDate($mvt['date_add'], $context->language->id).'</td>
</tr>';
}
echo '</table>';
@@ -138,9 +135,8 @@ class AdminStockMvt extends AdminTab
public function display()
{
global $currentIndex, $cookie;
$old_post = false;
$context = Context::getContext();
if (!isset($_GET['addstock_mvt_reason']) OR (Tools::isSubmit('submitAddstock_mvt_reason') AND Tools::getValue('id_stock_mvt_reason')))
{
@@ -153,7 +149,7 @@ class AdminStockMvt extends AdminTab
if (!isset($_GET['view'.$this->table]))
echo '
<fieldset>
<form method="post" action="'.$currentIndex.'&token='.$this->token.'&rebuildMvt=1">
<form method="post" action="'.$this->currentIndex.'&token='.$this->token.'&rebuildMvt=1">
<label for="stock_rebuild">'.$this->l('Calculate the movement of inventory missing').'</label>
<div class="margin-form">
<input class="button" type="submit" name="rebuildStock" value="'.$this->l('Submit').'" />
@@ -182,7 +178,7 @@ class AdminStockMvt extends AdminTab
'sign' => array('title' => $this->l('Sign'), 'width' => 15, 'align' => 'center', 'type' => 'select', 'icon' => array(-1 => 'arrow_down.png', 1 => 'arrow_up.png'), 'orderby' => false),
'name' => array('title' => $this->l('Name'), 'width' => 500));
$reasons = StockMvtReason::getStockMvtReasons((int)$cookie->id_lang);
$reasons = StockMvtReason::getStockMvtReasons($context->language->id);
$this->_fieldsOptions = array('PS_STOCK_MVT_REASON_DEFAULT' => array('title' => $this->l('Default Stock Movement reason:'),
'cast' => 'intval',
'type' => 'select',

View File

@@ -1190,7 +1190,7 @@ abstract class AdminTabCore
$assos = GroupShop::getAssoTables();
if (isset($assos[$this->table]) AND $assos[$this->table]['type'] == 'group_shop')
$filterKey = $assos[$this->table]['type'];
$idenfierShop = $context->shop->getGroup();
$idenfierShop = $context->shop->getGroupID();
}
if (isset($filterKey))
$filterShop = 'JOIN `'._DB_PREFIX_.$this->table.'_'.$filterKey.'` sa ON (sa.'.$this->identifier.' = a.'.$this->identifier.' AND sa.id_'.$filterKey.'='.(int)$idenfierShop.')';

View File

@@ -535,7 +535,7 @@ class CartCore extends ObjectModel
*/
public function updateQty($quantity, $id_product, $id_product_attribute = NULL, $id_customization = false, $operator = 'up', $id_shop = NULL, $id_group_shop = NULL)
{
if (is_null($id_shop)) $id_shop = Shop::getCurrentShop(true);
if (is_null($id_shop)) $id_shop = Context::getContext()->shop->getID();
$quantity = (int)$quantity;
$id_product = (int)$id_product;
$id_product_attribute = (int)$id_product_attribute;

View File

@@ -728,7 +728,7 @@ class CategoryCore extends ObjectModel
public function getName($id_lang = NULL, $id_shop = false, $context = null)
{
if (!$id_shop)
$id_shop = (int)Shop::getCurrentShop(true);
$id_shop = Context::getContext()->shop->getID();
if (!$id_lang)
{
if (!$context)

View File

@@ -97,11 +97,11 @@ class ConnectionCore extends ObjectModel
AND preg_match('/BotLink|ahoy|AlkalineBOT|anthill|appie|arale|araneo|AraybOt|ariadne|arks|ATN_Worldwide|Atomz|bbot|Bjaaland|Ukonline|borg\-bot\/0\.9|boxseabot|bspider|calif|christcrawler|CMC\/0\.01|combine|confuzzledbot|CoolBot|cosmos|Internet Cruiser Robot|cusco|cyberspyder|cydralspider|desertrealm, desert realm|digger|DIIbot|grabber|downloadexpress|DragonBot|dwcp|ecollector|ebiness|elfinbot|esculapio|esther|fastcrawler|FDSE|FELIX IDE|ESI|fido|H<>m<EFBFBD>h<EFBFBD>kki|KIT\-Fireball|fouineur|Freecrawl|gammaSpider|gazz|gcreep|golem|googlebot|griffon|Gromit|gulliver|gulper|hambot|havIndex|hotwired|htdig|iajabot|INGRID\/0\.1|Informant|InfoSpiders|inspectorwww|irobot|Iron33|JBot|jcrawler|Teoma|Jeeves|jobo|image\.kapsi\.net|KDD\-Explorer|ko_yappo_robot|label\-grabber|larbin|legs|Linkidator|linkwalker|Lockon|logo_gif_crawler|marvin|mattie|mediafox|MerzScope|NEC\-MeshExplorer|MindCrawler|udmsearch|moget|Motor|msnbot|muncher|muninn|MuscatFerret|MwdSearch|sharp\-info\-agent|WebMechanic|NetScoop|newscan\-online|ObjectsSearch|Occam|Orbsearch\/1\.0|packrat|pageboy|ParaSite|patric|pegasus|perlcrawler|phpdig|piltdownman|Pimptrain|pjspider|PlumtreeWebAccessor|PortalBSpider|psbot|Getterrobo\-Plus|Raven|RHCS|RixBot|roadrunner|Robbie|robi|RoboCrawl|robofox|Scooter|Search\-AU|searchprocess|Senrigan|Shagseeker|sift|SimBot|Site Valet|skymob|SLCrawler\/2\.0|slurp|ESI|snooper|solbot|speedy|spider_monkey|SpiderBot\/1\.0|spiderline|nil|suke|http:\/\/www\.sygol\.com|tach_bw|TechBOT|templeton|titin|topiclink|UdmSearch|urlck|Valkyrie libwww\-perl|verticrawl|Victoria|void\-bot|Voyager|VWbot_K|crawlpaper|wapspider|WebBandit\/1\.0|webcatcher|T\-H\-U\-N\-D\-E\-R\-S\-T\-O\-N\-E|WebMoose|webquest|webreaper|webs|webspider|WebWalker|wget|winona|whowhere|wlm|WOLP|WWWC|none|XGET|Nederland\.zoek/i', $_SERVER['HTTP_USER_AGENT']))
{
// This is a bot and we have to retrieve its connection ID
$sql = 'SELECT `id_connections` FROM `'._DB_PREFIX_.'connections` c
$sql = 'SELECT `id_connections` FROM `'._DB_PREFIX_.'connections`
WHERE ip_address = '.ip2long(Tools::getRemoteAddr()).'
AND DATE_ADD(c.`date_add`, INTERVAL 30 MINUTE) > \''.pSQL(date('Y-m-d H:i:00')).'\'
AND id_shop = '.Shop::getCurrentShop().'
ORDER BY c.`date_add` DESC';
AND DATE_ADD(`date_add`, INTERVAL 30 MINUTE) > \''.pSQL(date('Y-m-d H:i:00')).'\'
AND id_shop = '.Shop::sqlRestriction().'
ORDER BY `date_add` DESC';
if ($id_connections = Db::getInstance()->getValue($sql))
{
$cookie->id_connections = (int)$id_connections;
@@ -110,12 +110,12 @@ class ConnectionCore extends ObjectModel
}
// A new connection is created if the guest made no actions during 30 minutes
$sql = 'SELECT c.`id_guest`
FROM `'._DB_PREFIX_.'connections` c
WHERE c.`id_guest` = '.(int)($cookie->id_guest).'
AND DATE_ADD(c.`date_add`, INTERVAL 30 MINUTE) > \''.pSQL(date('Y-m-d H:i:00')).'\'
AND id_shop = '.Shop::getCurrentShop().'
ORDER BY c.`date_add` DESC';
$sql = 'SELECT `id_guest`
FROM `'._DB_PREFIX_.'connections`
WHERE `id_guest` = '.(int)($cookie->id_guest).'
AND DATE_ADD(`date_add`, INTERVAL 30 MINUTE) > \''.pSQL(date('Y-m-d H:i:00')).'\'
AND id_shop = '.Shop::sqlRestriction().'
ORDER BY `date_add` DESC';
$result = Db::getInstance()->getRow($sql);
if (!$result['id_guest'] AND (int)($cookie->id_guest))
{
@@ -130,8 +130,8 @@ class ConnectionCore extends ObjectModel
$connection->id_guest = (int)($cookie->id_guest);
$connection->id_page = Page::getCurrentId();
$connection->ip_address = Tools::getRemoteAddr() ? ip2long(Tools::getRemoteAddr()) : '';
$connection->id_shop = Shop::getCurrentShop();
$connection->id_group_shop = Shop::getCurrentGroupShop();
$connection->id_shop = Context::getContext()->shop->getID();
$connection->id_group_shop = Context::getContext()->shop->getGroupID();
if (Validate::isAbsoluteUrl($referer))
$connection->http_referer = $referer;
$connection->add();

View File

@@ -24,21 +24,72 @@
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* @since 1.5.0
*/
class ContextCore
{
/**
* @var Context
*/
protected static $instance;
/**
* @var Cart
*/
public $cart;
/**
* @var Customer
*/
public $customer;
/**
* @var Cookie
*/
public $cookie;
/**
* @var Link
*/
public $link;
/**
* @var Country
*/
public $country;
/**
* @var Employee
*/
public $employee;
/**
* @var Controller
*/
public $controller;
public $lang;
/**
* @var Language
*/
public $language;
/**
* @var Currency
*/
public $currency;
/**
* @var AdminTab
*/
public $tab;
/**
* @var Shop
*/
public $shop;
/**
* Create a context without singleton constraint
*/
@@ -48,7 +99,7 @@ class ContextCore
$link = null,
$country = null,
$employee = null,
$lang = null,
$language = null,
$currency = null,
$tab = null)
{
@@ -58,7 +109,7 @@ class ContextCore
$this->link = $link;
$this->country = $country;
$this->employee = $employee;
$this->lang = $lang;
$this->language = $language;
$this->currency = $currency;
$this->tab = $tab;
}

View File

@@ -198,7 +198,7 @@ class CurrencyCore extends ObjectModel
static public function getPaymentCurrenciesSpecial($id_module, $id_shop = null)
{
if (is_null($id_shop))
$id_shop = Shop::getCurrentShop(true);
$id_shop = Context::getContext()->shop->getID();
$sql = 'SELECT *
FROM '._DB_PREFIX_.'module_currency
@@ -210,7 +210,7 @@ class CurrencyCore extends ObjectModel
static public function getPaymentCurrencies($id_module, $id_shop = null)
{
if (is_null($id_shop))
$id_shop = Shop::getCurrentShop(true);
$id_shop = Context::getContext()->shop->getID();
$sql = 'SELECT c.*
FROM `'._DB_PREFIX_.'module_currency` mc
@@ -226,7 +226,7 @@ class CurrencyCore extends ObjectModel
static public function checkPaymentCurrencies($id_module, $id_shop = null)
{
if (is_null($id_shop))
$id_shop = Shop::getCurrentShop(true);
$id_shop = Context::getContext()->shop->getID();
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT mc.*

View File

@@ -155,8 +155,8 @@ class CustomerCore extends ObjectModel
public function add($autodate = true, $nullValues = true)
{
$this->id_shop = ($this->id_shop) ? $this->id_shop : Shop::getCurrentShop();
$this->id_group_shop = ($this->id_group_shop) ? $this->id_group_shop : Shop::getCurrentGroupShop();
$this->id_shop = ($this->id_shop) ? $this->id_shop : Context::getContext()->shop->getID();
$this->id_group_shop = ($this->id_group_shop) ? $this->id_group_shop : Context::getContext()->shop->getGroupID();
$this->birthday = (empty($this->years) ? $this->birthday : (int)($this->years).'-'.(int)($this->months).'-'.(int)($this->days));
$this->secure_key = md5(uniqid(rand(), true));
$this->last_passwd_gen = date('Y-m-d H:i:s', strtotime('-'.Configuration::get('PS_PASSWD_TIME_FRONT').'minutes'));

View File

@@ -82,8 +82,8 @@ class FrontControllerCore
return;
self::$initialized = true;
$this->id_current_shop = (int)Shop::getCurrentShop();
$this->id_current_group_shop = (int)Shop::getCurrentGroupShop();
$this->id_current_shop = Context::getContext()->shop->getID();
$this->id_current_group_shop = Context::getContext()->shop->getGroupID();
$this->css_files = array();
$this->js_files = array();

View File

@@ -240,10 +240,10 @@ abstract class ObjectModelCore
if (!Tools::isMultishopActivated())
{
if (isset($assos[$this->table]) && $assos[$this->table]['type'] == 'shop')
$result &= $this->associateTo(Shop::getCurrentShop(true), 'shop');
$result &= $this->associateTo(Context::getContext()->shop->getID(), 'shop');
$assos = GroupShop::getAssoTables();
if (isset($assos[$this->table]) && $assos[$this->table]['type'] == 'group_shop')
$result &= $this->associateTo(Shop::getCurrentGroupShop(), 'group_shop');
$result &= $this->associateTo(Context::getContext()->shop->getGroupID(), 'group_shop');
}
return $result;
}
@@ -284,7 +284,7 @@ abstract class ObjectModelCore
die(Tools::displayError());
if ($this->langMultiShop)
$field['id_shop'] = ($this->id_shop ? $this->id_shop : Shop::getCurrentShop(true));
$field['id_shop'] = ($this->id_shop ? $this->id_shop : Context::getContext()->shop->getID());
// used to insert missing lang entries
$where_lang = '`'.pSQL($this->identifier).'` = '.(int)$this->id.
@@ -739,7 +739,7 @@ abstract class ObjectModelCore
public function isAssociatedToShop($id_shop = null)
{
if (is_null($id_shop))
$id_shop = Shop::getCurrentShop();
$id_shop = Context::getContext()->shop->getID();
$sql = 'SELECT id_shop
FROM `'.pSQL(_DB_PREFIX_.$this->table).'_shop`
@@ -782,7 +782,7 @@ abstract class ObjectModelCore
public function isAssociatedToGroupShop($id_group_shop = null)
{
if (is_null($id_group_shop))
$id_shop = Shop::getCurrentGroupShop();
$id_group_shop = Context::getContext()->shop->getGroupID();
$sql = 'SELECT id_group_shop
FROM `'.pSQL(_DB_PREFIX_.$this->table).'_group_shop`

View File

@@ -125,7 +125,7 @@ class PageCore extends ObjectModel
'id_page' => (int)$id_page,
'counter' => 1,
'id_shop' => $context->shop->getID(),
'id_group_shop' => $context->shop->getGroup(),
'id_group_shop' => $context->shop->getGroupID(),
), 'INSERT');
}
}

View File

@@ -217,7 +217,7 @@ abstract class PaymentModuleCore extends Module
if (!empty($product['ecotax']))
$ecotaxTaxRate = Tax::getProductEcotaxRate($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
$quantityDiscount = SpecificPrice::getQuantityDiscount((int)$product['id_product'], Shop::getCurrentShop(), (int)$cart->id_currency, (int)$vat_address->id_country, (int)$customer->id_default_group, (int)$product['cart_quantity']);
$quantityDiscount = SpecificPrice::getQuantityDiscount((int)$product['id_product'], $this->shopID, (int)$cart->id_currency, (int)$vat_address->id_country, (int)$customer->id_default_group, (int)$product['cart_quantity']);
$unitPrice = Product::getPriceStatic((int)$product['id_product'], true, ($product['id_product_attribute'] ? intval($product['id_product_attribute']) : NULL), 2, NULL, false, true, 1, false, (int)$order->id_customer, NULL, (int)$order->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
$quantityDiscountValue = $quantityDiscount ? ((Product::getTaxCalculationMethod((int)$order->id_customer) == PS_TAX_EXC ? Tools::ps_round($unitPrice, 2) : $unitPrice) - $quantityDiscount['price'] * (1 + $tax_rate / 100)) : 0.00;
$query .= '('.(int)($order->id).',

View File

@@ -1375,7 +1375,7 @@ class ProductCore extends ObjectModel
public static function getNewProducts($id_lang, $pageNumber = 0, $nbProducts = 10, $count = false, $orderBy = NULL, $orderWay = NULL, $id_shop = null)
{
if (is_null($id_shop))
$id_shop = Shop::getCurrentShop();
$id_shop = Context::getContext()->shop->getID();
if ($pageNumber < 0) $pageNumber = 0;
if ($nbProducts < 1) $nbProducts = 10;
if (empty($orderBy) || $orderBy == 'position') $orderBy = 'date_add';
@@ -1456,7 +1456,7 @@ class ProductCore extends ObjectModel
$id_address = $context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')};
$ids = Address::getCountryAndState($id_address);
$id_country = (int)($ids['id_country'] ? $ids['id_country'] : Configuration::get('PS_COUNTRY_DEFAULT'));
return SpecificPrice::getProductIdByDate(Shop::getCurrentShop(), $context->currency->id, $id_country, $context->customer->id_default_group, $beginning, $ending);
return SpecificPrice::getProductIdByDate($context->shop->getID(), $context->currency->id, $id_country, $context->customer->id_default_group, $beginning, $ending);
}
/**
@@ -1523,7 +1523,7 @@ class ProductCore extends ObjectModel
if (!Validate::isBool($count))
die(Tools::displayError());
if (is_null($id_shop)) $id_shop = Shop::getCurrentShop(true);
if (is_null($id_shop)) $id_shop = Context::getContext()->shop->getID();
if ($pageNumber < 0) $pageNumber = 0;
if ($nbProducts < 1) $nbProducts = 10;
if (empty($orderBy) || $orderBy == 'position') $orderBy = 'price';
@@ -1810,9 +1810,7 @@ class ProductCore extends ObjectModel
if ($usetax != false AND !empty($address_infos['vat_number']) AND $address_infos['id_country'] != Configuration::get('VATNUMBER_COUNTRY') AND Configuration::get('VATNUMBER_MANAGEMENT'))
$usetax = false;
$id_shop = (int)(Shop::getCurrentShop());
return Product::priceCalculation($id_shop, $id_product, $id_product_attribute, $id_country, $id_state, $id_county, $id_currency, $id_group, $quantity, $usetax, $decimals, $only_reduc,
return Product::priceCalculation($context->shop->getID(), $id_product, $id_product_attribute, $id_country, $id_state, $id_county, $id_currency, $id_group, $quantity, $usetax, $decimals, $only_reduc,
$usereduc, $with_ecotax, $specificPriceOutput);
}
@@ -1950,6 +1948,9 @@ class ProductCore extends ObjectModel
public static function isDiscounted($id_product, $quantity = 1, $context = null)
{
if (!$context)
$context = Context::getContext();
$id_group = $context->customer->id_default_group;
$cart_quantity = !$context->cart ? 0 : Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
SELECT SUM(`quantity`)
@@ -1960,8 +1961,7 @@ class ProductCore extends ObjectModel
$id_currency = (int)$context->currency->id;
$ids = Address::getCountryAndState((int)($context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}));
$id_country = (int)($ids['id_country'] ? $ids['id_country'] : Configuration::get('PS_COUNTRY_DEFAULT'));
$id_shop = (int)(Shop::getCurrentShop());
return (bool)SpecificPrice::getSpecificPrice((int)$id_product, $id_shop, $id_currency, $id_country, $id_group, $quantity);
return (bool)SpecificPrice::getSpecificPrice((int)$id_product, $context->shop->getID(), $id_currency, $id_country, $id_group, $quantity);
}
/**
@@ -2084,7 +2084,7 @@ class ProductCore extends ObjectModel
{
if (!$this->id)
return ;
$shop = Shop::getCurrentShop(true);
$shop = Context::getContext()->shop->getID();
// For retrocompatibility
$id_product_attribute = (int)$id_product_attribute;
@@ -2157,7 +2157,7 @@ class ProductCore extends ObjectModel
if (!$this->id)
return 0;
$shop = Shop::getCurrentShop(true);
$shop = Context::getContext()->shop->getID();
$sql = 'SELECT quantity
FROM '._DB_PREFIX_.'stock
WHERE id_product = '.$this->id.'

View File

@@ -116,13 +116,13 @@ class ProductSaleCore
** @param integer $nbProducts Number of products to return (optional)
** @return array keys : id_product, link_rewrite, name, id_image, legend, sales, ean13, upc, link
*/
static public function getBestSalesLight($id_lang, $pageNumber = 0, $nbProducts = 10, $id_shop = null)
static public function getBestSalesLight($id_lang, $pageNumber = 0, $nbProducts = 10, $id_shop = null, $context = null)
{
global $link;
if (!$context)
$context = Context::getContext();
if ($pageNumber < 0) $pageNumber = 0;
if ($nbProducts < 1) $nbProducts = 10;
if (is_null($id_shop)) $id_shop = Shop::getCurrentShop();
if (is_null($id_shop)) $id_shop = $context->shop->getID();
$groups = FrontController::getCurrentCustomerGroups();
$sqlGroups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1');
@@ -150,7 +150,7 @@ class ProductSaleCore
foreach ($result AS &$row)
{
$row['link'] = $link->getProductLink($row['id_product'], $row['link_rewrite'], $row['category'], $row['ean13']);
$row['link'] = $context->link->getProductLink($row['id_product'], $row['link_rewrite'], $row['category'], $row['ean13']);
$row['id_image'] = Product::defineProductImage($row, $id_lang);
}
return $result;

View File

@@ -147,19 +147,18 @@ class SearchCore
public static function find($id_lang, $expr, $pageNumber = 1, $pageSize = 1, $orderBy = 'position', $orderWay = 'desc', $ajax = false, $useCookie = true, $id_shop = false, $context = null)
{
global $cookie;
if (!$context)
$context = Context::getContext();
$db = Db::getInstance(_PS_USE_SQL_SLAVE_);
// Only use cookie if id_customer is not present
if ($useCookie)
$id_customer = $cookie->id_customer;
$id_customer = $context->customer->id;
else
$id_customer = 0;
if (!$id_shop)
$id_shop = Shop::getCurrentShop();
$id_shop = $context->shop->getID();
// TODO : smart page management
if ($pageNumber < 1) $pageNumber = 1;
@@ -541,7 +540,7 @@ class SearchCore
$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;

View File

@@ -253,31 +253,34 @@ class ShopCore extends ObjectModel
/**
* 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.
* 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)
public function getID()
{
if (!$this->id && $forceContext)
return (int)Configuration::get('PS_SHOP_DEFAULT');
return (int)$this->id;
}
/**
* Get current shop group ID
*
* @return int
*/
public function getGroupID()
{
return (int)$this->id_group_shop;
}
/**
* Get root category of current shop
@@ -571,7 +574,7 @@ class ShopCore extends ObjectModel
$alias .= '.';
if (is_null($shopID))
$shopID = Shop::getCurrentShop(true);
$shopID = Context::getContext()->shop->getID();
if (!$shopID)
return ($shopGroupID) ? ' AND '.$alias.'id_group_shop = '.(int)$shopGroupID : '';

View File

@@ -87,7 +87,7 @@ class ShopUrlCore extends ObjectModel
if (!self::$main_domain)
self::$main_domain = Db::getInstance()->getValue('SELECT domain
FROM '._DB_PREFIX_.'shop_url
WHERE main=1 AND id_shop='.(int)Shop::getCurrentShop());
WHERE main=1 AND id_shop='.Context::getContext()->shop->getID());
return self::$main_domain;
}
@@ -96,7 +96,7 @@ class ShopUrlCore extends ObjectModel
if (!self::$main_domain)
self::$main_domain = Db::getInstance()->getValue('SELECT domain
FROM '._DB_PREFIX_.'shop_url
WHERE main=1 AND id_shop='.(int)Shop::getCurrentShop());
WHERE main=1 AND id_shop='.Context::getContext()->shop->getID());
return self::$main_domain_ssl;
}
}

View File

@@ -61,7 +61,7 @@ class ManufacturerControllerCore extends FrontController
{
if (Configuration::get('PS_DISPLAY_SUPPLIERS'))
{
$id_current_group_shop = (int)Shop::getCurrentGroupShop();
$id_current_group_shop = Context::getContext()->shop->getGroupID();
$data = call_user_func(array('Manufacturer', 'getManufacturers'), true, (int)self::$cookie->id_lang, true, false, false, false, $id_current_group_shop);
$nbProducts = count($data);
$this->pagination($nbProducts);

View File

@@ -75,7 +75,7 @@ class SearchControllerCore extends FrontController
$this->productSort();
$this->n = abs((int)(Tools::getValue('n', Configuration::get('PS_PRODUCTS_PER_PAGE'))));
$this->p = abs((int)(Tools::getValue('p', 1)));
$search = Search::find((int)(self::$cookie->id_lang), $query, $this->p, $this->n, $this->orderBy, $this->orderWay, false, true, (int)$this->id_current_shop);
$search = Search::find((int)(self::$cookie->id_lang), $query, false, $this->p, $this->n, $this->orderBy, $this->orderWay, true, (int)$this->id_current_shop);
Module::hookExec('search', array('expr' => $query, 'total' => $search['total']));
$nbProducts = $search['total'];
$this->pagination($nbProducts);
@@ -90,7 +90,7 @@ class SearchControllerCore extends FrontController
{
$nbProducts = (int)(Search::searchTag((int)(self::$cookie->id_lang), $tag, true));
$this->pagination($nbProducts);
$result = Search::searchTag((int)(self::$cookie->id_lang), $tag, false, $this->p, $this->n, $this->orderBy, $this->orderWay, false, true, (int)$this->id_current_shop);
$result = Search::searchTag((int)(self::$cookie->id_lang), $tag, false, $this->p, $this->n, $this->orderBy, $this->orderWay, true, (int)$this->id_current_shop);
Module::hookExec('search', array('expr' => $tag, 'total' => sizeof($result)));
$this->smarty->assign(array(
'search_tag' => $tag,

View File

@@ -140,8 +140,7 @@ class BlockCategories extends Module
public function hookLeftColumn($params)
{
global $smarty, $cookie;
$context = Context::getContext();
$id_current_shop = $this->shopID;
$id_customer = (int)($params['cookie']->id_customer);
@@ -185,35 +184,35 @@ class BlockCategories extends Module
unset($resultIds);
//TODO clean that
$res = $blockCategTree;
$shopcurrentroot = Shop::getCurrentRootCategory();
if($blockCategTree['id'] != Shop::getCurrentRootCategory())
$shopcurrentroot = $context->shop->id_category;
if ($blockCategTree['id'] != $shopcurrentroot)
$blockCategTree = $this->cleanTree($blockCategTree['children']);
$isDhtml = (Configuration::get('BLOCK_CATEG_DHTML') == 1 ? true : false);
if (Tools::isSubmit('id_category'))
{
$cookie->last_visited_category = $id_category;
$smarty->assign('currentCategoryId', $cookie->last_visited_category);
$context->cookie->last_visited_category = $id_category;
$context->controller->smarty->assign('currentCategoryId', $context->cookie->last_visited_category);
}
if (Tools::isSubmit('id_product'))
{
if (!isset($cookie->last_visited_category) OR !Product::idIsOnCategoryId($id_product, array('0' => array('id_category' => $cookie->last_visited_category))))
if (!isset($context->cookie->last_visited_category) OR !Product::idIsOnCategoryId($id_product, array('0' => array('id_category' => $context->cookie->last_visited_category))))
{
$product = new Product($id_product);
if (isset($product) AND Validate::isLoadedObject($product))
$cookie->last_visited_category = (int)($product->id_category_default);
$context->cookie->last_visited_category = (int)($product->id_category_default);
}
$smarty->assign('currentCategoryId', (int)($cookie->last_visited_category));
$context->controller->smarty->assign('currentCategoryId', (int)($context->cookie->last_visited_category));
}
$smarty->assign('blockCategTree', $blockCategTree);
$context->controller->smarty->assign('blockCategTree', $blockCategTree);
if (file_exists(_PS_THEME_DIR_.'modules/blockcategories/blockcategories.tpl'))
$smarty->assign('branche_tpl_path', _PS_THEME_DIR_.'modules/blockcategories/category-tree-branch.tpl');
$context->controller->smarty->assign('branche_tpl_path', _PS_THEME_DIR_.'modules/blockcategories/category-tree-branch.tpl');
else
$smarty->assign('branche_tpl_path', _PS_MODULE_DIR_.'blockcategories/category-tree-branch.tpl');
$smarty->assign('isDhtml', $isDhtml);
$context->controller->smarty->assign('branche_tpl_path', _PS_MODULE_DIR_.'blockcategories/category-tree-branch.tpl');
$context->controller->smarty->assign('isDhtml', $isDhtml);
}
$smarty->cache_lifetime = 31536000; // 1 Year
$context->controller->smarty->cache_lifetime = 31536000; // 1 Year
$display = $this->display(__FILE__, 'blockcategories.tpl', $smartyCacheId);
Tools::restoreCacheSettings();
return $display;
@@ -221,8 +220,7 @@ class BlockCategories extends Module
public function hookFooter($params)
{
global $smarty, $cookie;
$context = Context::getContext();
$id_current_shop = $this->shopID;
$id_customer = (int)($params['cookie']->id_customer);
@@ -262,43 +260,43 @@ class BlockCategories extends Module
$nbrColumns=3;
$numberColumn = abs(sizeof($result)/$nbrColumns);
$widthColumn= floor(100/$nbrColumns);
$smarty->assign('numberColumn', $numberColumn);
$smarty->assign('widthColumn', $widthColumn);
$context->controller->smarty->assign('numberColumn', $numberColumn);
$context->controller->smarty->assign('widthColumn', $widthColumn);
$blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH'));
unset($resultParents);
unset($resultIds);
//TODO clean that
$res = $blockCategTree;
if($blockCategTree['id'] != Shop::getCurrentRootCategory())
if($blockCategTree['id'] != $context->shop->id_category)
$blockCategTree = $this->cleanTree($blockCategTree['children']);
$isDhtml = (Configuration::get('BLOCK_CATEG_DHTML') == 1 ? true : false);
$isDhtml = (Configuration::get('BLOCK_CATEG_DHTML') == 1 ? true : false);
if (Tools::isSubmit('id_category'))
{
$cookie->last_visited_category = $id_category;
$smarty->assign('currentCategoryId', $cookie->last_visited_category);
$context->cookie->last_visited_category = $id_category;
$context->controller->smarty->assign('currentCategoryId', $context->cookie->last_visited_category);
}
if (Tools::isSubmit('id_product'))
{
if (!isset($cookie->last_visited_category) OR !Product::idIsOnCategoryId($id_product, array('0' => array('id_category' => $cookie->last_visited_category))))
if (!isset($context->cookie->last_visited_category) OR !Product::idIsOnCategoryId($id_product, array('0' => array('id_category' => $context->cookie->last_visited_category))))
{
$product = new Product($id_product);
if (isset($product) AND Validate::isLoadedObject($product))
$cookie->last_visited_category = (int)($product->id_category_default);
$context->cookie->last_visited_category = (int)($product->id_category_default);
}
$smarty->assign('currentCategoryId', (int)($cookie->last_visited_category));
$context->controller->smarty->assign('currentCategoryId', (int)($context->cookie->last_visited_category));
}
$smarty->assign('blockCategTree', $blockCategTree);
$context->controller->smarty->assign('blockCategTree', $blockCategTree);
if (file_exists(_PS_THEME_DIR_.'modules/blockcategories/blockcategories_footer.tpl'))
$smarty->assign('branche_tpl_path', _PS_THEME_DIR_.'modules/blockcategories/category-tree-branch.tpl');
$context->controller->smarty->assign('branche_tpl_path', _PS_THEME_DIR_.'modules/blockcategories/category-tree-branch.tpl');
else
$smarty->assign('branche_tpl_path', _PS_MODULE_DIR_.'blockcategories/category-tree-branch.tpl');
$smarty->assign('isDhtml', $isDhtml);
$context->controller->smarty->assign('branche_tpl_path', _PS_MODULE_DIR_.'blockcategories/category-tree-branch.tpl');
$context->controller->smarty->assign('isDhtml', $isDhtml);
}
$smarty->cache_lifetime = 31536000; // 1 Year
$context->controller->smarty->cache_lifetime = 31536000; // 1 Year
$display = $this->display(__FILE__, 'blockcategories_footer.tpl', $smartyCacheId);
Tools::restoreCacheSettings();
return $display;
@@ -306,7 +304,7 @@ class BlockCategories extends Module
public function cleanTree($categories)
{
$id_category_root = (int)Shop::getCurrentRootCategory();
$id_category_root = Context::getContext()->shop->id_category;
foreach ($categories AS $row)
{
if ($row['id'] == $id_category_root)

View File

@@ -283,10 +283,10 @@ class BlockLayered extends Module
public function getProductByFilters($selectedFilters = array())
{
global $cookie;
if (!empty($this->products))
return $this->products;
$context = Context::getContext();
/* If the current category isn't defined of if it's homepage, we have nothing to display */
$id_parent = (int)Tools::getValue('id_category', Tools::getValue('id_category_layered', 1));
@@ -387,15 +387,14 @@ class BlockLayered extends Module
p.ean13, pl.available_later, pl.description_short, pl.link_rewrite, pl.name, i.id_image, il.legend, m.name manufacturer_name, p.condition, p.id_manufacturer, s.quantity,
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 AS new
FROM '._DB_PREFIX_.'product p
LEFT JOIN '._DB_PREFIX_.'product_shop ps ON ps.id_product = p.id_product
LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = p.id_product AND pl.id_shop = '.Shop::getCurrentShop(true).')
LEFT JOIN '._DB_PREFIX_.'product_shop ps ON ps.id_product = p.id_product AND ps.id_shop = '.$this->shopID.'
LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = p.id_product AND pl.id_shop = '.$this->shopID.')
LEFT JOIN '._DB_PREFIX_.'stock s ON s.id_product = p.id_product AND s.id_product_attribute = 0 '.Shop::sqlSharedStock('s').'
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)($cookie->id_lang).')
LEFT JOIN '._DB_PREFIX_.'image_lang il ON (i.id_image = il.id_image AND il.id_lang = '.(int)$context->language->id.')
LEFT JOIN '._DB_PREFIX_.'manufacturer m ON (m.id_manufacturer = p.id_manufacturer)
WHERE p.`active` = 1
AND pl.id_lang = '.(int)$cookie->id_lang.'
AND ps.id_shop = '.Shop::getCurrentShop(true)
AND pl.id_lang = '.(int)$context->language->id
.$queryFilters.
' ORDER BY '.Tools::getProductsOrder('by', Tools::getValue('orderby')).' '.Tools::getProductsOrder('way', Tools::getValue('orderway')).
' LIMIT '.(((int)(Tools::getValue('p', 1)) - 1) * $n.','.$n);

View File

@@ -144,13 +144,15 @@ function submitConfirm()
function submitAccount()
{
global $cookie, $errors, $smarty;
global $errors;
$context = Context::getContext();
$email = Tools::getValue('email');
if (empty($email) OR !Validate::isEmail($email))
$errors[] = Tools::displayError('e-mail not valid');
elseif (!Validate::isPasswd(Tools::getValue('passwd')))
$errors[] = Tools::displayError('invalid password');
elseif (Customer::customerExists($email, false, true, (int)Shop::getCurrentGroupShop(), (int)Shop::getCurrentShop()))
elseif (Customer::customerExists($email))
$errors[] = Tools::displayError('someone has already registered with this e-mail address');
elseif (!@checkdate(Tools::getValue('months'), Tools::getValue('days'), Tools::getValue('years')) AND !(Tools::getValue('months') == '' AND Tools::getValue('days') == '' AND Tools::getValue('years') == ''))
$errors[] = Tools::displayError('invalid birthday');
@@ -180,15 +182,15 @@ function submitAccount()
$errors[] = Tools::displayError('an error occurred while creating your address');
else
{
if (Mail::Send((int)($cookie->id_lang), 'account', Mail::l('Welcome!'),
if (Mail::Send($context->language->id, 'account', Mail::l('Welcome!'),
array('{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{email}' => $customer->email, '{passwd}' => Tools::getValue('passwd')), $customer->email, $customer->firstname.' '.$customer->lastname))
$smarty->assign('confirmation', 1);
$cookie->id_customer = (int)($customer->id);
$cookie->customer_lastname = $customer->lastname;
$cookie->customer_firstname = $customer->firstname;
$cookie->passwd = $customer->passwd;
$cookie->logged = 1;
$cookie->email = $customer->email;
$context->controller->smarty->assign('confirmation', 1);
$context->cookie->id_customer = (int)($customer->id);
$context->cookie->customer_lastname = $customer->lastname;
$context->cookie->customer_firstname = $customer->firstname;
$context->cookie->passwd = $customer->passwd;
$context->cookie->logged = 1;
$context->cookie->email = $customer->email;
Module::hookExec('createAccount', array(
'_POST' => $_POST,
'newCustomer' => $customer
@@ -205,7 +207,7 @@ function submitAccount()
function submitLogin()
{
global $cookie, $errors;
global $errors;
$passwd = trim(Tools::getValue('passwd'));
$email = trim(Tools::getValue('email'));
@@ -222,21 +224,21 @@ function submitLogin()
else
{
$customer = new Customer();
$authentication = $customer->getByemail(trim($email), trim($passwd), (int)Shop::getCurrentGroupShop(), (int)Shop::getCurrentShop());
$authentication = $customer->getByemail(trim($email), trim($passwd));
/* Handle brute force attacks */
sleep(1);
if (!$authentication OR !$customer->id)
$errors[] = Tools::displayError('authentication failed');
else
{
$cookie->id_customer = (int)($customer->id);
$cookie->customer_lastname = $customer->lastname;
$cookie->customer_firstname = $customer->firstname;
$cookie->logged = 1;
$cookie->passwd = $customer->passwd;
$cookie->email = $customer->email;
if (Configuration::get('PS_CART_FOLLOWING') AND (empty($cookie->id_cart) OR Cart::getNbProducts($cookie->id_cart) == 0))
$cookie->id_cart = Cart::lastNoneOrderedCart($customer->id);
$context->cookie->id_customer = (int)($customer->id);
$context->cookie->customer_lastname = $customer->lastname;
$context->cookie->customer_firstname = $customer->firstname;
$context->cookie->logged = 1;
$context->cookie->passwd = $customer->passwd;
$context->cookie->email = $customer->email;
if (Configuration::get('PS_CART_FOLLOWING') AND (empty($context->cookie->id_cart) OR Cart::getNbProducts($context->cookie->id_cart) == 0))
$context->cookie->id_cart = Cart::lastNoneOrderedCart($customer->id);
Module::hookExec('authentication');
// Next !
@@ -383,7 +385,7 @@ else
unset($cookie->paypal_token);
Tools::redirect('modules/paypal/express/submit.php');
}
if (Customer::customerExists($email, false, true, (int)Shop::getCurrentGroupShop(), (int)Shop::getCurrentShop()) OR Tools::isSubmit('submitLogin'))
if (Customer::customerExists($email) OR Tools::isSubmit('submitLogin'))
displayLogin();
displayAccount();
}