Developer forum

Forum » Development » How do I create language variants of products in DW8?

How do I create language variants of products in DW8?

Ilja Alaoja
Reply
I am currently trying to create language variants of products and product variants. The API documentation mentions the method MakeFullCopyToGroupWithLanguage but this method doesn't seem to exist in DW8. I've tried a few different approaches, but I'm not having any success.

What is the best practice when creating language variants of products in DW8?

Replies

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply
Hi there,

You can just set the Language on the product and save. For some odd reason you also need to set the Context language. Something like this should work:
foreach (var language in myImportSettings.Languages)
{
  Context.LanguageID = language.LanguageId;
  Context.Language = new Language(language.LanguageId);

  dwBaseProduct.Language = new Language(language.LanguageId);
  dwBaseProduct.LongDescription = "Localized description";
  dwBaseProduct.Save();
}

Here, myImportSettings is some custom object that exposes a List<Language> where Language is a custom object which as, among other things a LanguageId property that contains the DW language, such as LANG2.

Don't forget to set the context language back to what it was afterwards.

Hope this helps,

Imar
 
Ilja Alaoja
Reply
Thank you for your reply, Imar. Your solution works indeed, but something that seems very curious to me happens when I create the language variants. After I've created the product and its product variants I try to create the language variants, but it seems that no matter what I do, the first product variant of the first language variant gets overwritten by the first product variant of the second language variant.

This is what it is supposed to look like:
ProductID ProductLanguageID ProductVariantID ProductDefaultShopID ProductNumber ProductName
PROD111111 LANG2   SHOP1 11111100 Testprodukt 1
PROD111111 LANG2 VO550.VO602 SHOP1 11111100 Testprodukt 1
PROD111111 LANG2 VO550.VO598 SHOP1 11111101 Testprodukt 2
PROD111111 LANG3   SHOP1 11111100 Testprodukt 1
PROD111111 LANG3 VO550.VO602 SHOP1 11111100 Testprodukt 1
PROD111111 LANG3 VO550.VO598 SHOP1 11111101 Testprodukt 2

This is what it looks like:
ProductID ProductLanguageID ProductVariantID ProductDefaultShopID ProductNumber ProductName
PROD111111 LANG2   SHOP1 11111100 Testprodukt 1
PROD111111 LANG2 VO550.VO598 SHOP1 11111101 Testprodukt 2
PROD111111 LANG3   SHOP1 11111100 Testprodukt 1
PROD111111 LANG3 VO550.VO602 SHOP1 11111100 Testprodukt 1
PROD111111 LANG3 VO550.VO598 SHOP1 11111101 Testprodukt 2
I am totally puzzled by this. Do you have any idea of what might cause this?
 
Vladimir
Reply
 Hi Llja,
this is unusual behavior for product saving.
But the method prod.Save() exactly the same as that used in DW admin.
May you check, when you are saving an extended variant for LANG3 in DW admin - will this operation cause the appearing of extended variant for LANG2?

Kind regards,
Vladimir

 

You must be logged in to post in the forum