From 2639b68fd87eedd1283b5fd4000b9fca1e98177a Mon Sep 17 00:00:00 2001 From: vChabot Date: Wed, 13 Jun 2012 13:23:52 +0000 Subject: [PATCH] [-] BO : BugFix : #PSCFV-2798 : Multistore : BUG on the "modify products page" with another shop device --- .../template/controllers/products/prices.tpl | 6 +++--- classes/Tools.php | 13 +++++++++++-- classes/controller/AdminController.php | 5 +++-- classes/shop/Shop.php | 17 +++++++++++++++++ config/smarty.config.inc.php | 6 ++++++ controllers/admin/AdminProductsController.php | 8 +++++++- 6 files changed, 47 insertions(+), 8 deletions(-) diff --git a/admin-dev/themes/default/template/controllers/products/prices.tpl b/admin-dev/themes/default/template/controllers/products/prices.tpl index 0485dc3ef..c474db9b6 100644 --- a/admin-dev/themes/default/template/controllers/products/prices.tpl +++ b/admin-dev/themes/default/template/controllers/products/prices.tpl @@ -120,7 +120,7 @@ jQuery(document).ready(Customer.init); - {$currency->prefix}{$currency->suffix} + {$currency->prefix}{$currency->suffix}

{l s='The wholesale price at which you bought this product'}

@@ -131,8 +131,8 @@ jQuery(document).ready(Customer.init); - - {$currency->prefix}{$currency->suffix} + + {$currency->prefix}{$currency->suffix}

{l s='The pre-tax retail price to sell this product'}

diff --git a/classes/Tools.php b/classes/Tools.php index ef4ff341e..0aa110639 100644 --- a/classes/Tools.php +++ b/classes/Tools.php @@ -414,12 +414,21 @@ class ToolsCore if ((int)$cookie->id_currency) { $currency = Currency::getCurrencyInstance((int)$cookie->id_currency); - if (is_object($currency) && (int)$currency->id && (int)$currency->deleted != 1 && $currency->active && $currency->isAssociatedToShop()) - return $currency; + if (is_object($currency) && (int)$currency->id && (int)$currency->deleted != 1 && $currency->active) + if ($currency->isAssociatedToShop()) + return $currency; + else + { + // get currency from context + $currency = Shop::getEntityIds('currency', Context::getContext()->shop->id); + $cookie->id_currency = $currency[0]['id_currency']; + return Currency::getCurrencyInstance((int)$cookie->id_currency); + } } $currency = Currency::getCurrencyInstance(Configuration::get('PS_CURRENCY_DEFAULT')); if (is_object($currency) && $currency->id) $cookie->id_currency = (int)$currency->id; + return $currency; } diff --git a/classes/controller/AdminController.php b/classes/controller/AdminController.php index 6a471fa16..ea49b5ba0 100644 --- a/classes/controller/AdminController.php +++ b/classes/controller/AdminController.php @@ -312,9 +312,10 @@ class AdminControllerCore extends Controller // Get the name of the folder containing the custom tpl files $this->tpl_folder = Tools::toUnderscoreCase(substr($this->controller_name, 5)).'/'; - $this->context->currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); - $this->initShopContext(); + + $currency = Shop::getEntityIds('currency', $this->context->shop->id); + $this->context->currency = new Currency($currency[0]['id_currency']); } /** diff --git a/classes/shop/Shop.php b/classes/shop/Shop.php index b54955a9f..e99eac49c 100644 --- a/classes/shop/Shop.php +++ b/classes/shop/Shop.php @@ -991,4 +991,21 @@ class ShopCore extends ObjectModel Tools::displayAsDeprecated(); return Context::getContext()->shop->id; } + + /** + * @param string $entity + * @param int $id_shop + * @return array|bool + */ + public static function getEntityIds($entity, $id_shop) + { + if (!Shop::isTableAssociated($entity)) + return false; + + return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' + SELECT `id_'.pSQL($entity).'` + FROM `'._DB_PREFIX_.pSQL($entity).'_shop` + WHERE `id_shop` = '.(int)$id_shop + ); + } } diff --git a/config/smarty.config.inc.php b/config/smarty.config.inc.php index b912526c6..6382e6bdb 100644 --- a/config/smarty.config.inc.php +++ b/config/smarty.config.inc.php @@ -70,6 +70,7 @@ smartyRegisterFunction($smarty, 'function', 'p', 'smartyShowObject'); // Debug o smartyRegisterFunction($smarty, 'function', 'd', 'smartyDieObject'); // Debug only smartyRegisterFunction($smarty, 'function', 'l', 'smartyTranslate', false); smartyRegisterFunction($smarty, 'function', 'hook', 'smartyHook'); +smartyRegisterFunction($smarty, 'function', 'toolsConvertPrice', 'toolsConvertPrice'); smartyRegisterFunction($smarty, 'function', 'dateFormat', array('Tools', 'dateFormat')); smartyRegisterFunction($smarty, 'function', 'convertPrice', array('Product', 'convertPrice')); @@ -188,6 +189,11 @@ function smartyHook($params, &$smarty) } } +function toolsConvertPrice($params, &$smarty) +{ + return Tools::convertPrice($params['price'], Context::getContext()->currency); +} + /** * Used to delay loading of external classes with smarty->register_plugin */ diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index 05c49cf6e..37758b427 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -279,7 +279,11 @@ class AdminProductsControllerCore extends AdminController { /* update product final price */ for ($i = 0; $i < $nb; $i++) + { + // convert price with the currency from context + $this->_list[$i]['price'] = Tools::convertPrice($this->_list[$i]['price'], $this->context->currency, true, $this->context); $this->_list[$i]['price_tmp'] = Product::getPriceStatic($this->_list[$i]['id_product'], true, null, 6, null, false, true, 1, true); + } } if ($orderByPriceFinal == 'price_final') @@ -2686,6 +2690,7 @@ class AdminProductsControllerCore extends AdminController $data->assign('ecotaxTaxRate', Tax::getProductEcotaxRate()); $data->assign('tax_exclude_taxe_option', Tax::excludeTaxeOption()); $data->assign('ps_use_ecotax', Configuration::get('PS_USE_ECOTAX')); + $product_price = Tools::convertPrice($product->price, $this->context->currency, true, $this->context); if ($product->unit_price_ratio != 0) $data->assign('unit_price', Tools::ps_round($product->price / $product->unit_price_ratio, 2)); else @@ -3423,7 +3428,8 @@ class AdminProductsControllerCore extends AdminController $combination_images = $product->getCombinationImages($this->context->language->id); foreach ($combinations as $k => $combination) { - $price = Tools::displayPrice($combination['price'], $currency); + $price_to_convert = Tools::convertPrice($combination['price'], $currency); + $price = Tools::displayPrice($price_to_convert, $currency); $comb_array[$combination['id_product_attribute']]['id_product_attribute'] = $combination['id_product_attribute']; $comb_array[$combination['id_product_attribute']]['attributes'][] = array($combination['group_name'], $combination['attribute_name'], $combination['id_attribute']);