Fixing Grid and List Views in WP e-Commerce Gold

Recently, one of my clients asked me to setup and configure an online store using WordPress and the plugin WP e-Commerce Gold by Instinct Entertainment. As a part of the design, I needed to implement the Grid View module to display the products in a nice layout. Unfortunately, whenever I tried to use the Grid View, I was confronted with this error:

Fatal error: Call to undefined function wpsc_product_url() in grid_display_functions.php on line 47

A quick search of all the files for this plugin revealed that function wpsc_product_url(){…} was nowhere to be found. Furthermore, searching on “undefined function wpsc_product_url()” revealed that others are having this problem too, and the admins on the forums at Instinct Entertainment don’t seem to be too helpful either. So, I had to come up with my own patch which I am happy to share with everyone else who has run into the same problem.

The Problem
The Grid View module currently available for purchase on the Instinct website requires the function wpsc_product_url() to generate links to each of the products featured in the grid view. The problem is that this function does not exist in the latest stable version of the plugin (3.5.1); however, it is found in the beta version (3.6 Beta 8).

The Solution
To get rid of the fatal error and get the grid view working, I took the wpsc_product_url() function from the file product_display_functions.php in WP e-Commerce 3.6 Beta 8, removed some 3.6 Beta 8 specific code and added the trimmed down function to the same file in WP e-Commerce 3.5.1.

And now, here’s the function we’ve all been waiting for ;) :

function wpsc_product_url($product_id, $category_id = null){
	global $wpdb;
	if(!stristr(get_option('product_list_url'), "?")) {
		$initial_seperator = "?";
	} else {
		$initial_seperator = "&";
	}
	if(is_numeric($category_id) && ($category_id > 0)) {
		$product_url = get_option('product_list_url').$initial_seperator."category=".$category_id."&product_id=".$product_id;
	} else {
		$product_url = get_option('product_list_url').$initial_seperator."product_id=".$product_id;
	}
	return $product_url;
}

To apply the patch, simply copy and paste the above function into product_display_functions.php in WP e-Commerce 3.5.1. This file should be located in the root folder of your WP e-Commerce plugin.

Conclusion
Finally, keep in mind, I am no expert on the WP e-Commerce plugin. I was in the same boat as everyone else until I started digging through the code of the stable and beta release versions. Therefore, I hope this post will be of service to others out there; however, beyond this patch, I probably don’t know any more about the plugin’s code than you do.