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:

 

12 thoughts on “Magento – Get the Total Price of items currently in the Cart”

  1. 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.

  2. 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…

  3. 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.

  4. 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

    {syntaxhighlighter brush: php}

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

    {/syntaxhighlighter}

    // Remove span tag from result

    {syntaxhighlighter brush: php}

    $grandTotal = str_replace(‘‘, ”, $grandTotal);

    $grandTotal = str_replace(‘‘, ”, $grandTotal);

    {/syntaxhighlighter}

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

  5. Hey Richard

    I’m trying to show/hide a div in the checkout process based on the cart subtotal or grand total (we show both, just not sure if either is easier to work with). Would I be able to use the above to do so?

    Thanks

    Adam Hodson

Leave a Reply

Your email address will not be published. Required fields are marked *