3

Can anybody tell me how to get applied rule ids in Flatrate.php page (shipping/Model/Carrier)? Actually I want get Rule_id which is applied for the order (table:salesrule) in Flatrate.php. In Flatrate.php page there is a function public function collectRates(Mage_Shipping_Model_Rate_Request $request) if I print the $request it shows a long result which is impossible for me to find out the rule id but I m sure it consists all the information of applied ruleids. So if anyone knows Please help me.

1
  • Thanks Vladimir, had the same issue. Your code works fine in 1.7.0.2. Commented Oct 31, 2013 at 6:28

2 Answers 2

5

You chould be able to get the current checkout/quote data thru:

$quote=Mage::getSingleton('checkout/session')->getQuote();

Then from the quote object you can get the getAppliedRuleIds:

$ruleIds = $quote->getAppliedRuleIds();

6
  • $quote->getAppliedRuleIds(); not working Commented Aug 19, 2013 at 9:33
  • If you check the 'sales_flat_quote' table in your database is the column 'applied_rule_ids' filled for the quote you check? Commented Aug 19, 2013 at 9:51
  • yes field(applied_rule_ids) is exist in sales_flat_quote table but i can't get rules ids by using $quote->getAppliedRuleIds(); Commented Aug 19, 2013 at 10:00
  • Can you post the complete code that you use? Commented Aug 19, 2013 at 10:01
  • I m using your code $quote=Mage::getSingleton('checkout/session')->getQuote();$ruleIds = $quote->getAppliedRuleIds();echo $ruleIds;exit; in Flatrate.php(shipping/Model/Carrier) page. Commented Aug 19, 2013 at 10:03
1

As also asked and answered here:

Get applied rule IDs separated by commas:

$appliedRuleIds = Mage::getSingleton('checkout/session')->getQuote()->getAppliedRuleIds();

Convert to array:

$appliedRuleIds = explode(',', $appliedRuleIds);

Convert to object

$rules =  Mage::getModel('salesrule/rule')->getCollection()->addFieldToFilter('rule_id' , array('in' => $appliedRuleIds));

Get rules:

foreach ($rules as $rule) {
        // do something with $rule

        // get rule name or label:
        echo $rule->name;

        // get discount amount:
        echo $rule->discount_amount;

        // inspect the rule yourself:        
        var_dump($rule);
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.