/** * {@inheritdoc} */ public function getPromotions(PromotionSubjectInterface $subject) { if (!$subject instanceof OrderInterface) { throw new UnexpectedTypeException($subject, OrderInterface::class); } $channel = $subject->getChannel(); $promotions = $this->promotionRepository->findActiveByChannel($channel); return $promotions; }
/** * @param PromotionSubjectInterface $subject * * @return array */ protected function getActivePromotions(PromotionSubjectInterface $subject) { if (!$subject instanceof OrderInterface) { throw new UnexpectedTypeException($subject, OrderInterface::class); } if (null === $this->promotions) { $channel = $subject->getChannel(); $this->promotions = $this->repository->findActiveByChannel($channel); } return $this->promotions; }
/** * {@inheritdoc} */ public function getPromotions(PromotionSubjectInterface $subject) { if (!$subject instanceof OrderInterface) { throw new UnexpectedTypeException($subject, OrderInterface::class); } $channel = $subject->getChannel(); if (null === $channel) { throw new \InvalidArgumentException('Order has no channel, but it should.'); } $promotions = $this->promotionRepository->findActiveByChannel($channel); return $promotions; }
/** * {@inheritdoc} */ public function execute(PromotionSubjectInterface $subject, array $configuration, PromotionInterface $promotion) { if (!$subject instanceof OrderInterface) { throw new UnexpectedTypeException($subject, OrderInterface::class); } $channelCode = $subject->getChannel()->getCode(); if (!isset($configuration[$channelCode]) || !isset($configuration[$channelCode]['percentage'])) { return false; } $filteredItems = $this->priceRangeFilter->filter($subject->getItems()->toArray(), array_merge(['channel' => $subject->getChannel()], $configuration[$channelCode])); $filteredItems = $this->taxonFilter->filter($filteredItems, $configuration[$channelCode]); $filteredItems = $this->productFilter->filter($filteredItems, $configuration[$channelCode]); if (empty($filteredItems)) { return false; } foreach ($filteredItems as $item) { $promotionAmount = (int) round($item->getUnitPrice() * $configuration[$channelCode]['percentage']); $this->setUnitsAdjustments($item, $promotionAmount, $promotion); } return true; }