/**
  * @param \Magento\Sales\Api\Data\OrderInterface $order
  */
 public function splitQty(\Magento\Sales\Api\Data\OrderInterface $order)
 {
     $storeId = $order->getStoreId();
     /* get stock ID for the store view */
     $stockId = $this->_manStock->getStockIdByStoreId($storeId);
     /** @var \Magento\Sales\Api\Data\OrderItemInterface[] $items */
     $items = $order->getItems();
     $itemsData = [];
     /** @var \Magento\Sales\Api\Data\OrderItemInterface $item */
     foreach ($items as $item) {
         $prodId = $item->getProductId();
         $itemId = $item->getItemId();
         /* qty of the product can be changed in invoice, but we use ordered only  */
         $qty = $item->getQtyOrdered();
         /* register sale item (fragment total qty by lots) */
         $itemData = $this->_manObj->create(\Praxigento\Warehouse\Service\QtyDistributor\Data\Item::class);
         $itemData->setItemId($itemId);
         $itemData->setProductId($prodId);
         $itemData->setQuantity($qty);
         $itemData->setStockId($stockId);
         $itemsData[] = $itemData;
     }
     $reqSale = $this->_manObj->create(\Praxigento\Warehouse\Service\QtyDistributor\Request\RegisterSale::class);
     $reqSale->setSaleItems($itemsData);
     $this->_callQtyDistributor->registerSale($reqSale);
 }
Ejemplo n.º 2
0
 /**
  * Save gift message for items of order
  *
  * @param \Magento\Sales\Api\Data\OrderInterface $order
  * @return \Magento\Sales\Api\Data\OrderInterface
  */
 protected function saveOrderItemGiftMessage(\Magento\Sales\Api\Data\OrderInterface $order)
 {
     if (null !== $order->getItems()) {
         /** @var \Magento\Sales\Api\Data\OrderItemInterface $orderItem */
         foreach ($order->getItems() as $orderItem) {
             if (null !== $orderItem->getExtensionAttributes() && null !== $orderItem->getExtensionAttributes()->getGiftMessage()) {
                 /* @var \Magento\GiftMessage\Api\Data\MessageInterface $giftMessage */
                 $giftMessage = $orderItem->getExtensionAttributes()->getGiftMessage();
                 try {
                     $this->giftMessageOrderItemRepository->save($order->getEntityId(), $orderItem->getItemId(), $giftMessage);
                 } catch (\Exception $e) {
                     throw new CouldNotSaveException(__('Could not add gift message to order\'s item: "%1"', $e->getMessage()), $e);
                 }
             }
         }
     }
     return $order;
 }
Ejemplo n.º 3
0
 /**
  * Get gift message for items of order
  *
  * @param \Magento\Sales\Api\Data\OrderInterface $order
  * @return \Magento\Sales\Api\Data\OrderInterface
  */
 protected function getOrderItemGiftMessage(\Magento\Sales\Api\Data\OrderInterface $order)
 {
     if (null !== $order->getItems()) {
         /** @var \Magento\Sales\Api\Data\OrderItemInterface $orderItem */
         foreach ($order->getItems() as $orderItem) {
             if ($orderItem->getExtensionAttributes() && $orderItem->getExtensionAttributes()->getGiftMessage()) {
                 continue;
             }
             try {
                 /* @var \Magento\GiftMessage\Api\Data\MessageInterface $giftMessage */
                 $giftMessage = $this->giftMessageOrderItemRepository->get($order->getEntityId(), $orderItem->getItemId());
             } catch (NoSuchEntityException $e) {
                 continue;
             }
             /** @var \Magento\Sales\Api\Data\OrderItemExtension $orderItemExtension */
             $orderItemExtension = $this->orderItemExtensionFactory->create();
             $orderItemExtension->setGiftMessage($giftMessage);
             $orderItem->setExtensionAttributes($orderItemExtension);
         }
     }
     return $order;
 }
Ejemplo n.º 4
0
 /**
  * @param \Magento\Sales\Api\Data\OrderInterface $order
  * @return \Praxigento\Pv\Service\Sale\Data\Item[]
  */
 public function getServiceItemsForMageSaleOrder(\Magento\Sales\Api\Data\OrderInterface $order)
 {
     $result = [];
     $storeId = $order->getStoreId();
     /* get stock ID for the store view */
     $stockId = $this->_manStock->getStockIdByStoreId($storeId);
     /** @var \Magento\Sales\Api\Data\OrderItemInterface[] $items */
     $items = $order->getItems();
     /** @var \Magento\Sales\Api\Data\OrderItemInterface $item */
     foreach ($items as $item) {
         $itemData = $this->getServiceItemForMageItem($item, $stockId);
         $result[] = $itemData;
     }
     return $result;
 }
Ejemplo n.º 5
0
 /**
  * Returns list of line items in the cart
  *
  * @return \Magento\Sales\Api\Data\OrderItemInterface[]
  */
 public function getItems()
 {
     return $this->order->getItems();
 }