I have programmatically generated coupon code, But it does not display on Admin->Promotions->Shopping Cart Price Rules. Why ?

    $coupon = Mage::getModel('salesrule/rule');
   ->setCustomerGroupIds(array(1)) //an array of customer groupids
   //serialized conditions.  the following examples are empty

At last print_r($coupon); Will give coupon detail But it not displays admin side.

  • 1
    I have used the same code and its working. Try to use try catch when you save coupon to get errors if any. Jun 14, 2017 at 6:39
  • I have used Try catch By default. Did you print object After $coupon->save(); ? Jun 14, 2017 at 6:48

1 Answer 1


OMG. Suppose we put exit after $coupon->save();exit; Then it does not display on the admin side. I have removed $coupon->save();exit; then it will appear on the admin side. I think this is not possible anyhow. But still thinking.

  • 1
    May be its because when you put exit it will break the code execution will not call any further functions like _afterSave. Check Mage_SalesRule_Model_Rule::_afterSave Jun 14, 2017 at 7:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.