Snippets with the tag: price

Format price

Description

Format of the price

Code

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

Get products data in cart

Description

Display products data in cart

Code

$items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();

foreach($items as $item) {
        echo 'ID: '.$item->getProductId().'<br />';
        echo 'Name: '.$item->getName().'<br />';
        echo 'Sku: '.$item->getSku().'<br />';
        echo 'Quantity: '.$item->getQty().'<br />';
        echo 'Price: '.$item->getPrice().'<br />';
        echo "<br />";
}

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

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

Round price

Description

Round product price

Code

echo Mage::getModel('sales/order')->formatPricePrecision($_product->getFinalPrice(), 3);