Developer forum

Forum » Ecommerce - Standard features » Include Group custom fields in navigation XML

Include Group custom fields in navigation XML

Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi guys,

I am wondering if there is any way to include custom group fields in Ecom Navigation xml.

I see that by default they are not included.

Thank you,

Adrian


Replies

 
Nicolai Pedersen
Reply

No, but you can use C#.

Rapido does it like this:

 

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:user="urn:my-scripts" exclude-result-prefixes="msxsl user">

  <msxsl:script language="C#" implements-prefix="user">

    <msxsl:assembly name="Dynamicweb" />

    <msxsl:assembly name="Dynamicweb.Ecommerce" />

    <msxsl:assembly name="Dynamicweb.Core" />

    <msxsl:assembly name="Dynamicweb.Security" />

    <msxsl:assembly name="System.IO" />

    <![CDATA[

    /*

     * Get group number from group id in query string

     */


    public string GetCustomFieldString(string groupLink, string systemName)

   {

 var match = System.Text.RegularExpressions.Regex.Match(groupLink, @"GroupID=(?<GroupID>[^&]+)");


 if (match.Success)

 {

 var groupId = match.Groups["GroupID"].Value;


 var g = Dynamicweb.Ecommerce.Products.Group.GetGroupById(groupId);

 if (g != null && !string.IsNullOrEmpty(g.ProductGroupFieldValues.GetProductGroupFieldValue(systemName).Value.ToString()))

 {

 var ctaHeading = Dynamicweb.Core.Converter.ToString(g.ProductGroupFieldValues.GetProductGroupFieldValue(systemName).Value);

 return ctaHeading;

 }

 }

 return string.Empty;

 }


    public string GenerateHeadingImageUrl(string image)

 {

      string imageUrl = image;


 if (System.IO.Path.GetExtension(image).ToLower() != ".svg") {

          imageUrl = "/Admin/Public/GetImage.ashx?width=150&height=100&amp;crop=5&DoNotUpscale=true&FillCanvas=true&Compression=75&image=" + @image;

      }

 return imageUrl.Replace("/Billeder", "/Files/Images");

 }

]]>

</msxsl:script>

 

 

<xsl:if test="count(Page) and /NavigationTree/Settings/LayoutNavigationSettings/@endlevel > @RelativeLevel">
                    <xsl:if test="@RelativeLevel=/NavigationTree/Settings/LayoutNavigationSettings/@ecomStartLevel">
                      <xsl:variable name="ctaImage" select="user:GetCustomFieldString(@Href, 'ctaImage')"/>
                      <xsl:variable name="ctaHeading" select="user:GetCustomFieldString(@Href, 'ctaHeader')"/>
                      <xsl:variable name="ctaLink" select="user:GetCustomFieldString(@Href, 'ctaLink')"/>
                      <xsl:variable name="ctaLinkText" select="user:GetCustomFieldString(@Href, 'ctaLinkText')"/>
 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

Got it. I can definitely use that.

Thank you

Adrian

 

You must be logged in to post in the forum