5

I'm using Magento 1.9.0.1 and here is the code on which I am working on:

$quote2 = Mage::getSingleton('checkout/session')->getQuote();
foreach ($quote2->getAllItems() as $item){
    $DiscountTotal = $item->getDiscountAmount();
}

This code is giving me the amount discounted with coupon code of the first item in the cart for the current session.

The problem is that this code is giving me the amount discounted only for the first item but not for all items in the cart for the current session.

So I have two questions:

  1. How I can get the total discount amount for all items the cart for the current session?
  2. How I can get the total discount amount for already completed order?
  • what you mean by lready completed order – Amit Bera Apr 29 '15 at 10:30
  • I mean when the order is finished, how i can get the amount in the order view page in the admin panel for example. It is more important for me to know the answer for the first question. – Venelin Vasilev Apr 29 '15 at 10:31
12
$quote2 = Mage::getSingleton('checkout/session')->getQuote();
$discountTotal = 0;
foreach ($quote2->getAllItems() as $item){
    $discountTotal += $item->getDiscountAmount();
}
10

Magento saves each item respective discount on sales_flat_quote_item table at column discount_amount. This Discount Amount is stored incurrent currency.

For getting total discount of current session, try the below code

$totals = Mage::getSingleton('checkout/session')->getQuote()->getTotals();
$totalDiscount = $totals["discount"]->getValue();

For getting the current order discount amount at order view, try the below code

$OrderObject->getDiscountAmount();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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