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.

  • Thanks Vladimir, had the same issue. Your code works fine in 1.7.0.2. – Mario Werner Oct 31 '13 at 6:28
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();

| improve this answer | |
  • $quote->getAppliedRuleIds(); not working – monojit banik Aug 19 '13 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? – Vladimir Kerkhoff Aug 19 '13 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(); – monojit banik Aug 19 '13 at 10:00
  • Can you post the complete code that you use? – Vladimir Kerkhoff Aug 19 '13 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. – monojit banik Aug 19 '13 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);
    }
| improve this answer | |

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.