Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

does anyone know how one can get the catalog- and cart price rules from an order?

I know that I can get the discount percentage from an order item via the method getDiscountPercent(), but how can I get all the rules that were applied to the whole order?

For example, I have a rule "Customer Group X gets 20% off all items in the store".

Now I want to determine which rules were actually applied when the order has been submitted by the user. I need this for an order export interface where I have to supply all discounts that the user got.

Thanks in advance!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.7k views
Welcome To Ask or Share your Answers For Others

1 Answer

Have a look in the sales_flat_order_item table. there is a field called applied_rule_ids which will give you the id of the rule applied to that item. Also you can find out in this table how much discount was applied and the percentage.

Example

//The order I want to check
    $order_id = 859;

    //Get the list of items for your order
    $items = Mage::getModel('sales/order_item')
    ->getCollection()
    ->addFilter('order_id',array('eq'=>$order_id));

    //loop through each item
    foreach($items as $item){

        //if the item has not had a rule applied to it skip it
        if($item->getAppliedRuleIds() == '')continue;

        /*
        * I cant remember in the database they might be comma separated or space if multiple rules were applied
        * the getAppliedRuleIds() function is the one you want
        */
        foreach(explode(",",$item->getAppliedRuleIds()) as $ruleID){        

            //Load the rule object
            $rule = Mage::getModel('catalogrule/rule')->load($ruleID);

            // Throw out some information like the rule name what product it was applied to

            echo "<p>".$item->getSku()." had rule ".$rule->getName()."(".$item->getAppliedRuleIds().") applied </p>";
        }

    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...