Jump to content

[SOLVED] Currency convertion problem


Recommended Posts

Hi everybody,

 

I'm currently using Prestashop 1.6.0.8, and i own multiple version of the same shop with different currencies (EUR - GBP).

 

Here's my problem :

In my BO, currencies are set with a good convertion ratio (let's say : 0.XX).

But in my FO, prices are displayed with the right currencies but not the good price ! a 1 ratio instead of 0.XX...

 

For example :

On the french website, a product will be at 20.00 EUR and on the UK website, it will be 20,00 GBP...

Whenever i change the currency symbol (£) in the BO, it changes in the FO. Only the prices are incorrect...

 

 

 

I had a look into the code to know where can this come from :

 

- in products.tpl : the price is displayed with :

 {convertPrice price=$productPrice}

- in smarty.config.inc.php : the function is registered with

 smartyRegisterFunction($smarty, 'function', 'convertPrice', array('Product', 'convertPrice'));

- in Product.php : 

public static function convertPrice($params, &$smarty)
{
     return Tools::displayPrice($params['price'], Context::getContext()->currency);
}

- and the displayPrice function DO NOT convert the price according to the currency that we want...

 

Is it a "normal" issue ? 

 

 

 

Anyone can help me ?

Thanks

Edited by Kekeno (see edit history)
Link to comment
Share on other sites

  • 2 weeks later...

Hi Kekeno,

 

Darn, I thought they fixed this long time ago....

 

I think if you use:

   {toolsConvertPrice price=$productPrice}    (*see edit below)

in your tpl file

 

instead, it should work...

 

 

Let us know,

pascal

 

 

* EDIT: toolsConvertPrice only changes the number of the currency, but doesn't add the currency unit and format of the currency to it, so you should use:

{convertAndFormatPrice price=$productPrice}

  • Like 1
Link to comment
Share on other sites

No changes on the FO product page...

 

But in fact, i don't want the "displayed price" to change but the real price. As if i change convertPrice to toolsConvertPrice, it'll (maybe) change the displayed price but at the end, the customer will pay the "not displayed price"...

I told about the 'convertPrice' on the product page to get back to the source and understand what's going on...

 

This issue is weird, because prestashop understand the currency but just don't want to convert my prices !

 

Thanks for the help Pascal..

To be continued 

Link to comment
Share on other sites

Hmm, not sure I follow your reasoning.

The displayed price, say 500 in Currency B, should be the same intrinsic value but then converted from Currency A?

 

Example: 

Say Currency A (Default in Back office) = Euro:

You want to show it in Currency B = GBP in Front office

 

Say, for easiness of calculation: 1 Euro = 0.5 GBP

 

So Back office price of 1000 Euro, should show as 500 GBP in Front office, or 1000 Euro in front office, dependent on the Currency choice?

 

So I don't think the real price should change?? In the end, you still want 1000 Euro from the customer, not something else, right?

 

Please elaborate.

pascal.

 

P.S. to see any change on the front office pages, please make sure that,  temporarily, in Advanced Parameters, the force compile is turned ON, and smarty Cache is OFF. After done so, reload the page and see if the change happened. If so, put back the settings to their previous state)

Link to comment
Share on other sites

Yes, you're right.

 

But if i just change by hand the "convertPrice" in the TPL file, it'll just modify my 'displayed' price on the associated page, so i'll have to change it everywhere (in every TPL file..).

And when the customer will have to pay (at the end of his order) it will still be the non converted price, won't it ?

 

I think the problem is deeper than in the TPL file, if you know what i mean :/

 

Thanks again for your help !

 

[EDIT]

I just saw that some of my products are ok on product page but not in category page..

Here's some real example:

 

Not-Working product :

- French website

- English website

 

Approximately working product :

- French product page

- English product page

As you can see in the English category page, the "Black display fridge, 78 L" is £ 379, but when you click on it, it becomes £ 276,33 and when you add it to cart, it goes back to £ 379...

I can't understand where this issue comes from !

[/EDIT]

Edited by Kekeno (see edit history)
Link to comment
Share on other sites

Your Euro is Default, right? And I believe the Euro prices (i.e. the prices everywhere on your French site) are always correct, right? So only the conversion to GBP is going wrong, so we have to fix this. This is done by fixing the display/convert command...

 

The internal price is always calculated in Default currency (Euro) and then converted to whatever currency you choose, either on the product page, category page, summary or final total, they all convert from the internally used (correct) Euro/default price to the new currency. So the internal price itself is calculated correctly, but not correctly shown to the (English) customer.

 

One thing I don't understand is the product page, where SOMETIMES the price is correct, but SOMETIMES not.

Did you already change the {convertPrice...} into {toolsConvertPrice...} {convertAndFormatPrice price=...}* in product.tpl?

 

* EDIT: in my previous post I suggested to use toolsConvertPrice. But this function only converts the value. The currency unit and the currency format is NOT added by this function. You should actually use {convertAndFormatPrice price=...}

 

 

 

If so, can you check for me one thing? Turn off the smarty Cache one more time, and turn on the Force Compilation one more time (Advanced Parameters) and check the two pages you showed me in the previous post. See if then both are displayed correctly.

If this is then working, read further. If not, let me know.

 

 

To be honest, this conversion error is known for at least a year, and I thought they had fixed it, but as we see now it hasn't been done yet. (Don't ask me why...)

But to really fix it correctly, you actually should go through all the tpl files (the final summary etc is also just a tpl file) that have this {convertPrice...} command and fix it. Cumbersome indeed...

 

I can help you with a list of files that use this command, to make fixing it faster:

post-455771-0-56595600-1429006614_thumb.png

 

 

 

But before you go through all these tpl files, consider this option:

 

You can try to fix it quick and dirty:

 

Try this:

 

In classes/product.php, (Make backup!!!)

find function:

 

public static function convertPrice($params, &$smarty)
{
    return Tools::displayPrice($params['price'], Context::getContext()->currency);
}
 

 

As we know, this function only adds the currency sign and format of the currency to the price value, but doesn't convert it.

 

If we now just add the conversion to it in this function, that would make the work a lot less. So let's try:

 

Change the function contents to:

 

public static function convertPrice($params, &$smarty)
{
  $context = Context::getContext();
  $currency = $context->currency;
  return Tools::displayPrice(Tools::convertPrice($params['price'], $currency), $currency);
}
 

What we still have to do, either by fixing it correctly OR fixing it quick and dirty is checking if it now works:

So always check the site thoroughly if all prices are now as expected: Home page (featured products, new products, etc.), Category page, Product detail page, cartblock top right, summary and final total page etc, as well as Emails reports.

 

Sorry there's not a simpler way than this...

 

My 2 cents,

pascal

Edited by PascalVG
changed tpl function to use into convertAndFormatPrice (see edit history)
Link to comment
Share on other sites

Your Euro is Default, right? And I believe the Euro prices (i.e. the prices everywhere on your French site) are always correct, right? So only the conversion to GBP is going wrong, so we have to fix this. This is done by fixing the display/convert command...

 

Yes, you're right. Prestashop just print the good GBP symbol, but do not convert the prices..

 

One thing I don't understand is the product page, where SOMETIMES the price is correct, but SOMETIMES not.

Did you already change the {convertPrice...} into {toolsConvertPrice...} {convertAndFormatPrice price=...}* in product.tpl?

 

* EDIT: in my previous post I suggested to use toolsConvertPrice. But this function only converts the value. The currency unit and the currency format is NOT added by this function. You should actually use {convertAndFormatPrice price=...}

 

If so, can you check for me one thing? Turn off the smarty Cache one more time, and turn on the Force Compilation one more time (Advanced Parameters) and check the two pages you showed me in the previous post. See if then both are displayed correctly.

If this is then working, read further. If not, let me know.

 

Whenever i change convertPrice to convertAndFormatPrice, i get a blank page ! I tried to clear cache etc.. same problem, blank page. (I'll investigate this)

 

But before you go through all these tpl files, consider this option:

 

You can try to fix it quick and dirty:

 

Try this:

 

In classes/product.php, (Make backup!!!)

find function:

 

public static function convertPrice($params, &$smarty)
{
    return Tools::displayPrice($params['price'], Context::getContext()->currency);
}
 

 

As we know, this function only adds the currency sign and format of the currency to the price value, but doesn't convert it.

 

If we now just add the conversion to it in this function, that would make the work a lot less. So let's try:

 

Change the function contents to:

 

public static function convertPrice($params, &$smarty)
{
  $context = Context::getContext();
  $currency = $context->currency;
  return Tools::displayPrice(Tools::convertPrice($params['price'], $currency), $currency);
}
 

What we still have to do, either by fixing it correctly OR fixing it quick and dirty is checking if it now works:

So always check the site thoroughly if all prices are now as expected: Home page (featured products, new products, etc.), Category page, Product detail page, cartblock top right, summary and final total page etc, as well as Emails reports.

 

This was a really good idea, maybe more efficient than changing all {convertPrice...} by {convertAndFormatPrice...} !

But unfortunately, no change... Still the same issue

 

A really big thanks for your help anyway !! You're awesome

Edited by Kekeno (see edit history)
Link to comment
Share on other sites

No change at all... How's that possible... Looks like it doesn't look at the file you edit...

 

Can you check if there's a file /override/classes/Product.php ?

If so, does this have the function

public static function convertPrice($params, &$smarty)
 
in it??

 

 

Just double-double check, but you use the multishop feature, right, not separate databases/set of files for each of the shops...?

 

 

 

 

 

Whenever i change convertPrice to convertAndFormatPrice, i get a blank page ! I tried to clear cache etc.. same problem, blank page. (I'll investigate this)

 

 

Oops, my bad. See now in smarty.config.inc.php that this is not a function, but a 'modifier'. They use it for example in product.tpl like this:

          {$ecotax_tax_inc|convertAndFormatPrice}

 

So you could try to use it like that:

     {convertAndFormatPrice price=$productPrice}

will then be:

 

     {$productPrice|convertAndFormatPrice}

 

or so.

 

But as you said, just changing the original function should be easier (if it worked...)

 

 

 

If nothing helps:

 

Would you mind to let me into your files and back office for a moment? Maybe I can find anything...

 

If you want that, please PM me some temporary ftp login info and also an administrator account for the back office. Don't forget to add the URL to your back office login.

 

(If you're not sure about creating an ftp account, please contact your host to set it up for you)

 

 

pascal

Link to comment
Share on other sites

No change at all... How's that possible... Looks like it doesn't look at the file you edit...

 

Can you check if there's a file /override/classes/Product.php ?

If so, does this have the function

public static function convertPrice($params, &$smarty)
 
in it??

 

Oh didn't expect that, but there's a Product.php file in the override folder, is there any way that, this may have a link with my issue ? here's the code :

public static function getPriceStatic($id_product, $usetax = true, $id_product_attribute = null, $decimals = 6, $divisor = null,
	$only_reduc = false, $usereduc = true, $quantity = 1, $force_associated_tax = false, $id_customer = null, $id_cart = null,
	$id_address = null, &$specific_price_output = null, $with_ecotax = true, $use_group_reduction = true, Context $context = null,
	$use_customer_price = true)
	{
		if ($id_product == 0 && !empty($id_product_attribute))
		{
			$quotation_product = new QuotationProduct((int)$id_product_attribute);

			if (!empty($quotation_product->id))
			{
				if ($only_reduc)
				{
					if ($usetax)
						return ($quotation_product->final_price_with_tax - $quotation_product->final_price_with_tax_discount);
					else
						return ($quotation_product->final_price_without_tax - $quotation_product->final_price_without_tax_discount);
				}

				if ($usereduc)
				{
					if ($usetax)
						return $quotation_product->final_price_with_tax_discount;
					else
						return $quotation_product->final_price_without_tax_discount;
				}
				else
				{
					if ($usetax)
						return $quotation_product->final_price_with_tax;
					else
						return $quotation_product->final_price_without_tax;
				}
			}
		}
		return parent::getPriceStatic($id_product, $usetax, $id_product_attribute, $decimals, $divisor,
			$only_reduc, $usereduc, $quantity, $force_associated_tax, $id_customer, $id_cart,
			$id_address, $specific_price_output, $with_ecotax, $use_group_reduction, $context,
			$use_customer_price);
	}

Just double-double check, but you use the multishop feature, right, not separate databases/set of files for each of the shops...?

 

No, there's only 1 database for all differents shops.

 

 

Oops, my bad. See now in smarty.config.inc.php that this is not a function, but a 'modifier'. They use it for example in product.tpl like this:

          {$ecotax_tax_inc|convertAndFormatPrice}

 

So you could try to use it like that:

     {convertAndFormatPrice price=$productPrice}

will then be:

 

     {$productPrice|convertAndFormatPrice}

 

or so.

 

This is what i found too, in smarty.config.inc.php, but no changes again...

 

 

If nothing helps:

 

Would you mind to let me into your files and back office for a moment? Maybe I can find anything...

 

If you want that, please PM me some temporary ftp login info and also an administrator account for the back office. Don't forget to add the URL to your back office login.

 

(If you're not sure about creating an ftp account, please contact your host to set it up for you)

 

If you think that my override/classes/Product.php do not affect the price convertion, i'll pm you right after :) !

 

Thanks again pascal !

Edited by Kekeno (see edit history)
Link to comment
Share on other sites

Since i have no news, and i can't fin the problem.

I found an other "temp" idea:

 

Should I develop a "mini-script" that will change the prices only for my UK website ?

I can change all prices in "ps_product_shop" ?

 

What do you think about it ?

Link to comment
Share on other sites

Kekeno,

 

Sorry, was 'out of order' last two days, (some sort of food poisoning...)

 

If you change the price, that will then be for all sites, as you only have one database, so the French site will get these prices then as well. So that's no option.

 

I believe you sent me some admin/ftp info let me have a look tonight...

 

pascal.

Link to comment
Share on other sites

No, "ps_product_shop" contains prices for specific shops as there is a "id_shop" field !

 

"ps_product" contains the "default" prices..

 

If i change the price of a product in "ps_product_shop" with id_shop=id_uk_shop, it only changes the price of this product for the uk website !

I can write a script to apply the currency on all products but it's a "hard" way to do it

Link to comment
Share on other sites

Pascal finally put me on the right way to solve this.

 

When you go on the Localization page with your shop selected (Not "all Shops"), find out the "Configuration" fields.

There is a "Default currency" with a dropdown to select the currency for the shop, and a box to set this currency as default.

If this box is checked (I don't know why, maybe this should be fixed...) : the prices will NEVER be converted because PS thinks this is default so it don't need to be converted.

 

So i unchecked this box, set GBP as currency again, save and all is now working fine !!

Link to comment
Share on other sites

After some more review of the code, I believe you can even 'really make it work', with eah shop just their own currency (which is then the default one, of course), you could do this:

 

in file:

    controllers/front/ProductController.php

in function:

    public function initContent()
 
For some reason, in one of the versions after 1.6.0.5, they took our this line
$this->context->smarty->assign(array(
    'stock_management' => Configuration::get('PS_STOCK_MANAGEMENT'),
    'jqZoomEnabled' => Configuration::get('PS_DISPLAY_JQZOOM'),
    ....
 
    'ENT_NOQUOTES' => ENT_NOQUOTES,
    'customizationFields' => $customization_fields,
    'currencyRate' => $this->context->currency->conversion_rate,  //!!!Pas
    ....
 
(as far as I can see, they are changing a lot in the currency/tax files somewhere in these versions between 1.6.0.5 and 1.6.0.14). Problem is, they still use this variable $currencyRate defined in this line elsewhere in the code (themes/<your theme folder>/product.tpl), so it should still be defined (or until they fix/modify that code at least)
 
The second modification, to fix the problem with the default currency that isn't converted, is done here:
In file:
    classes/Tools.php
 
in function:
    public static function convertPrice($price, $currency = null, $to_currency = true, Context $context = null)
 

comment out the following red lines:

 

    ...

    $c_id = (is_array($currency) ? $currency['id_currency'] : $currency->id);
    $c_rate = (is_array($currency) ? $currency['conversion_rate'] : $currency->conversion_rate);
 
//  if ($c_id != $default_currency)
//  {
        if ($to_currency)
            $price *= $c_rate;
        else
            $price /= $c_rate;
//  }
 
    return $price;
 

 

 

This way, the conversion will always be done, independent of being the default or not.

 

So now we can have a shop default (say $), with all our prices in $ in back office, and in our Euro shop, we can use a different 'default' currency (EUR), with a currency rate of xx.xx : 1 to the $. In the front office we then have only one currency (Euro), with the converted $ price to Euros visible.

 

Hope this may help anyone, if only the PrestaTeam :-)

 

pascal.

Link to comment
Share on other sites

  • 11 months later...

Hi all,

 

I have a problem with currency conversion. it's not working on HOME page but other pages it is working fine. Pls help me to sortout this. i am using prestashop 1.6

In localization it is set as default currency. 

 

Thanks

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...