Skip to main content
Tweeted twitter.com/#!/StackMagento/status/407550740815958018
added 2 characters in body
Source Link
tony09uk
  • 1.7k
  • 11
  • 41
  • 56

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?

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 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?

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?

Source Link
tony09uk
  • 1.7k
  • 11
  • 41
  • 56

getting the subTotal of the cart

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 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?