Magento - 从优惠券代码中获取规则 [英] Magento - get rule from coupon code
本文介绍了Magento - 从优惠券代码中获取规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须检索与优惠券代码关联的规则,以便在报价中显示该规则的折扣百分比.最简单的方法是直接从报价金额计算,但我想直接检索规则,然后从中获取折扣百分比.
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.
这是我试过的:
$rule = Mage::getModel('salesrule/coupon');
$rule->load($couponCode);
通过这种方式,我仍然没有检索到规则属性.有什么帮助吗?
by this way i still havent retrieved rules attributes. any help?
谢谢.
推荐答案
要通过代码加载优惠券,请将 'code'
作为第二个参数传递给 load()
.然后,您可以使用优惠券实例的 rule_id
值获取正确的规则实例:
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());
这篇关于Magento - 从优惠券代码中获取规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文