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 WernerCommented Oct 31, 2013 at 6:28
Add a comment
|
2 Answers
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();
-
-
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
-
-
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
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);
}