示例#1
0
 /**
  * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
  * @param \Generated\Shared\Transfer\DiscountTransfer $discountTransfer
  *
  * @return \Generated\Shared\Transfer\DiscountableItemTransfer[]|array
  */
 protected function collectItems(QuoteTransfer $quoteTransfer, DiscountTransfer $discountTransfer)
 {
     try {
         $collectorQueryString = $discountTransfer->getCollectorQueryString();
         $collectorComposite = $this->collectorBuilder->buildFromQueryString($collectorQueryString);
         return $collectorComposite->collect($quoteTransfer);
     } catch (QueryStringException $exception) {
         $this->getLogger()->warning($exception->getMessage(), ['exception' => $exception]);
     }
     return [];
 }
示例#2
0
 /**
  * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
  * @param \Orm\Zed\Discount\Persistence\SpyDiscount $discountEntity
  *
  * @return bool
  */
 protected function isDiscountApplicable(QuoteTransfer $quoteTransfer, SpyDiscount $discountEntity)
 {
     if ($discountEntity->getDiscountType() === DiscountConstants::TYPE_VOUCHER) {
         $voucherCode = $discountEntity->getVoucherCode();
         if ($this->voucherValidator->isUsable($voucherCode) === false) {
             return false;
         }
     }
     $queryString = $discountEntity->getDecisionRuleQueryString();
     if (!$queryString) {
         return true;
     }
     try {
         $compositeSpecification = $this->decisionRuleBuilder->buildFromQueryString($queryString);
         foreach ($quoteTransfer->getItems() as $itemTransfer) {
             if ($compositeSpecification->isSatisfiedBy($quoteTransfer, $itemTransfer) === true) {
                 return true;
             }
         }
     } catch (QueryStringException $exception) {
         $this->getLogger()->warning($exception->getMessage(), ['exception' => $exception]);
     }
     return false;
 }
示例#3
0
 /**
  * Dry run for collectors
  *
  * @param string $queryString
  *
  * @return void
  */
 protected function collectorQueryString($queryString)
 {
     $this->collectorBuilder->buildFromQueryString($queryString);
 }