nopSolutions / nopCommerce

ASP.NET Core eCommerce software. nopCommerce is a free and open-source shopping cart.
https://www.nopcommerce.com
Other
9.14k stars 5.25k forks source link

Store Specific Website not Switching Language based on Unique SEO Code #7257

Closed delisa-glover closed 1 month ago

delisa-glover commented 1 month ago

nopCommerce version: 4.60.6

Steps to reproduce the problem: Create a website with two stores: Store1 and Store2. Create languages like this: 1) Name: Store 1 English, Language Culture: en-US, Unique SEO Code: e1, Limited to Stores: Store1 2) Name: Store 1 Spanish, Language Culture: es-US, Unique SEO Code: s1, Limited to Stores: Store1 3) Name: Store 2 English, Language Culture: en-US, Unique SEO Code: e2, Limited to Stores: Store2 4) Name: Store 2 Spanish, Language Culture: es-US, Unique SEO Code: s2, Limited to Stores: Store2 Try to access the website with the following links: 1) store1.com/e1 - works fine 2) store1.com/s1 - works fine 3) store1.com/e1 - works fine 3) store2.com/e2 - works fine 4) store2.com/s2 - works fine 5) store2.com/e2 - (website gets stuck in the language of s2, doesn't switch back to English)

Expected Behavior: We have several stores using the same language culture but with unique SEO codes. When two or more stores have an entry in the Language table with the same language culture but with different unique SEO codes, the store website should be able to switch language.

Actual Behavior: The second store website is not able to switch language and gets stuck in the current language.

Problem: It seems like the website gets stuck because GetLanguageFromRequestAsync() is only getting the first language that matches the language culture, not taking into account if the store has access to that language.

Fix: We fixed the issue in our system by only returning languages that the store has access to: //try to get language by culture name var store = await _storeContext.GetCurrentStoreAsync(); var requestLanguage = (await _languageService.GetAllLanguagesAsync(false, store?.Id ?? 0)).FirstOrDefault(language => language.LanguageCulture.Equals(requestCultureFeature.RequestCulture.Culture.Name, StringComparison.InvariantCultureIgnoreCase));

AndreiMaz commented 1 month ago

@exileDev Please see https://www.nopcommerce.com/en/boards/topic/99538/store-specific-website-not-switching-language-based-on-unique-seo-code

exileDev commented 1 month ago

Closed #7257