WP E-Commerce Fix for Unique Product URLs

/ Published in: PHP
Save to your folder(s)

This snippet of code added to line 1404 of wpsc_query.php finds a single product by the product url AND category its in. The default is to only look up a product by its url only, not including the category, meaning you can't have a product in more than one category with the same name.

Copy this code and paste it in your HTML
  1. // ATD 22.DeireadhFomhair.2010 - find a unique product if it has the same product url as something else
  2. $page_url = $_SERVER['REQUEST_URI'];
  3. $product_url = $this->query_vars['product_url_name'];
  4. $products_url = get_option('product_list_url');
  5. $siteurl = get_option('siteurl');
  6. $products_url = str_replace($siteurl, "", $products_url);
  7. $products_url = str_replace('/', '\/', $products_url);
  8. if (preg_match("/$products_url\/(.*)\/$product_url/", $page_url, $matches)) {
  9. $category_url = $matches[1];
  10. $product_id = $wpdb->get_var("SELECT pm.`product_id` FROM `".WPSC_TABLE_PRODUCTMETA."` pm, `".WPSC_TABLE_PRODUCT_CATEGORIES."` pc, `".WPSC_TABLE_ITEM_CATEGORY_ASSOC."` ca WHERE `meta_key` IN ( 'url_name' ) AND `meta_value` IN ( '".stripslashes($this->query_vars['product_url_name'])."' ) AND pc.id = ca.category_id AND pm.product_id = ca.product_id AND pc.`nice-name` = '".stripslashes($category_url)."'");
  11. }

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.