[Skip to main content](#vessel-content)

#   Get the Category Menu in Product Listing view

##

- **[pipedream](/forum/user/22364-pipedream "View pipedream's Profile")**
- [![pipedream's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/22364-pipedream "View pipedream's Profile") Topic Author
- [ Offline](/forum/user/22364-pipedream)

Less More

- Posts: 8
- Thank you received: 1
-
-

13 years 4 months ago -  13 years 4 months ago [\#110163](#110163) by [pipedream](/forum/user/22364-pipedream "View pipedream's Profile")  *[Get the Category Menu in Product Listing view](/forum/4-how-to/83983-get-the-category-menu-in-product-listing-view#110163 "In a random product list, I need to now the menu item associated to the category of each product. The final goal is to always have the link of the product under the category link.  In more detail:  &#42; Each product belongs to a single category;  &#42; Every category has its own menu item, so that the URLs look just as: /category1, /category2,... /categoryN;  &#42; Every product should have an URL like: /category1/productA, /category1/productB,... /categoryN/productC; a) This works inside the category page because the Product Sef name is empty; b) This doesn't work if a product is accessed from the homepage where there is a module to present random products from all categories;  Since in the module it is only possible to configure an Itemid value, I fetched the Itemid of each product in the product/listing&#95;img&#95;desc.php view. So, I replaced this line:  with:  Is it possible to validate this solution and also tell if there is another way of getting the category&#95;id of the product in this view (without a database query)?")* was created by *[pipedream](/forum/user/22364-pipedream "View pipedream's Profile")*

In a random product list, I need to now the menu item associated to the category of each product.
The final goal is to always have the link of the product under the category link.

In more detail:

1. Each product belongs to a single category;
2. Every category has its own menu item, so that the URLs look just as: **/category1**, **/category2**,... **/categoryN**;
3. Every product should have an URL like: **/category1/productA**, **/category1/productB**,... **/categoryN/productC**;
a) This works inside the category page because the Product Sef name is empty;
b) This doesn't work if a product is accessed from the homepage where there is a module to present random products from **all** categories;

Since in the module it is only possible to configure an Itemid value, I fetched the Itemid of each product in the **product/listing\_img\_desc.php** view. So, I replaced this line:

Code:

$link = hikashop_completeLink('product&amp;task=show&amp;cid='.$this-&gt;row-&gt;product_id.'&amp;name='.$this-&gt;row-&gt;alias.$this-&gt;itemid.$this-&gt;category_pathway);

with:

Code:

$database = JFactory::getDBO(); $menuClass = hikashop_get('class.menus'); $query = "SELECT category_id FROM ".hikashop_table('product_category').' WHERE product_id='.$this-&gt;row-&gt;product_id.' ORDER BY product_category_id ASC'; $database-&gt;setQuery($query); $categories_id = $database-&gt;loadColumn(); $itemid = "&amp;Itemid=".$menuClass-&gt;getItemidFromCategory($categories_id[0]); $link = hikashop_completeLink('product&amp;task=show&amp;cid='.$this-&gt;row-&gt;product_id.'&amp;name='.$this-&gt;row-&gt;alias.$itemid.$this-&gt;category_pathway);

Is it possible to validate this solution and also tell if there is another way of getting the category_id of the product in this view (without a database query)?

Last edit: 13 years 4 months ago by [pipedream](/forum/user/22364-pipedream "View pipedream's Profile"). Reason: text correction

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzgzOTgzLWdldC10aGUtY2F0ZWdvcnktbWVudS1pbi1wcm9kdWN0LWxpc3Rpbmctdmlldz90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[Eliot](/forum/user/1824-eliot "View Eliot's Profile")**
- [![Eliot's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar1824.png)](/forum/user/1824-eliot "View Eliot's Profile")
- [ Offline](/forum/user/1824-eliot)

Less More

- Posts: 2334
- Thank you received: 403
-
-

13 years 4 months ago [\#110223](#110223) by [Eliot](/forum/user/1824-eliot "View Eliot's Profile")  Replied by *[Eliot](/forum/user/1824-eliot "View Eliot's Profile")* on topic *[Get the Category Menu in Product Listing view](/forum/4-how-to/83983-get-the-category-menu-in-product-listing-view#110223 "In a random product list, I need to now the menu item associated to the category of each product. The final goal is to always have the link of the product under the category link.  In more detail:  &#42; Each product belongs to a single category;  &#42; Every category has its own menu item, so that the URLs look just as: /category1, /category2,... /categoryN;  &#42; Every product should have an URL like: /category1/productA, /category1/productB,... /categoryN/productC; a) This works inside the category page because the Product Sef name is empty; b) This doesn't work if a product is accessed from the homepage where there is a module to present random products from all categories;  Since in the module it is only possible to configure an Itemid value, I fetched the Itemid of each product in the product/listing&#95;img&#95;desc.php view. So, I replaced this line:  with:  Is it possible to validate this solution and also tell if there is another way of getting the category&#95;id of the product in this view (without a database query)?")*

Hi there,

Your method should work but you can also try with this, which seems to be an easier way: Code:

$link = hikashop_completeLink('product&amp;task=show&amp;cid='.$this-&gt;row-&gt;product_id.'&amp;name='.$this-&gt;row-&gt;alias.$this-&gt;element-&gt;category_id.$this-&gt;category_pathway);

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzgzOTgzLWdldC10aGUtY2F0ZWdvcnktbWVudS1pbi1wcm9kdWN0LWxpc3Rpbmctdmlldz90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[pipedream](/forum/user/22364-pipedream "View pipedream's Profile")**
- [![pipedream's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/22364-pipedream "View pipedream's Profile") Topic Author
- [ Offline](/forum/user/22364-pipedream)

Less More

- Posts: 8
- Thank you received: 1
-
-

13 years 4 months ago -  13 years 4 months ago [\#110263](#110263) by [pipedream](/forum/user/22364-pipedream "View pipedream's Profile")  Replied by *[pipedream](/forum/user/22364-pipedream "View pipedream's Profile")* on topic *[Get the Category Menu in Product Listing view](/forum/4-how-to/83983-get-the-category-menu-in-product-listing-view#110263 "In a random product list, I need to now the menu item associated to the category of each product. The final goal is to always have the link of the product under the category link.  In more detail:  &#42; Each product belongs to a single category;  &#42; Every category has its own menu item, so that the URLs look just as: /category1, /category2,... /categoryN;  &#42; Every product should have an URL like: /category1/productA, /category1/productB,... /categoryN/productC; a) This works inside the category page because the Product Sef name is empty; b) This doesn't work if a product is accessed from the homepage where there is a module to present random products from all categories;  Since in the module it is only possible to configure an Itemid value, I fetched the Itemid of each product in the product/listing&#95;img&#95;desc.php view. So, I replaced this line:  with:  Is it possible to validate this solution and also tell if there is another way of getting the category&#95;id of the product in this view (without a database query)?")*

Hi Eliot,

**$this-&gt;element-&gt;category\_id** returns only the parent category.

I have the module configured to return all the sub-categories under this parent category.

Also, if I don't find and insert the correct **Itemid** in the **hikashop\_completeLink** function, the link returned has the format:

**/component/hikashop/productAcategoryId**
Ex.: /component/hikashop/33-product12

instead of the wanted:

**/categoryName/33-product**

Last edit: 13 years 4 months ago by [pipedream](/forum/user/22364-pipedream "View pipedream's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzgzOTgzLWdldC10aGUtY2F0ZWdvcnktbWVudS1pbi1wcm9kdWN0LWxpc3Rpbmctdmlldz90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[Eliot](/forum/user/1824-eliot "View Eliot's Profile")**
- [![Eliot's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar1824.png)](/forum/user/1824-eliot "View Eliot's Profile")
- [ Offline](/forum/user/1824-eliot)

Less More

- Posts: 2334
- Thank you received: 403
-
-

13 years 4 months ago [\#110267](#110267) by [Eliot](/forum/user/1824-eliot "View Eliot's Profile")  Replied by *[Eliot](/forum/user/1824-eliot "View Eliot's Profile")* on topic *[Get the Category Menu in Product Listing view](/forum/4-how-to/83983-get-the-category-menu-in-product-listing-view#110267 "In a random product list, I need to now the menu item associated to the category of each product. The final goal is to always have the link of the product under the category link.  In more detail:  &#42; Each product belongs to a single category;  &#42; Every category has its own menu item, so that the URLs look just as: /category1, /category2,... /categoryN;  &#42; Every product should have an URL like: /category1/productA, /category1/productB,... /categoryN/productC; a) This works inside the category page because the Product Sef name is empty; b) This doesn't work if a product is accessed from the homepage where there is a module to present random products from all categories;  Since in the module it is only possible to configure an Itemid value, I fetched the Itemid of each product in the product/listing&#95;img&#95;desc.php view. So, I replaced this line:  with:  Is it possible to validate this solution and also tell if there is another way of getting the category&#95;id of the product in this view (without a database query)?")*

My bad, I didn't understand the first time.
In this case your solution looks good.
You could make it cleaner by loading the categories for each product in the view.html.php so you object $this-&gt;row would already have the categories but it's not especially easy.

The following user(s) said Thank You: [pipedream](/forum/user/22364-pipedream "View pipedream's Profile")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzgzOTgzLWdldC10aGUtY2F0ZWdvcnktbWVudS1pbi1wcm9kdWN0LWxpc3Rpbmctdmlldz90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[pipedream](/forum/user/22364-pipedream "View pipedream's Profile")**
- [![pipedream's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/22364-pipedream "View pipedream's Profile") Topic Author
- [ Offline](/forum/user/22364-pipedream)

Less More

- Posts: 8
- Thank you received: 1
-
-

13 years 4 months ago [\#110268](#110268) by [pipedream](/forum/user/22364-pipedream "View pipedream's Profile")  Replied by *[pipedream](/forum/user/22364-pipedream "View pipedream's Profile")* on topic *[Get the Category Menu in Product Listing view](/forum/4-how-to/83983-get-the-category-menu-in-product-listing-view#110268 "In a random product list, I need to now the menu item associated to the category of each product. The final goal is to always have the link of the product under the category link.  In more detail:  &#42; Each product belongs to a single category;  &#42; Every category has its own menu item, so that the URLs look just as: /category1, /category2,... /categoryN;  &#42; Every product should have an URL like: /category1/productA, /category1/productB,... /categoryN/productC; a) This works inside the category page because the Product Sef name is empty; b) This doesn't work if a product is accessed from the homepage where there is a module to present random products from all categories;  Since in the module it is only possible to configure an Itemid value, I fetched the Itemid of each product in the product/listing&#95;img&#95;desc.php view. So, I replaced this line:  with:  Is it possible to validate this solution and also tell if there is another way of getting the category&#95;id of the product in this view (without a database query)?")*

Merci, Eliot!

Yes, I looked at view.html.php to copy the database query.
Even is less prettier, I prefer to have the code in the template, so that it can be easier to upgrade HikaShop. ![:)](/media/kunena/emoticons/3.png ":)")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzgzOTgzLWdldC10aGUtY2F0ZWdvcnktbWVudS1pbi1wcm9kdWN0LWxpc3Rpbmctdmlldz90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.072 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)

[](#top)
