/** * 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); }