Display product category hierarchy on product page

  • Posts: 18
  • Thank you received: 0
  • Hikashop Business
3 years 5 months ago #325253

-- HikaShop version -- : 4.3.0
-- Joomla version -- : 3.9.22

Hi Team,

Could you please help me in the below problem?

I am trying to display the product category including the category hierarchy on the product page.

Is this possible? If so can anyone point me in the right direction to get this working?


Many Thanks

Please Log in or Create an account to join the conversation.

  • Posts: 81539
  • Thank you received: 13069
  • MODERATOR
3 years 5 months ago #325256

Hi,

How about using the "breadcrumb" module of Joomla ? It will automatically display the path to the product page and so based on how you configured your menu items, the categories and if you have the "simplified breadcrumb" setting turned off in the HikaShop configuration, that module should do what you want.

Please Log in or Create an account to join the conversation.

  • Posts: 18
  • Thank you received: 0
  • Hikashop Business
3 years 5 months ago #325720

Hi Nicolas,

I don't believe this would work as we have products which sit in multiple categories. I am looking to list all product categories including hierarchy which a product is in within the product page.

Any idea on how this could be achieved?


Many Thanks,

Luke

Please Log in or Create an account to join the conversation.

  • Posts: 81539
  • Thank you received: 13069
  • MODERATOR
3 years 5 months ago #325725

Hi,

In that case, the breadcrumb module won't help you since it will only display the hierarchy of the categories for the category from which you accessed the product page, and not the hierarchy of all the categories the product is linked to.
So the solution would be to edit one of the view files of the product view via the menu Display>Views and add custom code there to display that yourself (or ask a developer to do that for you if you're not one yourself).
You can find which view file to edit using the "Display view files" setting of the HikaShop configuration:
www.hikashop.com/support/documentation/1...-display.html#layout
You'll find the categories of the product in $this->categories in these view files. So then, you'll have to loop on that array and call the getParents function to get the hierarchy of each category:

$categoryClass = hikashop_get('class.category');
foreach($this->categories as $c) {
 echo '<br/>';
 $hierarchy = $categoryClass->getParents($c->category_id);
 foreach($hierarchy as $category) {
  echo ' / '.$category->category_name;
 }
}

Please Log in or Create an account to join the conversation.

  • Posts: 18
  • Thank you received: 0
  • Hikashop Business
3 years 5 months ago #326233

Hi Nicolas.

Thanks for this.

I have tried to add this in as below to the img_desc.php file via the editor as you can see.




The aim was to put this info above the product description on the product pages.

Any ideas on why this is not working and how to fix it? I am far from a developer so any help would be appreciated.


Many Thanks,

Luke

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 81539
  • Thank you received: 13069
  • MODERATOR
3 years 5 months ago #326270

Hi,

The listing_desc.php file is used on the products listing page, not on the product details page.
First $this->categories is not available there, and second if you change the product details page or if you didn't select the layout using that view file on your products listing settings, you won't see any change.
To check which view file to modify, you can use the "Display view files" setting of the HikaShop configuration, as I explained in my previous message.
If you do and check the product details page, you should see that it uses product / show.php and then product / show_default.php or product / show_tabular.php and several show_block_*.php view files. So that in one of these that you'll want to add that code.

Please Log in or Create an account to join the conversation.

Time to create page: 0.061 seconds
Powered by Kunena Forum