Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get magento subtotal from cart

I'm currently using this snippet to show the cart totals in the topcart of my Magento shop. My problem is that it's not always updating when products is put in cart, it's just showing 0$, especially configurable products. But when a second product is put in the cart, it's working again.

Am I missing something, should there be a "check" of some kind before this piece of code?

<?php echo Mage::helper('checkout')->formatPrice($this->getSubtotal()) ?>
like image 514
Thomas Nielsen Avatar asked Dec 06 '12 19:12

Thomas Nielsen


2 Answers

You can also try following code it works for me

<?php echo Mage::helper('checkout/cart')->getQuote()->getSubtotal() ?>
like image 72
Swapna Taru Avatar answered Oct 09 '22 22:10

Swapna Taru


Make sure your top cart block is extending a relevant block type such as Mage_Checkout_Block_Cart_Sidebar. If you do, you will have access to useful functionality that will save you rewriting unnecessary code.

For example, if you extend Mage_Checkout_Block_Cart_Sidebar - you can call getSubtotal()

An alternative would be to use the following:

Mage::getSingleton('checkout/session')->getQuote()->getSubtotal();
like image 28
Drew Hunter Avatar answered Oct 09 '22 23:10

Drew Hunter