Magento: Get checkout cart total details | Subtotal /Grandtotal /Discount /Tax
In Magento, if you want to get shopping cart totals details anywhere across the site, you can do so by following piece of code:
$totalItemsInCart = Mage::helper(‘checkout/cart’)->getItemsCount(); //total items in cart
$totals = Mage::getSingleton(‘checkout/session’)->getQuote()->getTotals(); //Total object
$subtotal = round($totals[“subtotal”]->getValue()); //Subtotal value
$grandtotal = round($totals[“grand_total”]->getValue()); //Grandtotal value
if(isset($totals[‘discount’]) && $totals[‘discount’]->getValue()) {
$discount = round($totals[‘discount’]->getValue()); //Discount value if applied
} else {
$discount = ”;
}
if(isset($totals[‘tax’]) && $totals[‘tax’]->getValue()) {
$tax = round($totals[‘tax’]->getValue()); //Tax value if present
} else {
$tax = ”;
}
#checkout #discount #grandtotal #magento #subtotal #tax #totals