Jump to content

[Solved] Different currency in Front Office and Back Office


Recommended Posts

You can set the default currency on the Payment > Currencies tab to "Dollar", then enter the currency rate of "Dollar" to 1 and the currency rate of "Rupiah" to the appropriate multipler. You can then enter the prices in the Back Office in "Dollar" and customers will be able to see the prices in either "Dollar" or "Rupiah" on your website.

Link to comment
Share on other sites

You can set the default currency on the Payment > Currencies tab to "Dollar", then enter the currency rate of "Dollar" to 1 and the currency rate of "Rupiah" to the appropriate multipler. You can then enter the prices in the Back Office in "Dollar" and customers will be able to see the prices in either "Dollar" or "Rupiah" on your website.


i don't want to use 2 option of currency in Front Office ($ | Rp)("Dollar" or "Rupiah") .. but , i want to automattically only use Rupiah in front office ..
Link to comment
Share on other sites

Then uninstall the "Currency block" and change line 22 of init.php from:

$cookie = new Cookie('ps');



$cookie = new Cookie('ps');
$cookie->id_currency = 2;



Change 2 to the ID of the currency you want to be used in the Front Office. This will force the currency to 2 whenever a customer visits your site.

Link to comment
Share on other sites

Then uninstall the "Currency block" and change line 22 of init.php from:

$cookie = new Cookie('ps');



$cookie = new Cookie('ps');
$cookie->id_currency = 2;



Change 2 to the ID of the currency you want to be used in the Front Office. This will force the currency to 2 whenever a customer visits your site.



IT WORKS .... THANK YOU VERY MUCH .....
Link to comment
Share on other sites

  • 3 months later...

Hi there, the solution works perfectly for previous versions, but in the new 1.4 doesn't, I was trying to solve that, so I have a temporal solution, (at least while some one else get a better solution)

In your headet.tpl file from your template directory add this in the line 63 or wherever your body tag is:

<body {if $page_name}onLoad="setCurrency(1);" id="{$page_name|escape:'htmlall':'UTF-8'}"{/if}>


I just added the command that call the function to change the currency when loads the page "setCurrency();", you have to change the value for your prefered currency value

Link to comment
Share on other sites

  • 2 months later...

for v1.4 you can override the Tools class using the following code.

This code forces the Front Office currency to ZAR (or Rand), while leaving the Back Office currency whatever the default currency is.

class Tools extends ToolsCore
{
   public static function setCurrency()
   {
       global $cookie;
       $currency = Currency::getCurrencyInstance((int)Currency::getIdByIsoCode('ZAR'));
       if (is_object($currency) AND $currency->id)
           $cookie->id_currency = (int)($currency->id);
       return $currency;
   }
}

Link to comment
Share on other sites

i have 2 currency, dollar & rupiah .. i want input the price in the admin (BO) with dollar ,, and appears in the website (FO) with Rupiah .. of course, after automatically converted ..

anyone can tell me the way to do that .. ?? :)

*thanks before for the answer .. :)


i hope , this module could be useful for you

http://prestashopmodul.com/en/11-multi-currency-solution.html
  • Like 1
Link to comment
Share on other sites

  • 1 month later...

Thanks for your help

Y arriba Mexico!!!

 

 

Hi there, the solution works perfectly for previous versions, but in the new 1.4 doesn't, I was trying to solve that, so I have a temporal solution, (at least while some one else get a better solution)<br/><br/>In your headet.tpl file from your template directory add this in the line 63 or wherever your body tag is:<br/>

<body {if $page_name}onLoad="setCurrency(1);" id="{$page_name|escape:'htmlall':'UTF-8'}"{/if}>

<br/>I just added the command that call the function to change the currency when loads the page "setCurrency();", you have to change the value for your prefered currency value

Link to comment
Share on other sites

  • 6 months later...
  • 2 months later...
  • 6 months later...

for v1.4 you can override the Tools class using the following code.

 

This code forces the Front Office currency to ZAR (or Rand), while leaving the Back Office currency whatever the default currency is.

 

class Tools extends ToolsCore
{
public static function setCurrency()
{
	global $cookie;
	$currency = Currency::getCurrencyInstance((int)Currency::getIdByIsoCode('ZAR'));
	if (is_object($currency) AND $currency->id)
		$cookie->id_currency = (int)($currency->id);
	return $currency;
}
}

Hello,

Works for Prestashop 1.5

Thank you!

 

public static function setCurrency($cookie)
{

  $currency = Currency::getCurrencyInstance((int)Currency::getIdByIsoCode('UAH'));
 if (is_object($currency) && $currency->id)
  $cookie->id_currency = (int)$currency->id;
 return $currency;
}

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

  • 9 months later...

The problem with this solution is that it prevents users from being able to switch currencies. I need to have a separate default in front and back while maintaining the ability to change on the front.

 

for v1.4 you can override the Tools class using the following code.

 

This code forces the Front Office currency to ZAR (or Rand), while leaving the Back Office currency whatever the default currency is.

 

class Tools extends ToolsCore
{
public static function setCurrency()
{
	global $cookie;
	$currency = Currency::getCurrencyInstance((int)Currency::getIdByIsoCode('ZAR'));
	if (is_object($currency) AND $currency->id)
		$cookie->id_currency = (int)($currency->id);
	return $currency;
}
}

Link to comment
Share on other sites

My solution:

 

////////////////////////////////////////////////////////////////////////////////////////////////
 // Override to show USD by default on front-end while maintaining KRW default in the back-end //
 ////////////////////////////////////////////////////////////////////////////////////////////////
 /**
  * Set cookie currency from POST or default currency
  *
  * @return Currency object
  */
 public static function setCurrency($cookie)
 {
   if (Tools::isSubmit('SubmitCurrency'))
     if (isset($_POST['id_currency']) && is_numeric($_POST['id_currency']))
     {
       $currency = Currency::getCurrencyInstance($_POST['id_currency']);
       if (is_object($currency) && $currency->id && !$currency->deleted && $currency->isAssociatedToShop())
         $cookie->id_currency = (int)$currency->id;
     }

   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)
       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(2);
   if (is_object($currency) && $currency->id)
     $cookie->id_currency = (int)$currency->id;

   return $currency;
 }

Link to comment
Share on other sites

  • 1 month later...

Then uninstall the "Currency block" and change line 22 of init.php from:

 

$cookie = new Cookie('ps');

$cookie = new Cookie('ps');$cookie->id_currency = 2;

Change 2 to the ID of the currency you want to be used in the Front Office. This will force the currency to 2 whenever a customer visits your site.

 

 

hi Rocky,

 

what I need to do to make prestashop 1.5.4.1 work ?

 

thanks my friend.

Link to comment
Share on other sites

prestashop 1.5 doesnt use $cookie variable, in new ps you have to use context object to achieve this

hi Vekia...

 

Is this correct line ? 

 

q59f.jpg

 

if yes, how I change ? 

 

$context->currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));$context->id_currency = 2;

 

like this not work...

 

if this line is wrong, what is correct line ?

 

thanks my friend.

Link to comment
Share on other sites

  • 2 weeks later...
  • 5 weeks later...
  • 2 weeks later...

you can use many currencies in prestashop, you can define default shop currency in back office: localization > localization

there is option to define default currency.

 

for what purposes you want different currencies? it's not useful 

Link to comment
Share on other sites

  • 2 weeks later...

Hello, I found a way around to solve my problem. As I don't need people to access my store from other countries, I turned on the geolocation feature and blocked everyone but my country. Also, turned off the Block Currency. This way, I have the USD as the default currency but in the frontpage is always displayed my country's currency.  :)

Link to comment
Share on other sites

  • 4 months later...

Hello,

 

How can I use this default currency override in multistore?

 

Two shops have the same default currency in BO.

I need one shop to show default currency in front office and another to show non-default currency on front office, so that user does not have to change it manually.

 

Is it possible?

PrestaShop version 1.5.6.2

 

 

 

you have to define whole new object, instead of :

$context->currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT'));$context->id_currency = 2;

just use:

$context->currency = new Currency(2);

 

Link to comment
Share on other sites

  • 2 months later...

Hello....

 

i just install Prestashop 1.5.6.2 for my web store.

i want to use US Dollar as default currency in Back Office and Rupiah as default currency in Front Office (only one currency).

My products is imported, so have to use US Dollar.

 

Anybody can help me, please....

 

 

Best regards

  • Like 1
Link to comment
Share on other sites

  • 1 month later...
  • 3 months later...
  • 1 month later...

Hi,

For Prestashop 1.6.0.9 force currency in frontend.

 

/public_html/classes/tools.php

Replace  line 431
$currency = Currency::getCurrencyInstance((int)$cookie->id_currency);
with
$currency = Currency::getCurrencyInstance((int)$cookie->id_currency=2);

Replace line 433
$currency = Currency::getCurrencyInstance(Configuration::get('PS_CURRENCY_DEFAULT'));
with
$currency = Currency::getCurrencyInstance(Configuration::get('id_currency'));
 

It works on my website.

Edited by cristidam (see edit history)
  • Like 4
Link to comment
Share on other sites

  • 5 months later...
class Tools extends ToolsCore
{
	public static function setCurrency()
	{
		global $cookie;
		$currency = Currency::getCurrencyInstance((int)Currency::getIdByIsoCode('GBP'));
		if (is_object($currency) AND $currency->id)
			$cookie->id_currency = (int)($currency->id);
		return $currency;
	}
}

eg. for GBP.. in PS1.4

but my question is:

 

how to exclude payment modules?

does it work for home, product pages, categories or that override works for any page?

I need to exclude the payment module, if it has to show another currency with the correct exchange..

thanks

Link to comment
Share on other sites

  • 1 month later...

hello, the real problem is another:

if the default shop currency is GBP but the front currency for payment method is EUR

the final invoice with this override method is GBP and it's not good...it should be EUR

so I need to show GBP as default FRONT currency BUT in case the user chooses a payment method which allows EUR only

after the final callback from the gateway the invoice must be in EUR... and THEN just the front currency has to return in GBP

please, how to do it?

 

Bellini,

"...while leaving the Back Office currency whatever the default currency is."

do you mean that in my case I should leave EUR as default shop currency and use the override for the front part only?

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

Hi,

For Prestashop 1.6.0.9 force currency in frontend.

 

/public_html/classes/tools.php

Replace  line 431
$currency = Currency::getCurrencyInstance((int)$cookie->id_currency);
with
$currency = Currency::getCurrencyInstance((int)$cookie->id_currency=2);

Replace line 433
$currency = Currency::getCurrencyInstance(Configuration::get('PS_CURRENCY_DEFAULT'));
with
$currency = Currency::getCurrencyInstance(Configuration::get('id_currency'));
 

It works on my website.

 

 

 

this not work, because when i try to do it, cart is empty and i dont get checkout. beyond it, we get this error:

 

Use of undefined constant PS_ROUND_HALF_DOWN - assumed 'PS_ROUND_HALF_DOWN'

 

 

how to solve all this?

Link to comment
Share on other sites

  • 1 month later...

Then uninstall the "Currency block" and change line 22 of init.php from:

 

$cookie = new Cookie('ps');

$cookie = new Cookie('ps');$cookie->id_currency = 2;

Change 2 to the ID of the currency you want to be used in the Front Office. This will force the currency to 2 whenever a customer visits your site.

 

 hi ,

 

does it work on 1.6.0.14 ? 

and what is the path of the file 

 

thank you 

Link to comment
Share on other sites

  • 3 months later...

Im using the latest version of Prestashop 1.6.1.4 and I am using USD as default currency in the backend (Importe products with cost in USD) of the store but I would like to use MXN (mexican peso) in the front end. Also I would like that PayPal module takes the MXN as input but in the website where is displayed the amount of the order is changed to USD taking into account the currency rate of Prestashop NOT PayPal.

Link to comment
Share on other sites

  • 1 month later...

I have been scratching my head whole day but cannot find the reason for this issue. My site is ginbaba.com

 

 I am having a similar problem, it is not possible to change the currency on the front office. I tried to make a new installation of prestashop 1.6.x  and change the currency but that did not worked either. 

 

I hope someone can help. I have cleaned all the cashes ...... kindly help anyone .....

Link to comment
Share on other sites

  • 1 year later...

You can buy an extension for PrestaShop or you can do it yourself, fix just two lines of code.

So, open the file /classes/tools.php and find this (twice):

Currency::getCurrencyInstance((int)$cookie->id_currency);

 

And replace it to

Currency::getCurrencyInstance(N);

 

where N is an id of currency (1, 2, 3 etc.).

That's all. Don't forget to save the file. Tested with PrestaShop 1.6.

Link to comment
Share on other sites

  • 3 weeks later...

 

You can buy an extension for PrestaShop or you can do it yourself, fix just two lines of code.

So, open the file /classes/tools.php and find this (twice):

Currency::getCurrencyInstance((int)$cookie->id_currency);

 

And replace it to

Currency::getCurrencyInstance(N);

 

where N is an id of currency (1, 2, 3 etc.).

That's all. Don't forget to save the file. Tested with PrestaShop 1.6.

 

Hi

you copied this solution from another page on the web.... that's ok, but i was looking for some explanations more, the text is not clear for whom that are not developers :-)

 

Can you please tell me what it means?

 

N is an id of currency (1, 2, 3 etc.).

 

Can you make an example? 

So, in my backoffice i pay EUR to my suppliers and i calculate the selling price in EUR.

To do this, if i don't misunderstand, i set up the default currency to EUR.

But I want my frontoffice to show another currency, for example USD, because my buyers will pay USD to me. 

So how should i change that line?

 

Thank you very much for your help :-)

 

V

Link to comment
Share on other sites

  • 1 year later...

Hello,

Is there any solution for this for Prestashop 1.7.4.4?

I want to set default currency on back office in Euro but Malaysian RInggit (MYR) for front office?
And of course the MYR currency displayed after converted from Euro to MYR.

Anyone can assist me on this, please?

Thank You

Link to comment
Share on other sites

  • 10 months later...

 

On 11/18/2018 at 5:55 AM, El Patron said:

This module support different default front office currency than what is defined as your shop default currency.

https://www.prestaheroes.com/en-us/modules/front-office-default-currency

 

7 hours ago, Donny said:

Thank you for the tip EL Patron! I bought that module 2 days ago after i saw this post and it works like a dream! Very reasonable price to.

 

Thanks for trusting in our work, happy selling.

el

Link to comment
Share on other sites

  • 5 months later...

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...