Author Topic: Product details page - show all categories a product is assigned to  (Read 13195 times)

AndyNZL

  • Beginner
  • *
  • Posts: 32
    • IPO Digital Design
1: administrator\components\com_virtuemart\classes\ps_product.php
Add a new function to the bottom of the page (inside the last curly bracket)

Code: [Select]
  /** custom method
   * ps_product::get_product_categories()
   *
   * @param mixed $product_id
   * @return array - array of categories e.g. array(0=>array('id'=>234,'name'=>'bla','href'=>'xyz'),1=>array...);
   */
    function get_product_categories($product_id){
    $db = new ps_DB;

$q = " SELECT cx.category_id, c.category_name 
FROM #__{vm}_category c, #__{vm}_product_category_xref cx
WHERE cx.product_id = '".$product_id."'
AND c.category_id=cx.category_id";

$db->query($q);
if($db->num_rows() == 0){
return false;
}

$c = array();
while($db->next_record()) {
$url = $_SERVER['PHP_SELF']."?page=shop.browse&category_id=".$db->f('category_id')."&option=com_virtuemart";
$c[] = array('id'=>$db->f('category_id'),'name'=>$db->f('category_name'),'href'=>$url);
}

return $c;
    }

2: administrator\components\com_virtuemart\html\ shop.product_details.php
Set the variable to make it available to lower templates (around line 202)

Code: [Select]
$tpl->set( 'products_categories', $ps_product->get_product_categories($product_id)); // Added by Gregor
3: On your chosen flypage

Code: [Select]
<ul>
<?php  foreach($products_categories AS $k => $cate){ ?>
<li><a href="<?php echo $cate['href'?>"><?php echo $cate['name'?></a></li>
<?php  // endforeach; ?>
</ul>

Hope this all helps someone :-)

zeevee

  • Beginner
  • *
  • Posts: 25
    • Euphoric Graphics
Re: Product details page - show all categories a product is assigned to
« Reply #1 on: November 10, 2008, 17:35:28 pm »
Awesome, that's what I have been looking for. Can you please also tell me how to implement this on shop.browse page (in my case browse2? I placed the code for flypage above into shop.browse page but it didn't work :-(

Thanks.

zeevee

  • Beginner
  • *
  • Posts: 25
    • Euphoric Graphics
Re: Product details page - show all categories a product is assigned to
« Reply #2 on: November 10, 2008, 17:53:48 pm »
I implemented the browse page, but it does not work on search results, any help for me please.

darengr

  • Beginner
  • *
  • Posts: 44
Re: Product details page - show all categories a product is assigned to
« Reply #3 on: February 19, 2009, 14:23:36 pm »
@AndyNZL:  ;)  8)
Many thanks for this addition, I implemented it and it works beautifully! I would like to ask you a small addition, if you could give me a hint.

I would like to modify also the Recently visited produvts, that show up under the prod flypage, to also use the above code with the multiple categories. (by default is shows only one of the categories...).
Can you give me some direction as to what files should I look into and what to include/amend?
Many thanks, and take care!
darenGR


lostmail

  • Jr. Member
  • **
  • Posts: 255
Re: Product details page - show all categories a product is assigned to
« Reply #5 on: October 03, 2009, 10:42:53 am »
I made all changes but i get an error message:

Quote
Fatal error: Call to undefined method ps_product::get_product_categories() in /var/www/web1/html/mysite/administrator/components/com_virtuemart/html/shop.product_details.php on line 202
Joomla 3.x + VM 3.6.x (for Testing without any additional Extensions)

lostmail

  • Jr. Member
  • **
  • Posts: 255
Re: Product details page - show all categories a product is assigned to
« Reply #6 on: October 03, 2009, 10:52:09 am »
OK - Solved - but I nee not only the last subcategory of assigned categories - I need the full path category:

Like this Product which is assigned to 3 different Categories:

Category => Subcategory => Subcategory
Category => Subcategory
Category => Subcategory

Currently the Listing shows only the last Category from the tree.

So I get as result :
Subcategory
Subcategory
Subcategory

As my Subcategories have all the same name it is not visible in which main category it belongs.

Any idea how i can get the full Category Path in the listing of the assigned categories of a prodct ?
Joomla 3.x + VM 3.6.x (for Testing without any additional Extensions)

buzi

  • Beginner
  • *
  • Posts: 35
    • Hubeza web design & Development
Re: Product details page - show all categories a product is assigned to
« Reply #7 on: October 19, 2009, 19:47:46 pm »
Thanks alot ! i was just looking for this, googled it and there it is.
wonderful !
Buzi

rgie

  • Beginner
  • *
  • Posts: 4
Re: Product details page - show all categories a product is assigned to
« Reply #8 on: October 22, 2009, 10:13:18 am »
Works like a charm... thanks a lot :D

anwell

  • Beginner
  • *
  • Posts: 5
Re: Product details page - show all categories a product is assigned to
« Reply #9 on: October 23, 2009, 11:52:52 am »
How do paging?

Chinese:
如何分页?如果类别太多的话

jellytool

  • Beginner
  • *
  • Posts: 5
Re: Product details page - show all categories a product is assigned to
« Reply #10 on: July 19, 2010, 11:32:56 am »
Thanks for posting this. This was exactly what I was looking for. Unfortunately, I can't get it to work.

When I put the line "$tpl->set( 'products_categories', $ps_product->get_product_categories($product_id));      // Added by Gregor" in line 202 of the shop.product_details, and refresh my product details page, I get a blank screen (presumably a parsing error).

Can somebody please tell me exactly where I am supposed to put this line of code.  I am using Virtuemart 1.1.4 with Joomla 1.5.10.

Many thanks

larbut

  • Beginner
  • *
  • Posts: 2
Re: Product details page - show all categories a product is assigned to
« Reply #11 on: July 30, 2010, 21:51:32 pm »
Like jellytool:
I can not get it to work either. Followed AndyNZL recepie, but get a blank page after editing the flypage.

I hope someone can help...

Thanks,
Lars

darengr

  • Beginner
  • *
  • Posts: 44
show all categories a product is assigned to WITH IMAGES
« Reply #12 on: December 08, 2010, 12:35:02 pm »
Small php code addition wanted:
Can somebody please add to the quoted code a piece of code to also display the category thumbnail or main image), before or after the category name?

Code: [Select]
<ul>
<?php foreach($products_categories AS $k => $cate){ ?>
<li><a href="<?php echo $cate['href'?>"><?php echo $cate['name'?></a></li>
<?php // endforeach; ?>
</ul>

maybe the array needs to also carry the category)id, and then with another function, to get the image from the category. Or, look it up, by category name, which exists already in the array above..
this shouldn't be difficult, but I do not know how to code it!
thanks for any help, I appreciate so much!
darengr

webs4travel

  • Beginner
  • *
  • Posts: 33
Re: Product details page - show all categories a product is assigned to
« Reply #13 on: December 15, 2011, 18:57:29 pm »
I could not get this to work initially (Virtuemart 1.1.6) but it was the positioning of the code in ps_products - I moved it to line 1702 (although I cannot guarantee I've not already altered the file) to get it to work :-)  I just need to work out how to add category thumbnails too!

webs4travel

  • Beginner
  • *
  • Posts: 33
Re: Product details page - show all categories a product is assigned to
« Reply #14 on: February 02, 2012, 16:09:28 pm »
Thanks for posting this. This was exactly what I was looking for. Unfortunately, I can't get it to work.

When I put the line "$tpl->set( 'products_categories', $ps_product->get_product_categories($product_id));      // Added by Gregor" in line 202 of the shop.product_details, and refresh my product details page, I get a blank screen (presumably a parsing error).

Can somebody please tell me exactly where I am supposed to put this line of code.  I am using Virtuemart 1.1.4 with Joomla 1.5.10.

Many thanks

I got this to work with Virtuemart 1.16 but have now upgraded to 1.1.9 and am also getting the same error and can't work out exactly which line to add code to :-(