I can get the currency code from the order object. How can I derive currency symbol by using it? Any suggestions will be appreciated.
6 Answers
Try this one:
Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol();
Store currency code eg. USD
$currency_code = Mage::app()->getStore()->getCurrentCurrencyCode();
store currency symbol eg. $
$currency_symbol = Mage::app()->getLocale()->currency( $currency_code )->getSymbol();
store currency name eg. US Dollar
$currency_name = Mage::app()->getLocale()->currency( $currency_code)->getName();
The following worked.
// store currency symbol eg. $
$currency_symbol = Mage::app()->getLocale()->currency( $currency_code )->getSymbol();
Try:
$currencyCode = '';
$currency = $order->getOrderCurrency(); //$order object
if (is_object($currency)) {
$currencyCode = $currency->getCurrencyCode();
}
$currencySymbol = Mage::app()->getLocale()->currency($currencyCode)->getSymbol();
var_dump($currencySymbol);
-
Mage::app()->getLocale() will return the current locale object isn't it? What I want is get the currency symbol of the given currency code regardless of locale. Commented Sep 25, 2013 at 6:28
-
-
It won't work if you've set a different symbol in your locale. It would still return your default currency symbol.– ShathishCommented Sep 25, 2013 at 6:56
-
-
Can you paste your code? I just tested and it was working fine for me. Commented Sep 25, 2013 at 8:30
Using any given currency code you can derive the symbol using Zend_Locale:
$curr = new Zend_Currency('en_US');
echo $curr->getSymbol();
-
According to your solution we have to pass the locale to create Zend_Currency object right? What I expected was is there a way to get currency symbol regardless of locale? I mean by just passing the currency code can we get currency symbol in magento CE 1.7? Commented Sep 26, 2013 at 16:00
-
-
Yes. See the docs framework.zend.com/manual/1.12/en/zend.currency.html Commented Sep 26, 2013 at 16:06
-
My problem background is like this. I have several stores with several websites. I'm creating a php file which runs outside of the project and get all the order collection regardless of the store or any other factor. In that case if I get all details of an order I can get order total amount and currency code as separate values. I want to get the currency symbol and show the order total as a complete amount in my php file. So I cannot put whatever the locale I want. Thanks in advance. Commented Sep 26, 2013 at 16:14
Just pass the value in variable .. will return current currency format price
$Formatted_Price = Converted Price with Currency
$Variable_Price = Your Variable value
$Formatted_Price= Mage::helper('core')->currency($Variable_Price, true, false);