Magento - get rule from coupon code

前端 未结 3 2017
粉色の甜心
粉色の甜心 2020-12-29 10:55

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 quo

相关标签:
3条回答
  • 2020-12-29 11:15

    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();

    0 讨论(0)
  • 2020-12-29 11:24

    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.

    0 讨论(0)
  • 2020-12-29 11:28

    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());
    
    0 讨论(0)
提交回复
热议问题