1

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?

1 Answer 1

6

You can get the subtotal like this easier:

Mage::getSingleton('checkout/session')->getQuote()->getSubtotal();
2
  • Thankyou, so thats the correct way (i knew there would be a better way). As a matter of interest was it returning a collection?
    – tony09uk
    Dec 2, 2013 at 14:57
  • You were getting a list of available totals (subtotal, grand total, tax and other).
    – Marius
    Dec 2, 2013 at 15:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.