Blog » Enhancing your ASPDotNetStorefront Search Page

Enhancing your ASPDotNetStorefront Search Page

Enhanced Search Page for AspDotNetStoreFront I recently completed a search page upgrade on one of my client websites (http://www.tobacco-barn.com) and was pleased enough with some of the code on this that I thought I’d share it with the community. Our goals were as follows:

  1. Limit search to just show products and not each variant of the a product
  2. Include images with the search results
  3. Include a description (no more than 500 characters) with each search result
  4. Try and maintain all changes within the page.search.xml.config file

[more]

Of course the first step is to copy the original xml.config file from the /XmlPackages folder into the XmlPackages folder under the skin we are working on.

The next step was to exclude multiple variations (variants) of a product from showing on the result page. At first I figured that I would set up the Product template to ignore the variants after the first one. Then I stumbled on a post on the ASPDNSF support forums indicating that by changing the value of the @ViewType parameter from 0 to 1, I could signal to the stored procedure to only return the product information for a product using the default variant.

The next step was similarly easy to accomplish. After adding another column to the table holding the Product Results (found almost at the end of the / (root) template), i inserted the following lines of code into the Product template:

<td valign="middle" align="left"><a href="{aspdnsf:ProductLink(ProductID, SEName, 0, '')}"><xsl:value-of select="aspdnsf:LookupProductImage(ProductID, ImageFileNameOverride, SKU, 'icon', 0)" disable-output-escaping="yes" /></a></td>

Next up is to get the description to include in the search results listing. First try was to apply substring() to the results from description to just truncate them. The challenge is that if you truncate the product description and the description contains HTML tags, you might accidently split the tags and cause display problems for the remainder of the page. So, I stumbled on some XSTL code that will remove the HTML tags from the content.

So, at the top of the Product template, we create a param and store the Description value that has been transformed by the removeTags template.

<xsl:param name="pDescription"><xsl:call-template name="removeTags"><xsl:with-param name="field" select="Description"/></xsl:call-template></xsl:param>

and the following code gets added to the cell that contains the product name. It checks the length of Description and truncates it if necessary.

<br /><xsl:if test="string-length($pDescription) &gt; 500"><xsl:value-of select="substring($pDescription,0,497)" disable-output-escaping="yes" />...</xsl:if><xsl:if test="string-length($pDescription) &lt;= 500"><xsl:value-of select="$pDescription" disable-output-escaping="yes" /></xsl:if>

Of course all of this is dependant upon the following template to strip out the HTML tags:

<xsl:template name="removeTags"><xsl:param name="field"/><xsl:choose><xsl:when test="contains($field, '&lt;') and contains(substring-after($field, '&lt;'), '>')"><xsl:value-of select="substring-before($field, '&lt;')"/><xsl:call-template name="removeTags"><xsl:with-param name="field" select="substring-after(substring-after($field, '&lt;'), '>')"/></xsl:call-template></xsl:when><xsl:otherwise><xsl:value-of select="$field"/></xsl:otherwise></xsl:choose></xsl:template>

Hopefully you’ll find this code useful. If you have similar code that has some improvements to it, please feel free to use the comments
section below to give us our opinion on this solution.

Michael Gibbs
Stalk Me...
Latest posts by Michael Gibbs (see all)