Snippets with the tag: currency

Format price

Description

Format of the price

Code

$formattedPrice = Mage::helper('core')->currency($_finalPrice,true,false);

Get actual and special price of a product

Description

Get actual and special price of a product

Code

$_productId = 102;
$_product = Mage::getModel('catalog/product')->load($_productId);

// without currency sign
$_actualPrice = number_format($_product->getPrice(), 2);
// with currency sign
$_formattedActualPrice = Mage::helper('core')->currency(number_format($_product->getPrice(), 2),true,false);

// without currency sign
$_specialPrice = $_product->getFinalPrice();
// with currency sign
$_formattedSpecialPrice = Mage::helper('core')->currency(number_format($_product->getFinalPrice(), 2),true,false);

Get currency symbol

Description

Get currency symbol

Code

Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol();

Get currency code

Description

Get currency code

Code

Mage::app()->getStore()->getCurrentCurrencyCode();

Convert price from current currency to base currency and vice-versa

Description

Convert price from current currency to base currency and vice-versa

Code

$baseCurrencyCode = Mage::app()->getStore()->getBaseCurrencyCode();
$currentCurrencyCode = Mage::app()->getStore()->getCurrentCurrencyCode();
$price = 150;

// convert price from current currency to base currency
$priceOne = Mage::helper('directory')->currencyConvert($price, $currentCurrencyCode, $baseCurrencyCode); 

// convert price from base currency to current currency
$priceTwo = Mage::helper('directory')->currencyConvert($price, $baseCurrencyCode, $currentCurrencyCode);

Changing price from any one currency to another

Description

Changing price from any one currency to another

Code

$from = 'USD';
$to = 'NPR';
$price = 10;

$newPrice = Mage::helper('directory')->currencyConvert($price, $from, $to);

Get currency rates

Description

Get currency rates

Code

    /**
     * Get the base currency
     */
    $baseCurrencyCode = Mage::app()->getBaseCurrencyCode();

    /**
     * Get all allowed currencies
     * returns array of allowed currency codes
     */
    $allowedCurrencies = Mage::getModel('directory/currency')->getConfigAllowCurrencies();

    /**
     * Get the currency rates
     * returns array with key as currency code and value as currency rate
     */
    $currencyRates = Mage::getModel('directory/currency')->getCurrencyRates($baseCurrencyCode, array_values($allowedCurrencies));

    $allowedCurrencies = Mage::getModel('directory/currency')->getConfigAllowCurrencies();

    /**
     * Get currency rates for Nepalese Currency
     */
    $currencyRates = Mage::getModel('directory/currency')->getCurrencyRates('NPR', array_values($allowedCurrencies));