Is this a v9 site?
If it is, the 'QueryString/categoryid' field is no longer populated (not sure why) but it's relatively easy to solve but needs some code creating.
All, please note, this code can be used by anyone but if you do use it, please credit Webopius somewhere on your site with a genuine link to http://www.webopius.com.
Many thanks
Adam
1. In the App_Code folder, create a new file called something like 'CustomExtension.cs' containing:
Code:
// ------------------------------------------------------------------------------------------
// Copyright Webopius.com 2010
// Custom XSLT Extensions for the ASPDotNetStorefront forum
// ------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Xml;
using System.Xml.Xsl;
using System.Xml.XPath;
using System.Web;
using System.Globalization;
using System.Text.RegularExpressions;
using System.Runtime.CompilerServices;
using AspDotNetStorefrontCore;
/// <summary>
/// Custom Xslt Extension Class
/// </summary>
public class CustomXsltExtension : XSLTExtensionBase
{
#region Variable Declaration
#endregion
#region Constructor
public CustomXsltExtension()
: this(null, 1, null)
{
}
public CustomXsltExtension(Customer cust, int SkinID, Dictionary<string, EntityHelper> EntityHelpers)
: base(cust, SkinID)
{
}
#endregion
#region Methods
// ---===---===---===---===---===---===---===---===---===---===---===---===---===---===
// getEntityName, v9 no longer gives you the entity name and id in general XML functions
// this method returns the entity name of the page (e.g. 'Category')
public string getEntityName(string pagename)
{
String entityname = "";
Match m = Regex.Match(pagename, "^([c|p|g|m|d|v|s])-([0-9]*)-([\\w-]*)\\.aspx(?:\\?(.*))?", RegexOptions.IgnoreCase);
if (m.Success)
{
Group g = m.Groups[1];
String entity = g.ToString().ToLower();
switch (entity)
{
case "c": entityname = "category"; break;
case "p": entityname = "product"; break;
case "g": entityname = "genre"; break;
case "m": entityname = "manufacturer"; break;
case "d": entityname = "distributor"; break;
case "v": entityname = "vector"; break;
case "s": entityname = "section"; break;
}
}
return entityname;
}
// ---===---===---===---===---===---===---===---===---===---===---===---===---===---===
// getEntityID, v9 no longer gives you the entity name and id in general XML functions
// this method returns the entity ID of the page (e.g. '2234')
public string getEntityID(string pagename)
{
string id = "0";
string entity = "";
Match m = Regex.Match(pagename,"^([c|p|g|m|d|v|s])-([0-9]*)-([\\w-]*)\\.aspx(?:\\?(.*))?",RegexOptions.IgnoreCase);
if (m.Success)
{
entity = m.Groups[1].ToString().ToLower();
id = m.Groups[2].ToString();
switch (entity)
{
case "c": AppLogic.SetCookie("lastviewedcategoryid", id, new TimeSpan(30, 0, 0, 0, 0)); break;
case "p": AppLogic.SetCookie("lastviewedproductid", id, new TimeSpan(30, 0, 0, 0, 0)); break;
case "g": AppLogic.SetCookie("lastviewedgenreid", id, new TimeSpan(30, 0, 0, 0, 0)); break;
case "m": AppLogic.SetCookie("lastviewedmanufacturerid", id, new TimeSpan(30, 0, 0, 0, 0)); break;
case "d": AppLogic.SetCookie("lastvieweddistributorid", id, new TimeSpan(30, 0, 0, 0, 0)); break;
case "v": AppLogic.SetCookie("lastviewedvectorid", id, new TimeSpan(30, 0, 0, 0, 0)); break;
case "s": AppLogic.SetCookie("lastviewedsectionid", id, new TimeSpan(30, 0, 0, 0, 0)); break;
}
}
return id;
}
#endregion
}
2. Edit your web.config to register this new XsltExtension so that the 'Extensions' section looks like this:
Code:
<extensions>
<clear />
<add name="receipt" namespace="urn:receipt" type="ReceiptXsltExtension, app_code"></add>
<add name="custom" namespace="urn:custom" type="CustomXsltExtension, app_code"></add>
</extensions>
3. Now, in your rev.categories (or any other XMLPackage that needs to get the Current or last viewed category ID):
Edit the <xsl:stylesheet> section to look something like this:
Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:custom="urn:custom" xmlns:aspdnsf="urn:aspdnsf" exclude-result-prefixes="aspdnsf custom">
And change the category parameter code block to something like this (extend it for other page types):
Code:
<xsl:param name="CategoryID">
<xsl:choose>
<xsl:when test="custom:getEntityName(/root/System/PageName) = 'category' and custom:getEntityID(/root/System/PageName) != 0">
<xsl:value-of select="custom:getEntityID(/root/System/PageName)"/>
</xsl:when>
<xsl:when test="custom:getEntityName(/root/System/PageName) = 'product' and boolean(/root/Cookies/lastviewedcategoryid)">
<xsl:value-of select="/root/Cookies/lastviewedcategoryid"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:param>
It's difficult 'talking code' on the forum but hopefully this all works - let me know if not.
Adam