I have the below code on success.phtml to get some order info. I also need to be able to get the discount amount (if any) on the order. This would be the discount amount from any discount codes used.

/*Use this to get sale attributes - to get additional view the code in app>code>core>mage>googleanalytics>block>ga.php*/
$lastOrderId = Mage::getSingleton('checkout/session')->getLastOrderId();
$order = Mage::getSingleton('sales/order');
$_grandTotal = $order->getBaseGrandTotal(); #order total
$orderNumber = $this->__($this->getOrderId()); #order number
$voucher = $order->getCouponCode(); #voucher code used
$_totalData =$order->getData(); 
    $_sub = $_totalData['subtotal'];
    $_sub = round($_sub,2); 
    $currency = Mage::app()->getStore()->getCurrentCurrencyCode();
    $currency_symbol = Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol();

Any ideas?


If you can load order object then you should be able to get discount by this simple code:


Moreover, if you want to see all applied discount codes then:

$items = Mage::getModel('sales/order_item')->getCollection()

foreach($items as $item){
    if($item->getAppliedRuleIds() == '') {
    foreach(explode(",",$item->getAppliedRuleIds()) as $ruleId){       
         //Load the rule object
        $rule = Mage::getModel('salesrule/rule')->load($ruleId); //Shopping Cart Rules //$rule = Mage::getModel('catalogrule/rule')->load($ruleId); catalog rules
        // Throw out some information like the rule name what product it was applied to
        echo "<p> Applied Rule Name: ".$rule->getName()." & Code : ".$rule->getCouponCode()."</p>";
        echo "\t";

This should work.

$orderDetails = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());

echo "Your Coupon code is==".$orderDetails->getCouponCode();//display coupon code

$discountTotal = 0; 
$items =$orderDetails->getAllItems();
foreach($items as $item)
        $discountTotal += $item->getDiscountAmount();
echo "Discount Amount is".$discountTotal;

Use the following code to avail discount amount on success:

    $order_id = Mage::getSingleton('checkout/session')->getLastRealOrderId();
    $order_details = Mage::getModel('sales/order')->loadByIncrementId($order_id);
    echo $order_details->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.