Magento - get rule from coupon code

喜你入骨 提交于 2019-11-29 03:47:44

问题


I have to retrieve the rule associated to a coupon code in order to display in quote the discount percentage of that rule. the simplest way is to calculate directly from quote amounts, but i want to retrieve directly the rule and then get the discount percentage from it.

this is what i tried:

 $rule = Mage::getModel('salesrule/coupon');
 $rule->load($couponCode);

by this way i still havent retrieved rules attributes. any help?

thanks.


回答1:


To load a coupon by code, pass 'code' as 2nd param to load(). Then you can get the proper rule instance by using the rule_id value of your coupon instance:

$oCoupon = Mage::getModel('salesrule/coupon')->load($couponCode, 'code');
$oRule = Mage::getModel('salesrule/rule')->load($oCoupon->getRuleId());
var_dump($oRule->getData());



回答2:


First get the coupon code

$orderNumber = 100000105; //order number with coupon code

$order = Mage::getModel('sales/order')->loadByIncrementId($orderNumber);

$orderDetails = $order->getData();

$couponCode = $orderDetails['coupon_code'];

Then use solution by Jürgen Thelen.




回答3:


May be this solution will help you to get couponcode amount by coupon code.

$couponCode = 'YOUR COUPONCODE';

$oCoupon = Mage::getModel('salesrule/coupon')->load($couponCode, 'code');

$oRule = Mage::getModel('salesrule/rule')->load($oCoupon->getRuleId());

print_r($oRule->getData());exit();



来源:https://stackoverflow.com/questions/10531765/magento-get-rule-from-coupon-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!