VirtueMart Forum

VirtueMart 2 + 3 + 4 => Language/Translations => Topic started by: drizzt99 on August 08, 2012, 21:06:41 PM

Title: Change currency per language?
Post by: drizzt99 on August 08, 2012, 21:06:41 PM
Hi,
I have a multilingual shop.
I've setup the products in one language to be in the currency of this language (e.g. English -> USD and Hebrew -> NIS).
Is there a way to show the prices in NIS when choosing the Hebrew language and the prices in USD when viewing the English language?
Thanks
Title: Re: Change currency per language?
Post by: alatak on August 09, 2012, 10:58:49 AM
Hello,

I have heard that you can do that with the GeopIp plugin. But i have not used it myself.
Title: Re: Change currency per language?
Post by: drizzt99 on August 09, 2012, 11:32:49 AM
Why should it be related to the geoIP plugin?
I just need fixed prices in USD for English and fixed prices in NIS for heb.  The user switches between the languages manually.
Title: Re: Change currency per language?
Post by: alatak on August 09, 2012, 11:36:50 AM
Hello,

It is a solution used by somebody else to force the language of the website according to the IP, and to force the currency also.

The other solution is to write a module that changes the currency according to the language.
I don't think that exists yet.
Title: Re: Change currency per language?
Post by: drizzt99 on August 09, 2012, 11:44:09 AM
Alrighty then :)
Title: Re: Change currency per language?
Post by: drizzt99 on August 09, 2012, 12:45:09 PM
Ok, I'm trying something, but it's not working.
Here's my code:

if ($_SESSION['lang']  == "he-il") {
$virtuemart_currency_id = 67;
}else{
$virtuemart_currency_id = 144;
}

$virtuemart_currency_id = $mainframe->getUserStateFromRequest( "virtuemart_currency_id", 'virtuemart_currency_id', $virtuemart_currency_id );


It doesn't change anything.  How can I set the userState var to be the correct currency ID?
Title: Re: Change currency per language?
Post by: alatak on August 09, 2012, 13:12:01 PM
Hello

use this instead


$jlang =JFactory::getLanguage();
$jlang->getDefault()


will return you the language tag

and to set the user state
$mainframe->setUserState( "virtuemart_currency_id", $virtuemart_currency_id );

for the user states documentation you can read this http://docs.joomla.org/How_to_use_user_state_variables
Title: Re: Change currency per language?
Post by: drizzt99 on August 17, 2012, 15:41:54 PM
Hi,
Thanks. It's working strange... it's as if the session changes after I refresh the screen.
Anyway - is there a way to setup a fixed price per currency and not a conversion (e.g. disable the conversion plugin)?
Title: Re: Change currency per language?
Post by: SamF on August 17, 2012, 18:08:30 PM
Hello,

"fixed price per currency" means fixed exchange rate, right?

The easy way is to set non-zero rates in currencies table (your_site/administrator/index.php?option=com_virtuemart&view=currency). Try 1USD = 1EUR, and see the prices in both currencies... What's nice in VM2, is that you can even set your private VM$)).

If you want to dig deeper, it's here: your_site\administrator\components\com_virtuemart\plugins\currency_converter\convertECB.php
Title: Re: Change currency per language?
Post by: drizzt99 on August 18, 2012, 18:58:18 PM
Hi,
THanks for the reply.
I do not mean "fixed exchanged rate".
I mean "fixed prices".
So, for instance, one product would cost 10$ and 100 in another currency.
Another product would cost 20$ and 150 in another currency.
Title: Re: Change currency per language?
Post by: jjk on August 18, 2012, 19:38:21 PM
I think this doesn't work. It is possible to assign different country specific price rules to a product, but then the customers would only see the correct price after they have entered their address in the cart.
Title: Re: Change currency per language?
Post by: drizzt99 on August 18, 2012, 20:43:55 PM
hmmm...
So... I can create products in 1 language, and the same products in another language with different prices.
The only thing's that's left is to force a certain currency on a certain language (e.g. USD for English and other currencies for other languages).
I tried to change the converter module, but it doesn't work. 
Here's my code:

$jlang =JFactory::getLanguage();
$lang = $jlang->getTag();

if ($lang == "he-il") {
$virtuemart_currency_id = 67;
}else{
$virtuemart_currency_id = 144;
}

$virtuemart_currency_id = $mainframe->setUserState("virtuemart_currency_id", $virtuemart_currency_id);

Any idea why it doesn't work?
Thanks
Title: Re: Change currency per language?
Post by: SamF on August 19, 2012, 08:53:24 AM
Hello,

Quote from: drizzt99 on August 18, 2012, 18:58:18 PM
So, for instance, one product would cost 10$ and 100 in another currency.
Another product would cost 20$ and 150 in another currency.

What is this another currency? Is it common base currency for product 1 and product 2? Or two products have individual base currencies? So, the rate between products 1 and 2 is 100/150?  How about the payment currency? Why not just use the ILS/USD exchange rate (fixed or market)? Too many "? ? ?", sorry)) Still, there is a couple of hack-free methods... 1) set individual currency for each product, 2) set separate shop for each language...

You can force the currency settings per language or visitor IP, but the visitor can force his or her language for the one with cheapest prices, or use proxy IP anywhere from Alaska to Timbuktu...
Title: Re: Change currency per language?
Post by: drizzt99 on August 19, 2012, 09:27:01 AM
Hi,
The other currency is NIS in this case, for both products.
I don't mind if users get to the site from another country to get the "cheaper" price.
I sent the code that was supposed to "force" the currency setting per language.  It's not working for some reason. 
What I did is the following:
I've created the products in English in the category "Products".  I've set the prices there for USD.
Then, I've created a copy of this category and products, only in Hebrew.   I've set the prices there for NIS.
Then I've added the code above so it would change the currency in the session according to the site's language:

$jlang =JFactory::getLanguage();
$lang = $jlang->getTag();

if ($lang == "he-il") {
$virtuemart_currency_id = 67;
}else{
$virtuemart_currency_id = 144;
}

$virtuemart_currency_id = $mainframe->setUserState("virtuemart_currency_id", $virtuemart_currency_id);

Can you please guide me how to do it?
I'd rather not use 2 different sites for this.
Title: Re: Change currency per language?
Post by: SamF on August 19, 2012, 09:30:39 AM
your_site\modules\mod_virtuemart_currencies\mod_virtuemart_currencies.php

lines between 26 and 37
Title: Re: Change currency per language?
Post by: drizzt99 on August 19, 2012, 09:32:33 AM
What do I do with it?
This is where I put my code...
Title: Re: Change currency per language?
Post by: drizzt99 on August 19, 2012, 09:42:39 AM
Ok,
I've made the following changes:
Template file -

Ok,
I did the change:

<?php // no direct access
defined('_JEXEC') or die('Restricted access'); ?>


<!-- Currency Selector Module -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(document).ready(function(){
        $("form#converter").submit();
    });

    </script>
<?php echo $text_before ?>
<form action="<?php echo JURI::getInstance()->toString(); ?>" method="post" id="converter">
<br />
<?php echo JHTML::_('select.genericlist'$currencies'virtuemart_currency_id''class="inputbox"''virtuemart_currency_id''currency_txt'$virtuemart_currency_id) ; ?>
    <input class="button" type="submit" name="submit" value="<?php echo JText::_('MOD_VIRTUEMART_CURRENCIES_CHANGE_CURRENCIES'?>" />
</form>


Inside the module main file I've added this:

$jlang =JFactory::getLanguage();
$lang = $jlang->getTag();
if ($lang == "he-il") {
$virtuemart_currency_id = 67;
}else{
$virtuemart_currency_id = 144;
}


It still doesn't work... any idea why?
Thanks
Title: Re: Change currency per language?
Post by: SamF on August 20, 2012, 07:40:23 AM
Hello,

Code (your_site\modules\mod_virtuemart_currencies\mod_virtuemart_currencies.php after line 37) Select

$jlang =JFactory::getLanguage();
$lang = $jlang->getTag();
if ($lang == "he-IL")
    {$virtuemart_currency_id = 67;}
    else
    {$virtuemart_currency_id = 144;}
$mainframe->setUserState("virtuemart_currency_id", $virtuemart_currency_id);


works for me... does not require to submit the form.
Title: Re: Change currency per language?
Post by: drizzt99 on August 20, 2012, 07:57:25 AM
That's the first thing I tried.
It doesn't work... for some reason, it works when I use the form, but doesn't work when I just switch language...
Can you send me a link of where it works for you?
Title: Re: Change currency per language?
Post by: SamF on August 20, 2012, 10:57:09 AM
http://virtuext.com/joomla25/virtuemart (http://virtuext.com/joomla25/virtuemart)

Switch the language; English comes with $, French gives you old good French francs).
Title: Re: Change currency per language?
Post by: drizzt99 on August 20, 2012, 12:04:45 PM
It's not working for you either.
I click on the French flag, and price remains in USD.
If I click a second time, it switches to Euros.
Then, when I click on the English flag, I get the site in Eng, but prices in Euros.
Click a second time on the Eng flag, and you get the prices in USD.
This is exactly what happens to me.  There's the "lag" in switching the currency.
Any way around this problem?
Title: Re: Change currency per language?
Post by: SamF on August 20, 2012, 12:16:29 PM
Quote from: drizzt99 on August 20, 2012, 12:04:45 PM
I click on the French flag, and price remains in USD.
If I click a second time, it switches to Euros.
...
Any way around this problem?

Cache...

When you switch the language, the currency selector switches too, right? So does the vm_currency_id. But the prices on the page (if any are shown) remain in previous currency until you refresh the page. You do it by clicking on the flag again, or F5...

Click on the flag once, then go to the category or product details page. Did it work?

So, the question is "how to clean cache on lang switch?".

P.S.: I think, it does work (in terms of your task). Set aside, if your browser is in certain language, you will get the page in certain currency at entry.
Title: Re: Change currency per language?
Post by: drizzt99 on August 20, 2012, 12:19:16 PM
hmmm...
So if it is cache, is there a way to disable cache for prices only?
Title: Re: Change currency per language?
Post by: SamF on August 20, 2012, 12:21:23 PM
Would appreciate, if you find out the answer, then share it))
Title: Re: Change currency per language?
Post by: drizzt99 on August 20, 2012, 12:48:00 PM
Ok,
I think it's done right now, but it's changing core files, which is bad for biz.
Add this code:

$lang =& JFactory::getLanguage();
   
        if ($lang->get('tag') == "he-IL" ) {
             $currencyId  = 67;
              }
           else {
             $currencyId  = 144;
            }


In 2 places in the file (/administrator/components/com_virtuemart/helpers/currencydisplay.php):
1) Right after public function getCurrencyForDisplay( $currencyId=0 ){
2) Right after self::$_instance = new CurrencyDisplay($vendorId);

Just don't forget to change he-IL to french and the 67 to the french number.

Worked for me...
Title: Re: Change currency per language?
Post by: blistar on October 12, 2012, 13:51:25 PM
Doesn't work

PHP Fatal error: Call to a member function get() on a non-object in /var/www/vhosts/insanto.org/httpdocs/administrator/components/com_virtuemart/helpers/currencydisplay.php on line 96

Title: Re: Change currency per language?
Post by: blistar on October 15, 2012, 01:40:28 AM
Sory, no comment about this solution? May be somebody knows one or more solutions?
Title: Re: Change currency per language?
Post by: bytelord on October 15, 2012, 07:11:25 AM
Hello

You forgot to mention your joomla, vm and PHP version.

Regards
Title: Re: Change currency per language?
Post by: blistar on October 15, 2012, 09:47:04 AM
Sorry.

We have two shops.

One one Joomla is 2.5.7 and one more 2.5.4

Virtuemart 2.0.10 och Virtuemart 2.0.12

PHP on the server 5.2.17

:)

Title: Re: Change currency per language?
Post by: bytelord on October 20, 2012, 14:22:58 PM
hi, i think i had reply on you :)

Please upgrade your php to 5.3.x and post your results.

Regards
Title: Re: Change currency per language?
Post by: Ihateit on November 22, 2012, 14:59:22 PM
Has anyone got a solution for this??? I think it's an pretty important feature. Someone must have made it work

(i want to change currency, when language is changed)

//Anders J.
Title: Re: Change currency per language?
Post by: SamF on November 22, 2012, 16:28:52 PM
Did you try this: https://forum.virtuemart.net/index.php?topic=106192.msg355855#msg355855 ?
Title: Re: Change currency per language?
Post by: Ihateit on November 23, 2012, 11:57:01 AM
That worked like a charm. Thank you very much. Where do i find the virtuemart_currency_id list? I dont know what IDs Danish Kroner, Swedish Kroner, Norweigan Kroner and Euro has.

To clarify what i did to make this work, to future troubleshooters:

I pasted the code under this line, after the line 37: $virtuemart_currency_id = $mainframe->getUserStateFromRequest( "virtuemart_currency_id", 'virtuemart_currency_id',JRequest::getInt('virtuemart_currency_id', $vendor_currency['vendor_currency']) );   ----- in the \modules\mod_virtuemart_currencies\mod_virtuemart_currencies.php file.
$jlang =JFactory::getLanguage();
$lang = $jlang->getTag();
if ($lang == "da-DK")
    {$virtuemart_currency_id = 208;}
    elseif ($lang == "se-SV")
    {$virtuemart_currency_id = 752;}
elseif ($lang == "no-NO")
    {$virtuemart_currency_id = 578;}
else
    {$virtuemart_currency_id = 978;}

The Currency IDs are random though..
Title: Re: Change currency per language?
Post by: SamF on November 23, 2012, 12:11:12 PM
There is no "list", I think. Not in VM backend. Browse your database table jos_virtuemart_currencies for virtuemart_currency_id.
Title: Re: Change currency per language?
Post by: Ihateit on November 23, 2012, 13:38:24 PM
Again thanks a lot. That really helped out. Everything is working perfectly now. Except i can't remove the decimals from my prices(even when disabling it in administration). But that is different topic :-P
Title: Re: Change currency per language?
Post by: Honza on November 28, 2012, 17:49:54 PM
Hi. I tried this plugin: http://www.easyjoomla.org/virtuemart-language-currency-switcher (http://www.easyjoomla.org/virtuemart-language-currency-switcher)

And it works just like I need it  ;)
Title: Change currency per language?
Post by: atrus on December 03, 2012, 20:14:57 PM
Hi to all,

This feature is also implemented in Artio's Joomsef for anyone interested. (We had asked this to the developers)

Rgrds,
Chris

Sent from my BlackBerry 9360 using Tapatalk
Title: Re: Change currency per language?
Post by: nhinzky on April 05, 2013, 14:17:47 PM
Quote from: drizzt99 on August 20, 2012, 12:48:00 PM
Ok,
I think it's done right now, but it's changing core files, which is bad for biz.
Add this code:

$lang =& JFactory::getLanguage();
   
        if ($lang->get('tag') == "he-IL" ) {
             $currencyId  = 67;
              }
           else {
             $currencyId  = 144;
            }


In 2 places in the file (/administrator/components/com_virtuemart/helpers/currencydisplay.php):
1) Right after public function getCurrencyForDisplay( $currencyId=0 ){
2) Right after self::$_instance = new CurrencyDisplay($vendorId);

Just don't forget to change he-IL to french and the 67 to the french number.

Worked for me...
Thanks! works for me  :D
Title: Re: Change currency per language?
Post by: davidator on May 03, 2013, 21:50:13 PM
hello
do you think its possible, with your code,  to change currencie for a specific category ?
I mean,  category number  instead of a language   

Products of Category1 (11111)=> $             other Category Products=>€


   
        if ($cat==11111 ) {
             $currencyId  = 67;
              }
           else {
             $currencyId  = 144;
            }

Thank You