getLegacyStockItem = $getLegacyStockItem; $this->stockItemConfigurationFactory = $stockItemConfigurationFactory; $this->isProductAssignedToStock = $isProductAssignedToStock; $this->defaultStockProvider = $defaultStockProvider; $this->isSourceItemManagementAllowedForSku = $isSourceItemManagementAllowedForSku; } /** * @inheritdoc */ public function execute(string $sku, int $stockId): StockItemConfigurationInterface { if ($this->defaultStockProvider->getId() !== $stockId && true === $this->isSourceItemManagementAllowedForSku->execute($sku) && false === $this->isProductAssignedToStock->execute($sku, $stockId)) { throw new SkuIsNotAssignedToStockException( __('The requested sku is not assigned to given stock.') ); } return $this->stockItemConfigurationFactory->create( [ 'stockItem' => $this->getLegacyStockItem->execute($sku) ] ); } }