Developer forum

Forum » Templates » EcomNavigation fails because of having 2 shops on 1 solution

EcomNavigation fails because of having 2 shops on 1 solution

Keerthy Sethupathy
Reply

Greetings, 

For some reason the EcomNavigation fails. We have a sulotion with 2 shops and one of them is a custom made sulotion and the other is a Rapido sulotion. 

I am trying to activate EcomNavigation on the Rapido solution. I have Enabled all customfields on all languages, Enabled productcategories and all products and productgroups are activated on all Languages.

 

I have recieve the following error: 

  

Error transforming XSLT System.NullReferenceException: Object reference not set to an instance of an object. at System.Xml.Xsl.CompiledQuery.Script1.GetCustomFieldString(String groupLink, String systemName) at(3)(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator {urn:schemas-microsoft-com:xslt-debug}current, String type, IList`1 depth) at (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator {urn:schemas-microsoft-com:xslt-debug}current, IList`1 depth, String type) at (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator {urn:schemas-microsoft-com:xslt-debug}current, String type, IList`1 depth) at (XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator {urn:schemas-microsoft-com:xslt-debug}current) at (2)(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator ) at Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime) at Execute(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime) at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlSequenceWriter results) at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer) at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, XmlWriter results, XmlResolver documentResolver) at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, Stream results) at Dynamicweb.Content.Files.XsltParser.XmlXsltTransform(XmlDocument xmlDocument, XslCompiledTransform xslTransformer, TextWriter textWriter, XsltArgumentList xsltArguments)


Replies

 
Nicolai Pedersen
Reply

Hi Keerthy 

Take a look inside BaseMegaMenu.xslt - it has a GetCustomFieldString method that uses something  you do not have on your solution.

This is how the method should look like - it should be checking for the possible null issues - maybe you changed it?:

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");

 }
 
Keerthy Sethupathy
Reply

Hi Nicolai, 

 

I am unsure what you mean by 'that uses something  you do not have on your solution'?

 

The Code is exactly the same as yours: 

 

/*
     * 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");
}
 
Nicolai Pedersen
Reply
This post has been marked as an answer

That is a method - that is being called in your XSLT - see dump.

The fields being called are probably missing? Or maybe the groupLink parameter does not have a value?

You have a method - it has null reference exception - you need to figure out what is null in your specific solution. Or wrap the entire method in try, catch and return an empty string if it fails - bad solution but then you have no exceptions.

BR Nicolai

Capture.JPG
Votes for this answer: 1
 
Nicolai Pedersen
Reply

My guess is that your 

ProductGroupFieldValues

property is null because you do not have any custom group fields.

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

>> it should be checking for the possible null issues - maybe you changed it?:

This piece doesn't though:

!string.IsNullOrEmpty(g.ProductGroupFieldValues.GetProductGroupFieldValue(systemName).Value.ToString()

If the value is null, the ToString call will fail. Maybe a better version would be this:

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

Imar

 
Nicolai Pedersen
Reply

Hi Imar

Thanks - you are right. And just checking - ProductGroupFieldValues cannot be null.

So it might be 

g.ProductGroupFieldValues.GetProductGroupFieldValue(systemName) != null

instead of

g.ProductGroupFieldValues.GetProductGroupFieldValue(systemName).Value != null

BR Nicolai

 
Keerthy Sethupathy
Reply

It works!

I created the four productgroupFields and now it works as it should. 

Thank you very much!

 

 

 

You must be logged in to post in the forum