resource = $resource; $this->defaultStockProvider = $defaultStockProvider; $this->stockIndexTableNameResolver = $stockIndexTableNameResolver; $this->productTableName = $productTableName; } /** * @param array $stockIds * @return array */ public function execute(array $stockIds): array { $productIds = [[]]; foreach ($stockIds as $stockId) { if ($this->defaultStockProvider->getId() === (int)$stockId) { continue; } $stockIndexTableName = $this->stockIndexTableNameResolver->execute($stockId); $connection = $this->resource->getConnection(); if ($connection->isTableExists($stockIndexTableName)) { $sql = $connection->select() ->from(['stock_index' => $stockIndexTableName], []) ->join( ['product' => $this->resource->getTableName($this->productTableName)], 'product.sku = stock_index.' . IndexStructure::SKU, ['product.entity_id'] ); $productIds[] = $connection->fetchCol($sql); } } $productIds = array_merge(...$productIds); return array_unique($productIds); } }