Tutorialsplane

Magento – get price rules from order


Magento – get price rules from order: Mage::getModel(‘catalogrule/rule’) is used to get the price rules applied on items. If you want to get price rules applied on order items first load order items and then load rules ids applied on the items. Here in this tutorial we are going to explain this with simple example.


Magento – get price rules from order

First order items using the model – Mage::getModel(‘sales/order_item’) and then load the rules applied on the items as below-

Magento – get price rules from order:

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

    foreach($items as $item){

        if($item->getAppliedRuleIds() == ''){
        /*if multiple rules applied**/
        foreach(explode(",",$item->getAppliedRuleIds()) as $ruleId){        

            //Load object
            $rule = Mage::getModel('catalogrule/rule')->load($ruleId);
            echo "".$item->getName()." - Rule ".$rule->getName()."<br/>";
        }
		}

    }

The above example will give you the rules applied on the order items.