Category Description Localization

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 anni tempo fa
Hi,

I am trying to use the Item.Description in my category listing : /Views/Catalog/CategoryTemplate.ProductsInGridOrLines.cshtml

I am using that code : @Html.Raw(item.Description)

It is working fine, but the localization is not working. When I switch language, it took the standard version.

Any help will be very appreciate.

Thanks,
Nicolas
12 anni tempo fa
I presume that you're using not a category description (something else) because it should be referenced by Model.Description (not item.Description). Where exactly are you using it in /Views/Catalog/CategoryTemplate.ProductsInGridOrLines.cshtml?
12 anni tempo fa
It is returning nothing if I use the Model.Description.

    @if (Model.SubCategories.Count > 0)
    {
        <div class="sub-category-grid ">
            @(Html.DataList<CategoryModel.SubCategoryModel>(Model.SubCategories, itemPerRow,
                @<div class="item-box @widthItem">                    
                    <div class="sub-category-item @widthItem">
                        <h2 class="category-title">
                            <a href="@Url.RouteUrl("Category", new { categoryId = item.Id, SeName = item.SeName })" title="@item.PictureModel.Title">
                                @item.Name</a>
                        </h2>
                        <div class="picture">
                            <a href="@Url.RouteUrl("Category", new { categoryId = item.Id, SeName = item.SeName })" title="@item.PictureModel.Title">
                                <img style="border-width: 0px;width:150px;" alt="@item.PictureModel.AlternateText" src="@item.PictureModel.ImageUrl"
                                    title="@item.PictureModel.Title" /></a>
                                    <p>@Html.Raw(@item.Description)</p>
                        </div>
                        
                    </div>
                </div>
            ))
        </div>
        <div class="clear">
        </div>
    }
12 anni tempo fa
Actually CategoryModel.SubCategoryModel class doesn't have Description property which you're using. So you customized the source code. BTW, you're trying to display the localized description of subcategories (not the main category). How exactly have you changed the 'Category' method of the 'CatalogController' (how are you setting this Description property)?
12 anni tempo fa
Ok, sorry I didn't remember I had changed the controller : CatalogController.cs

That is the problem, I have add this line :

            //subcategories
            model.SubCategories = _categoryService
                .GetAllCategoriesByParentCategoryId(categoryId)
                .Select(x =>
                {
                    var subCatName = x.GetLocalized(y => y.Name);
                    var subCatModel = new CategoryModel.SubCategoryModel()
                    {
                        Id = x.Id,
                        Name = subCatName,
         Description = x.Description,
                        SeName = x.GetSeName(),
                    };
                    subCatModel.PictureModel.ImageUrl = _pictureService.GetPictureUrl(x.PictureId, _mediaSetting.CategoryThumbPictureSize, true);
                    subCatModel.PictureModel.Title = string.Format(_localizationService.GetResource("Media.Category.ImageLinkTitleFormat"), subCatName);
                    subCatModel.PictureModel.AlternateText = string.Format(_localizationService.GetResource("Media.Category.ImageAlternateTextFormat"), subCatName);
                    return subCatModel;
                })
                .ToList();

What I need to add to the return value to get the localization working ?
12 anni tempo fa
Ok it working now ... I change the controller code for these :

            //subcategories
            model.SubCategories = _categoryService
                .GetAllCategoriesByParentCategoryId(categoryId)
                .Select(x =>
                {
                    var subCatName = x.GetLocalized(y => y.Name);
                    var subCatDesc = x.GetLocalized(y => y.Description);
                    var subCatModel = new CategoryModel.SubCategoryModel()
                    {
                        Id = x.Id,
                        Name = subCatName,
                        Description = subCatDesc,
                        SeName = x.GetSeName(),
                    };
                    subCatModel.PictureModel.ImageUrl = _pictureService.GetPictureUrl(x.PictureId, _mediaSetting.CategoryThumbPictureSize, true);
                    subCatModel.PictureModel.Title = string.Format(_localizationService.GetResource("Media.Category.ImageLinkTitleFormat"), subCatName);
                    subCatModel.PictureModel.AlternateText = string.Format(_localizationService.GetResource("Media.Category.ImageAlternateTextFormat"), subCatName);
                    return subCatModel;
                })
                .ToList();

Many thanks for your help !
Nicolas
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.