1

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

    $coupon = Mage::getModel('salesrule/rule');
    $coupon->setName('testing_name')
   ->setDescription('testing_name')
   ->setFromDate(date('2017-01-01'))
   ->setCouponType(2)
   ->setCouponCode('ASASASASAS')
   ->setUsesPerCoupon(1000)
   ->setUsesPerCustomer(100)
   ->setCustomerGroupIds(array(1)) //an array of customer groupids
   ->setIsActive(1)
   //serialized conditions.  the following examples are empty
   ->setConditionsSerialized('')
   ->setActionsSerialized('')
   ->setStopRulesProcessing(0)
   ->setIsAdvanced(1)
   ->setProductIds('')
   ->setSortOrder(0)
   ->setSimpleAction('by_percent')
   ->setDiscountAmount(100)
   ->setDiscountQty(null)
   ->setDiscountStep('0')
   ->setSimpleFreeShipping('0')
   ->setApplyToShipping('0')
   ->setIsRss(0)
   ->setWebsiteIds(array(1));      
    $coupon->save();

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

2
  • 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

0

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
  • 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.