/** * Save/delete coupon * * @return $this */ protected function _afterSave() { $couponCode = trim($this->getCouponCode()); if (strlen($couponCode) && $this->getCouponType() == self::COUPON_TYPE_SPECIFIC && !$this->getUseAutoGeneration()) { $this->getPrimaryCoupon()->setCode($couponCode)->setUsageLimit($this->getUsesPerCoupon() ? $this->getUsesPerCoupon() : null)->setUsagePerCustomer($this->getUsesPerCustomer() ? $this->getUsesPerCustomer() : null)->setExpirationDate($this->getToDate())->save(); } else { $this->getPrimaryCoupon()->delete(); } parent::_afterSave(); return $this; }