3

I am trying to retrive the text set in the Magento Coupon Description field to use as part of a validation rule. Does anyone know how to load a coupon price rule using the coupon code and retrieve the associated coupon description text?

paj
  • 1,177
  • 16
  • 33

3 Answers3

2

Under Magento 1.3, you can use this code (not tested as I have no 1.3 within easy reach) :

$rule = Mage::getModel('salesrule/rule')->load($code, 'coupon_code');

if ($rule->getId()) {
    $description = $rule->getDescription();
}
blmage
  • 4,214
  • 1
  • 23
  • 25
  • It is Magento 1.3.x and there is no /Mage/SalesRule/Model/Coupon.php your example doesn't work. – paj Jun 10 '13 at 14:40
  • Updated my answer for Magento 1.3 (my previous example should work for 1.4+ versions only) – blmage Jun 10 '13 at 14:49
  • Yes, salesrule/rule works for 1.3, thanks very much for the answer. – paj Jun 10 '13 at 14:50
  • $rule = Mage::getModel('salesrule/rule')->load($code, 'coupon_code'); this will give error as unknown column error. See my answer for the same – Neeraj Garg May 26 '14 at 07:22
2

I have used in magento 1.9 and below code is working fine for me.

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

                $this->_getSession()->addError(
                    $this->__($description, Mage::helper('core')->escapeHtml($couponCode))
                );
rakesh37
  • 21
  • 2
0
$oCoupon = Mage::getModel('salesrule/coupon')->load($couponCode, 'code');
$oRule = Mage::getModel('salesrule/rule')->load($oCoupon->getRuleId());
var_dump($oRule->getData());

you can refer for same Magento - get rule from coupon code

Community
  • 1
  • 1
Neeraj Garg
  • 695
  • 3
  • 17
  • 38