First, we have to get the user’s customer group and the current currency code.
1 2 3 |
$groupId = Mage::getSingleton('customer/session')->getCustomerGroupId(); $groupName = Mage::getModel('customer/group')->load($groupId)->getCode(); $currencyCode = Mage::app()->getStore()->getCurrentCurrencyCode(); |
So for example, if we have a customer groups naming “Euro” and “Yen” and we want to switch to their respective currencies, we will do it this way…
If the group name is “Euro”, then we have to set the target currency code to “EUR”. While If the group name is “Yen”, we have to set the target currency code to “JPY”.
But first, make sure that these currencies are enabled in the backend.
System > Configuration > Currency Setup > Allowed Currencies
To get currency codes.
System > Manage Currency > Rates
1 2 |
if ($groupName=="Euro") $userCurrency = "EUR"; else if ($groupName=="Yen") $userCurrency = "JPY"; |
1 2 3 4 |
if ($currencyCode!=$userCurrency) { $switchURL = Mage::helper('directory/url')->getSwitchCurrencyUrl()."currency/".$userCurrency; Mage::app()->getResponse()->setRedirect($switchURL); } |
1 2 3 4 5 6 7 8 9 10 11 |
$groupId = Mage::getSingleton('customer/session')->getCustomerGroupId(); $groupName = Mage::getModel('customer/group')->load($groupId)->getCode(); $currencyCode = Mage::app()->getStore()->getCurrentCurrencyCode(); if ($groupName=="Euro") $userCurrency = "EUR"; else if ($groupName=="Yen") $userCurrency = "JPY"; if ($currencyCode!=$userCurrency) { $switchURL = $this->helper('directory/url')->getSwitchCurrencyUrl()."currency/".$userCurrency; Mage::app()->getResponse()->setRedirect($switchURL); } |