/** * @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); }
/** * @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; }
/** * @param \Magento\Sales\Api\Data\OrderInterface $mageOrder * @return \Praxigento\Odoo\Data\Odoo\SaleOrder\Line[] */ public function getSaleOrderLines(\Magento\Sales\Api\Data\OrderInterface $mageOrder) { $lines = []; /* collect data */ $orderId = $mageOrder->getId(); $storeId = $mageOrder->getStoreId(); $stockId = $this->_manStock->getStockIdByStoreId($storeId); $aggSaleOrderItems = $this->_repoAggSaleOrderItem->getByOrderAndStock($orderId, $stockId); foreach ($aggSaleOrderItems as $item) { $productIdOdoo = $item->getOdooIdProduct(); /* process order line */ if (isset($lines[$productIdOdoo])) { $line = $lines[$productIdOdoo]; } else { $line = $this->_extractLine($item); } /* process lot for order line ($item is a flat structure - if one sale item consists of 2 lots then two entries will be in aggregated results) */ $lots = $line->getLots(); $lot = $this->_extractLineLot($item); /* save Odoo data object into Odoo line */ $lots[] = $lot; $line->setLots($lots); $lines[$productIdOdoo] = $line; } /* remove keys from array */ $result = array_values($lines); return $result; }
/** * @param \Magento\CatalogSearch\Model\Search\IndexBuilder $subject * @param \Closure $proceed * @param \Magento\Framework\Search\RequestInterface $request * @return \Magento\Framework\DB\Select */ public function aroundBuild(\Magento\CatalogSearch\Model\Search\IndexBuilder $subject, \Closure $proceed, \Magento\Framework\Search\RequestInterface $request) { /** @var \Magento\Framework\DB\Select $result */ $result = $proceed($request); $from = $result->getPart(\Magento\Framework\DB\Select::FROM); if (isset($from[self::AS_STOCK_INDEX])) { $dimensions = $request->getDimensions(); /** @var \Magento\Framework\Search\Request\Dimension $dimension */ $dimension = reset($dimensions); $storeId = $dimension->getValue(); $stockId = (int) $this->_manStock->getStockIdByStoreId($storeId); $byStockId = self::AS_STOCK_INDEX . '.' . Cfg::E_CATINV_STOCK_STATUS_A_STOCK_ID . '=' . $stockId; $result->where($byStockId); } return $result; }