Any one know how to get discount rule and discount from cart? See the pic

enter image description here

Can i get this from external script using cart object? This part of code generate the discount amount section:

public function renderTotal($total, $area = null, $colspan = 1)
    //if the code is "discount"
    $code = $total->getCode();

    if ($total->getAs()) {
        $code = $total->getAs();
    return $this->_getTotalRenderer($code)
        ->setRenderingArea(is_null($area) ? -1 : $area)


try {
    $product_id = '907'; // Replace id with your product id
    $qty = '1'; // Replace qty with your qty
    $product = Mage::getModel('catalog/product')->load($product_id);
    $cart = Mage::getModel('checkout/cart');
    $cart->addProduct($product, array('qty' => $qty));
    Mage::getSingleton('core/session')->addSuccess('Product added successfully');

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

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

foreach ($quote2->getAllItems() as $item){
    $discountTotal += $item->getDiscountAmount();

echo $discountTotal."<br>";

The left question is how to get discount label?

  • What exactly you want? discount rule means exact condition ??? Feb 27 '17 at 15:43
  • discount rule name, the discount amount. The selected text of the pic
    – hkguile
    Feb 27 '17 at 15:46

To get the different summs for the rules I implemented an observer and save the sums into the item:


class Project_AddRuleSpecificDiscountToItem_Model_Observer
    public function salesruleValidatorProcess(Varien_Event_Observer $event)
        $item = $event->getItem();
        $discount = $item->getDiscountPerRule() ?: [];

        $discount[$event->getRule()->getId()] = array_merge(
            $event->getResult()->getData(), ['qty' => $event->getQty()]


And the config.xml part for it:


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.