Improve Interspire Shopping Cart Search with Smart Redirections

This article is about the Interspire Shopping Cart. Don't use it? Check it out!
Go to Interspire.com and Learn More

Good search results are magical

I am always impressed when a website’s search goes where I want and finds what I expect it to. When trying to find a specific product by SKU in Interspire, you will be presented with a search result that shows the product you’re looking for first. But this is not good enough, as it adds an extra click in the process.

If your users are specific enough to type in an exact product name, brand name, product SKU or product ID, you better get them to the product they want, right away — they’re likely to buy! I don’t want to show them a search results page, I want them to see the product or brand page itself.

If it’s a damn good match, send’em along!

This script will redirect users if there’s a good reason to.

  • Products
    • Exact product name match (case-insensitive)
    • Exact product SKU match
    • Exact product ID match
    • “Good’nuf” product match: if there’s only one product result, and that result has a relevance score of 75 or above
  • Brands
    • Exact brand name match (case-insensitive)

Installation of the Smart Search Redirection mod

Open the class.products.php, found at includes/classes/class.products.php. Find the searchForItems() function (near line 1160), and above return $products; at the end of the function, insert the following code:

/*
 * Begin Smart Search Redirection mod
 */
$redirect = false;
 
// Product redirect
foreach($products as $row) {
	if(	trim(strtolower($searchQuery['search_query'])) == trim(strtolower($row['prodcode'])) ||  // Query = SKU
		trim(strtolower($searchQuery['search_query'])) == trim(strtolower($row['productid'])) || // Query = Product ID
		trim(strtolower($searchQuery['search_query'])) == trim(strtolower($row['prodname'])) || // Query = Product Name
		$row['score'] > 75 && sizeof($products) == 1 // Relevance is good, and there's only one product result
	) {
		$redirect = ProdLink($row["prodname"]);
	}
}
 
if(empty($redirect)) {
	// Generate list of brand names
	foreach($products as $p) { $brands[] = $p['prodbrandid']; }
	$brandQuery = '"'.implode('" OR brandid="', array_unique($brands)).'"'; // Group brands by ID, generate query string
	$query = sprintf("select brandname from [|PREFIX|]brands where brandid=$brandQuery", $p['prodbrandid']);
	$result = $GLOBALS['ISC_CLASS_DB']->Query($query);
 
	// Brand name match redirect
	while($brand = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
		if(trim(strtolower($searchQuery['search_query'])) == trim(strtolower($brand['brandname'])) && $redirect === false) {
			$redirect = BrandLink($brand["brandname"]);
		}
	}
}
 
// If there's a redirection found, do it up!
if(!empty($redirect)) {
	ob_end_clean();
	header("Location: $redirect");
	die();
}
/*
 * End Smart Search Redirection mod
 */

Ahh, nothing like better search!

Now that your search is taking users where they want to go, your user satisfaction should go up, and hopefully your sales and conversion rate!

Let me know if you have improvements to this code, and what your experience has been with it.

Author: Zack Katz

Zack Katz is the creator of GravityView and the President of Katz Web Services. He lives in Denver with his wife and cute beast of a cat.

6 thoughts on “Improve Interspire Shopping Cart Search with Smart Redirections”

      1. This is a nice attempt, but does not work unfortunately.

        Fatal error: Call to undefined function CalculateProductPrice() in /home/username/public_html/includes/classes/class.product.php on line 1348

  1. hello dear,
    would you like to solve my problem.
    when i click on search button then nothing display on new page, however if i insert product words then ajax search option shows correct.
    what the reason may be there?
    web address is shirtmate.com

Leave a Reply

Your email address will not be published. Required fields are marked *