Problem with UrlRewriting in NopCommerce

I am trying to make changes to NopCommerce to include the language in the addreess panel. I know that seems like a problem.

When I turn off UrlRewriting, everything works fine, when I turn it on, when I am in the default language, everything works fine when I switch to another language, which is not the default, I have problems.

I have two pieces of code for the standard language and for other languages

I am changing the code a bit, so now the main function chooses between languages:

    public static string GetCategoryUrl(Category category, int languageId)
    {
        if (category == null)
            throw new ArgumentNullException("category");
        string seName = GetSEName(category.SEName);

        if (String.IsNullOrEmpty(seName))
        {
            var categoryLocalized = CategoryManager.GetCategoryLocalizedByCategoryIdAndLanguageId(category.CategoryId, languageId);
            if (categoryLocalized != null)
            {
                seName = GetSEName(categoryLocalized.Name);
            }
            else
            {
            seName = GetSEName(category.Name);
            }
        }            

        int defaultLanguage = Convert.ToInt32(SettingManager.GetSettingValue("Localization.DefaultLanguageID"));
        string url = String.Empty;

        string url2 = String.Empty;

        //***for default language***
        if (languageId == defaultLanguage)
        {
            url2 = SEOHelper.EnableUrlRewriting ? SettingManager.GetSettingValue("SEO.Category.UrlRewriteFormat") : "{0}Category.aspx?CategoryID={1}";
            url = string.Format(url2, CommonHelper.GetStoreLocation(), category.CategoryId, seName);
        }

        //***for other languages***
        else
        {
            url2 = SEOHelper.EnableUrlRewriting ? SettingManager.GetSettingValue("SEO.Category.UrlRewriteFormat2") : "{0}Category.aspx?Language={1}&CategoryID={2}";
            url = string.Format(url2, CommonHelper.GetStoreLocation(), GetLocaleSubFolder(languageId), category.CategoryId, seName);
        }
        return url.ToLowerInvariant();
    }

For the default language, I also have: For SEO.Category.UrlRewriteFormat I have a default database: {0} c {1} / {2}

In UrlRewriting.config I have these rules for the default language:

url www.nopcomerce.com/category.aspx?categoryid=10

, www.nopcomerce.com/c10/somecategory

:

SEO.Category.UrlRewriteFormat2 : {0} {1}/c {2}/{3}

URL : www.nopcomerce.com/category.aspx?language=de&categoryid=10

, , , www.nopcomerce.com/de/c10/somecategorylocalizedingerman

, , , UrlRewriting NopCommerce, . , .

UrlRewriting, (www.nopcomerce.com/c10/somecategory), , , , , , (, ), , , - , ( www.nopcomerce.com/de/c10/somecategorylocalizedingerman).

, , . ?

NopCommerce, .

, , , .

http://www.nopcommerce.com/boards/t/1039/seo-and-multilingual-pages.aspx?p=1

.

+3
1

, , .

, , :

nopcommerce.com///

, , -

nopcommerce.com/category/country/name-of-category.

, ImageButton, , .

NopCommerce cookie .

cookie NopContext.Current.WorkingLanguage.

javascript setCookie()

function setCookie(c_name, value, expiredays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + "=" + escape(value) +
        ((expiredays == null) ? "" : ";expires=" + exdate.toUTCString());
}

cookie , .

,

string coockie = String.Format("javascript:setCookie('{0}','{1}','{2}');", "Nop.CustomerLanguage", language.LanguageId.ToString(), new TimeSpan(365, 0, 0, 0, 0));
hpLanguage.Attributes.Add("onclick", coockie);

, , , .

,

, , - . () , .

, ?

0

Source: https://habr.com/ru/post/1778311/


All Articles