6 declare(strict_types=1);
10 use Magento\InventorySourceSelectionApi\Api\Data\ItemRequestInterfaceFactory;
11 use Magento\InventorySourceSelectionApi\Api\Data\InventoryRequestInterfaceFactory;
21 private $itemRequestFactory;
26 private $inventoryRequestFactory;
31 private $sourceSelectionService;
36 private $getDefaultSourceSelectionAlgorithmCode;
41 private $sourceRepository;
46 private $sources = [];
56 ItemRequestInterfaceFactory $itemRequestFactory,
57 InventoryRequestInterfaceFactory $inventoryRequestFactory,
62 $this->itemRequestFactory = $itemRequestFactory;
63 $this->inventoryRequestFactory = $inventoryRequestFactory;
64 $this->sourceSelectionService = $sourceSelectionService;
65 $this->getDefaultSourceSelectionAlgorithmCode = $getDefaultSourceSelectionAlgorithmCode;
76 public function execute(
int $stockId,
string $sku,
float $qty): array
78 $algorithmCode = $this->getDefaultSourceSelectionAlgorithmCode->execute();
80 $requestItem = $this->itemRequestFactory->create([
84 $inventoryRequest = $this->inventoryRequestFactory->create([
85 'stockId' => $stockId,
86 'items' => [$requestItem]
88 $sourceSelectionResult = $this->sourceSelectionService->execute(
93 foreach ($sourceSelectionResult->getSourceSelectionItems() as
$item) {
98 'qtyAvailable' =>
$item->getQtyAvailable(),
99 'qtyToDeduct' =>
$item->getQtyToDeduct()
113 private function getSourceName(
string $sourceCode): string
execute(int $stockId, string $sku, float $qty)
__construct(ItemRequestInterfaceFactory $itemRequestFactory, InventoryRequestInterfaceFactory $inventoryRequestFactory, SourceSelectionServiceInterface $sourceSelectionService, GetDefaultSourceSelectionAlgorithmCodeInterface $getDefaultSourceSelectionAlgorithmCode, SourceRepositoryInterface $sourceRepository)