Developer forum

Forum » Development » Changing the language context

Changing the language context

Martin Nielsen
Reply

Hi DW,

 

I have a B2B shop where i'd like for customers to log in and see their products in the right language and the right currency, but i don't want to build multiple sites for each language.

 

Is it possible to change the context language in a Dynamicweb.Notifications.Standard.User.OnExtranetLogin notification?

 

That would allow me to have one website/area that can manage either combination of language and currency.

 

// Martin

 


Replies

 
Martin Nielsen
Reply

I tried this:

Dynamicweb.eCommerce.Common.Context.LanguageID = "LANG5";
Dynamicweb.eCommerce.Common.Context.LanguageSetByCustomer = true;

And it works up until i click on a product. Then i get a blank screen.

The productlist is rendering, but not a product.

 

 

 
Nicolai Høeg Pedersen
Reply

Try setting Context.Language = Application.Language("LANG5") instead.

You can also say &LanguageID=LANG5 in a URL to any page. So when a user is logging in, redirect to a page with the parameter set.

BR Nicolai

 
Martin Nielsen
Reply

Hi Nicolai,

Thank you for getting back on this.

I've tried your solution but i still get a blank product page.

I've made the following test to see if it's my languages that are wrong:

  • Create a new website (A) - Set language to LANG5, Currency DKK - Browse to a product on the website - Product is rendered fine
  • Create a new website (B) - Set language to LANG4, Currency DKK - Browse to a product on the website - Product is rendered fine
  • Go to product in website (B) - Add &LanguageID=LANG5 to URL - Browse to a product on the website - Product page is blank

Any idea what could cause this? I'm on version 8.3.0.4 atm.

// Martin

 

 
Nicolai Høeg Pedersen
Reply

Is the product translated into that language?

BR Nicolai

 
Nicolai Høeg Pedersen
Reply

Oh, I think I need a URL.

On the website properties you can set the language of website B. And in URLs you can set a setting so it will not show products from other languages. Could be that...

Nicolai

 
Martin Nielsen
Reply

I just sent you a link to the site.

The product i testet with exists in the current language. The product lists are filteret by wether the products are available on the LangID i switched to, but clicking a product in the list gives a blank page.

 
Martin Nielsen
Reply

Hi Nicloai,

So i tried to update my local developer version to 8.3.1.13, and now i get 404 errors instead of a blank page when clicking my products.
This is probably better, but i don't understand why my products don't show. So it's kinda the same product still.

// Martin

 
Mikkel Ricky
Reply

Try unchecking "404 for products not in website language" in Management Center > Web and HTTP > Customized URLs > Ecommerce.

Best regards,
Mikkel

 
Martin Nielsen
Reply

Hi Mikkel,

That did the trick. Must be a setting that wasn't in the previous version of DW i had on my solution.

It's working now.

Are there any drawbacks with overriding the Language on login? Can something breaks? 
I know changing Currency can cause some problems with carts, is language id the same?

// Martin

 
Nicolai Høeg Pedersen
Reply

It should not be an issue. If you run into problems it is more likely a bug.

BR Nicolai

 
Martin Nielsen
Reply

I ended up with this code inside my OnLogin notification:

 

if ( isB2BUser == true ) {

  Dynamicweb.Modules.Common.CustomFields.CustomFieldValue cfLanguage = user.CustomFieldValues.FirstOrDefault( p => p.CustomField.SystemName.Equals( "AccessUser_LoginLanguage" ) );

  if ( cfLanguage != null )

  {

    // Make sure Language ID is valid before changing the context

    string userLanguageID = cfLanguage.Value.ToString();

    if ( string.IsNullOrEmpty( userLanguageID ) == false && Dynamicweb.eCommerce.International.Language.GetLanguage( userLanguageID ) != null )

    {
      Dynamicweb.eCommerce.Common.Context.LanguageSetByCustomer = true;
      Dynamicweb.eCommerce.Common.Context.Language = Dynamicweb.eCommerce.Common.Application.get_Language( userLanguageID );

    }

  }

}

 

 

You must be logged in to post in the forum