Orders – Find All Applied Coupon Codes and Rules

couponorders

Is it possible to find out all coupon codes was applied for an specific order?

i can only found out 1 coupon codes was applied for an order in sales_flat_order table. In the table, only 1 field was storing a coupon code (last code applied).

anyone know how to do that?

Best Answer

Try this code

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

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";
    }
}

?>

OR

<?php
$order_id = 11060;
$order = Mage::getModel('sales/order')->load($order_id);

foreach(explode(",",$order->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";
}    

?>
Related Topic