Magento – Set coupon expire date for individual coupon

couponcoupon-codespromotions

I want to create coupon code and I need to set also expiration date. Magento offers to set expiration date only for promotion rules and it affects globally all coupons inside this rule. Anyway inside database table salesrule_coupon has also field expiration_date but it seems that this field is not used anywhere.

Has anybody managed to set expiration date for individual coupon successfully? Otherwise I am thinking the only way to make it right would be to create observer which will observe entering coupon code and delete the coupon if expired and thus it will make coupon code unusable before it is applied.

Any ideas are appreciated.

Best Answer

I have not found any solution for it, But I have used an alternate way to achieve it.

  1. create rule which will be always expired by date.
  2. push condition based coupon codes to it based on cron.

code:

$couponCode = 'XZY';//auto-generated code or get collection of auto-generated               codes from a rule.
$oCoupon = Mage::getModel('salesrule/coupon')->load($couponCode, 'code');

$ruleName = 'referral_expired'; //existing rule with this name
$shoppingRule = Mage::getResourceModel('salesrule/rule_collection')->addFieldToFilter('name',$ruleName)->load()->getFirstItem();
$shoppingRuleId = $shoppingRule->getRuleId();
$oCoupon->setData('rule_id',$shoppingRuleId);
$oCoupon->save(); 
Related Topic