Question

I am trying to get the subtotal that is in the cart. To do this I am calling Mage::getBlockSingleton('checkout/cart_totals') this appears to be returning a collection.

I need to get a single value from this collection so I am currently using the below code

$collection = Mage::getBlockSingleton('checkout/cart_totals');
$total = $collection->getTotals();
echo $total['subtotal']['value'];

While the code returns the expected value I know this is not the way to do it. In the past I have used mage::getModel('namespace/file')->addFieldToFilter() but in this case I am getting an error when I try to use this method (obviously because I using a block not a model).

This leads me to believe that I am not getting a collection, so my questions are:

1 What is being returned?

2 Am I pulling the sub total value from the correct place?

3 How do I pull a single value out from all that information the correct way?

Was it helpful?

Solution

You can get the subtotal like this easier:

Mage::getSingleton('checkout/session')->getQuote()->getSubtotal();
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top