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 = ''; | |
} |
13 Comments
Leave a comment
Welcome to my Blog
Certifications
Honor
Recognition
Contributions
Categories
- Apache (2)
- ChatGPT (1)
- Domain name (2)
- eCommerce (2)
- htaccess (1)
- Humor (3)
- Instagram API (1)
- jQuery (4)
- JSON (1)
- Linux (10)
- Magento (142)
- Magento admin (58)
- Magento Certification (5)
- Magento error (13)
- Magento frontend (68)
- Magento Imagine (2)
- Magento Interview (5)
- Magento Master (2)
- Magento2 (10)
- Mobile (1)
- MySQL (7)
- OpenAI (1)
- OroCRM (2)
- Performance (2)
- PHP (8)
- Prototype JS (3)
- Security (4)
- Wordpress (3)
- XML (2)
Tag Cloud
500 internal server error admin answers attribute bug category checkbox checkout cookie customer difference domain name EAV error event extension interview invoice jquery linux magento magento2 magento admin magento error magento interview questions magento orm mysql observer order pinterest product products questions redirect register remove script session simplexml to array state status study guide tax url wordpress
you should to read it again and think about last sentence. but it`s only my opinion
$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 = ”;
}
Thanks Kalpesh! It helped!
Thank you for the nice snippet kalpesh, your blog is one of my favorite Magento resource. Keep updating with new idea and codes. thanks again 🙂
I would like to know whether the code will give the details of tax even afer the transaction is complete and the customer is in thanks page. I need it in thanks page
pliiiz how get date of checkout ?
3 Years later and still extremely useful. I’ve spent countless hours trying to find something so simple, and I have found it. Thank you
I cant find the page for tax without round-off in my site. am using version 1.9
Hello,
I want to update this subtotal price at checkout onepage via event observer() method, with below code.
$session = Mage::getSingleton(‘checkout/session’);
$quote= $session->getQuote();
$quote->setSubtotal($mycustomvalue);
$quote->setBaseSubtotal($mycustomvalue);
$quote->save();
but its not working. can anyone tell me whats problem?
Why are you using round() when dealing with currency?
Use: Mage::helper(‘core’)->currency($totals[‘subtotal’]->getValue() , true, false);
hi we need to calculate the shipping after the discount apply, how to do this.
Thanks Kalpesh..
I have to give free shipping order over and 1000 and zipcode between 600001 to 600010, i am using webshop matrix rate for shipping method, in this case, shopping cart pricing rule not working free shipping, so i have to plan for do custom PHP code for giving free shipping, My condition how can i give condition like subtotal is equal or greated than 1000 and zipcode 600001 and 600010 in /public_html/app/design/frontend/base/default/template/checkout/cart/shipping.phtml