SKU Search: Want to go to Detail Product Page
Printed From: ProductCart E-Commerce Solutions
Category: ProductCart
Forum Name: Customizing ProductCart
Forum Description: Exchange messages with other users that are customizing ProductCart.
URL: https://forum.productcart.com/forum_posts.asp?TID=4282
Printed Date: 14-July-2025 at 9:31am Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com
Topic: SKU Search: Want to go to Detail Product Page
Posted By: avalight
Subject: SKU Search: Want to go to Detail Product Page
Date Posted: 29-January-2011 at 12:52am
Hi Using information in another post, I have put this small search box code on my pages so that a SKU search can be performed. It works fine, except that the search results is the generic search results page, and I want it to go directly to the detailed product page. Is that possible? And if so, how or what do I change in the code to make it work. Thanks
<div id="pcStoreSearch" > <!-- Start Search Box --> <form action="/productcart/pc/showsearchresults.asp" name="search" method="get" class="pcForms"> <input type="hidden" name="pageStyle" value="<%=bType%>"> <SPAN style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; COLOR: rgb(0,161,0);">PRODUCT SEARCH:</span> <input type="hidden" name="resultCnt" value="10"> <input type="Text" name="SKU" size="14" value="Enter Product No." onclick="this.value=''"> <b><input type="image" name="submit" src=" view-source:http://www.avalanche-ranch.com/rusticlighting/PC/images/btn_go_gray.gif - /productcart/PC/images/btn_go_gray.gif " id="submit"></b> </form> <!-- End Search Box --></div>
|
-------------
Curt
|
Replies:
Posted By: Brett
Date Posted: 29-January-2011 at 8:46am
Hey avalight,
Paste this code into showsearchresults.asp around line 147, just before this section:
'//===========================
'// BRAND Information - Start
'//===========================
|
Paste this code:
'//===========================
'// SKU Jump - Start
'//===========================
intSkuJump=cint(request.querystring("skuJump"))
if intSkuJump<>0 then
query="SELECT idProduct, description FROM products WHERE sku='" & pSearchSKU & "';"
set rstemp=Server.CreateObject("ADODB.Recordset")
set rstemp=conntemp.execute(query)
if not rstemp.eof then
pIdProduct=rstemp("idProduct")
pDescription=rstemp("description")
%><!--#include file="pcSeoFirstCat.asp"--><%
 pcGenerateSeoLinks
response.redirect pcStrPrdLink
end if
set rstemp=nothing
end if
'//===========================
'// SKU Jump - End
'//===========================
|
Then, edit your search form to include this hidden field:
<input type="hidden" name="skuJump" value="1">
|
*edit*
The cool thing about this is that if they put a partial SKU in, it will still show the regular results page. For example if I have a product with SKU P112 and they search P11, it will show the results page, however P112 will direct them straight to the SEO link.
|
Posted By: Brett
Date Posted: 29-January-2011 at 8:51am
Is this a safe way to use this query string? Will converting it to an integer address any sql injection issues?
intSkuJump=cint(request.querystring("skuJump"))
|
|
Posted By: Greg Dinger
Date Posted: 29-January-2011 at 10:25am
go look at the getuserinput command in stringfunctions.asp
------------- GreyBeard Design Group
Certified ProductCart Developer
Web Design/Development/Hosting
http://tinyurl.com/5c8t4t" rel="nofollow - Add-Ons & Custom Code |
|
Posted By: Brett
Date Posted: 29-January-2011 at 10:40am
I knew about getuserinput. It's all over showsearchresults.asp. However, I believe it causes a tech error if there is no variable (for example, a checkbox that isn't checked doesn't send anything to the query string). Therefore, an if statement! I'm pretty sure this is unnecessary, but here's an updated version of the code block to put into showsearchresults.asp.
'//===========================
'// SKU Jump - Start
'//===========================
if request.querystring("skuJump") <> "" then
intSkuJump=cint(getUserInput(request.querystring("skuJump"),0))
else
intSkuJump=0
end if
if intSkuJump<>0 then
query="SELECT idProduct, description FROM products WHERE sku='" & pSearchSKU & "';"
set rstemp=Server.CreateObject("ADODB.Recordset")
set rstemp=conntemp.execute(query)
if not rstemp.eof then
pIdProduct=rstemp("idProduct")
pDescription=rstemp("description")
%><!--#include file="pcSeoFirstCat.asp"--><%
pcGenerateSeoLinks
response.redirect pcStrPrdLink
end if
set rstemp=nothing
end if
'//===========================
'// SKU Jump - End
'//===========================
|
|
Posted By: avalight
Date Posted: 29-January-2011 at 3:14pm
Hi Brett Before putting in this code, does it affect the behaviour of how any other searches work? Specifically, the custom search field search? From looking at this, it looks pretty specific to the SKU Search Box, but I wanted to make sure. Thanks curt
-------------
Curt
|
Posted By: Brett
Date Posted: 29-January-2011 at 5:32pm
hey, this shouldn't do anything unless the skuJump query variable has been defined. it won't be defined unless it is included on the form. I haven't tested it against the custom field search, but it doesn't interfere with the rest of the search functions.
it just checks to see if skuJump is not zero, and if true then it redirects straight from the category search.
i just tested it on my advanced search and everything appears to be working normally. i enabled it on our site because i thought it was a cool idea. you can see it here: http://www.liftchair.com/search.asp
You'll notice that if it isn't checked, everything works as normal. However, if it is checked, it has a couple different behaviors:
if you enter a complete sku, AND the checkbox is checked it jumps to that product's page (try P112)
if you enter a partial sku, it shows the search results like normal. if it doesn't match a complete sku, it just continues running the search as usual. (try P11)
if the checkbox is NOT checked, the sku box behaves how it originally did.
|
Posted By: Brett
Date Posted: 29-January-2011 at 5:36pm
Here's my showsearchresults.asp file. I don't know if it's been modified besides this change, so make sure you back up your old file first. uploads/1159/showsearchresults.zip - showsearchresults.zip
Like I said earlier, it won't work unless you make a form field called skuJump. I used a checkbox, but your original example called for a hidden field.
This is probably what you want your "SKU Search" form to look like:
<div id="pcStoreSearch" >
<!-- Start Search Box -->
<form action="/productcart/pc/showsearchresults.asp" name="search" method="get" class="pcForms">
<input type="hidden" name="pageStyle" value="<%=bType%>">
<SPAN style="FONT-WEIGHT: bold; FONT-SIZE: 11pt; COLOR: rgb(0,161,0);">PRODUCT SEARCH:</span>
<input type="hidden" name="resultCnt" value="10">
<input type="hidden" name="skuJump" value="1">
<input type="Text" name="SKU" size="14" value="Enter Product No." onclick="this.value=''">
<b><input type="image" name="submit" src="/productcart/PC/images/btn_go_gray.gif" id="submit"></b>
</form>
<!-- End Search Box --></div>
|
Here's the checkbox I added to my search.asp:
<input name="skuJump" type="checkbox" value="1">
|
|
Posted By: Brett
Date Posted: 03-February-2011 at 3:17pm
Hey Avalight, I made a couple updates to the showsearchresults.asp file. I simplified the first if statement and added another statement allowing me to use my regular search box for SKU jump, rather than needing a specific SKU search box: That way, people can use the search box as normal, but if they type a SKU in then it jumps to that page. Thought you might be interested.
'//===========================
'// SKU Jump - Start
'//===========================
intSkuJump=0
if request.querystring("skuJump") <> "" then
intSkuJump=cint(getUserInput(request.querystring("skuJump"),0))
end if
if intSkuJump<>0 then
skuSearchTerm = ""
if pSearchSKU <> "" then
skuSearchTerm = pSearchSKU
else
skuSearchTerm = pKeywords
end if
query="SELECT idProduct, description FROM products WHERE sku='" & skuSearchTerm & "';"
set rstemp=Server.CreateObject("ADODB.Recordset")
set rstemp=conntemp.execute(query)
if not rstemp.eof then
pIdProduct=rstemp("idProduct")
pDescription=rstemp("description")
%><!--#include file="pcSeoFirstCat.asp"--><%
pcGenerateSeoLinks
response.redirect pcStrPrdLink
end if
set rstemp=nothing
end if
'//===========================
'// SKU Jump - End
'//===========================
|
|
Posted By: avalight
Date Posted: 03-February-2011 at 3:24pm
Okay thanks. But the code in your Jan 29th post will work too, right? I want to just leave it as a sku search only.
-------------
Curt
|
Posted By: Brett
Date Posted: 03-February-2011 at 3:27pm
Yeah the code from before will of course work just as it has been. I just wanted to do what you did and add a sku search to all of my pages, but i didnt want to change my search box to a sku search or add a second box, so I coded that solution. The only other thing I changed was a slightly redundant if statement, which I reworded as:
intSkuJump=0
if request.querystring("skuJump") <> "" then
intSkuJump=cint(getUserInput(request.querystring("skuJump"),0))
end if
|
instead of what it used to be:
if request.querystring("skuJump") <> "" then
intSkuJump=cint(getUserInput(request.querystring("skuJump"),0))
else
intSkuJump=0
end if
|
Not a huge difference, but I was in the code and I saw the opportunity for a small optimization.
|
|