2

How do I get the Shopping cart discounts? For a payment integration I need to sent all items in cart. For products that is easy, but how do I get the following for all applied discounts:

  • amount with and without tax
  • name
  • vat%
4

Hi you can get this details using cart session

$totals = Mage::getSingleton('checkout/session')->getQuote()->getTotals(); //Total object
$subtotal = $totals["subtotal"]->getValue(); //Subtotal value
$grandtotal = $totals["grand_total"]->getValue(); //Grandtotal value
if(isset($totals['discount']) && $totals['discount']->getValue()) {
 $discount = Mage::helper('core')->currency($totals['discount']->getValue()); //Discount value if applied
} else {
 $discount = '';
}




if(isset($totals['tax']) && $totals['tax']->getValue()) {
 $tax = $totals['tax']->getValue(); //Tax value if present
} else {
 $tax = '';
}

You can get details by Checkout session

$quote = Mage::getSingleton('checkout/session')->getQuote();

TO get the list of items in the cart :

$cartItems = $quote->getAllVisibleItems();

For getting each item and it details and discount :

foreach ($cartItems as $item) {
    echo $item->getQty();
$item->getPrice();
$item->getDiscountAmount();
}

For getting coupon code try this Mage::getSingleton('checkout/session')->getQuote()getCouponCode(); more details to check table sales_flat_quote_item in your magento system

  • $tax = $totals['tax']->getValue(); --> This is the total tax, not tax on the discount. You did not answer how to get the name of the discount. – Tero Lahtinen Aug 27 '14 at 10:05

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.