Esempio n. 1
0
 /**
  * Adds a Variant to Order Item
  *
  * @param \Extcode\Cart\Domain\Model\Cart\BeVariant $variant
  * @param int $level Level
  *
  * @return void
  */
 protected function addBeVariant(\Extcode\Cart\Domain\Model\Cart\BeVariant $variant, $level)
 {
     /** @var \Extcode\Cart\Domain\Model\Order\Tax $orderTax */
     $orderTax = new \Extcode\Cart\Domain\Model\Order\Tax($variant->getTax(), $this->taxClasses[$variant->getTaxClass()->getId()]);
     $orderTax->setPid($this->storagePid);
     $this->taxRepository->add($orderTax);
     /**
      * Order Product
      * @var \Extcode\Cart\Domain\Model\Order\Product $orderProduct
      */
     $orderProduct = new \Extcode\Cart\Domain\Model\Order\Product($variant->getCompleteSku(), $variant->getCompleteTitle(), $variant->getQuantity());
     $orderProduct->setPid($this->storagePid);
     $skuWithVariants = [];
     $titleWithVariants = [];
     $variantInner = $variant;
     for ($count = $level; $count > 0; $count--) {
         $skuWithVariants['variantsku' . $count] = $variantInner->getSku();
         $titleWithVariants['varianttitle' . $count] = $variantInner->getTitle();
         if ($count > 1) {
             $variantInner = $variantInner->getParentBeVariant();
         } else {
             $cartProduct = $variantInner->getProduct();
         }
     }
     unset($variantInner);
     $skuWithVariants['sku'] = $cartProduct->getSku();
     $titleWithVariants['title'] = $cartProduct->getTitle();
     $orderProduct->setProductType($cartProduct->getProductType());
     $orderProduct->setPrice($variant->getPriceCalculated());
     $orderProduct->setDiscount($variant->getDiscount());
     $orderProduct->setGross($variant->getGross());
     $orderProduct->setNet($variant->getNet());
     $orderProduct->setTaxClass($this->taxClasses[$variant->getTaxClass()->getId()]);
     $orderProduct->setTax($variant->getTax());
     if (!$orderProduct->_isDirty()) {
         $this->productRepository->add($orderProduct);
     }
     $this->addFeVariants($orderProduct, $cartProduct->getFeVariant());
     $variantInner = $variant;
     for ($count = $level; $count > 0; $count--) {
         /**
          * @var \Extcode\Cart\Domain\Model\Order\ProductAdditional $productAdditional
          */
         $orderProductAdditional = new \Extcode\Cart\Domain\Model\Order\ProductAdditional('variant_' . $count, $variantInner->getCompleteSku(), $variantInner->getTitle());
         $orderProductAdditional->setPid($this->storagePid);
         $this->productAdditionalRepository->add($orderProductAdditional);
         $orderProduct->addProductAdditional($orderProductAdditional);
         if ($count > 1) {
             $variantInner = $variantInner->getParentBeVariant();
         } else {
             $cartProduct = $variantInner->getProduct();
         }
     }
     unset($variantInner);
     $additionalArray = $cartProduct->getAdditionalArray();
     $data = ['cartProduct' => $cartProduct, 'orderProduct' => &$orderProduct, 'additionalArray' => &$additionalArray, 'storagePid' => $this->storagePid];
     $signalSlotDispatcher = $this->objectManager->get('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher');
     $signalSlotDispatcher->dispatch(__CLASS__, __FUNCTION__ . 'BeforeSetAdditionalData', [$data]);
     $orderProduct->setAdditionalData(json_encode($data['additionalArray']));
     $this->productRepository->add($orderProduct);
     $this->orderItem->addProduct($orderProduct);
 }
Esempio n. 2
0
 /**
  * @param \Extcode\Cart\Domain\Model\Cart\BeVariant $newBeVariant
  * @return mixed
  */
 public function addBeVariant(\Extcode\Cart\Domain\Model\Cart\BeVariant $newBeVariant)
 {
     $newBeVariantId = $newBeVariant->getId();
     /** @var \Extcode\Cart\Domain\Model\Cart\BeVariant $beVariant */
     $beVariant = $this->beVariants[$newBeVariantId];
     if ($beVariant) {
         if ($beVariant->getBeVariants()) {
             $beVariant->addBeVariants($newBeVariant->getBeVariants());
         } else {
             $newQuantity = $beVariant->getQuantity() + $newBeVariant->getQuantity();
             $beVariant->setQuantity($newQuantity);
         }
     } else {
         $this->beVariants[$newBeVariantId] = $newBeVariant;
     }
     $this->reCalc();
 }
Esempio n. 3
0
 /**
  * @test
  */
 public function getQuantityReturnsQuantitySetByConstructor()
 {
     $this->assertSame($this->quantity, $this->beVariant->getQuantity());
 }