Developer forum

Forum » Templates » How to get CategoryFields in different langauges

How to get CategoryFields in different langauges

Søren Jakobsen
Reply

Hi Community,

Working on a solution with Danish and English as languages (Rapido 3.4.3 and DW 9.9.4). We're having some issues with the standard Rapido generate PDF function at the productpage. When a user selects to download a product PDF with Danish as language. PDF is downloaded correct but when you change language to English (still on the Danish site) product details are correct but all product specifications will be in danish. Template used is ProductDataSheet.cshtml.

Looks like below code doesn't take product languageid into consideration:

if (!Convert.ToBoolean(Pageview.CurrentParagraph.Item["HideCategoryFields"])) {
        foreach (LoopItem categoryGroup in productCategories)
        {
            var categoryFields = categoryGroup.GetLoop("ProductCategoryFields");
 
            var productFromApi = Dynamicweb.Ecommerce.Services.Products.GetProductById(productId, null, languageId);
 
            Dictionary <string, string> categoryFieldsToRender = new Dictionary<string, string>();
            foreach (LoopItem field in categoryFields)
            {
//string fieldValue = Convert.ToString(productFromApi.GetCategoryValue(categoryGroup.GetString("Ecom:Product.Category.ID"), field.GetString("Ecom:Product.CategoryField.ID")));
                string fieldValue = field.GetString("Ecom:Product.CategoryField.Value");
fieldValue = fieldValue == "True" ? Translate("Yes") : fieldValue;
fieldValue = fieldValue == "False" ? Translate("No") : fieldValue;
 
                if (!String.IsNullOrEmpty(fieldValue) && field.GetString("Ecom:Product.CategoryField.TypeID") != "8" && field.GetString("Ecom:Product.CategoryField.TypeID") != "9")
                {
                    categoryFieldsToRender.Add(field.GetString("Ecom:Product.CategoryField.Label"), fieldValue);
 
                    totalFields++;
                }
            }
            fieldGroupsToRender.Add(categoryGroup.GetString("Ecom:Product.Category.Name"), categoryFieldsToRender); 
        }
    }
 
I have tried to use the api to get the product: var productFromApi = Dynamicweb.Ecommerce.Services.Products.GetProductById(productId, null, languageId); And after that to get the category from: string fieldValue = Convert.ToString(productFromApi.GetCategoryValue(categoryId, field.GetString("Ecom:Product.CategoryField.ID"))); But this will still get me danish even though the product language selected is English. How do I get the Product categories fields values in the language selected?
BR Søren 
 
download.png

Replies

 

You must be logged in to post in the forum