/**
  * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
  *
  * @return int
  */
 protected function getQuoteItemQuantity(QuoteTransfer $quoteTransfer)
 {
     $totalQuantity = 0;
     foreach ($quoteTransfer->getItems() as $itemTransfer) {
         $totalQuantity += $itemTransfer->getQuantity();
     }
     return $totalQuantity;
 }
示例#2
0
 /**
  * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
  *
  * @return int
  */
 protected function sumItemTaxes(QuoteTransfer $quoteTransfer)
 {
     $totalTaxAmount = 0;
     foreach ($quoteTransfer->getItems() as $itemTransfer) {
         $totalTaxAmount += $itemTransfer->getSumTaxAmount();
     }
     return $totalTaxAmount;
 }
 /**
  * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
  *
  * @return void
  */
 public function recalculate(QuoteTransfer $quoteTransfer)
 {
     foreach ($quoteTransfer->getItems() as $item) {
         $item->setCalculatedDiscounts(new \ArrayObject());
     }
     foreach ($quoteTransfer->getExpenses() as $expense) {
         $expense->setCalculatedDiscounts(new \ArrayObject());
     }
 }
 /**
  * QuoteTransfer $quoteTransfer
  *
  * @return int
  */
 protected function getCalculatedSubtotal(QuoteTransfer $quoteTransfer)
 {
     $subTotal = 0;
     foreach ($quoteTransfer->getItems() as $itemTransfer) {
         $itemTransfer->requireSumGrossPriceWithProductOptions();
         $subTotal += $itemTransfer->getSumGrossPriceWithProductOptions();
     }
     return $subTotal;
 }
 /**
  * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
  *
  * @return void
  */
 public function recalculate(QuoteTransfer $quoteTransfer)
 {
     foreach ($quoteTransfer->getItems() as $itemTransfer) {
         $this->assertItemRequirements($itemTransfer);
         $this->setProductOptionSumGrossPrice($itemTransfer);
         $productOptionUnitTotal = $this->getProductOptionUnitTotal($itemTransfer);
         $productOptionSumTotal = $this->getProductOptionSumTotal($itemTransfer);
         $itemTransfer->setUnitGrossPriceWithProductOptions($itemTransfer->getUnitGrossPrice() + $productOptionUnitTotal);
         $itemTransfer->setSumGrossPriceWithProductOptions($itemTransfer->getSumGrossPrice() + $productOptionSumTotal);
     }
 }
示例#6
0
 /**
  * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
  * @param \Generated\Shared\Transfer\ClauseTransfer $clauseTransfer
  *
  * @return \Generated\Shared\Transfer\DiscountableItemTransfer[]
  */
 public function collect(QuoteTransfer $quoteTransfer, ClauseTransfer $clauseTransfer)
 {
     $discountableItems = [];
     foreach ($quoteTransfer->getItems() as $itemTransfer) {
         if ($this->comparators->compare($clauseTransfer, $itemTransfer->getSku()) === false) {
             continue;
         }
         $discountableItems[] = $this->createDiscountableItemTransfer($itemTransfer->getUnitGrossPrice(), $itemTransfer->getQuantity(), $itemTransfer->getCalculatedDiscounts());
     }
     return $discountableItems;
 }
 /**
  * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
  * @param \Generated\Shared\Transfer\CheckoutResponseTransfer $checkoutResponse
  *
  * @return void
  */
 public function checkCondition(QuoteTransfer $quoteTransfer, CheckoutResponseTransfer $checkoutResponse)
 {
     $groupedItemQuantities = $this->groupItemsBySku($quoteTransfer->getItems());
     foreach ($groupedItemQuantities as $sku => $quantity) {
         if (!$this->isProductSellable($sku, $quantity)) {
             $checkoutErrorTransfer = $this->createCheckoutErrorTransfer();
             $checkoutErrorTransfer->setErrorCode(CheckoutConstants::ERROR_CODE_PRODUCT_UNAVAILABLE)->setMessage('product.unavailable');
             $checkoutResponse->addError($checkoutErrorTransfer)->setIsSuccess(false);
         }
     }
 }
 /**
  * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
  *
  * @return int
  */
 protected function calculateItemDiscounts(QuoteTransfer $quoteTransfer)
 {
     $itemTotalDiscountAmount = 0;
     foreach ($quoteTransfer->getItems() as $itemTransfer) {
         $itemDiscountAmount = $this->getItemTotalDiscountAmount($itemTransfer);
         if ($itemDiscountAmount > $itemTransfer->getSumGrossPrice()) {
             $itemDiscountAmount = $itemTransfer->getSumGrossPrice();
         }
         $itemTotalDiscountAmount += $itemDiscountAmount;
     }
     return $itemTotalDiscountAmount;
 }
示例#9
0
 /**
  * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
  *
  * @return void
  */
 public function recalculate(QuoteTransfer $quoteTransfer)
 {
     $this->accruedTaxCalculator->resetRoundingErrorDelta();
     foreach ($quoteTransfer->getItems() as $itemTransfer) {
         $itemTransfer->setUnitTaxAmount(0);
         $itemTransfer->setSumTaxAmount(0);
         if (!$itemTransfer->getTaxRate()) {
             continue;
         }
         $unitTaxAmount = $this->calculateTaxAmount($itemTransfer->getUnitGrossPrice(), $itemTransfer->getTaxRate());
         $sumTaxAmount = $this->calculateTaxAmount($itemTransfer->getSumGrossPrice(), $itemTransfer->getTaxRate());
         $itemTransfer->setUnitTaxAmount($unitTaxAmount);
         $itemTransfer->setSumTaxAmount($sumTaxAmount);
     }
 }
 /**
  * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
  *
  * @return void
  */
 public function recalculate(QuoteTransfer $quoteTransfer)
 {
     foreach ($quoteTransfer->getItems() as $itemTransfer) {
         $this->addCalculatedItemGrossAmounts($itemTransfer);
     }
 }
示例#11
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;
 }
 /**
  * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
  * @param array $taxRates
  *
  * @return void
  */
 protected function setItemsTax(QuoteTransfer $quoteTransfer, array $taxRates)
 {
     foreach ($quoteTransfer->getItems() as $itemTransfer) {
         $itemTransfer->setTaxRate($this->getEffectiveTaxRate($taxRates, $itemTransfer->getIdProductAbstract()));
     }
 }
 /**
  * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
  *
  * @return float
  */
 protected function getProductItemsTaxRateAverage(QuoteTransfer $quoteTransfer)
 {
     $taxSum = 0;
     $productOptionCount = 0;
     foreach ($quoteTransfer->getItems() as $item) {
         $taxSum += $this->getEffectiveProductOptionTaxRate($item);
         $productOptionCount += count($item->getProductOptions());
     }
     $taxAverage = $taxSum / $productOptionCount;
     return $taxAverage;
 }
示例#14
0
 /**
  * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
  *
  * @return float
  */
 protected function getProductItemsTaxRateAverage(QuoteTransfer $quoteTransfer)
 {
     $taxSum = 0;
     foreach ($quoteTransfer->getItems() as $item) {
         $taxSum += $item->getTaxRate();
     }
     $taxAverage = $taxSum / count($quoteTransfer->getItems());
     return $taxAverage;
 }
示例#15
0
 /**
  * @param \Generated\Shared\Transfer\SaveOrderTransfer $saveOrderTransfer
  * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
  *
  * @return void
  */
 protected function hydrateSaveOrderTransfer(SaveOrderTransfer $saveOrderTransfer, QuoteTransfer $quoteTransfer)
 {
     foreach ($quoteTransfer->getItems() as $itemTransfer) {
         $saveOrderTransfer->addOrderItem(clone $itemTransfer);
     }
 }
示例#16
0
 /**
  * @return void
  */
 public function testSaveDiscountMustNotSaveSalesDiscountCodesIfUsedCodeCanNotBeFound()
 {
     $discountSaver = $this->getDiscountOrderSaverMock(['persistSalesDiscount', 'persistSalesDiscountCode', 'getDiscountVoucherEntityByCode']);
     $discountSaver->expects($this->once())->method('persistSalesDiscount');
     $discountSaver->expects($this->never())->method('persistSalesDiscountCode');
     $discountSaver->expects($this->once())->method('getDiscountVoucherEntityByCode')->will($this->returnValue(false));
     $calculatedDiscountTransfer = new CalculatedDiscountTransfer();
     $calculatedDiscountTransfer->setVoucherCode(self::USED_CODE_1);
     $quoteTransfer = new QuoteTransfer();
     $orderItemTransfer = new ItemTransfer();
     $orderItemTransfer->addCalculatedDiscount($calculatedDiscountTransfer);
     $quoteTransfer->addItem($orderItemTransfer);
     $checkoutResponseTransfer = new CheckoutResponseTransfer();
     $saverOrderTransfer = new SaveOrderTransfer();
     $saverOrderTransfer->setIdSalesOrder(self::ID_SALES_ORDER);
     $saverOrderTransfer->setOrderItems($quoteTransfer->getItems());
     $checkoutResponseTransfer->setSaveOrder($saverOrderTransfer);
     $discountSaver->saveDiscounts($quoteTransfer, $checkoutResponseTransfer);
 }
 /**
  * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
  *
  * @return void
  */
 protected function calculateItemGrossAmounts(QuoteTransfer $quoteTransfer)
 {
     foreach ($quoteTransfer->getItems() as $itemTransfer) {
         $this->setItemGrossAmounts($itemTransfer);
     }
 }
示例#18
0
 /**
  * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
  *
  * @return array|\Generated\Shared\Transfer\DiscountableItemTransfer[]
  */
 protected function createDiscountableItemsFromQuoteTransfer(QuoteTransfer $quoteTransfer)
 {
     $discountableItems = [];
     foreach ($quoteTransfer->getItems() as $itemTransfer) {
         $discountableItemTransfer = new DiscountableItemTransfer();
         $discountableItemTransfer->fromArray($itemTransfer->toArray(), true);
         $discountableItemTransfer->setOriginalItemCalculatedDiscounts($itemTransfer->getCalculatedDiscounts());
         $discountableItems[] = $discountableItemTransfer;
     }
     return $discountableItems;
 }
 /**
  * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
  * @param array $taxRates
  *
  * @return void
  */
 protected function setItemsTaxRate(QuoteTransfer $quoteTransfer, array $taxRates)
 {
     foreach ($quoteTransfer->getItems() as $item) {
         $this->setProductOptionTaxRate($item, $taxRates);
     }
 }