// Context part 2

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@7598 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
tDidierjean
2011-07-12 12:50:00 +00:00
parent 39d0acc30b
commit 25b1bceffd
21 changed files with 221 additions and 230 deletions
+1
View File
@@ -95,4 +95,5 @@ else
$context->cookie = $cookie;
$context->link = $link;
$context->language = $language;
$context->country = new Country(Configuration::get('PS_COUNTRY_DEFAULT'));
}
+25 -22
View File
@@ -36,7 +36,8 @@ class AdminProducts extends AdminTab
public function __construct()
{
global $currentIndex;
$context = Context::getContext();
$this->table = 'product';
$this->className = 'Product';
$this->lang = true;
@@ -63,7 +64,7 @@ class AdminProducts extends AdminTab
LEFT JOIN '._DB_PREFIX_.'stock stock ON stock.id_product = a.id_product AND stock.id_product_attribute = 0 '.Shop::sqlSharedStock('stock').'
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = a.`id_product` AND i.`cover` = 1)
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_product` = a.`id_product`)
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (a.`id_tax_rules_group` = tr.`id_tax_rules_group` AND tr.`id_country` = '.(int)Country::getDefaultCountryId().' AND tr.`id_state` = 0)
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (a.`id_tax_rules_group` = tr.`id_tax_rules_group` AND tr.`id_country` = '.(int)$context->country->id.' AND tr.`id_state` = 0)
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)';
$this->_filter = 'AND cp.`id_category` = '.(int)($this->_category->id);
$this->_select = 'cp.`position`, i.`id_image`, (a.`price` * ((100 + (t.`rate`))/100)) AS price_final, stock.quantity AS quantity';
@@ -1017,6 +1018,8 @@ class AdminProducts extends AdminTab
throw new Exception(Tools::displayError('Image format not recognized, allowed formats are: .gif, .jpg, .png'));
}
if (!$image->createImgFolder())
throw new Exception(Tools::displayError('An error occurred during new folder creation'));
if (!imageResize($subdir.$file, _PS_PROD_IMG_DIR_.$image->getImgPath().'.jpg'))
{
$image->delete();
@@ -1662,13 +1665,13 @@ class AdminProducts extends AdminTab
protected function _displaySpecificPriceModificationForm($defaultCurrency, $shops, $currencies, $countries, $groups)
{
global $currentIndex;
$context = Context::getContext();
if (!($obj = $this->loadObject()))
return;
$specificPrices = SpecificPrice::getByProductId((int)($obj->id));
$specificPricePriorities = SpecificPrice::getPriority((int)($obj->id));
$default_country = new Country((int)Configuration::get('PS_COUNTRY_DEFAULT'));
$taxRate = TaxRulesGroup::getTaxesRate($obj->id_tax_rules_group, Configuration::get('PS_COUNTRY_DEFAULT'), 0, 0);
$taxRate = TaxRulesGroup::getTaxesRate($obj->id_tax_rules_group, $context->country->id, 0, 0);
$tmp = array();
foreach ($shops as $shop)
@@ -1699,11 +1702,11 @@ class AdminProducts extends AdminTab
<th class="cell border" style="width: 12%;">'.$this->l('Currency').'</th>
<th class="cell border" style="width: 11%;">'.$this->l('Country').'</th>
<th class="cell border" style="width: 13%;">'.$this->l('Group').'</th>
<th class="cell border" style="width: 12%;">'.$this->l('Price').' '.($default_country->display_tax_label ? $this->l('(tax excl.)') : '').'</th>
<th class="cell border" style="width: 12%;">'.$this->l('Price').' '.($context->country->display_tax_label ? $this->l('(tax excl.)') : '').'</th>
<th class="cell border" style="width: 10%;">'.$this->l('Reduction').'</th>
<th class="cell border" style="width: 15%;">'.$this->l('Period').'</th>
<th class="cell border" style="width: 10%;">'.$this->l('From (quantity)').'</th>
<th class="cell border" style="width: 15%;">'.$this->l('Final price').' '.($default_country->display_tax_label ? $this->l('(tax excl.)') : '').'</th>
<th class="cell border" style="width: 15%;">'.$this->l('Final price').' '.($context->country->display_tax_label ? $this->l('(tax excl.)') : '').'</th>
<th class="cell border" style="width: 2%;">'.$this->l('Action').'</th>
</tr>
</thead>
@@ -1818,8 +1821,7 @@ class AdminProducts extends AdminTab
{
if (!($product = $this->loadObject()))
return;
$default_country = new Country((int)Configuration::get('PS_COUNTRY_DEFAULT'));
$default_country = new Country((int)Configuration::get('PS_COUNTRY_DEFAULT'));
$context = Context::getContext();
echo '
<a href="#" onclick="$(\'#add_specific_price\').slideToggle();return false;"><img src="../img/admin/add.gif" alt="" /> '.$this->l('Add a new specific price').'</a>
@@ -1869,7 +1871,7 @@ class AdminProducts extends AdminTab
</div>
<label>'.$this->l('Product price');
if ($default_country->display_tax_label)
if ($context->country->display_tax_label)
echo ' '.$this->l('(tax excl.):');
echo '</label>
<div class="margin-form">
@@ -2102,9 +2104,9 @@ class AdminProducts extends AdminTab
{
parent::displayForm(false);
global $currentIndex, $cookie, $link;
$context = Context::getContext();
$default_country = new Country((int)Configuration::get('PS_COUNTRY_DEFAULT'));
$iso = Language::getIsoById((int)($cookie->id_lang));
$context->country->getIsoById((int)($cookie->id_lang));
$has_attribute = $obj->hasAttributes();
$qty = $obj->getStock();
$cover = Product::getCover($obj->id);
@@ -2525,7 +2527,7 @@ class AdminProducts extends AdminTab
</td>
</tr>';
$tax_rules_groups = TaxRulesGroup::getTaxRulesGroups(true);
$taxesRatesByGroup = TaxRulesGroup::getAssociatedTaxRatesByIdCountry(Country::getDefaultCountryId());
$taxesRatesByGroup = TaxRulesGroup::getAssociatedTaxRatesByIdCountry($context->country->id);
$ecotaxTaxRate = Tax::getProductEcotaxRate();
echo '<script type="text/javascript">';
echo 'noTax = '.(Tax::excludeTaxeOption() ? 'true' : 'false'), ";\n";
@@ -2575,7 +2577,7 @@ class AdminProducts extends AdminTab
</td>
</tr>';
if ($default_country->display_tax_label)
if ($context->country->display_tax_label)
{
echo '
<tr '.(Tax::excludeTaxeOption() ? 'style="display:none"' : '' ).'>
@@ -2592,7 +2594,7 @@ class AdminProducts extends AdminTab
<td class="col-left">'.$this->l('Unit price without tax:').'</td>
<td style="padding-bottom:5px;">
'.($currency->format % 2 != 0 ? ' '.$currency->sign : '').' <input size="11" maxlength="14" id="unit_price" name="unit_price" type="text" value="'.($this->getFieldValue($obj, 'unit_price_ratio') != 0 ? Tools::ps_round($this->getFieldValue($obj, 'price') / $this->getFieldValue($obj, 'unit_price_ratio'), 2) : 0).'" onkeyup="if (isArrowKey(event)) return ;this.value = this.value.replace(/,/g, \'.\'); unitPriceWithTax(\'unit\');"/>'.($currency->format % 2 == 0 ? ' '.$currency->sign : '').' '.$this->l('per').' <input size="6" maxlength="10" id="unity" name="unity" type="text" value="'.htmlentities($this->getFieldValue($obj, 'unity'), ENT_QUOTES, 'UTF-8').'" onkeyup="if (isArrowKey(event)) return ;unitySecond();" onchange="unitySecond();"/>'.
(Configuration::get('PS_TAX') && $default_country->display_tax_label ? '<span style="margin-left:15px">'.$this->l('or').' '.($currency->format % 2 != 0 ? ' '.$currency->sign : '').'<span id="unit_price_with_tax">0.00</span>'.($currency->format % 2 == 0 ? ' '.$currency->sign : '').' '.$this->l('per').' <span id="unity_second">'.$this->getFieldValue($obj, 'unity').'</span> '.$this->l('with tax') : '').'</span>
(Configuration::get('PS_TAX') && $context->country->display_tax_label ? '<span style="margin-left:15px">'.$this->l('or').' '.($currency->format % 2 != 0 ? ' '.$currency->sign : '').'<span id="unit_price_with_tax">0.00</span>'.($currency->format % 2 == 0 ? ' '.$currency->sign : '').' '.$this->l('per').' <span id="unity_second">'.$this->getFieldValue($obj, 'unity').'</span> '.$this->l('with tax') : '').'</span>
<p>'.$this->l('Eg. $15 per Lb').'</p>
</td>
</tr>
@@ -2605,15 +2607,15 @@ class AdminProducts extends AdminTab
<tr>
<td class="col-left"><b>'.$this->l('Final retail price:').'</b></td>
<td style="padding-bottom:5px;">
<span style="'.($default_country->display_tax_label ? '' : 'display:none').'">
<span style="'.($context->country->display_tax_label ? '' : 'display:none').'">
'.($currency->format % 2 != 0 ? $currency->sign.' ' : '').'<span id="finalPrice" style="font-weight: bold;"></span>'.($currency->format % 2 == 0 ? ' '.$currency->sign : '').'<span'.(!Configuration::get('PS_TAX') ? ' style="display:none;"' : '').'> ('.$this->l('tax incl.').')</span>
</span>
<span'.(!Configuration::get('PS_TAX') ? ' style="display:none;"' : '').'>';
if ($default_country->display_tax_label)
if ($context->country->display_tax_label)
echo ' / ';
echo ($currency->format % 2 != 0 ? $currency->sign.' ' : '').'<span id="finalPriceWithoutTax" style="font-weight: bold;"></span>'.($currency->format % 2 == 0 ? ' '.$currency->sign : '').' '.($default_country->display_tax_label ? '('.$this->l('tax excl.').')' : '').'</span>
echo ($currency->format % 2 != 0 ? $currency->sign.' ' : '').'<span id="finalPriceWithoutTax" style="font-weight: bold;"></span>'.($currency->format % 2 == 0 ? ' '.$currency->sign : '').' '.($context->country->display_tax_label ? '('.$this->l('tax excl.').')' : '').'</span>
</td>
</tr>
<tr>
@@ -2681,7 +2683,7 @@ class AdminProducts extends AdminTab
<td class="col-left">'.$this->l('Additional shipping cost:').'</td>
<td style="padding-bottom:5px;">
<input type="text" name="additional_shipping_cost" value="'.($this->getFieldValue($obj, 'additional_shipping_cost')).'" />'.($currency->format % 2 == 0 ? ' '.$currency->sign : '');
if ($default_country->display_tax_label)
if ($context->country->display_tax_label)
echo ' ('.$this->l('tax excl.').')';
echo '<p>'.$this->l('Carrier tax will be applied.').'</p>
@@ -3136,14 +3138,15 @@ class AdminProducts extends AdminTab
function displayFormAttributes($obj, $languages, $defaultLanguage)
{
global $currentIndex, $cookie;
$context = Context::getContext();
$attributeJs = array();
$attributes = Attribute::getAttributes((int)($cookie->id_lang), true);
foreach ($attributes AS $k => $attribute)
$attributeJs[$attribute['id_attribute_group']][$attribute['id_attribute']] = $attribute['name'];
$currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));
$attributes_groups = AttributeGroup::getAttributesGroups((int)($cookie->id_lang));
$default_country = new Country((int)Configuration::get('PS_COUNTRY_DEFAULT'));
$images = Image::getImages((int)($cookie->id_lang), $obj->id);
if ($obj->id)
@@ -3227,7 +3230,7 @@ class AdminProducts extends AdminTab
</select>
<span id="span_impact">&nbsp;&nbsp;'.$this->l('of').'&nbsp;&nbsp;'.($currency->format % 2 != 0 ? $currency->sign.' ' : '').'
<input type="text" size="6" name="attribute_price" id="attribute_price" value="0.00" onKeyUp="if (isArrowKey(event)) return ;this.value = this.value.replace(/,/g, \'.\'); calcImpactPriceTI();"/>'.($currency->format % 2 == 0 ? ' '.$currency->sign : '');
if ($default_country->display_tax_label)
if ($context->country->display_tax_label)
{
echo ' '.$this->l('(tax excl.)').'<span '.(Tax::excludeTaxeOption() ? 'style="display:none"' : '' ).'> '.$this->l('or').' '.($currency->format % 2 != 0 ? $currency->sign.' ' : '').'
<input type="text" size="6" name="attribute_priceTI" id="attribute_priceTI" value="0.00" onKeyUp="if (isArrowKey(event)) return ;this.value = this.value.replace(/,/g, \'.\'); calcImpactPriceTE();"/>'.($currency->format % 2 == 0 ? ' '.$currency->sign : '').' '.$this->l('(tax incl.)').'</span> '.$this->l('final product price will be set to').' '.($currency->format % 2 != 0 ? $currency->sign.' ' : '').'<span id="attribute_new_total_price">0.00</span>'.($currency->format % 2 == 0 ? $currency->sign.' ' : '');
+5 -5
View File
@@ -235,10 +235,10 @@ class AddressFormatCore extends ObjectModel
* @addressFormat is the format
* @return double Array
*/
public static function getFormattedAddressFieldsValues($address, $addressFormat)
public static function getFormattedAddressFieldsValues($address, $addressFormat, $context = null)
{
global $cookie;
if (!$context)
$context = Context::getContext();
$tab = array();
$temporyObject = array();
@@ -268,8 +268,8 @@ class AddressFormatCore extends ObjectModel
$temporyObject[$associateName[0]] = new $associateName[0]($address->{$idFieldName});
if ($temporyObject[$associateName[0]])
$tab[$pattern] = (is_array($temporyObject[$associateName[0]]->{$associateName[1]})) ?
((isset($temporyObject[$associateName[0]]->{$associateName[1]}[(isset($cookie) ? $cookie->id_lang : Configuration::get('PS_LANG_DEFAULT'))])) ?
$temporyObject[$associateName[0]]->{$associateName[1]}[(isset($cookie) ? $cookie->id_lang : Configuration::get('PS_LANG_DEFAULT'))] : '') :
((isset($temporyObject[$associateName[0]]->{$associateName[1]}[$context->language->id])) ?
$temporyObject[$associateName[0]]->{$associateName[1]}[$context->language->id] : '') :
$temporyObject[$associateName[0]]->{$associateName[1]};
}
}
+13 -17
View File
@@ -145,13 +145,13 @@ class CMSCategoryCore extends ObjectModel
*
* @return array Subcategories lite tree
*/
function recurseLiteCategTree($maxDepth = 3, $currentDepth = 0, $idLang = NULL, $excludedIdsArray = NULL)
function recurseLiteCategTree($maxDepth = 3, $currentDepth = 0, $idLang = NULL, $excludedIdsArray = NULL, $context = null)
{
global $link;
if (!$context)
$context = Context::getContext();
//get idLang
$idLang = is_null($idLang) ? _USER_ID_LANG_ : (int)($idLang);
$idLang = is_null($idLang) ? $context->language->id : (int)($idLang);
//recursivity for subcategories
$children = array();
if (($maxDepth == 0 OR $currentDepth < $maxDepth) AND $subcats = $this->getSubCategories($idLang, true) AND sizeof($subcats))
@@ -167,10 +167,9 @@ class CMSCategoryCore extends ObjectModel
}
}
return array(
'id' => $this->id_cms_category,
'link' => $link->getCMSCategoryLink($this->id, $this->link_rewrite),
'link' => $context->link->getCMSCategoryLink($this->id, $this->link_rewrite),
'name' => $this->name,
'desc'=> $this->description,
'children' => $children
@@ -215,7 +214,6 @@ class CMSCategoryCore extends ObjectModel
static public function recurseCMSCategory($categories, $current, $id_cms_category = 1, $id_selected = 1, $is_html = 0)
{
global $currentIndex;
$html = '<option value="'.$id_cms_category.'"'.(($id_selected == $id_cms_category) ? ' selected="selected"' : '').'>'.
str_repeat('&nbsp;', $current['infos']['level_depth'] * 5).self::hideCMSCategoryPosition(stripslashes($current['infos']['name'])).'</option>';
if ($is_html == 0)
@@ -359,7 +357,6 @@ class CMSCategoryCore extends ObjectModel
*/
public function getSubCategories($id_lang, $active = true)
{
global $cookie;
if (!Validate::isBool($active))
die(Tools::displayError());
@@ -477,20 +474,19 @@ class CMSCategoryCore extends ObjectModel
return $result['link_rewrite'];
}
public function getLink()
public function getLink($context = null)
{
global $link;
return $link->getCMSCategoryLink($this->id, $this->link_rewrite);
if (!$context)
$context = Context::getContext();
return $context->link->getCMSCategoryLink($this->id, $this->link_rewrite);
}
public function getName($id_lang = NULL)
public function getName($id_lang = NULL, $context = null)
{
if (!$id_lang)
{
global $cookie;
if (isset($this->name[$cookie->id_lang]))
$id_lang = $cookie->id_lang;
if (isset($this->name[$context->language->id]))
$id_lang = $context->language->id;
else
$id_lang = (int)(Configuration::get('PS_LANG_DEFAULT'));
}
+9 -9
View File
@@ -388,14 +388,14 @@ class CarrierCore extends ObjectModel
return $carriers;
}
public static function getCarriersForOrder($id_zone, $groups = NULL)
public static function getCarriersForOrder($id_zone, $groups = NULL, $context = null)
{
global $cookie, $cart;
if (!$context)
$context = Context::getContext();
if (is_array($groups) AND !empty($groups))
$result = Carrier::getCarriers((int)$cookie->id_lang, true, false, (int)$id_zone, $groups, PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE);
$result = Carrier::getCarriers((int)$context->language->id, true, false, (int)$id_zone, $groups, PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE);
else
$result = Carrier::getCarriers((int)$cookie->id_lang, true, false, (int)$id_zone, array(1), PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE);
$result = Carrier::getCarriers((int)$context->language->id, true, false, (int)$id_zone, array(1), PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE);
$resultsArray = array();
foreach ($result AS $k => $row)
@@ -420,8 +420,8 @@ class CarrierCore extends ObjectModel
$id_zone = (int)$defaultCountry->id_zone;
// Get only carriers that have a range compatible with cart
if (($shippingMethod == Carrier::SHIPPING_METHOD_WEIGHT AND (!Carrier::checkDeliveryPriceByWeight($row['id_carrier'], $cart->getTotalWeight(), $id_zone)))
OR ($shippingMethod == Carrier::SHIPPING_METHOD_PRICE AND (!Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $cart->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING), $id_zone, $cart->id_currency))))
if (($shippingMethod == Carrier::SHIPPING_METHOD_WEIGHT AND (!Carrier::checkDeliveryPriceByWeight($row['id_carrier'], $context->cart->getTotalWeight(), $id_zone)))
OR ($shippingMethod == Carrier::SHIPPING_METHOD_PRICE AND (!Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $context->cart->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING), $id_zone, $context->currency->id))))
{
unset($result[$k]);
continue ;
@@ -430,8 +430,8 @@ class CarrierCore extends ObjectModel
}
$row['name'] = (strval($row['name']) != '0' ? $row['name'] : Configuration::get('PS_SHOP_NAME'));
$row['price'] = ($shippingMethod == Carrier::SHIPPING_METHOD_FREE ? 0 : $cart->getOrderShippingCost((int)$row['id_carrier']));
$row['price_tax_exc'] = ($shippingMethod == Carrier::SHIPPING_METHOD_FREE ? 0 : $cart->getOrderShippingCost((int)$row['id_carrier'], false));
$row['price'] = ($shippingMethod == Carrier::SHIPPING_METHOD_FREE ? 0 : $context->cart->getOrderShippingCost((int)$row['id_carrier']));
$row['price_tax_exc'] = ($shippingMethod == Carrier::SHIPPING_METHOD_FREE ? 0 : $context->cart->getOrderShippingCost((int)$row['id_carrier'], false));
$row['img'] = file_exists(_PS_SHIP_IMG_DIR_.(int)($row['id_carrier']).'.jpg') ? _THEME_SHIP_DIR_.(int)($row['id_carrier']).'.jpg' : '';
// If price is false, then the carrier is unavailable (carrier module)
+49 -38
View File
@@ -333,13 +333,17 @@ class CartCore extends ObjectModel
*
* @result array Products
*/
public function getProducts($refresh = false, $id_product = false)
public function getProducts($refresh = false, $id_product = false, $context = null)
{
if (!$this->id)
return array();
// Product cache must be strictly compared to NULL, or else an empty cart will add dozens of queries
if ($this->_products !== NULL AND !$refresh)
return $this->_products;
if (!$context)
$context = Context::getContext();
$sql = '
SELECT cp.`id_product_attribute`, cp.`id_product`, cu.`id_customization`, cp.`quantity` AS cart_quantity, cu.`quantity` AS customization_quantity, pl.`name`,
pl.`description_short`, pl.`available_now`, pl.`available_later`, p.`id_product`, p.`id_category_default`, p.`id_supplier`, p.`id_manufacturer`, p.`on_sale`, p.`ecotax`, p.`additional_shipping_cost`, p.`available_for_order`,
@@ -356,7 +360,7 @@ class CartCore extends ObjectModel
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$this->id_lang.')
LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (pa.`id_product_attribute` = cp.`id_product_attribute`)
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group`
AND tr.`id_country` = '.(int)Country::getDefaultCountryId().'
AND tr.`id_country` = '.(int)$context->country->id.'
AND tr.`id_state` = 0)
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)
LEFT JOIN `'._DB_PREFIX_.'tax_lang` tl ON (t.`id_tax` = tl.`id_tax` AND tl.`id_lang` = '.(int)$this->id_lang.')
@@ -640,13 +644,13 @@ class CartCore extends ObjectModel
/*
** Customization management
*/
protected function _updateCustomizationQuantity($quantity, $id_customization, $id_product, $id_product_attribute, $operator = 'up')
protected function _updateCustomizationQuantity($quantity, $id_customization, $id_product, $id_product_attribute, $operator = 'up', $context = null)
{
global $cookie;
if (!$context)
$context = Context::getContext();
/* Getting datas */
$files = $cookie->getFamily('pictures_'.(int)($id_product).'_');
$textFields = $cookie->getFamily('textFields_'.(int)($id_product).'_');
$files = $context->cookie->getFamily('pictures_'.(int)($id_product).'_');
$textFields = $context->cookie->getFamily('textFields_'.(int)($id_product).'_');
/* Customization addition */
if (count($files) > 0 OR count($textFields) > 0)
return $this->_addCustomization((int)$id_product, (int)$id_product_attribute, $files, $textFields, (int)$quantity);
@@ -973,10 +977,10 @@ class CartCore extends ObjectModel
* @param integer $id_carrier Carrier ID (default : current carrier)
* @return float Shipping total
*/
function getOrderShippingCost($id_carrier = NULL, $useTax = true)
function getOrderShippingCost($id_carrier = NULL, $useTax = true, $context = null)
{
global $defaultCountry;
if (!$context)
$context = Context::getContext();
if ($this->isVirtualCart())
return 0;
@@ -1022,6 +1026,7 @@ class CartCore extends ObjectModel
else
{
// This method can be called from the backend, and $defaultCountry won't be defined
$defaultCountry = $context->country;
if (!Validate::isLoadedObject($defaultCountry))
$defaultCountry = new Country(Configuration::get('PS_COUNTRY_DEFAULT'), Configuration::get('PS_LANG_DEFAULT'));
$id_zone = (int)$defaultCountry->id_zone;
@@ -1228,10 +1233,10 @@ class CartCore extends ObjectModel
*
* @return mixed Return a string if an error occurred and false otherwise
*/
function checkDiscountValidity($discountObj, $discounts, $order_total, $products, $checkCartDiscount = false, $id_group_shop = false, $id_shop = false)
function checkDiscountValidity($discountObj, $discounts, $order_total, $products, $checkCartDiscount = false, $id_group_shop = false, $id_shop = false, $context = null)
{
global $cookie;
if (!$context)
$context = Context::getContext();
if (!$order_total)
return Tools::displayError('Cannot add voucher if order is free.');
if (!$discountObj->active)
@@ -1244,7 +1249,7 @@ class CartCore extends ObjectModel
if ($checkCartDiscount
AND (
$this->getDiscountsCustomer($discountObj->id) >= $discountObj->quantity_per_user
OR (Order::getDiscountsCustomer((int)($cookie->id_customer), $discountObj->id) + $this->getDiscountsCustomer($discountObj->id) >= $discountObj->quantity_per_user) >= $discountObj->quantity_per_user
OR (Order::getDiscountsCustomer((int)($context->customer->id), $discountObj->id) + $this->getDiscountsCustomer($discountObj->id) >= $discountObj->quantity_per_user) >= $discountObj->quantity_per_user
)
)
return Tools::displayError('You cannot use this voucher anymore (usage limit attained).');
@@ -1272,7 +1277,7 @@ class CartCore extends ObjectModel
if (($discountObj->id_customer OR $discountObj->id_group) AND ($this->id_customer != $discountObj->id_customer AND !in_array($discountObj->id_group, $groups)))
{
if (!$cookie->isLogged())
if (!$context->cookie->isLogged())
return Tools::displayError('You cannot use this voucher.').' - '.Tools::displayError('Please log in.');
return Tools::displayError('You cannot use this voucher.');
}
@@ -1329,9 +1334,10 @@ class CartCore extends ObjectModel
*
* @return array Cart details
*/
function getSummaryDetails()
function getSummaryDetails($context = null)
{
global $cookie;
if (!$context)
$context = Context::getContext();
$delivery = new Address((int)($this->id_address_delivery));
$invoice = new Address((int)($this->id_address_invoice));
@@ -1359,7 +1365,7 @@ class CartCore extends ObjectModel
'delivery_state' => State::getNameById($delivery->id_state),
'invoice' => $invoice,
'invoice_state' => State::getNameById($invoice->id_state),
'carrier' => new Carrier((int)($this->id_carrier), $cookie->id_lang),
'carrier' => new Carrier($this->id_carrier, $context->language->id),
'products' => $this->getProducts(false),
'discounts' => $this->getDiscounts(false, true),
'is_virtual_cart' => (int)$this->isVirtualCart(),
@@ -1480,17 +1486,18 @@ class CartCore extends ObjectModel
*
* @return bool Always true
*/
public function addPictureToProduct($id_product, $index, $identifier)
public function addPictureToProduct($id_product, $index, $identifier, $context = null)
{
global $cookie;
if (!$context)
$context = Context::getContext();
$varName = 'pictures_'.(int)($id_product).'_'.(int)($index);
if ($cookie->$varName)
if ($context->cookie->$varName)
{
@unlink(_PS_UPLOAD_DIR_.$cookie->$varName);
@unlink(_PS_UPLOAD_DIR_.$cookie->$varName.'_small');
@unlink(_PS_UPLOAD_DIR_.$context->cookie->$varName);
@unlink(_PS_UPLOAD_DIR_.$context->cookie->$varName.'_small');
}
$cookie->$varName = $identifier;
$context->cookie->$varName = $identifier;
return true;
}
@@ -1499,13 +1506,14 @@ class CartCore extends ObjectModel
*
* @return bool Always true
*/
public function addTextFieldToProduct($id_product, $index, $textValue)
public function addTextFieldToProduct($id_product, $index, $textValue, $context = null)
{
global $cookie;
if (!$context)
$context = Context::getContext();
$textValue = str_replace(array("\n", "\r"), '', nl2br($textValue));
$textValue = str_replace('\\', '\\\\', $textValue);
$textValue = str_replace('\'', '\\\'', $textValue);
$cookie->{'textFields_'.(int)($id_product).'_'.(int)($index)} = $textValue;
$context->cookie->{'textFields_'.(int)($id_product).'_'.(int)($index)} = $textValue;
return true;
}
@@ -1514,11 +1522,12 @@ class CartCore extends ObjectModel
*
* @return bool Always true
*/
public function deleteTextFieldFromProduct($id_product, $index)
public function deleteTextFieldFromProduct($id_product, $index, $context = null)
{
global $cookie;
if (!$context)
$context = Context::getContext();
unset($cookie->{'textFields_'.(int)($id_product).'_'.(int)($index)});
unset($context->cookie->{'textFields_'.(int)($id_product).'_'.(int)($index)});
return true;
}
@@ -1527,29 +1536,31 @@ class CartCore extends ObjectModel
*
* @return bool
*/
public function deletePictureToProduct($id_product, $index)
public function deletePictureToProduct($id_product, $index, $context = null)
{
global $cookie;
if (!$context)
$context = Context::getContext();
$varName = 'pictures_'.(int)($id_product).'_'.(int)($index);
// if cookie->varName is empty, use index which is the name of the picture
$picture = !empty($cookie->$varName)?$cookie->$varName:$index;
$picture = !empty($context->cookie->$varName) ? $context->cookie->$varName : $index;
if ($picture)
{
if (!@unlink(_PS_UPLOAD_DIR_.$picture) OR !@unlink(_PS_UPLOAD_DIR_.$picture.'_small'))
return false;
unset($cookie->$varName);
unset($context->cookie->$varName);
return true;
}
return false;
}
static public function deleteCustomizationInformations($id_product)
static public function deleteCustomizationInformations($id_product, $context = null)
{
global $cookie;
if (!$context)
$context = Context::getContext();
$cookie->unsetFamily('pictures_'.(int)($id_product).'_');
$cookie->unsetFamily('textFields_'.(int)($id_product).'_');
$context->cookie->unsetFamily('pictures_'.(int)($id_product).'_');
$context->cookie->unsetFamily('textFields_'.(int)($id_product).'_');
return true;
}
+18 -17
View File
@@ -189,10 +189,10 @@ class CategoryCore extends ObjectModel
*
* @return array Subcategories lite tree
*/
function recurseLiteCategTree($maxDepth = 3, $currentDepth = 0, $idLang = NULL, $excludedIdsArray = NULL)
function recurseLiteCategTree($maxDepth = 3, $currentDepth = 0, $idLang = NULL, $excludedIdsArray = NULL, $context = null)
{
global $link;
if (!$context)
$context = Context::getContext();
$idLang = is_null($idLang) ? _USER_ID_LANG_ : (int)($idLang);
$children = array();
@@ -210,7 +210,7 @@ class CategoryCore extends ObjectModel
return array(
'id' => (int)$this->id_category,
'link' => $link->getCategoryLink((int)$this->id, $this->link_rewrite),
'link' => $context->link->getCategoryLink((int)$this->id, $this->link_rewrite),
'name' => $this->name,
'desc'=> $this->description,
'children' => $children
@@ -219,7 +219,6 @@ class CategoryCore extends ObjectModel
static public function recurseCategory($categories, $current, $id_category = 1, $id_selected = 1)
{
global $currentIndex;
echo '<option value="'.$id_category.'"'.(($id_selected == $id_category) ? ' selected="selected"' : '').'>'.
str_repeat('&nbsp;', $current['infos']['level_depth'] * 5).stripslashes($current['infos']['name']).'</option>';
if (isset($categories[$id_category]))
@@ -414,7 +413,6 @@ class CategoryCore extends ObjectModel
*/
public function getSubCategories($id_lang, $active = true)
{
global $cookie;
if (!Validate::isBool($active))
die(Tools::displayError());
@@ -453,10 +451,11 @@ class CategoryCore extends ObjectModel
* @param boolean $checkAccess set to false to return all products (even if customer hasn't access)
* @return mixed Products or number of products
*/
public function getProducts($id_lang, $p, $n, $orderBy = NULL, $orderWay = NULL, $getTotal = false, $active = true, $random = false, $randomNumberProducts = 1, $checkAccess = true, $id_shop = null)
public function getProducts($id_lang, $p, $n, $orderBy = NULL, $orderWay = NULL, $getTotal = false, $active = true, $random = false, $randomNumberProducts = 1, $checkAccess = true, $id_shop = null, $context = null)
{
global $cookie;
if (!$checkAccess OR !$this->checkAccess($cookie->id_customer))
if (!$context)
$context = Context::getContext();
if (!$checkAccess OR !$this->checkAccess($context->customer->id))
return false;
if (!$id_shop)
@@ -520,7 +519,7 @@ class CategoryCore extends ObjectModel
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group`
AND tr.`id_country` = '.(int)Country::getDefaultCountryId().'
AND tr.`id_country` = '.(int)$context->country->id.'
AND tr.`id_state` = 0)
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)
LEFT JOIN `'._DB_PREFIX_.'tax_lang` tl ON (t.`id_tax` = tl.`id_tax` AND tl.`id_lang` = '.(int)$id_lang.')
@@ -719,22 +718,24 @@ class CategoryCore extends ObjectModel
return $result['link_rewrite'];
}
public function getLink()
public function getLink($context = null)
{
global $link;
return $link->getCategoryLink($this->id, $this->link_rewrite);
if (!$context)
$context = Context::getContext();
return $context->link->getCategoryLink($this->id, $this->link_rewrite);
}
public function getName($id_lang = NULL, $id_shop = false)
public function getName($id_lang = NULL, $id_shop = false, $context = null)
{
if (!$id_shop)
$id_shop = (int)Shop::getCurrentShop(true);
if (!$id_lang)
{
global $cookie;
if (!$context)
$context = Context::getContext();
if (isset($this->name[(int)$id_shop][$cookie->id_lang]))
$id_lang = $cookie->id_lang;
if (isset($this->name[(int)$id_shop][$context->language->id]))
$id_lang = $context->language->id;
else
$id_lang = (int)(Configuration::get('PS_LANG_DEFAULT'));
}
+4 -4
View File
@@ -59,11 +59,11 @@ class ConnectionsSourceCore extends ObjectModel
return $result;
}
public static function logHttpReferer()
public static function logHttpReferer($context = null)
{
global $cookie;
if (!isset($cookie->id_connections) OR !Validate::isUnsignedId($cookie->id_connections))
if (!$context)
$context = Context::getContext();
if (!isset($context->cookie->id_connections) OR !Validate::isUnsignedId($context->cookie->id_connections))
return false;
if (!isset($_SERVER['HTTP_REFERER']) AND !Configuration::get('TRACKING_DIRECT_TRAFFIC'))
return false;
+25 -43
View File
@@ -1,4 +1,29 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision$
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class ContextCore
{
protected static $instance;
@@ -16,7 +41,6 @@ class ContextCore
/**
* Create a context without singleton constraint
* @param array $data
*/
public function __construct($cart = null,
$customer = null,
@@ -50,46 +74,4 @@ class ContextCore
self::$instance = new self();
return self::$instance;
}
public function setData($cart = null,
$customer = null,
$cookie = null,
$link = null,
$country = null,
$employee = null,
$lang = null,
$currency = null,
$tab = null)
{
$this->cart = $cart;
$this->customer = $customer;
$this->cookie = $cookie;
$this->link = $link;
$this->country = $country;
$this->employee = $employee;
$this->lang = $lang;
$this->currency = $currency;
$this->tab = $tab;
}
/*public function __get($var)
{
return (isset($this->data[$var]) ? $this->data[$var] : null);
}
public function __set($var, $value)
{
$this->data[$var] = $value;
}
public function __isset($var)
{
return isset($this->data[$var]);
}
public function __unset($var)
{
if (isset($this->data[$var]))
unset($this->data[$var]);
}*/
}
+3 -9
View File
@@ -280,21 +280,15 @@ class CountryCore extends ObjectModel
/**
* Returns the default country Id
*
* @deprecated use $context->country->id instead
* @return integer default country id
*/
public static function getDefaultCountryId()
{
global $cookie;
if (Configuration::get('PS_GEOLOCATION_ENABLED') AND Validate::isLanguageIsoCode($cookie->iso_code_country))
$id_country = (int)Country::getByIso($cookie->iso_code_country);
else
$id_country = (int)Configuration::get('PS_COUNTRY_DEFAULT');
return $id_country;
Tools::displayAsDeprecated();
return Context::getContext()->country->id;
}
public static function getCountriesByZoneId($id_zone, $id_lang, $id_shop = false)
{
if (empty($id_zone) OR empty($id_lang))
+8 -12
View File
@@ -67,8 +67,6 @@ class CurrencyCore extends ObjectModel
protected $table = 'currency';
protected $identifier = 'id_currency';
/** @var Currency Current currency */
static protected $current = NULL;
/** @var array Currency cache */
static protected $currencies = array();
@@ -353,18 +351,16 @@ class CurrencyCore extends ObjectModel
}
/**
* Get current currency
*
* @deprecated use $context->currency instead
* @return Currency
*/
static public function getCurrent()
{
global $cookie;
if (!self::$current)
{
if (isset($cookie->id_currency) AND $cookie->id_currency)
self::$current = new Currency((int)($cookie->id_currency));
else
self::$current = new Currency((int)(Configuration::get('PS_CURRENCY_DEFAULT')));
}
return self::$current;
Tools::displayAsDeprecated();
return Context::getContext()->currency;
}
static public function getCurrencyInstance($id)
+4 -2
View File
@@ -276,7 +276,7 @@ class DiscountCore extends ObjectModel
* @param boolean $order_total_products Total cart products amount
* @return mixed Return a float value or '!' if reduction is 'Shipping free'
*/
public function getValue($nb_discounts = 0, $order_total_products = 0, $shipping_fees = 0, $idCart = false, $useTax = true, $id_group_shop = false, $id_shop = false)
public function getValue($nb_discounts = 0, $order_total_products = 0, $shipping_fees = 0, $idCart = false, $useTax = true, $id_group_shop = false, $id_shop = false, $context = null)
{
$totalAmount = 0;
@@ -323,7 +323,9 @@ class DiscountCore extends ObjectModel
/* Absolute value */
case 2:
// An "absolute" voucher is available in one currency only
$currency = ((int)$cart->id_currency ? Currency::getCurrencyInstance($cart->id_currency) : Currency::getCurrent());
if (!$context)
$context = Context::getContext();
$currency = ((int)$cart->id_currency ? Currency::getCurrencyInstance($cart->id_currency) : $context->currency);
if ($this->id_currency != $currency->id)
return 0;
+12 -17
View File
@@ -96,9 +96,6 @@ class FrontControllerCore
}
ob_start();
/* Loading default country */
$defaultCountry = new Country((int)Configuration::get('PS_COUNTRY_DEFAULT'), Configuration::get('PS_LANG_DEFAULT'));
$cookie = new Cookie('ps');
@@ -111,8 +108,12 @@ class FrontControllerCore
elseif (basename($_SERVER['PHP_SELF']) != 'disabled.php' AND !(int)(Configuration::get('PS_SHOP_ENABLE')))
$this->maintenance = true;
elseif (Configuration::get('PS_GEOLOCATION_ENABLED'))
$this->geolocationManagement();
$defaultCountry = $this->geolocationManagement();
/* Loading default country */
if (!isset($defaultCountry) && Validate::isLoadedObject($defaultCountry))
$defaultCountry = new Country((int)Configuration::get('PS_COUNTRY_DEFAULT'), Configuration::get('PS_LANG_DEFAULT'));
// Switch language if needed and init cookie language
if ($iso = Tools::getValue('isolang') AND Validate::isLanguageIsoCode($iso) AND ($id_lang = (int)(Language::getIdByIso($iso))))
$_GET['id_lang'] = $id_lang;
@@ -135,7 +136,6 @@ class FrontControllerCore
Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : NULL);
}
global $currency;
$currency = Tools::setCurrency($cookie);
$_MODULES = array();
@@ -324,12 +324,9 @@ class FrontControllerCore
if (!is_dir(_PS_ROOT_DIR_.DIRECTORY_SEPARATOR.$ad))
die(Tools::displayError());
$this->iso = $iso;
$this->setMedia();
//$defaultCountry
if (isset($cookie->id_customer) && (int)$cookie->id_customer)
$customer = new Customer($cookie->id_customer);
else
@@ -350,6 +347,7 @@ class FrontControllerCore
$context->currency = $currency;
$context->controller = $this;
$context->language = $ps_language;
$context->country = $defaultCountry;
}
/* Display a maintenance page if shop is closed */
@@ -366,10 +364,8 @@ class FrontControllerCore
/* Display a specific page if the user country is not allowed */
protected function displayRestrictedCountryPage()
{
global $smarty;
header('HTTP/1.1 503 temporarily overloaded');
$smarty->display(_PS_THEME_DIR_.'restricted-country.tpl');
$this->smarty->display(_PS_THEME_DIR_.'restricted-country.tpl');
exit;
}
@@ -399,7 +395,7 @@ class FrontControllerCore
protected function geolocationManagement()
{
global $cookie, $smarty;
global $cookie;
if (!in_array($_SERVER['SERVER_NAME'], array('localhost', '127.0.0.1')))
{
@@ -419,7 +415,7 @@ class FrontControllerCore
if (Configuration::get('PS_GEOLOCATION_BEHAVIOR') == _PS_GEOLOCATION_NO_CATALOG_)
$this->restrictedCountry = true;
elseif (Configuration::get('PS_GEOLOCATION_BEHAVIOR') == _PS_GEOLOCATION_NO_ORDER_)
$smarty->assign(array(
$this->smarty->assign(array(
'restricted_country_mode' => true,
'geolocation_country' => $record->country_name
));
@@ -437,11 +433,12 @@ class FrontControllerCore
$defaultCountry = new Country($id_country);
if (isset($hasBeenSet) AND $hasBeenSet)
$cookie->id_currency = (int)(Currency::getCurrencyInstance($defaultCountry->id_currency ? (int)$defaultCountry->id_currency : Configuration::get('PS_CURRENCY_DEFAULT'))->id);
return $defaultCountry;
}
elseif (Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR') == _PS_GEOLOCATION_NO_CATALOG_)
$this->restrictedCountry = true;
elseif (Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR') == _PS_GEOLOCATION_NO_ORDER_)
$smarty->assign(array(
$this->smarty->assign(array(
'restricted_country_mode' => true,
'geolocation_country' => 'Undefined'
));
@@ -450,6 +447,7 @@ class FrontControllerCore
else
Configuration::updateValue('PS_GEOLOCATION_ENABLED', 0);
}
return false;
}
public function preProcess()
@@ -458,8 +456,6 @@ class FrontControllerCore
public function setMedia()
{
global $cookie;
$this->addCSS(_THEME_CSS_DIR_.'global.css', 'all');
$this->addJS(array(_PS_JS_DIR_.'jquery/jquery-1.4.4.min.js', _PS_JS_DIR_.'jquery/jquery.easing.1.3.js', _PS_JS_DIR_.'tools.js'));
if (Tools::isSubmit('live_edit') AND $ad = Tools::getValue('ad') AND (Tools::getValue('liveToken') == sha1(Tools::getValue('ad')._COOKIE_KEY_)))
@@ -526,7 +522,6 @@ class FrontControllerCore
public function displayFooter()
{
global $cookie;
if (!self::$initialized)
$this->init();
+4 -2
View File
@@ -273,8 +273,10 @@ class ManufacturerCore extends ObjectModel
return Tools::link_rewrite($this->name, false);
}
static public function getProducts($id_manufacturer, $id_lang, $p, $n, $orderBy = NULL, $orderWay = NULL, $getTotal = false, $active = true)
static public function getProducts($id_manufacturer, $id_lang, $p, $n, $orderBy = NULL, $orderWay = NULL, $getTotal = false, $active = true, $context = null)
{
if (!$context)
$context = Context::getContext();
if ($p < 1) $p = 1;
if (empty($orderBy) ||$orderBy == 'position') $orderBy = 'name';
if (empty($orderWay)) $orderWay = 'ASC';
@@ -311,7 +313,7 @@ class ManufacturerCore extends ObjectModel
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)($id_lang).')
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group`
AND tr.`id_country` = '.(int)Country::getDefaultCountryId().'
AND tr.`id_country` = '.(int)$context->country->id.'
AND tr.`id_state` = 0)
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)
LEFT JOIN `'._DB_PREFIX_.'tax_lang` tl ON (t.`id_tax` = tl.`id_tax` AND tl.`id_lang` = '.(int)($id_lang).')
+2 -2
View File
@@ -100,7 +100,7 @@ class PackCore extends Product
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_.'category_lang` cl ON (p.`id_category_default` = cl.`id_category` AND cl.`id_lang` = '.(int)($id_lang).')
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group`
AND tr.`id_country` = '.(int)Country::getDefaultCountryId().'
AND tr.`id_country` = '.(int)Context::getContext()->country->id.'
AND tr.`id_state` = 0)
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)
LEFT JOIN `'._DB_PREFIX_.'tax_lang` tl ON (t.`id_tax` = tl.`id_tax` AND tl.`id_lang` = '.(int)($id_lang).')
@@ -133,7 +133,7 @@ class PackCore extends Product
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group`
AND tr.`id_country` = '.(int)Country::getDefaultCountryId().'
AND tr.`id_country` = '.(int)Context::getContext()->country->id.'
AND tr.`id_state` = 0)
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)
LEFT JOIN `'._DB_PREFIX_.'tax_lang` tl ON (t.`id_tax` = tl.`id_tax` AND tl.`id_lang` = '.(int)$id_lang.')
+11 -9
View File
@@ -800,7 +800,7 @@ class ProductCore extends ObjectModel
'.($id_shop ? 'LEFT JOIN '._DB_PREFIX_.'product_shop ps ON (p.id_product = ps.id_product)' : '').'
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product`)
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group`
AND tr.`id_country` = '.(int)Country::getDefaultCountryId().'
AND tr.`id_country` = '.(int)Context::getContext()->country->id.'
AND tr.`id_state` = 0)
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)
@@ -1417,7 +1417,7 @@ class ProductCore extends ObjectModel
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)($id_lang).')
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group`
AND tr.`id_country` = '.(int)Country::getDefaultCountryId().'
AND tr.`id_country` = '.(int)Context::getContext()->country->id.'
AND tr.`id_state` = 0)
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)
@@ -1501,7 +1501,7 @@ class ProductCore extends ObjectModel
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)($id_lang).')
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group`
AND tr.`id_country` = '.(int)Country::getDefaultCountryId().'
AND tr.`id_country` = '.(int)Context::getContext()->country->id.'
AND tr.`id_state` = 0)
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)
WHERE p.id_product = '.(int)$id_product);
@@ -1569,7 +1569,7 @@ class ProductCore extends ObjectModel
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group`
AND tr.`id_country` = '.(int)Country::getDefaultCountryId().'
AND tr.`id_country` = '.(int)Context::getContext()->country->id.'
AND tr.`id_state` = 0)
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)
@@ -1776,7 +1776,7 @@ class ProductCore extends ObjectModel
$id_currency = (int)(Validate::isLoadedObject($context->currency) ? $context->currency->id : Configuration::get('PS_CURRENCY_DEFAULT'));
// retrieve address informations
$id_country = (int)Country::getDefaultCountryId();
$id_country = (int)$context->country->id;
$id_state = 0;
$id_county = 0;
@@ -1939,10 +1939,12 @@ class ProductCore extends ObjectModel
return self::$_prices[$cacheId];
}
public static function convertAndFormatPrice($price, $currency = false)
public static function convertAndFormatPrice($price, $currency = false, $context = null)
{
if (!$context)
$context = Context::getContext();
if (!$currency)
$currency = Currency::getCurrent();
$currency = $context->currency;
return Tools::displayPrice(Tools::convertPrice($price, $currency), $currency);
}
@@ -2357,7 +2359,7 @@ class ProductCore extends ObjectModel
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_.'manufacturer` m ON (p.`id_manufacturer`= m.`id_manufacturer`)
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group`
AND tr.`id_country` = '.(int)Country::getDefaultCountryId().'
AND tr.`id_country` = '.(int)Context::getContext()->country->id.'
AND tr.`id_state` = 0)
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)
WHERE `id_product_1` = '.(int)($this->id).
@@ -2500,7 +2502,7 @@ class ProductCore extends ObjectModel
'.($id_shop ? 'LEFT JOIN '._DB_PREFIX_.'product_shop ps ON (ps.id_product = p.id_product)' : '').'
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)($id_lang).')
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group`
AND tr.`id_country` = '.(int)Country::getDefaultCountryId().'
AND tr.`id_country` = '.(int)Context::getContext()->country->id.'
AND tr.`id_state` = 0)
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)
LEFT JOIN `'._DB_PREFIX_.'tax_lang` tl ON (t.`id_tax` = tl.`id_tax` AND tl.`id_lang` = '.(int)($id_lang).')
+1 -1
View File
@@ -87,7 +87,7 @@ class ProductSaleCore
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_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group`
AND tr.`id_country` = '.(int)Country::getDefaultCountryId().'
AND tr.`id_country` = '.(int)Context::getContext()->country->id.'
AND tr.`id_state` = 0)
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)
WHERE p.`active` = 1
+10 -8
View File
@@ -145,9 +145,11 @@ class SearchCore
return $string;
}
public static function find($id_lang, $expr, $pageNumber = 1, $pageSize = 1, $orderBy = 'position', $orderWay = 'desc', $ajax = false, $useCookie = true, $id_shop = false)
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
@@ -262,7 +264,7 @@ class SearchCore
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='.(int)$id_shop.')
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group`
AND tr.`id_country` = '.(int)Country::getDefaultCountryId().'
AND tr.`id_country` = '.(int)$context->country->id.'
AND tr.`id_state` = 0)
LEFT JOIN `'._DB_PREFIX_.'tax` tax ON (tax.`id_tax` = tr.`id_tax`)
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer`
@@ -277,7 +279,7 @@ class SearchCore
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='.(int)$id_shop.')
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group`
AND tr.`id_country` = '.(int)Country::getDefaultCountryId().'
AND tr.`id_country` = '.(int)Context::getContext()->country->id.'
AND tr.`id_state` = 0)
LEFT JOIN `'._DB_PREFIX_.'tax` tax ON (tax.`id_tax` = tr.`id_tax`)
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer`
@@ -531,13 +533,13 @@ class SearchCore
$queryArray3 = array();
}
public static function searchTag($id_lang, $tag, $count = false, $pageNumber = 0, $pageSize = 10, $orderBy = false, $orderWay = false, $useCookie = true)
public static function searchTag($id_lang, $tag, $count = false, $pageNumber = 0, $pageSize = 10, $orderBy = false, $orderWay = false, $useCookie = true, $context = null)
{
global $link, $cookie;
if (!$context)
$context = Context::getContext();
// Only use cookie if id_customer is not present
if ($useCookie)
$id_customer = (int)$cookie->id_customer;
$id_customer = (int)$context->customer->id;
else
$id_customer = 0;
@@ -573,7 +575,7 @@ class SearchCore
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group`
AND tr.`id_country` = '.(int)Country::getDefaultCountryId().'
AND tr.`id_country` = '.(int)$context->country->id.'
AND tr.`id_state` = 0)
LEFT JOIN `'._DB_PREFIX_.'tax` tax ON (tax.`id_tax` = tr.`id_tax`)
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)
+1 -1
View File
@@ -223,7 +223,7 @@ class SupplierCore extends ObjectModel
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)($id_lang).')
LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group`
AND tr.`id_country` = '.(int)Country::getDefaultCountryId().'
AND tr.`id_country` = '.(int)Context::getContext()->country->id.'
AND tr.`id_state` = 0)
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)
LEFT JOIN `'._DB_PREFIX_.'tax_lang` tl ON (t.`id_tax` = tl.`id_tax` AND tl.`id_lang` = '.(int)($id_lang).')
+5 -5
View File
@@ -279,7 +279,7 @@ class TaxCore extends ObjectModel
*/
public static function getProductTaxRate($id_product, $id_address = NULL)
{
$id_country = (int)Country::getDefaultCountryId();
$id_country = (int)Context::getContext()->country->id;
$id_state = 0;
$id_county = 0;
$rate = 0;
@@ -288,7 +288,7 @@ class TaxCore extends ObjectModel
$address_infos = Address::getCountryAndState($id_address);
if ($address_infos['id_country'])
{
$id_country = (int)($address_infos['id_country']);
$id_country = (int)($address_infos['id_country']);
$id_state = (int)$address_infos['id_state'];
$id_county = (int)County::getIdCountyByZipCode($address_infos['id_state'], $address_infos['postcode']);
}
@@ -305,7 +305,7 @@ class TaxCore extends ObjectModel
public static function getProductEcotaxRate($id_address = NULL)
{
$id_country = (int)Country::getDefaultCountryId();
$id_country = (int)Context::getContext()->country->id;
$id_state = 0;
$id_county = 0;
$rate = 0;
@@ -350,7 +350,7 @@ class TaxCore extends ObjectModel
public static function getCarrierTaxRate($id_carrier, $id_address = NULL)
{
$id_country = (int)Country::getDefaultCountryId();
$id_country = (int)Context::getContext()->country->id;
$id_state = 0;
$id_county = 0;
if (!empty($id_address))
@@ -358,7 +358,7 @@ class TaxCore extends ObjectModel
$address_infos = Address::getCountryAndState($id_address);
if ($address_infos['id_country'])
{
$id_country = (int)($address_infos['id_country']);
$id_country = (int)($address_infos['id_country']);
$id_state = (int)$address_infos['id_state'];
$id_county = (int)County::getIdCountyByZipCode($address_infos['id_state'], $address_infos['postcode']);
}
+11 -7
View File
@@ -341,15 +341,17 @@ class ToolsCore
* Return price with currency sign for a given product
*
* @param float $price Product price
* @param object $currency Current currency (object, id_currency, NULL => getCurrent())
* @param object $currency Current currency (object, id_currency, NULL => context currency)
* @return string Price correctly formated (sign, decimal separator...)
*/
public static function displayPrice($price, $currency = NULL, $no_utf8 = false)
public static function displayPrice($price, $currency = NULL, $no_utf8 = false, $context = null)
{
if (!$context)
$context = Context::getContext();
if ($currency === NULL)
$currency = Currency::getCurrent();
/* if you modified this function, don't forget to modify the Javascript function formatCurrency (in tools.js) */
if (is_int($currency))
$currency = $context->currency;
// if you modified this function, don't forget to modify the Javascript function formatCurrency (in tools.js)
elseif (is_int($currency))
$currency = Currency::getCurrencyInstance((int)($currency));
$c_char = (is_array($currency) ? $currency['sign'] : $currency->sign);
$c_format = (is_array($currency) ? $currency['format'] : $currency->format);
@@ -404,10 +406,12 @@ class ToolsCore
* @param object $currency Current currency object
* @param boolean $to_currency convert to currency or from currency to default currency
*/
public static function convertPrice($price, $currency = NULL, $to_currency = true)
public static function convertPrice($price, $currency = NULL, $to_currency = true, $context = null)
{
if (!$context)
$context = Context::getContext();
if ($currency === NULL)
$currency = Currency::getCurrent();
$currency = $context->currency;
elseif (is_numeric($currency))
$currency = Currency::getCurrencyInstance($currency);