Пример #1
0
 /**
  * Save Order
  *
  * @param array $pluginSettings TypoScript Plugin Settings
  * @param \Extcode\Cart\Domain\Model\Cart\Cart $cart
  * @param \Extcode\Cart\Domain\Model\Order\Item $orderItem
  * @param \Extcode\Cart\Domain\Model\Order\Address $billingAddress
  * @param \Extcode\Cart\Domain\Model\Order\Address $shippingAddress
  *
  * @return void
  */
 public function saveOrderItem(array $pluginSettings, \Extcode\Cart\Domain\Model\Cart\Cart $cart, \Extcode\Cart\Domain\Model\Order\Item $orderItem, \Extcode\Cart\Domain\Model\Order\Address $billingAddress, \Extcode\Cart\Domain\Model\Order\Address $shippingAddress = null)
 {
     $this->storagePid = $pluginSettings['settings']['order']['pid'];
     $this->cart = $cart;
     $this->orderItem = $orderItem;
     if (!$this->objectManager) {
         $this->objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
     }
     $orderItem->setPid($this->storagePid);
     $orderItem->setFeUser((int) $GLOBALS['TSFE']->fe_user->user['uid']);
     $orderItem->setGross($this->cart->getGross());
     $orderItem->setNet($this->cart->getNet());
     $orderItem->setTotalGross($this->cart->getTotalGross());
     $orderItem->setTotalNet($this->cart->getTotalNet());
     $billingAddress->setPid($this->storagePid);
     $orderItem->setBillingAddress($billingAddress);
     if ($shippingAddress && !$shippingAddress->_isDirty()) {
         $shippingAddress->setPid($this->storagePid);
         $orderItem->setShippingAddress($shippingAddress);
     }
     if (!$orderItem->_isDirty()) {
         $this->orderItemRepository->add($orderItem);
         $this->addTaxClasses();
         $this->addTaxes('TotalTax');
         $this->addTaxes('Tax');
         if ($this->cart->getProducts()) {
             $this->addProducts();
         }
         if ($this->cart->getCoupons()) {
             $this->addCoupons();
         }
         if ($this->cart->getPayment()) {
             $this->addPayment();
         }
         if ($this->cart->getShipping()) {
             $this->addShipping();
         }
     }
     $orderNumber = $this->getOrderNumber($pluginSettings);
     $orderItem->setOrderNumber($orderNumber);
     $orderItem->setOrderDate(new \DateTime());
     $this->persistenceManager->persistAll();
     $this->cart->setOrderId($orderItem->getUid());
     $this->cart->setOrderNumber($orderItem->getOrderNumber());
 }