/** * Build a CouponInterface from its Model data contained in the DataBase * * @param Coupon $model Database data * * @return CouponInterface ready to use CouponInterface object instance */ public function buildCouponFromModel(Coupon $model) { $isCumulative = $model->getIsCumulative() == 1 ? true : false; $isRemovingPostage = $model->getIsRemovingPostage() == 1 ? true : false; if (!$this->container->has($model->getType())) { return false; } /** @var CouponInterface $couponManager*/ $couponManager = $this->container->get($model->getType()); $couponManager->set($this->facade, $model->getCode(), $model->getTitle(), $model->getShortDescription(), $model->getDescription(), $model->getEffects(), $isCumulative, $isRemovingPostage, $model->getIsAvailableOnSpecialOffers(), $model->getIsEnabled(), $model->getMaxUsage(), $model->getExpirationDate(), $model->getFreeShippingForCountries(), $model->getFreeShippingForModules(), $model->getPerCustomerUsageCount()); /** @var ConditionFactory $conditionFactory */ $conditionFactory = $this->container->get('thelia.condition.factory'); $conditions = $conditionFactory->unserializeConditionCollection($model->getSerializedConditions()); $couponManager->setConditions($conditions); return clone $couponManager; }
/** * Manage how a Condition is updated * * @param Coupon $coupon Coupon Model * @param ConditionCollection $conditions Condition collection */ protected function manageConditionUpdate(Coupon $coupon, ConditionCollection $conditions) { $couponEvent = new CouponCreateOrUpdateEvent($coupon->getCode(), $coupon->getType(), $coupon->getTitle(), $coupon->getEffects(), $coupon->getShortDescription(), $coupon->getDescription(), $coupon->getIsEnabled(), $coupon->getExpirationDate(), $coupon->getIsAvailableOnSpecialOffers(), $coupon->getIsCumulative(), $coupon->getIsRemovingPostage(), $coupon->getMaxUsage(), $coupon->getLocale(), $coupon->getFreeShippingForCountries(), $coupon->getFreeShippingForModules(), $coupon->getPerCustomerUsageCount()); $couponEvent->setCouponModel($coupon); $couponEvent->setConditions($conditions); $eventToDispatch = TheliaEvents::COUPON_CONDITION_UPDATE; // Dispatch Event to the Action $this->dispatch($eventToDispatch, $couponEvent); $this->adminLogAppend(AdminResources::COUPON, AccessManager::UPDATE, sprintf('Coupon %s (ID %s) conditions updated', $couponEvent->getCouponModel()->getTitle(), $couponEvent->getCouponModel()->getType()), $couponEvent->getCouponModel()->getId()); }