Skip to content

Commit

Permalink
Merge pull request magento#871 from magento-engcom/get-source-action-…
Browse files Browse the repository at this point in the history
…all-items-it-one-call

Refacoring: Source Selection Algoritm on Shipping page - call by all requestedItems
  • Loading branch information
maghamed authored Apr 10, 2018
2 parents f91fd23 + 61382ac commit cde574a
Showing 1 changed file with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,29 +96,38 @@ public function execute(): ResultInterface
$websiteId = $postRequest['websiteId'] ?? 1;
$stockId = (int)$this->stockByWebsiteIdResolver->get((int)$websiteId)->getStockId();

$result = [];
$result = $requestItems = [];
foreach ($requestData as $data) {
$orderItem = $data['orderItem'];
$requestItem = $this->itemRequestFactory->create([
'sku' => $data['sku'],
'qty' => $data['qty']
]);
$inventoryRequest = $this->inventoryRequestFactory->create([
'stockId' => $stockId,
'items' => [$requestItem]
]);
$sourceSelectionResult = $this->sourceSelectionService->execute(
$inventoryRequest,
$algorithmCode
$requestItems[] = $this->itemRequestFactory->create(
[
'sku' => $data['sku'],
'qty' => $data['qty']
]
);
}
$inventoryRequest = $this->inventoryRequestFactory->create(
[
'stockId' => $stockId,
'items' => $requestItems
]
);
$sourceSelectionResult = $this->sourceSelectionService->execute(
$inventoryRequest,
$algorithmCode
);
foreach ($requestData as $data) {
$orderItem = $data['orderItem'];
foreach ($sourceSelectionResult->getSourceSelectionItems() as $item) {
$result[$orderItem][] = [
'sourceCode' => $item->getSourceCode(),
'qtyAvailable' => $item->getQtyAvailable(),
'qtyToDeduct' => $item->getQtyToDeduct()
];
if ($item->getSku() == $data['sku']) {
$result[$orderItem][] = [
'sourceCode' => $item->getSourceCode(),
'qtyAvailable' => $item->getQtyAvailable(),
'qtyToDeduct' => $item->getQtyToDeduct()
];
}
}
}

$resultJson->setData($result);
}
return $resultJson;
Expand Down

0 comments on commit cde574a

Please sign in to comment.