Magento - Get the Total Price of items currently in the Cart

Ever wanted to get the total price of items in your Magento cart? Here you go:

<?php echo $this->helper('checkout')->formatPrice(Mage::getSingleton('checkout/cart')->getQuote()->getGrandTotal()); ?>

9 comments for Magento - Get the Total Price of items currently in the Cart

Keith's picture

Hello Richard, I really like...

Hello Richard,
I really like your blog...not just the information but the way you display the information.

I was wondering if there's a way to store custom options on the product page to be able to add into the shopping cart? The reason why I'm asking is I'm working on a project and I need complete flexibility over my custom options.

I have an eyeglass prescription website and adding prescription lenses process needs to be very unique and easy to use but I'm finding it very difficult to do this in Magento. I just want to add things in the custom options without it being checked and omitted.

morak's picture

Hi did you ever have a...

Hi did you ever have a solution on this for how to do custom options for lenses,need this fora site ,would also consider purchasing some code for this

Joenas Ejes's picture

Thanks Richard!...

Thanks Richard!

vishal lakhani's picture

Hi Thanx Richard !!! its...

Hi Thanx Richard !!! its Works for me but i have one more Query..

how can i get Discount Price ?

Waiting for your help

Thanx again

vishal lakhani's picture

Thanx Very very Much for...

Thanx Very very Much for this..

But have 1 more Query.. how can i get Discount Amount?i have applied Shopping Cart rules and want discount amount...

Can you help me

and can you tell me whats use of getSingleton

why its uses?

how can i use?

Thanx in Advance...

john's picture

This is partially correct. It...

This is partially correct. It answers the question "Ever wanted to get the total price of items in your Magento cart formatted in a span with the price class and a dollar sign?
$138.00
The simple act of trying to just get the damn FLOAT value to assign to a variable is wasting my time.

Joakim Aglo's picture

As mentioned above, this...

As mentioned above, this returns the total price in a span tag like this (with tags instead of brackets):
$135.13

I used the PHP function str_replace to remove the span:

// Get grand total in cart


$grandTotal = $this->helper('checkout')->formatPrice(Mage::getSingleton('checkout/cart')->getQuote()->getGrandTotal());

// Remove span tag from result


$grandTotal = str_replace('<span class="price">', '', $grandTotal);
$grandTotal = str_replace('</span>', '', $grandTotal);

(Note that $grandTotal will still show the dollar sign or similar - not only the number)

Gurria's picture

Hi Richard! Thanks a lot!...

Hi Richard!
Thanks a lot! Such a helpful tutorial. Can you please post a tutorial on custom payment gateway creation in magento.

=)

Marko's picture

Thanks for the code! Now, how...

Thanks for the code! Now, how to get items and their names in an array??

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account associated with the e-mail address you provide, it will be used to display your avatar.
Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.