Developer forum

Forum » Ecommerce - Standard features » Products navigation with two languages

Products navigation with two languages

Ivan Marijanović
Ivan Marijanović
Reply

Hi

We have a solution with master website and one additioal language layer. I have a issue that all products links generated points to master page and not appropriate language layer. so for example when I visit page in english and click on link to products group we are redirected to master page.

Ivan


Replies

 
Nicolai Pedersen
Reply

That is probably due to the template implementation.

Can you show us your product list template?

 
Ivan Marijanović
Ivan Marijanović
Reply

Here it is! But I think issue is in menu generator which generates links to masterpages instead of language layer!

@inherits Dynamicweb.Rendering.RazorTemplateBase<Dynamicweb.Rendering.RazorTemplateModel<Dynamicweb.Rendering.Template>>
@using Dynamicweb.Frontend.Devices
@using Dynamicweb.Extensibility
@using Dynamicweb.Content
@using Dynamicweb.Core
@using System
@using System.IO
@using System.Web
@using System.Collections.Generic;
@using System.Linq
@using System.Text.RegularExpressions
@using Dynamicweb.Rapido.Blocks
  
@functions { 
    BlocksPage productListPage = BlocksPage.GetBlockPage("ProductList");
    string favoriteListId = HttpContext.Current.Request.QueryString.Get("ListID");
    bool isFavoriteList = !string.IsNullOrEmpty(HttpContext.Current.Request.QueryString.Get("ListID"));
}
 
@{
    Block pageContainer = new Block()
    {
        Id = "PageContainer",
        Template = RenderPageContainer(),
        SkipRenderBlocksList = true
    };
    productListPage.Add(pageContainer);
 
    Block productListNavigation = new Block()
    {
        Id = "Navigation",
        SortId = 20,
        Design = new Design
        {
            RenderType = RenderType.Column,
            Size = "3"
        }
    };
    productListPage.Add("PageContainer", productListNavigation);
 
    Block productListContainer = new Block()
    {
        Id = "ProductList",
        SortId = 30,
        Template = RenderProductList(),
        SkipRenderBlocksList = true,
        BlocksList = new List<Block>
        {
            new Block
            {
                Id = "ProductListHeader",
                SortId = 10,
                Design = new Design
                {
                    RenderType = RenderType.Row,
                    CssClass = "grid--justify-end grid--bleed u-margin-bottom--lg grid--wrap u-flex-grow--0"
                },
                BlocksList = new List<Block>
                {
                    new Block
                    {
                        Id = "ProductListTitle",
                        SortId = 10,
                        Design = new Design
                        {
                            CssClass = "grid__col-sm-6"
                        },
                        Template = RenderProductListTitle()
                    }
                }
            }
        }
    };
    productListPage.Add("PageContainer", productListContainer);
 
    if (isFavoriteList)
    {
        productListPage.Add("ProductListHeader", new Block
        {
            Id = "FavoriteListSearch",
            SortId = 20,
            Template = RenderFavoriteListSearch(),
            Design = new Design
            {
                CssClass = "grid__col-sm-6 u-margin-bottom u-margin-top grid--align-self-center"
            }
        });
    }
 
    Block productListSnippets = new Block()
    {
        Id = "BottomSnippets",
        SortId = 40
    };
    productListPage.Add(productListSnippets);
}
 
@* This is required for the product list feed to work *@
@GetValue("DoNotRenderProductListTemplate")
 
@* Include the required Grid builder (Contains the methods @RenderBlockList and @RenderBlock) *@
@Include("../../Components/GridBuilder.cshtml")
@Include("../../Components/GeneralComponents.cshtml")
@Include("../../Components/EcommerceComponents.cshtml")
 
@* Include the Blocks for the page *@
@Include("Blocks/Products.cshtml")
 
@Include("Blocks/ViewList.cshtml")
@Include("Blocks/ViewGrid.cshtml")
@Include("Blocks/ViewDetails.cshtml")
@Include("Blocks/Promotions.cshtml")
@Include("Blocks/Menu.cshtml")
@Include("Blocks/Facets.cshtml")
@Include("Blocks/ListMore.cshtml")
@Include("Blocks/BottomSnippets.cshtml")
@Include("Blocks/ListActions.cshtml")
 
@Include("Blocks/Custom__Blocks.cshtml")
 
 
@if (productListNavigation.BlocksList.Count == 0)
{
    productListNavigation.Design.RenderType = RenderType.Hide;
}
 
<form name="multiForm" id="multiForm" method="post" onkeypress="return event.keyCode != 13;">
    @* onkeypress is the fix for disabling submit form on Enter key from any field in product list *@
<input type="hidden" name="CartCmd" id="CartCmd" value="addMulti" />
    @* The @RenderBlockList base helper is included in Components/GridBuilder.cshtml *@
    @RenderBlockList(productListPage.BlocksRoot.BlocksList)
</form>
 
@helper RenderPageContainer()
{
    List<Block> subBlocks = this.productListPage.GetBlockListById("PageContainer").OrderBy(item => item.SortId).ToList();
 
    string pageUrl = GetGlobalValue("Global:Pageview.Url.Raw");
    string feedFullUrl = pageUrl + "&feed=true";
    feedFullUrl += !isFavoriteList ? "&DoNotShowVariantsAsSingleProducts=True" : "";
    string smallDeviceCss = Pageview.Device.ToString() == "Mobile" ? "" : "u-padding"; 
 
    <div class="grid grid--align-content-start @smallDeviceCss js-handlebars-root" id="productList" data-template="ProductContainer" data-pre-render-template="ProductPreRenderContainer" data-json-feed="@feedFullUrl" data-preloader="overlay"></div>
 
    <script id="ProductContainer" type="text/x-template">
        {{#each .}}
            @RenderBlockList(subBlocks)
        {{else}}
            <div class="grid__col-12">
                <h2 class="u-ta-center">@Translate("Your search gave 0 results")</h2>
            </div>
        {{/each}}
    </script>
}
 
@helper RenderProductList()
{
    @*This is part of a script template *@
 
    List<Block> subBlocks = productListPage.GetBlockListById("ProductList").OrderBy(item => item.SortId).ToList();
    string smallDeviceCss = Pageview.Device.ToString() == "Mobile" ? "u-no-padding" : "";
    string columnClass = "auto";
    
    if (productListPage.GetBlockListById("Navigation").Count == 0)
    {
        columnClass = "12";
    }
 
    <div class="grid__col-@columnClass @smallDeviceCss">
        @RenderBlockList(subBlocks)
    </div>
}
 
@helper RenderProductListTitle()
{
    var header = new Heading { Title = "{{{header}}}", CssClass = "u-no-margin" };
 
    if (isFavoriteList) 
    {
        var selectedFavoriteIcon = Pageview.AreaSettings.GetItem("Layout").GetItem("Icons").GetList("FavoriteIcon") != null ? Pageview.AreaSettings.GetItem("Layout").GetItem("Icons").GetList("FavoriteIcon").SelectedValue : "star";
        
        header.Icon = new Icon { Prefix = "fas", Name = "fa-" + selectedFavoriteIcon };
    }
    @Render(header)
}
 
@helper RenderFavoriteListSearch()
{
    string pageId = GetGlobalValue("Global:Page.ID");
    string pageUrl = GetGlobalValue("Global:Pageview.Url.Raw");
    string feedFullUrl = pageUrl + "&feed=true";
    string searchPlaceholder = Translate("Search favorite products");
    string searchValue = HttpContext.Current.Request.QueryString.Get("Search") ?? "";
    
    <div class="typeahead u-color-inherit typeahead--favorites js-typeahead" data-page-size="10" id="FavoritesSearch" data-list-id="@favoriteListId" data-search-feed-id="@pageId&feed=true" data-result-page-id="@pageId">
        <input type="text" class="typeahead-search-field u-no-margin u-full-width js-typeahead-search-field" placeholder="@searchPlaceholder" value="@searchValue">
        <ul class="dropdown dropdown--absolute-position u-full-width js-handlebars-root js-typeahead-search-content u-min-w220px u-full-width dw-mod" id="FavoritesSearchContent" data-template="SearchProductsTemplate" data-json-feed="@feedFullUrl&ListID=@favoriteListId" data-init-onload="false" data-preloader="minimal"></ul>
        <button type="button" class="btn btn--condensed btn--primary u-no-margin dw-mod js-typeahead-enter-btn"><i class="fas fa-search"></i></button>
    </div>
 
Nicolai Pedersen
Reply

My guess is that your "Show on page" setting on the product catalog app is the same on the 2 languages. Update on the language page to the product page in the language version.

 
Ivan Marijanović
Ivan Marijanović
Reply

Nicolai

 

I dont understand what you mean. They are identical in fact English layer is generated from Crotatian.

 

Ivan

 
Nicolai Pedersen
Reply

Yes, and that is what I think is the problem.

On the language version, change the page selected in "Show on paragraph" from pointing to the master "products" page to point to the language "products" page. See dump.

Capture.JPG
 
Ivan Marijanović
Ivan Marijanović
Reply

Hi Nicolai.

 

It is set correctlly:

 

I think the issue could be that when I change site the LanguagId is not set correctly. Where can I chekc that?

 

Ivan

 
Ivan Marijanović
Ivan Marijanović
Reply

This is xml I get for menu. You can see that top level page is correct (frendly href= /english/products) but the Pages with product groups are wrong. They should also have /english in friendly hrefs but they have /proizvodi which is refereing to main web site in Croatian.

 

Ivan

 

<Page CanAccessPasswordProtectedPage="False" CanAccessUserProtectedPage="True" IsPagePasswordProtected="False" IsPageUserProtected="False" ItemType="ContentPage" MenuText="Products" MouseOver="" Image="" ImageActive="" ImageMouseOver="" Allowclick="True" ShowInSitemap="True" ShowInLegend="True" Href="Default.aspx?ID=6740" FriendlyHref="/english/products" Title="Products" RelativeLevel="1" Sort="1" LastInLevel="False" ChildCount="1" class="L1" NavigationTag="ProductsPage" ID="6740" AreaID="23" InPath="False" Active="False" AbsoluteLevel="1" Type="page" ItemId="218" ItemSort="0" CustomSettings="514">
    <Page SmallImage="" LargeImage="" Icon="" GroupNumber="MEN" ProductCount="0" MenuText="For Men" MouseOver="" Image="" ImageActive="" ImageMouseOver="" Allowclick="True" ShowInSitemap="False" ShowInLegend="False" Href="Default.aspx?ID=6301&amp;GroupID=ImportedGROUP66" FriendlyHref="/proizvodi/for-men" Title="Products" RelativeLevel="2" Sort="1" LastInLevel="True" ChildCount="1" class="L2" NavigationTag="" ID="6740" AreaID="23" InPath="False" Active="False" AbsoluteLevel="2" Type="group">
      <Page SmallImage="" LargeImage="" Icon="" GroupNumber="" ProductCount="0" MenuText="Novo u ponudi" MouseOver="" Image="" ImageActive="" ImageMouseOver="" Allowclick="True" ShowInSitemap="True" ShowInLegend="False" Href="Default.aspx?ID=6301&amp;GroupID=GROUP274" FriendlyHref="/proizvodi/for-men/novo-u-ponudi" Title="Products" RelativeLevel="3" Sort="1" LastInLevel="True" ChildCount="0" class="L3" NavigationTag="" ID="6740" AreaID="23" InPath="False" Active="False" AbsoluteLevel="3" Type="group" />
    </Page>
  </Page>
  <Page CanAccessPasswordProtectedPage="False" CanAccessUserProtectedPage="True" IsPagePasswordProtected="False" IsPageUserProtected="False" ItemType="ContentPage" MenuText="Contacts" MouseOver="" Image="" ImageActive="" ImageMouseOver="" Allowclick="True" ShowInSitemap="True" ShowInLegend="True" Href="Default.aspx?ID=6742" FriendlyHref="/english/contacts" Title="Contacts" RelativeLevel="1" Sort="2" LastInLevel="False" ChildCount="1" class="L1" NavigationTag="" ID="6742" AreaID="23" InPath="False" Active="False" AbsoluteLevel="1" Type="page" ItemId="220" ItemSort="0" CustomSettings="516" />
  <Page CanAccessPasswordProtectedPage="False" CanAccessUserProtectedPage="True" IsPagePasswordProtected="False" IsPageUserProtected="False" ItemType="DynamicArticleListPage" MenuText="News" MouseOver="" Image="" ImageActive="" ImageMouseOver="" Allowclick="True" ShowInSitemap="True" ShowInLegend="True" Href="Default.aspx?ID=6743" FriendlyHref="/english/news" Title="News" RelativeLevel="1" Sort="3" LastInLevel="True" ChildCount="3" class="L1" NavigationTag="" ID="6743" AreaID="23" InPath="False" Active="False" AbsoluteLevel="1" Type="page" ItemId="221" ItemSort="0" CustomSettings="517" />

 
Nicolai Pedersen
Reply

I have forwarded this to the support. They will contact you and help you configure it correctly.

 

You must be logged in to post in the forum