unassignValidator = $unassignValidator; $this->bulkSourceUnassign = $bulkSourceUnassign; $this->sourceIndexer = $sourceIndexer; $this->legacyIndexer = $legacyIndexer; $this->defaultSourceProvider = $defaultSourceProvider; $this->getProductIdsBySkus = $getProductIdsBySkus; } /** * Reindex legacy stock (for default source) * @param array $skus * @throws \Magento\Framework\Exception\NoSuchEntityException */ private function reindexLegacy(array $skus): void { $productIds = array_values($this->getProductIdsBySkus->execute($skus)); $this->legacyIndexer->executeList($productIds); } /** * @inheritdoc * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function execute(array $skus, array $sourceCodes): int { $validationResult = $this->unassignValidator->validate($skus, $sourceCodes); if (!$validationResult->isValid()) { throw new ValidationException(__('Validation Failed'), null, 0, $validationResult); } $res = $this->bulkSourceUnassign->execute($skus, $sourceCodes); $this->sourceIndexer->executeList($sourceCodes); if (in_array($this->defaultSourceProvider->getCode(), $sourceCodes, true)) { $this->reindexLegacy($skus); } return $res; } }