Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

Product Details: Display all associated Categories Rate Topic   - - - - -

 
  • xkevin
  • Junior Member
  • Members
  • Join Date: 02-Jul 07
  • 24 posts

Posted 28 July 2007 - 07:05 PM #1


{php}

$smarty_product_id = $this->get_template_vars( 'product' );
$product_id = $smarty_product_id['product_id'];

$select_1 = mysql_query( "SELECT * FROM cscart_products_categories WHERE product_id=$product_id");
while ($row_1 = mysql_fetch_array($select_1)) {
$category_id = $row_1["category_id"];

$select_2 = mysql_query( "SELECT * FROM cscart_categories WHERE category_id=$category_id");
while ($row_2 = mysql_fetch_array($select_2)) {

$id_path = $row_2["id_path"];
$id_path_boom = explode("/", $id_path);

foreach($id_path_boom as $category_id_2){

$select_3 = mysql_query( "SELECT * FROM cscart_category_descriptions WHERE category_id=$category_id_2");
while ($row_3 = mysql_fetch_array($select_3)) {

echo $row_3["category"];

}

echo " ";
}

echo "<br>";
}

}

{/php}



If you copy the above to "product_details.tpl" it will display all categories associated with your product. The coding is somewhat crude but its all I knew how to do as this Smarty stuff is new ground for me. You may have to modify the queries depending on your installation. I'm not sure if all the queries will slow anything down, so YMMV.

If anyone wants to clean it up and maybe Smarty-ize it, be my guest. I'm strill trying to figure out how to get just the first three levels to display instead of all of them.

 

Posted 29 July 2007 - 01:25 PM #2

Appreciated mate ;D
I've moved on from CS-Cart to WooC******** - If you need anything I can be of little help.

 
  • xkevin
  • Junior Member
  • Members
  • Join Date: 02-Jul 07
  • 24 posts

Posted 31 July 2007 - 06:26 PM #3


{php}

$smarty_product_id = $this->get_template_vars( 'product' );
$product_id = $smarty_product_id['product_id'];

$select_1 = mysql_query( "SELECT * FROM cscart_products_categories WHERE product_id=$product_id");
while ($row_1 = mysql_fetch_array($select_1)) {
$category_id = $row_1["category_id"];

$select_2 = mysql_query( "SELECT * FROM cscart_categories WHERE category_id=$category_id");
while ($row_2 = mysql_fetch_array($select_2)) {

$h = "0";
$id_path = $row_2["id_path"];
$id_path_boom = explode("/", $id_path);

foreach($id_path_boom as $category_id_2){

$select_3 = mysql_query( "SELECT * FROM cscart_category_descriptions WHERE category_id=$category_id_2");
while ($row_3 = mysql_fetch_array($select_3) and $h < "3") {

echo $row_3["category"];
$h ++;

}

echo " ";
}

echo "<br>";
}

}

{/php}


Added the counter to trap only the first 3 occurrences. Since my store is automotive related, I have the categories set up Manufacturer - Model - Year, so only the first 3 are needed. You can change the number if needed.

 

Posted 24 February 2010 - 06:17 AM #4

hi guys
can you please help me modify the above code to display the link and images for these secondary categories as well?

ill greatly appreciate your help