wp-e-commerce subcategories

Recently I was working on a project, which have subcategory under there main category, the client wanted to view only the subcategories related to the main category, not any product, when a main category is clicked. the get-shop e-commerce was not working that way. It show all the category and subcategory on the same page. After doing some google i came to know that the issue is being reported and accepted by getshopped team. We have to cross our finger till it come, but u know client they will not wait… so checked further more and found a code that worked perfect on 1st run. But on the next day client inform me that the subcategory page is broken. 🙁

After tore my 259 hair, I found that it was the $catlink(code from forum) which creating the problem. The $catlink was using the category title name as term to get the subcat link. Fortunate or unfortunately my client had put (‘s) on the category name and the bad things  happened.

Now to overcome the problem, i used the wpsc-product term slug to get the subcategories link, and it worked awesome. 🙂

$category_id = wpsc_category_id();
$getsubs = "SELECT term_id FROM wp_term_taxonomy WHERE taxonomy = 'wpsc_product_category' AND parent = '".$category_id."' ORDER BY term_id ASC limit 15";
$subcats = mysql_query($getsubs); //this gets the ids of the subcategories
$num_subcats = mysql_num_rows($subcats); //this is a count of how many subcategories the current category has
while ($row = mysql_fetch_row($subcats)) {
if ($num_subcats > 0){
foreach ($row as $subcat) //this loops through the subcategories of the current category
$catname = wpsc_category_name($subcat); //just assigning variables here to call the category name, image and url
$catimage = wpsc_category_image($subcat);
$catdesc = wpsc_category_description($subcat);
$getsubslug= "SELECT slug FROM wp_terms WHERE term_id = '".$subcat."' limit 1";// query wp terms * rc
$xsubslug = mysql_query($getsubslug);
$subslugs = mysql_fetch_row($xsubslug);
foreach ($subslugs as $subslug)
$subcatlink = get_term_link($subslug,'wpsc_product_category');// here what I chaged $catlink to $subslug * rc
//$catlink = get_term_link($catname,'wpsc_product_category');
if ($category_id == '0' || $category_id == '') {
// this code handles the main shop page
echo '

<div class="main_subcat">
<h3>'.$catname.'</h3>
</div>

';
} else {
//this code is for all other categories with subcategories
echo '

<div class="product_grid_item">
<h2 class="prodtitle">'.$catname.'</h2>
';?&gt;
<div class="item_image"></div>
<p class="wpsc_subcategory"></p>

</div>

&nbsp;

}
//echo '

';//our own sub cat display end
} if ($num_subcats == 0) { //If there are no subcategories, just display the products as usual

Replace line 61 of wpsc-grid_view.php where the product_grid_display div starts with the pastebin code and make sure to close the new if statement with a } at around line 155 right after the endwhile; that closes the product loop.

 

One thought on “wp-e-commerce subcategories”

  1. I wish I could use your code, but your “how to” lacks all the “How To” needed to use it.

Comments are closed.