From 59e5dfd931135932fb49607003406f12c52b5dd6 Mon Sep 17 00:00:00 2001 From: Serhii Chepela Date: Mon, 14 Oct 2024 18:07:53 +0300 Subject: [PATCH] FRW-9023 updated store locale expander to have the same structure as in DMS OFF mode (#11141) FRW-9023 Fixed locale store expander in order to have same structure in both Dynamic Multistore ON and OFF modes. --- .../Business/Expander/StoreExpander.php | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Spryker/Zed/Locale/Business/Expander/StoreExpander.php b/src/Spryker/Zed/Locale/Business/Expander/StoreExpander.php index b3b6943..5026016 100644 --- a/src/Spryker/Zed/Locale/Business/Expander/StoreExpander.php +++ b/src/Spryker/Zed/Locale/Business/Expander/StoreExpander.php @@ -38,15 +38,34 @@ public function expandStoreTransfersWithLocales(array $storeTransfers): array } $localeNamesGroupedByIdStore = $this->localeRepository->getLocaleNamesGroupedByIdStore($storeIds); + $indexedLocaleNamesGroupedByIdStore = $this->indexLocaleNamesByShortName($localeNamesGroupedByIdStore); $defaultLocaleNamesIndexedByIdStore = $this->localeRepository->getDefaultLocaleNamesIndexedByIdStore($storeIds); foreach ($storeTransfers as $storeTransfer) { $storeTransfer ->setDefaultLocaleIsoCode($defaultLocaleNamesIndexedByIdStore[$storeTransfer->getIdStoreOrFail()]) - ->setAvailableLocaleIsoCodes($localeNamesGroupedByIdStore[$storeTransfer->getIdStoreOrFail()] ?? []); + ->setAvailableLocaleIsoCodes($indexedLocaleNamesGroupedByIdStore[$storeTransfer->getIdStoreOrFail()] ?? []); } return $storeTransfers; } + + /** + * @param array> $localeNamesGroupedByIdStore + * + * @return array> + */ + protected function indexLocaleNamesByShortName(array $localeNamesGroupedByIdStore): array + { + $indexedLocaleNamesGroupedByIdStore = []; + foreach ($localeNamesGroupedByIdStore as $idStore => $localeNames) { + foreach ($localeNames as $localeName) { + [$locale, $region] = explode('_', $localeName); + $indexedLocaleNamesGroupedByIdStore[$idStore][$locale] = $localeName; + } + } + + return $indexedLocaleNamesGroupedByIdStore; + } }