Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento - get rule from coupon code

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.

like image 733
Luke Avatar asked May 10 '12 10:05

Luke


2 Answers

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());
like image 105
Jürgen Thelen Avatar answered Sep 20 '22 11:09

Jürgen Thelen


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.

like image 42
Mukesh Avatar answered Sep 19 '22 11:09

Mukesh