/** * Call the Model and delegate the create or delete action * Feed the Event with the updated model * * @param CouponModel $coupon Model to save * @param CouponCreateOrUpdateEvent $event Event containing data */ protected function createOrUpdate(CouponModel $coupon, CouponCreateOrUpdateEvent $event) { $coupon->setDispatcher($event->getDispatcher()); // Set default condition if none found /** @var ConditionInterface $noConditionRule */ $noConditionRule = $this->noConditionRule; /** @var ConditionFactory $conditionFactory */ $conditionFactory = $this->conditionFactory; $couponRuleCollection = new ConditionCollection(); $couponRuleCollection[] = $noConditionRule; $defaultSerializedRule = $conditionFactory->serializeConditionCollection($couponRuleCollection); $coupon->createOrUpdate($event->getCode(), $event->getTitle(), $event->getEffects(), $event->getServiceId(), $event->isRemovingPostage(), $event->getShortDescription(), $event->getDescription(), $event->isEnabled(), $event->getExpirationDate(), $event->isAvailableOnSpecialOffers(), $event->isCumulative(), $event->getMaxUsage(), $defaultSerializedRule, $event->getLocale(), $event->getFreeShippingForCountries(), $event->getFreeShippingForMethods(), $event->getPerCustomerUsageCount()); $event->setCouponModel($coupon); }