bulkInventoryTransferValidator = $inventoryTransferValidator; $this->bulkInventoryTransfer = $bulkInventoryTransfer; $this->getProductIdsBySkus = $getProductIdsBySkus; $this->legacyIndexer = $legacyIndexer; $this->defaultSourceProvider = $defaultSourceProvider; $this->sourceIndexer = $sourceIndexer; } /** * Reindex legacy stock (for default source) * @param array $productIds */ private function reindexLegacy(array $productIds): void { $this->legacyIndexer->executeList($productIds); } /** * @inheritdoc * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function execute( array $skus, string $originSource, string $destinationSource, bool $unassignFromOrigin ): bool { $validationResult = $this->bulkInventoryTransferValidator->validate( $skus, $originSource, $destinationSource ); if (!$validationResult->isValid()) { throw new ValidationException(__('Validation Failed'), null, 0, $validationResult); } $this->bulkInventoryTransfer->execute( $skus, $originSource, $destinationSource, $unassignFromOrigin ); $this->sourceIndexer->executeList([$originSource, $destinationSource]); if (($this->defaultSourceProvider->getCode() === $originSource) || ($this->defaultSourceProvider->getCode() === $destinationSource)) { $productIds = array_values($this->getProductIdsBySkus->execute($skus)); $this->reindexLegacy($productIds); } return true; } }