1

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.

<?php
/*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');
$order->load($lastOrderId);
$_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?

1

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

$order->getDiscountAmount();

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

$items = Mage::getModel('sales/order_item')->getCollection()
    ->addFilter('order_id',array('eq'=>$lastOrderId));

foreach($items as $item){
    if($item->getAppliedRuleIds() == '') {
        continue;
    }
    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.

0
$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;
0

Use the following code to avail discount amount on success:

<?php
    $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.