6 declare(strict_types=1);
32 private $orderRepository;
37 private $stockByWebsiteIdResolver;
42 private $getStockItemConfiguration;
47 private $getSourcesByStockIdSkuAndQty;
52 private $getSkuFromOrderItem;
57 private $sources = [];
89 $this->stockByWebsiteIdResolver = $stockByWebsiteIdResolver;
90 $this->getStockItemConfiguration = $getStockItemConfiguration;
91 $this->getSourcesByStockIdSkuAndQty = $getSourcesByStockIdSkuAndQty;
92 $this->getSkuFromOrderItem = $getSkuFromOrderItem;
113 $orderId = $this->request->getParam(
'order_id');
115 $order = $this->orderRepository->get($orderId);
117 $stockId = (int)$this->stockByWebsiteIdResolver->execute((
int)
$websiteId)->getStockId();
127 $qty =
$item->getSimpleQtyToShip();
128 $qty = $this->castQty(
$item, $qty);
129 $sku = $this->getSkuFromOrderItem->execute(
$item);
130 $data[$orderId][
'items'][] = [
131 'orderItemId' =>
$item->getId(),
133 'product' => $this->getProductName(
$orderItem),
135 'sources' => $this->getSources($stockId, $sku, $qty),
136 'isManageStock' => $this->isManageStock($sku, $stockId)
140 $data[$orderId][
'order_id'] = $orderId;
142 $data[$orderId][
'sourceCodes'][] = [
158 private function getSources(
int $stockId,
string $sku,
float $qty): array
160 $sources = $this->getSourcesByStockIdSkuAndQty->execute($stockId, $sku, $qty);
161 foreach ($sources as
$source) {
173 private function isManageStock($itemSku, $stockId)
175 $stockItemConfiguration = $this->getStockItemConfiguration->execute($itemSku, $stockId);
177 return $stockItemConfiguration->isManageStock();
185 private function getProductName(Item
$item)
189 if ($parentItem =
$item->getParentItem()) {
190 $name = $parentItem->getName();
220 private function castQty(Item
$item, $qty)
222 if (
$item->getIsQtyDecimal()) {
228 return $qty > 0 ? $qty : 0;
addFilter(Filter $filter)
__construct( $name, $primaryFieldName, $requestFieldName, RequestInterface $request, OrderRepository $orderRepository, StockByWebsiteIdResolverInterface $stockByWebsiteIdResolver, GetStockItemConfigurationInterface $getStockItemConfiguration, GetSourcesByStockIdSkuAndQty $getSourcesByStockIdSkuAndQty, GetSkuFromOrderItemInterface $getSkuFromOrderItem, array $meta=[], array $data=[])