Проверить настройки Skip to content

Валюта в магазине Magento

Как известно Magento — это система электронной магазинов для разных  стран, и хорошо реализована поддержка валют и курсов валют.

Подборка кусочков кода Magento для игр с курсами валют :)

 

$targetCurrency = Mage::getModel('directory/currency')->load('EUR');
$price = round(Mage::helper('directory')->currencyConvert($priceToConvert, 'GBP', $targetCurrency), 2);

$baseCode = Mage::app()->getBaseCurrencyCode();      

$allowedCurrencies = Mage::getModel('directory/currency')->getConfigAllowCurrencies();
$rates = Mage::getModel('directory/currency')->getCurrencyRates($baseCode, array_values($allowedCurrencies));

var_dump($rates);
echo Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol();
$price = $_Pdetails->getPrice();
$magento_style_price = Mage::helper('core')->currency($price);

$currentCurrencyPrice = Mage::helper('core')->currencyByStore($baseCurrencyPrice, null, false, false);

$fromCur = 'USD'; // currency code to convert from
$toCur = 'EUR'; // currency code to convert to
$toCurrencyPrice = Mage::helper('directory')->currencyConvert($fromCurrencyPrice, $fromCur, $toCur);

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

$priceOne = Mage::helper('directory')->currencyConvert($price, $currentCurrencyCode, $baseCurrencyCode); 

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

$price = "100";
$block = Mage::getBlockSingleton('checkout/cart_shipping');
$block->getQuote()->getStore()->convertPrice(Mage::helper('tax')->getShippingPrice($price));

echo Mage::helper('core')->currency($_price);
echo Mage::helper('core')->currency($_price, array('precision' => -1) );

/**
 * 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));

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

// 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);

 

http://www.tall-paul.co.uk/2012/03/28/magento-round-up-currency-conversions/

 

 

 

 

 

 

 

 

 

 

 

$baseCode =Mage::app()->getBaseCurrencyCode();       $allowedCurrencies =Mage::getModel('directory/currency')->getConfigAllowCurrencies(); $rates =Mage::getModel('directory/currency')->getCurrencyRates($baseCode, array_values($allowedCurrencies)); var_dump($rates);
Magento 1.*