Important Notice from AspDotNetStorefront
It is with dismay that we report that we have been forced, through the action of hackers, to shut off write-access to this forum. We are keen to leave the wealth of material available to you for research. We have opened a new forum from which our community of users can seek help, support and advice from us and from each other. To post a new question to our community, please visit: http://forums.vortx.com
Results 1 to 5 of 5

Thread: If Single search result go to product page directly skip search results page

  1. #1
    Jeanne is offline Junior Member
    Join Date
    Feb 2009
    Posts
    3

    Default If Single search result go to product page directly skip search results page

    How can I alter the page.search.xml.config to go directly to the product page if only one search result. I have already written the logic to do something differently if there is only on search result verus many, but I cannot get it to do the redirect.

  2. #2
    esedirect is offline Senior Member
    Join Date
    Feb 2010
    Location
    Norfolk, UK
    Posts
    343

    Default

    You can test in the searchadv.aspx.cs page if an exact match is made for the SKU and then do the redirect there.

    Try our search. Type B10 into the search box and press the green search button, rather than choosing it from the drop-down list. If you press the green search button, it is actually going to the searchadv.aspx page and making an SKU match on B10 then re-directing to the product page.
    http://www.esedirect.co.uk
    --------------------------------------------------------------------------
    Using MS 9.2.0.0 with the following customisations:

    Lightbox/Fancybox enlarged images;
    Auto-suggest searchbox;
    Extra product information shown only to our IP Address (such as supplier info, costs, etc.);
    Failed transactions emailed via trigger;
    Custom app to show basket contents when customer online;
    Orders pushed through to accounting systems.

    All the above without source!

  3. #3
    chrismartz is offline Senior Member
    Join Date
    Apr 2010
    Posts
    339

    Default

    How did you do your redirect via the xml package? Javascript?

  4. #4
    esedirect is offline Senior Member
    Join Date
    Feb 2010
    Location
    Norfolk, UK
    Posts
    343

    Default

    No. As I said in the previous post we do the test and re-direct in searchadv.aspx.cs.

    Use the searchterm which is passed in as a querystring and immediately perfrom a database lookup using the searchterm as the SKUSuffix (or whatever works for you). If one record is returned then you have an exact match, and re-direct to the page.

    This is the code snippet we use to match and re-direct:

    Code:
    		private bool SearchSKU(string searchTerm)
    		{
    		
    			using (SqlConnection dbconn = new SqlConnection(DB.GetDBConn()))
    			{
    				dbconn.Open();
    							
    				string sql = "SELECT TOP 1";
    					  sql += "	[PV].[ProductID], ";
    					  sql += "	[PV].[VariantID], ";
    					  sql += "	[P].[SEName] ";
    					  sql += "FROM ";
    					  sql += "	[ProductVariant] AS [PV] ";
    					  sql += "INNER JOIN "; 
    					  sql += "	[Product] AS [P] ON [P].[ProductID] = [PV].[ProductID] ";
    					  sql += "WHERE ";											  
    					  sql += "	[PV].[SKUSuffix] = '"	+ searchTerm + "'";								  
    				using (IDataReader rs = DB.GetRS(sql, dbconn))
    				{
    					while (rs.Read())
    					{
    					
    						try
    						{
    							Response.Redirect("/p-" + DB.RSFieldInt(rs, "ProductID").ToString() + "-" + DB.RSField(rs, "SEName") + ".aspx?v=" + DB.RSFieldInt(rs, "VariantID").ToString());
    							Response.Clear();
    							
    							return true;
    						}
    						catch (Exception ex)
    						{
    							throw (ex);
    						}
    					}
    				}
    			}
    			
    			return false;
    
    		}
    http://www.esedirect.co.uk
    --------------------------------------------------------------------------
    Using MS 9.2.0.0 with the following customisations:

    Lightbox/Fancybox enlarged images;
    Auto-suggest searchbox;
    Extra product information shown only to our IP Address (such as supplier info, costs, etc.);
    Failed transactions emailed via trigger;
    Custom app to show basket contents when customer online;
    Orders pushed through to accounting systems.

    All the above without source!

  5. #5
    cjbarth is offline Senior Member
    Join Date
    Oct 2008
    Posts
    392

    Default

    I used a simpler approach:

    Code:
    <xsl:template match="/">
    	<xsl:param name="oneProductID">
    		<xsl:value-of select="/root/Products/Product[1]/ProductID/text()" />
    	</xsl:param>
    	<xsl:param name="oneSEName">
    		<xsl:value-of select="/root/Products/Product[1]/SEName/text()" />
    	</xsl:param>
    	<xsl:if test="count(/root/Products/Product)=1">
    		<script type="text/javascript" Language="JavaScript">
    			window.location.href = '<xsl:value-of select="aspdnsf:ProductLink($oneProductID, $oneSEName, 0)" />';
    		</script>
    	</xsl:if>
    ML9.3.1.1
    SQL 2012 Express
    VS 2010
    Azure VM