Jump to content

[TUTORIAL] Disable some currencies in front office


Recommended Posts

In this tutorial, we show how to disable currencies in the front office. Imagine that you have 2 currencies in back office, but you only want to show 1 currency in the back office. 

The currencies are EUR and ARS as example.

You need to open the modules/blockcurrencies/blockcurrencies.tpl, or check if you have the file in your theme folder themes/yourthemename/blockcurrencies/blockcurrencies.tpl

 

The original code must looks liek this (in PS 1.6)

 

{if count($currencies) > 1}
<div id="currencies-block-top">
<form id="setCurrency" action="{$request_uri}" method="post">
<div class="current">
<input type="hidden" name="id_currency" id="id_currency" value=""/>
<input type="hidden" name="SubmitCurrency" value="" />
<span class="cur-label">{l s='Currency' mod='blockcurrencies'} :</span>
{foreach from=$currencies key=k item=f_currency}
{if $cookie->id_currency == $f_currency.id_currency}<strong>{$f_currency.iso_code}</strong>{/if}
{/foreach}
</div>
<ul id="first-currencies" class="currencies_ul toogle_content">
{foreach from=$currencies key=k item=f_currency}
{if strpos($f_currency.name, '('|cat:$f_currency.iso_code:')') === false}
{assign var="currency_name" value={l s='%s (%s)' sprintf=[$f_currency.name, $f_currency.iso_code][spam-filter]
{else}
{assign var="currency_name" value=$f_currency.name}
{/if}
<li {if $cookie->id_currency == $f_currency.id_currency}class="selected"{/if}>
<a href="javascript:setCurrency({$f_currency.id_currency});" rel="nofollow" title="{$currency_name}">
{$currency_name}
</a>
</li>
{/foreach}
</ul>
</form>
</div>
{/if}

 

The variable that contains the ID of the currenci is  $f_currency.id_currency, so we can use an IF statment to show only 1 currency adding:

 

{if $f_currency.id_currency eq 1}

 

Where 1 is the ID of the currency to show. 

 

Full code:

 

{if count($currencies) > 1}
<div id="currencies-block-top">
<form id="setCurrency" action="{$request_uri}" method="post">
<div class="current">
<input type="hidden" name="id_currency" id="id_currency" value=""/>
<input type="hidden" name="SubmitCurrency" value="" />
<span class="cur-label">{l s='Currency' mod='blockcurrencies'} :</span>
{foreach from=$currencies key=k item=f_currency}
{if $f_currency.id_currency eq 1}
{if $cookie->id_currency == $f_currency.id_currency}<strong>{$f_currency.iso_code}</strong>{/if}
{/if}
{/foreach}
</div>
<ul id="first-currencies" class="currencies_ul toogle_content">
{foreach from=$currencies key=k item=f_currency}
{if strpos($f_currency.name, '('|cat:$f_currency.iso_code:')') === false}
{assign var="currency_name" value={l s='%s (%s)' sprintf=[$f_currency.name, $f_currency.iso_code][spam-filter]
{else}
{assign var="currency_name" value=$f_currency.name}
{/if}
{if $f_currency.id_currency eq 1}
<li {if $cookie->id_currency == $f_currency.id_currency}class="selected"{/if}>
<a href="javascript:setCurrency({$f_currency.id_currency});" rel="nofollow" title="{$currency_name}">
{$currency_name}
</a>
</li>
{/if}
{/foreach}
</ul>
</form>
</div>
{/if}

 
Link to comment
Share on other sites

  • 1 month later...

I have USD and Mexican Pesos.

 

I used your code and it doest remove USD, but I need to display Mexican pesos as the mainly currency for new visitors.

 

I can´t change default currency from USD to Pesos cause all my prices are in USD and they change everyday

 

can someone help me ?

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

I have USD and Mexican Pesos.

 

I used your code and it doest remove USD, but I need to display Mexican pesos as the mainly currency for new visitors.

 

I can´t change default currency from USD to Pesos cause all my prices are in USD and they change everyday

 

can someone help me ?

 

You only need to change the currendies ID of the example for your currency ID

Hello,

 

"In this tutorial, we show how to disable currencies in the front office. Imagine you have two currencies in back office, but you want to show 1 currency in the back office."

 

It would be to show 1 currency in the front office or I'm wrong ?

1 currency or more, this example disable only 1 currency from front office

Link to comment
Share on other sites

You only need to change the currendies ID of the example for your currency ID

1 currency or more, this example disable only 1 currency from front office

 

I have disabled USD on my front office now clients only see prices on MXN thats what i wanted but here is the problem:

 

When a new customer enters the shop it sees the prices on USD (cause my default currency is USD) and I want them to enter the shop

and see prices on MXN. Cuase I´m running an Adwords campaign I don´t want new people see prices on USD.

Link to comment
Share on other sites

you can change this part of the code

 

{if $f_currency.id_currency eq 1}

 

to

 

{if $f_currency.id_currency eq 1 or $f_currency.id_currency eq 2}

 

That code enables the currency 1 and 2 and hide the 3

 

 

 Hi, 

 

 I need to hide currency 2 and only show only currency 1 on the front end. can you help me out with the code?

 

also, the line you mention shows twice in the code, should i replace it on both places?

Link to comment
Share on other sites

Hello,

 

You can use the example given at the top and copy twice :

{if $f_currency.id_currency eq 1}

This will hide all currencies except the one you choose !

 

Don't forget to check the ID for the currency !

 

Tested and works fine

 

 

Hi, that is exactly what I did and it does hide currency #2 from the currency selection box but the prices still show in currency #2, until you manually change them: please see for yourself http://laimportaderia.com/ 

Link to comment
Share on other sites

Here is my file working fine :

{if count($currencies) > 1}
    <div id="currencies-block-top">
	<form id="setCurrency" action="{$request_uri}" method="post">
		<div class="current">
		<input type="hidden" name="id_currency" id="id_currency" value=""/>
		<input type="hidden" name="SubmitCurrency" value="" />
		<span class="cur-label">{l s='Currency' mod='blockcurrencies'} :</span>
			{foreach from=$currencies key=k item=f_currency} 
			{if $f_currency.id_currency eq 1}
		  {if $cookie->id_currency == $f_currency.id_currency}<strong>{$f_currency.iso_code}</strong>{/if}
		{/if}   
		{/foreach}
		</div>
		<ul id="first-currencies" class="currencies_ul toogle_content">
		{foreach from=$currencies key=k item=f_currency}
	       {if strpos($f_currency.name, '('|cat:$f_currency.iso_code:')') === false}
                 {assign var="currency_name" value={l s='%s (%s)' sprintf=[$f_currency.name, $f_currency.iso_code][spam-filter]
		{else}
		{assign var="currency_name" value=$f_currency.name}
		{/if}
		{if $f_currency.id_currency eq 1}
	         <li {if $cookie->id_currency == $f_currency.id_currency}class="selected"{/if}>
                  <a href="javascript:setCurrency({$f_currency.id_currency});" rel="nofollow" title="{$currency_name}">
	       {$currency_name}
		</a>
	    </li>
	{/if}
      {/foreach}
   </ul>
</form>
</div>
{/if}

Remember to clear the cache !

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

 thank you, that is exactly the same code I am using. 

 

 And it works to limited extend. 

 

 My default currency has id = 2 

 

In the front end I only wish to show currency id = 1

 

currently the first time a user loads the site it loads currency 2. once they change to 1 they cannot go back to 2. 

 

is there a way to set currenyid to 1 everytime without the user having to change it ?

Link to comment
Share on other sites

Well,

 

I tested and installed on local Peso Mexico (MXN).

 

You can convert to Dollars ; Euro ; etc.

 

If you have selected ID currency 1 (MXN) you see Dollars and it's right !

 

You can browse to :

 

Localisation | Import |Mexico (Taxes, Devises, Unités monétaires and look at the change !!

 

I can see on your background site :

var currency = {"id":1,"name":"Peso","iso_code":"MXN","iso_code_num":"484","sign":"$","blank":"1","conversion_rate":"16.750112","deleted":"0","format":"1","decimals":"1","active":"1","prefix":"$ ","suffix":"","id_shop_list":null,"force_id":false};

Friendly

 

Your configuration is OK.

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

Yes, you're right !

 

Mexican Peso and USD have the same symbol... And United States of America copied the Mexican symbol !

 

https://vivre.aumexique.com/payer-en-dollars-ou-en-pesos-au-mexique/

 

Tested on local and works fine for me ! PS 1.6.0.6

 

I can see for Dollars the symbol is on the left and for MXN Pesos the symbol is on the right place !

Because the default currency - in your case -  is Dollars and customers need to change the currency with MXN for the first time.

 

It would be useful to change the default currency to MXN in your case !

You can do this change inside your Back-Office :

 

Localization | Setting | and change : Default language , Default currency, etc.

 

Remember to clear the cache !

 

And you will see the currency now is MXN at first load ;-)

Edited by myselfidem (see edit history)
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...