1

I am trying to get the subtotal from the cart using the code

<?php echo Mage::helper('checkout/cart')->getQuote()->getSubtotal(); ?>

It only works when i clean the cache, i don't know why. how to get the subtotal in a correct way? . Any help will be greatly appreciated.

Thank you in advance

jarus
  • 1,853
  • 11
  • 44
  • 76

1 Answers1

0
$session= Mage::getSingleton('checkout/session');

$getotal = Mage::helper('checkout')->getQuote()->getGrandTotal();

//Total object
$totals = Mage::getSingleton('checkout/session')->getQuote()->getTotals(); 

//Subtotal value
$subtotal = $totals["subtotal"]->getValue(); 

Use the above mentioned code you will surely get subtotal at the end.:-)

Alex Hadley
  • 2,125
  • 2
  • 28
  • 50
Chiragit007
  • 1,646
  • 2
  • 16
  • 31
  • Thank you for the answer, i am able to get the subtotal but i cannot get it to update when the cart item is updated. The subtotal stays the same as before even when the cart item is removed or cart item's has been changed. – jarus May 19 '13 at 21:59
  • you have to create a cutom module in which you need to create event observer of this event "sales_quote_collect_totals_after". Create a observer of the event PACKAGENAME_MODULENAME_Model_Observer and paste your code over there. Things will work by following this. – Chiragit007 May 20 '13 at 12:56
  • I put the code in a custom module from which i need to add items to cart and get the subtotal from the cart. – jarus May 20 '13 at 13:58
  • you got the result as expected ? – Chiragit007 May 21 '13 at 04:56
  • i could not get it to update without refreshing the cache, but, i found a work around to my problem, i got the subtotal from the 'My cart' at the header using javascript and displayed it where i wanted. but, it still is not the correct solution to the problem. – jarus May 22 '13 at 14:04