Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

Use MetaTemplate to change VM currency!

Use MetaTemplate to change VM currency!


UPDATE 2016:
In Chameleon v2.58 released 1 June 2016, there's a new feature:
In any SUCCEED or FAIL action you can now directly set a new currency. In the rule you can use a drop-down selector to choose out of all supported currencies in VirtueMart.

This makes it very easy to set a particular currency for people connecting from a given country, using a certain language, or who are part of a given shopper group.

Enjoy!




Someone was asking me about how to use MetaMod to automatically change VirtueMart's currency, based on GeoIP.

MetaMod probably isn't the best way to do it, since the modules are run only after the rest of the page is generated. i.e. by that time, the currencies are already displayed in the "wrong" currency, so the MetaMod would have to do a redirect... not very efficient.

Anyway it turns out that it's really easy to change the currency as a result of a MetaTemplate or MetaTemplate Pro rule.

All you need to do in the SUCCEED or FAIL action is the following:

// use the 3-letter currency code for the desired currency,
// e.g. GBP, USD, NZD, EUR etc:
JRequest::setVar("product_currency","GBP");


So if you want to force this to a particular currency based on the country the person is connecting from, then in the "detection" side of MetaTemplate you would just detect a particular country with GeoIP.

e.g. in the main PHP box on the LEFT side of the rule page:

if ($fromCountryId == "US") return true;

Now, if you want to still allow people to override the preset currency selection, it's a little more tricky. You would want to only do the SUCCEED action the first time they hit a VM page(*), and then only if the product_currency had not already been set.

(*) that is, any page that is a com_virtuemart page, or any page that contains a VM module that includes virtuemart's global.php file. This includes any page that has the mod_virtuemart module displayed.

I think this would work, on the left side of a MetaTemplate/Pro rule:

// force a "succeed" action to set the currency, but only
// if there's not already one set in this session, and only
// if someone didn't use the drop-down to force a particular
// currency.

if ( !isset($_SESSION['product_currency']) and !isset( $_REQUEST['product_currency'] ) ) return true;


Of course, you probably want to combine that with a GeoIP rule to detect a particular country.

If you want any help with variations of this technique, please post replies in this forum thread.

Hope this helps someone - I think it's a very cool technique!

Cheers,
Stephen

Edited By: metamodguy
02-Jun-16 09:10:19

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3329 Posts
User info in posts
Administrator has disabled public posting

Re: Use MetaTemplate to change VM currency!

Hi Stephen,

I've tried out the method you suggested and it works great by tracking country IP and showing the currency. But i still need users to be able to override the rule when they change currency from home page on my currency selector module. Right now it just gets stuck unable to change to any other currency.

Rules currently set: if ( $fromCountryId == "SG")return true;
Succeed action: JRequest::setVar("product_currency","SGD");

I think that it might be because it's looping back to the rule i've set. A few methods i've tried hoping to get pass the loop if users change a currency from the module selector.

(Method 1)
Rule 1: if ( !isset($_SESSION['product_currency']) and !isset( $_REQUEST['product_currency'] ) ) return true;
Succeed action: proceed to next rule

Rule 2: if ( $fromCountryId == "SG")return true;
Succeed action: JRequest::setVar("product_currency","SGD");
End process

(Method 2)
Rule 1: if ( $fromCountryId == "SG")return true;
Set Session variable A
Succeed action: proceed to next rule

Rule 2: if ( !isset($_SESSION['product_currency']) and !isset( $_REQUEST['product_currency'] ) ) return true;
Detect Session variable A
Remove Session variable A
Re Set Session variable A
Succeed action: JRequest::setVar("product_currency","SGD");
End process

(Method 3) - Just trying a workaround to see if it can override if i select USD input from my currency selector
Rule 1: if ( $fromCountryId == "SG")return true;
Set Session variable A
Succeed action: JRequest::setVar("product_currency","SGD");

Rule 2: if ( $product_currency == "USD")return true;
Detect Session variable A
Remove Session variable A
Re Set Session variable A
Succeed action: JRequest::setVar("product_currency","USD");
End process

I've been meddling for days with no clues on how the process or looping should go. Hoping that you can give me a little suggestions. Thanks a million!

jimmy85
Beginner Modder
ranks
useravatar
Offline
2 Posts
Administrator has disabled public posting

Re: Use MetaTemplate to change VM currency!

ok, let's look at some steps here:

1 - if we detect that the person has manually specified a currency, then we bail out and allow VM to set and remember that currency.

2 - if there's no currency in the session (i.e. they have not yet manually specified a currency, and we haven't set one in Chameleon yet), and they are from singapore, set SGP as currency.

To achieve this I'd create 2 rules:


Rule 1: bail out if currency has already been set by user or in Chameleon:

if ( isset($_SESSION['product_currency']) or isset($_POST['product_currency'])) return true;

... and in the Succeed action, just "Stop processing".


Rule 2: we only get here if the currency has not been set yet. So we just check if they are from Singapore:

if ($fromCountryId == "SG") return true;

... and in the Succeed action:

JRequest::setVar("product_currency","SGD");


This works on my test setup - I think it should work for you too.

Cheers,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3329 Posts
User info in posts
Administrator has disabled public posting

Re: Use MetaTemplate to change VM currency!

Hi Stephen,

Thks for the advise set up. It works perfectly. Perfect solutions for people looking to do currency selection in virtuemart tracking geoip.

Will definitely recommend chameleon for the implementation. Simple and easy to use! Cheers! Ur the man! big_smile

jimmy85
Beginner Modder
ranks
useravatar
Offline
2 Posts
Administrator has disabled public posting

Re: Use MetaTemplate to change VM currency!

Hi there Stephen,

I remember chatting to you I'd say at least 5 years ago re: MetaMod.... Great to see you're still going strong (just checked and it was 1/18/09 and you got me sorted back then smile ).

I just purchased Chameleon and have been trying to configure it as per your post in 2011.

I'm running the first rule:
if ( isset($_SESSION['product_currency']) or isset($_POST['product_currency'])) return true;

and have the 2nd as:
if ($geoip->country_code3 == "USA") return true;
and
JRequest::setVar("product_currency","USD");
on the succeed actions side but now joy.

I know your post is a couple of years old and referenced MetaTemplate. Should these settings work with Chameleon? If not any advice?

I have the Enable GeoIP/GeoCity side working (tested that in MetaMod Pro off US IP).

Regards,

Mike

lowemail
Guest
useravatar
Offline
Administrator has disabled public posting

Re: Use MetaTemplate to change VM currency!

Hi Mike,

Things have changed a little in VM2.0 for currency setting. Currencies now have numerical IDs associated with them, and a different variable name.

So when you set the currency, you would need to do this:

JRequest::setVar('virtuemart_currency_id',144); // 144 is USD at least on my setup

Some of the other currencies are:

52 GBP
26 CAD
47 EUR
144 USD

Others will be found in the database table #_virtuemart_currencies, with column virtuemart_currency_id holding the id number and currency_code_3 holding the 3-letter currency code.

For your 1st rule, which I guess is there to bypass the rest of the rules if the currency has already been set, you might want to change it to:

// test to see if the currency has already been set:
$currency = JFactory::getApplication()->getUserState('virtuemart_currency_id');
if ( $currency != '' ) return true;

The thing I am not sure about before testing is whether the userstate gets set only when the currency is explicitly changed, or whether it gets populated the 1st time you do anything VM-related in a session. If the latter, you'd need to adjust the bypass rule so that it only triggers once the currency has been *explicitly* set via Chameleon or via the standard currency module. You could do that by setting a session variable when such a change is detected, then triggering based on that session variable on subsequent page loads.

Hope that helps,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3329 Posts
User info in posts
Administrator has disabled public posting

Re: Use MetaTemplate to change VM currency!

To follow up:

On a newly installed Joomla 3.4.1, VM 3.0.9, the codes and currencies are as follows. If these codes don't work on your system, check the #_vm_currencies table for the codes according to your database.

To use, type the following into the PHP box in the Succeed (or Fail) action:

JRequest::setVar('virtuemart_currency_id',XXX);
// replace XXX with the code for the currency you want to change to, e.g. 4 for Albanian Lek.


On with the values:

virtuemart_currency_id, currency_code_3, currency_name
2, AED, United Arab Emirates dirham
4, ALL, Albanian lek
5, ANG, Netherlands Antillean gulden
7, ARS, Argentine peso
9, AUD, Australian dollar
10, AWG, Aruban florin
11, BBD, Barbadian dollar
12, BDT, Bangladeshi taka
15, BHD, Bahraini dinar
16, BIF, Burundian franc
17, BMD, Bermudian dollar
18, BND, Brunei dollar
19, BOB, Bolivian boliviano
20, BRL, Brazilian real
21, BSD, Bahamian dollar
22, BTN, Bhutanese ngultrum
24, BWP, Botswana pula
25, BZD, Belize dollar
26, CAD, Canadian dollar
27, CHF, Swiss franc
28, CLF, Unidad de Fomento
29, CLP, Chilean peso
30, CNY, Chinese renminbi yuan
31, COP, Colombian peso
32, CRC, Costa Rican colÌ_n
33, CZK, Czech koruna
34, CUP, Cuban peso
35, CVE, Cape Verdean escudo
40, DKK, Danish krone
41, DOP, Dominican peso
42, DZD, Algerian dinar
44, EGP, Egyptian pound
46, ETB, Ethiopian birr
47, EUR, Euro
49, FJD, Fijian dollar
50, FKP, Falkland pound
52, GBP, British pound
54, GIP, Gibraltar pound
55, GMD, Gambian dalasi
56, GNF, Guinean franc
58, GTQ, Guatemalan quetzal
60, GYD, Guyanese dollar
61, HKD, Hong Kong dollar
62, HNL, Honduran lempira
63, HTG, Haitian gourde
64, HUF, Hungarian forint
65, IDR, Indonesian rupiah
67, ILS, Israeli new sheqel
68, INR, Indian rupee
69, IQD, Iraqi dinar
70, IRR, Iranian rial
73, JMD, Jamaican dollar
74, JOD, Jordanian dinar
75, JPY, Japanese yen
76, KES, Kenyan shilling
77, KHR, Cambodian riel
78, KMF, Comorian franc
79, KPW, North Korean won
80, KRW, South Korean won
81, KWD, Kuwaiti dinar
82, KYD, Cayman Islands dollar
83, LAK, Lao kip
84, LBP, Lebanese pound
85, LKR, Sri Lankan rupee
86, LRD, Liberian dollar
87, LSL, Lesotho loti
89, LYD, Libyan dinar
90, MAD, Moroccan dirham
92, MNT, Mongolian țgr̦g
93, MOP, Macanese pataca
94, MRO, Mauritanian ouguiya
96, MUR, Mauritian rupee
97, MVR, Maldivian rufiyaa
98, MWK, Malawian kwacha
100, MYR, Malaysian ringgit
102, NGN, Nigerian naira
105, NOK, Norwegian krone
106, NPR, Nepalese rupee
107, NZD, New Zealand dollar
108, OMR, Omani rial
109, PAB, Panamanian balboa
110, PEN, Peruvian nuevo sol
111, PGK, Papua New Guinean kina
112, PHP, Philippine peso
113, PKR, Pakistani rupee
114, PLN, Polish Zâoty
116, PYG, Paraguayan guaranÌ_
117, QAR, Qatari riyal
118, RON, Romanian leu
119, RWF, Rwandan franc
120, SAR, Saudi riyal
121, SBD, Solomon Islands dollar
122, SCR, Seychellois rupee
124, SEK, Swedish krona
125, SGD, Singapore dollar
126, SHP, Saint Helenian pound
127, SLL, Sierra Leonean leone
128, SOS, Somali shilling
130, STD, SÌ£o TomÌ© and PrÌ_ncipe dobra
131, RUB, Russian ruble
132, SVC, Salvadoran colÌ_n
133, SYP, Syrian pound
134, SZL, Swazi lilangeni
135, THB, Thai baht
136, TND, Tunisian dinar
137, TOP, Tongan paæÈanga
139, TRY, Turkish new lira
140, TTD, Trinidad and Tobago dollar
141, TWD, New Taiwan dollar
142, TZS, Tanzanian shilling
144, USD, United States dollar
147, VND, Vietnamese Dong
148, VUV, Vanuatu vatu
149, WST, Samoan tala
151, YER, Yemeni rial
152, RSD, Serbian dinar
153, ZAR, South African rand
154, ZMK, Zambian kwacha
156, ZWD, Zimbabwean dollar
158, AMD, Armenian dram
159, MMK, Myanmar kyat
160, HRK, Croatian kuna
161, ERN, Eritrean nakfa
162, DJF, Djiboutian franc
163, ISK, Icelandic krÌ_na
164, KZT, Kazakhstani tenge
165, KGS, Kyrgyzstani som
166, LVL, Latvian lats
167, LTL, Lithuanian litas
168, MXN, Mexican peso
169, MDL, Moldovan leu
170, NAD, Namibian dollar
171, NIO, Nicaraguan cÌ_rdoba
172, UGX, Ugandan shilling
173, MKD, Macedonian denar
174, UYU, Uruguayan peso
175, UZS, Uzbekistani som
176, AZN, Azerbaijani manat
177, GHS, Ghanaian cedi
178, VEF, Venezuelan bolÌ_var
179, SDG, Sudanese pound
180, UYI, Uruguay Peso
181, MZN, Mozambican metical
182, CHE, WIR Euro
183, CHW, WIR Franc
184, XAF, Central African CFA franc
185, XCD, East Caribbean dollar
186, XOF, West African CFA franc
187, XPF, CFP franc
188, SRD, Surinamese dollar
189, MGA, Malagasy ariary
190, COU, Unidad de Valor Real
191, AFN, Afghan afghani
192, TJS, Tajikistani somoni
193, AOA, Angolan kwanza
194, BYR, Belarusian ruble
195, BGN, Bulgarian lev
196, CDF, Congolese franc
197, BAM, Bosnia and Herzegovina convert
198, MXV, Mexican Unid
199, UAH, Ukrainian hryvnia
200, GEL, Georgian lari
201, BOV, Mvdol

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3329 Posts
User info in posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1683
Total Polls:
6
Total Posts:
5940
Posts this week:
11
User Info:
 
Total Users:
5142
Newest User:
zaki98040
Members Online:
0
Guests Online:
177

Online: 
There are no members online

Forum Legend:

 Topic
 New
 Locked
 Sticky
 Active
 New/Active
 New/Locked
 New Sticky
 Locked/Active
 Active/Sticky
 Sticky/Locked
 Sticky/Active/Locked