sakiri Posted November 24, 2013 Share Posted November 24, 2013 Hello everybody, I stumbled upon a bug (?) in the discount.tpl: In line 53 (of the default template) there is this expression: {convertPrice price=$discountDetail.value} But it does not convert the price correctly, just substitutes one currency sign by another, but not re-calculating the value of the voucher. Now there IS a difference between € 5,00 and $ 5.00 and £ 5.00 ... For the time being I changed the expression to: € {$discountDetail.value} thus not converting the values of the vouchers in the listing at all, showing the (correct) €-values only, but that's not the smartest solution. Has anyone an idea how to change the discount.tpl (or the associated .php file) to have the values converted to different currencies correctly? Thank you! Link to comment Share on other sites More sharing options...
makson Posted December 4, 2013 Share Posted December 4, 2013 (edited) I can confirm this bug in PrestaShop™ 1.5.6.1 too. Minimum values are not recalculated. Moreover, minimum values are not recalculated correctly in checkout process and doesn't trigger voucher. Sample in checkout: 100$ = 73€ Voucher with MINIMUM 100$ doesnt' triger at 73€ but rather at 100€ which is incorrect. Bug reported: http://forge.prestashop.com/browse/PSCFV-11220 Edited December 5, 2013 by makson (see edit history) Link to comment Share on other sites More sharing options...
Julien Bourdeau Posted February 26, 2014 Share Posted February 26, 2014 Hi, I Just fixed that bug in PrestaShop 1.6, you can review the code changes here: https://github.com/PrestaShop/PrestaShop/commit/e9badc831485b1c7ace5b65c9570943e7a3d79fb The price is now converted from the voucher currency to the context currency. Please let me know you get any other bug about this. Best regards, 1 Link to comment Share on other sites More sharing options...
skboon Posted March 11, 2014 Share Posted March 11, 2014 (edited) I tried to replace the codes but problem remains. I change the currency but in My account>My vouchers, only the sign of currency change but the value remains same. My PS version is 1.5.6.2. Edited March 11, 2014 by skboon (see edit history) Link to comment Share on other sites More sharing options...
skboon Posted March 12, 2014 Share Posted March 12, 2014 (edited) Hi, Can you help to fix this in PS 1.5.6.2 ? Value of voucher not changed when currency switched in My account>My vouchers. Please refer to attached image. Thanks. Hi, I Just fixed that bug in PrestaShop 1.6, you can review the code changes here: https://github.com/PrestaShop/PrestaShop/commit/e9badc831485b1c7ace5b65c9570943e7a3d79fb The price is now converted from the voucher currency to the context currency. Please let me know you get any other bug about this. Best regards, Edited March 12, 2014 by skboon (see edit history) Link to comment Share on other sites More sharing options...
skboon Posted March 15, 2014 Share Posted March 15, 2014 Any solution on this problem? Thanks. Link to comment Share on other sites More sharing options...
PascalVG Posted March 15, 2014 Share Posted March 15, 2014 Error is in classes/Product.php: The conversion is not done here. Function: /** * Display price with right format and currency * * @param array $params Params * @param $smarty Smarty object * @return string Price with right format and currency */ public static function convertPrice($params, &$smarty) { return Tools::displayPrice($params['price'], Context::getContext()->currency); } To add the conversion, change to this: public static function convertPrice($params, &$smarty) { return Tools::displayPrice(Tools::convertPrice($params['price']), Context::getContext()->currency); } Hope that helps. If so, let me know, then we can report it back to forge. pascal. 1 Link to comment Share on other sites More sharing options...
skboon Posted March 15, 2014 Share Posted March 15, 2014 Hi, Thanks for your respond. The currency conversion problem found in My account -> My voucher section but not on the product's price. There is more than one currency. Therefore users can log in to check the voucher's value in different currency. Current problem is there is no conversion in voucher's value when user switch between currencies. Can you recheck this? My PS version is 1.5.6.2. Thank you. Error is in classes/Product.php: The conversion is not done here. Function: /** * Display price with right format and currency * * @param array $params Params * @param $smarty Smarty object * @return string Price with right format and currency */ public static function convertPrice($params, &$smarty) { return Tools::displayPrice($params['price'], Context::getContext()->currency); } To add the conversion, change to this: public static function convertPrice($params, &$smarty) { return Tools::displayPrice(Tools::convertPrice($params['price']), Context::getContext()->currency); } Hope that helps. If so, let me know, then we can report it back to forge. pascal. Link to comment Share on other sites More sharing options...
skboon Posted March 15, 2014 Share Posted March 15, 2014 (edited) Sorry that misplaced your code just now. Your solution is fine I got the problem fixed. How come the error is not in classes/CartRule.php ? I can't figure out... Thank you. Dear Mod, please add [solved] on the subject, thanks Hi, Thanks for your respond. The currency conversion problem found in My account -> My voucher section but not on the product's price. There is more than one currency. Therefore users can log in to check the voucher's value in different currency. Current problem is there is no conversion in voucher's value when user switch between currencies. Can you recheck this? My PS version is 1.5.6.2. Thank you. Edited March 15, 2014 by skboon (see edit history) Link to comment Share on other sites More sharing options...
skboon Posted March 15, 2014 Share Posted March 15, 2014 (edited) Hi Pascal, I found another problem happens during currency exchange on conversion of loyalty point to voucher after replaced the code. My default currency is USD. I set the loyalty point: Ratio 1 =1 reward point. 1 point = 0.01 for the discount. The currency exchange rate is USD1 : 0.72EUR I try to switch currency during exchange: 1170 points = USD 11.70 (correct) 1170 points = EUR 6.07 (wrong, supposed to be EUR8.42) Here I attached the file. Kindly advised on this, thank you. Edited March 15, 2014 by skboon (see edit history) Link to comment Share on other sites More sharing options...
PascalVG Posted March 16, 2014 Share Posted March 16, 2014 Hi skboon, Glad the first problem is solved :-) Strange that this pretty obvious error didn't pop up earlier :-) About the 2nd problem, mentioned in post #10: Hmm, can't see this (after adding my modification of post #7). Here it seems to all work well. Can you attach some screendumps of your currency conversion table, and your loyalty conversion settings? (Click on the grey "More reply Options" button below the edit field when writing your reply here, and there you can upload images/files) What are the exact steps you take to change the currency? Where do you go first, when exactly do you change the currency, etc. Please mention some steps. pascal. Link to comment Share on other sites More sharing options...
skboon Posted March 16, 2014 Share Posted March 16, 2014 (edited) Hi Pascal, here i explain the attached files: pic1: currency & loyalty point settings at back office 1USD = 0.72 EUR USD1 = 1 loyalty point 1 loyalty point = USD0.01 pic2: switch currency and view the value of voucher can be converted from loyalty points before replaced the code: 1170 points can be converted to USD11.70 or 8.42EUR (both correct) after replaced the code: 1170 points can be converted to USD11.70 or EUR6.07 (USD correct; EUR incorrect)** pic3: after replaced the code and converted loyaty point convert history showed 1170 poinst was converted to 8.42 EUR** at vouchers section, vouchers worth USD8.42 or EUR6.07** ** they should be consistent but not. Please let me know if you don't understand any part i state here, thanks. Hi skboon, Glad the first problem is solved :-) Strange that this pretty obvious error didn't pop up earlier :-) About the 2nd problem, mentioned in post #10: Hmm, can't see this (after adding my modification of post #7). Here it seems to all work well. Can you attach some screendumps of your currency conversion table, and your loyalty conversion settings? (Click on the grey "More reply Options" button below the edit field when writing your reply here, and there you can upload images/files) What are the exact steps you take to change the currency? Where do you go first, when exactly do you change the currency, etc. Please mention some steps. pascal. Edited March 16, 2014 by skboon (see edit history) Link to comment Share on other sites More sharing options...
PascalVG Posted March 17, 2014 Share Posted March 17, 2014 Hi skboon, Officially, the fix is simple. The price given to the page template (loyalty.tpl) is already converted. But in the template, it converts it one more time: $11.70*0.72 = €8.42, -> 8.42*0.72 = 6.06 As they did the conversion already in the loyalty.php, they SHOULDN'T use the convertPrice function in the loyalty.tpl file but just use displayPrice function, BUT, as the convertPrice function USED TO DO no conversion, it gave sneakily the correct answer!! There is the exactly problem we face now: I don't know if there are more places in PrestaShop where they wrongly use the convertPrice, where they actually should have used displayPrice!! Everywhere they do this, the price will now get "converted twice": Explanation: By adding the fix I suggested, the function convertPrice will be corrected, and does what it should do, but maybe they used the convertPrice function just to add the currency sign (like they did in loyalty.tpl, instead of the correct function displayPrice for this. As we fixed the convertPrice now, everywhere where they mistakenly use convertPrice instead of displayPrice, it will convert the price on more time ( So, should we fix it, as I suggested and try to fix the other places where it now converts twice (This is officially the way to do it, as it creates correct code in the end) with the risk that we oversee any screen where this is needed OR should we live with the error introduced here and 'fix' (ahem) the voucher page ONLY in a different way, by adding the "Tools::convertPrice" here, instead of in the Product::convertPrice function... Your choice... To fix the loyalty page the correct way: Open file: modules/loyalty/views/templates/front/loyalty.tpl (or if you have an override of this file in the themes/<your theme folder>/loyalty folder, open that one) and change all convertPrice into displayPrice ( I believe 2 times) This will then take away the second conversion, giving the correct amount. Hope this helps, pascal Link to comment Share on other sites More sharing options...
skboon Posted March 18, 2014 Share Posted March 18, 2014 (edited) hi Pascal, it's too risky to add Tools::convertPrice in class/product.php because it will convert twice on all products' display price. Seem there is no solution to fix the loyalty page without affect on other price conversion at the moment. Edited March 18, 2014 by skboon (see edit history) Link to comment Share on other sites More sharing options...
skboon Posted March 19, 2014 Share Posted March 19, 2014 Does this problem happen on prestashop 1.6? Link to comment Share on other sites More sharing options...
PascalVG Posted March 19, 2014 Share Posted March 19, 2014 skboon, Indeed, we actually need to go through all 1.5.x files to check if the conversion is done elsewhere or not, to make it really correct. If you don't want to change Product::convertPrice, we come back to the original problem, i.e. in the vouchers. You can fix that as follows: In discount.tpl, find the (wrong) function {convertPrice price=.... } Apparently, PrestaTeam knows that there is a problem here, as they ALREADY MADE a new function in Product.php: function convertAndFormatPrice So, in discount.tpl, try to change {convertPrice ....... } into: {convertAndFormatPrice .... } and it should be fixed here. As said, convertPrice should actually do what it says it does, but it doesn't. It only Formats the price, NOT converts. ConvertAndFormatPrice does exactly what we found formatPrice SHOULD do: it returns: return Tools::displayPrice(Tools::convertPrice($price, $currency), $currency); exactly what we did to fix the convertPrice in the first place. PrestaTeam apparently were lazy to go through all files to see where the correct fix would have any impact, and also chose to leave the error 'as is', and fix it wherever needed by using this new function convertAndFormatPrice. As we now know, they overlooked at least one location, as there was still an error in discount.php, (and who knows where else.) pascal. Link to comment Share on other sites More sharing options...
PascalVG Posted March 19, 2014 Share Posted March 19, 2014 Not sure if 1.6. has the error. Will install 1.6 this week, and will have a look. pascal. Link to comment Share on other sites More sharing options...
skboon Posted March 19, 2014 Share Posted March 19, 2014 (edited) hi Pascal, i try to change in /themes/default/discount.tpl replace {convertPrice ....... } into: {convertAndFormatPrice .... } the page is broken, cannot be loaded there is no convertAndFormatPrice function in discount.tpl Edited March 19, 2014 by skboon (see edit history) Link to comment Share on other sites More sharing options...
bellini13 Posted November 17, 2014 Share Posted November 17, 2014 Hi, I Just fixed that bug in PrestaShop 1.6, you can review the code changes here: https://github.com/PrestaShop/PrestaShop/commit/e9badc831485b1c7ace5b65c9570943e7a3d79fb The price is now converted from the voucher currency to the context currency. Please let me know you get any other bug about this. Best regards, As a discount can be one of three types, I believe you may have fixed one issue and introduced a new issue. Consider that a discount can be one of three types 1) a percent off, like 10% off 2) a fixed amount, like $10 off 3) free shipping The 'fix' that you applied might correct the issue when the discount type is #2, however it breaks when the discount type is #1 I believe another fix is required in the DiscountController so that is checks the discount type before applying the Tools::convertPriceFull conversion? 1 Link to comment Share on other sites More sharing options...
iggywebprom Posted August 4, 2015 Share Posted August 4, 2015 Hi, I Just fixed that bug in PrestaShop 1.6, you can review the code changes here: https://github.com/PrestaShop/PrestaShop/commit/e9badc831485b1c7ace5b65c9570943e7a3d79fb The price is now converted from the voucher currency to the context currency. Please let me know you get any other bug about this. Best regards, I confirm this fix has worked for me on PrestaShop 1.5.3.1 Link to comment Share on other sites More sharing options...
Alegra Posted October 19, 2016 Share Posted October 19, 2016 (edited) As a discount can be one of three types, I believe you may have fixed one issue and introduced a new issue. Consider that a discount can be one of three types 1) a percent off, like 10% off 2) a fixed amount, like $10 off 3) free shipping The 'fix' that you applied might correct the issue when the discount type is #2, however it breaks when the discount type is #1 I believe another fix is required in the DiscountController so that is checks the discount type before applying the Tools::convertPriceFull conversion? I had as Bellini13 described the problem exactly with discount type # 2 on page "My Vouchers". My Presta version is 1.6.1.4 I create a voucher with the following parameters: Conditions - Custumer - Limit to a single customer - Minimum amount - 0 - Total available - 1 - Total available for each user - 1 - Restrictions - All groups Actions - Apply a discount - Percent - Value - 10% - Apply a discount to - Order (without shipping) In the shop I use two currencies: - BGN - EUR On the page "My Vouchers" discount is shown as follows for both currencies: - BGN - EUR To solve this problem, I did the following: In controllers/front/DiscountController.php found: public function initContent() { parent::initContent(); $cart_rules = CartRule::getCustomerCartRules($this->context->language->id, $this->context->customer->id, true, false); $nb_cart_rules = count($cart_rules); foreach ($cart_rules as &$discount) { $discount['value'] = Tools::convertPriceFull( $discount['value'], new Currency((int)$discount['reduction_currency']), new Currency((int)$this->context->cart->id_currency) ); } $this->context->smarty->assign(array( 'nb_cart_rules' => (int)$nb_cart_rules, 'cart_rules' => $cart_rules, 'discount' => $cart_rules, 'nbDiscounts' => (int)$nb_cart_rules) ); $this->setTemplate(_PS_THEME_DIR_.'discount.tpl'); } } And add: public function initContent() { parent::initContent(); $cart_rules = CartRule::getCustomerCartRules($this->context->language->id, $this->context->customer->id, true, false); $nb_cart_rules = count($cart_rules); foreach ($cart_rules as &$discount) { +++ if ($discount['id_discount_type'] == Discount::AMOUNT){ $discount['value'] = Tools::convertPriceFull( $discount['value'], new Currency((int)$discount['reduction_currency']), new Currency((int)$this->context->cart->id_currency) ); } $this->context->smarty->assign(array( 'nb_cart_rules' => (int)$nb_cart_rules, 'cart_rules' => $cart_rules, 'discount' => $cart_rules, 'nbDiscounts' => (int)$nb_cart_rules) ); $this->setTemplate(_PS_THEME_DIR_.'discount.tpl'); } +++ } } Now percent in both currencies are the same. Edited October 19, 2016 by Alegra (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now