diff --git a/vendor/magento/module-inventory-indexer/Model/ResourceModel/GetStockItemsData.php b/vendor/magento/module-inventory-indexer/Model/ResourceModel/GetStockItemsData.php index 970c74a1ac4e..0c3e9312a48e 100644 --- a/vendor/magento/module-inventory-indexer/Model/ResourceModel/GetStockItemsData.php +++ b/vendor/magento/module-inventory-indexer/Model/ResourceModel/GetStockItemsData.php @@ -107,6 +107,7 @@ public function execute(array $skus, int $stockId): array GetStockItemsDataInterface::IS_SALABLE => $row['is_salable'], ]; } + $results = $this->normalizeResults($skus, $results); } else { /** * Fallback to the legacy cataloginventory_stock_item table. @@ -126,4 +127,41 @@ public function execute(array $skus, int $stockId): array return $results; } + + /** + * Return results with original SKUs as keys. + * + * @param array $originalSkus + * @param array $results + * @return array + */ + private function normalizeResults(array $originalSkus, array $results): array + { + $normalizedResults = []; + foreach ($results as $sku => $result) { + $normalizedResults[$this->normalizeSku((string) $sku)] = $result; + } + + $finalResults = []; + foreach (array_unique($originalSkus) as $sku) { + $normalizedSku = $this->normalizeSku((string) $sku); + if (isset($results[$sku])) { + $finalResults[$sku] = $results[$sku]; + } elseif (isset($normalizedResults[$normalizedSku])) { + $finalResults[$sku] = $normalizedResults[$normalizedSku]; + } + } + return $finalResults; + } + + /** + * Normalize SKU by converting it to lowercase. + * + * @param string $sku + * @return string + */ + private function normalizeSku(string $sku): string + { + return mb_convert_case($sku, MB_CASE_LOWER, 'UTF-8'); + } }