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

#   Prevent product from being displayed in categories it's not published in

##

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

Less More

- Posts: 88
- Thank you received: 20
-
-

7 years 11 months ago -  7 years 11 months ago [\#301380](#301380) by [dyvel](/forum/user/39996-dyvel "View dyvel's Profile")  *[Prevent product from being displayed in categories it's not published in](/forum/31-development/896408-prevent-product-from-being-displayed-in-categories-its-not-published-in#301380 "-- HikaShop version -- : 4.0.1  Hi  Hikashop allow a product to be displayed in all categories, even if the product is not published in more than one category. I would like to prevent this, so I'm looking to modify the product/show&#95;default.php file.  I can get an array of the categories, the product belong to with this code:  My problem is finding the category that I'm currently &quot;in&quot;. The best way I could come up with, is access the active menu items hikashop parameters, like this:  Can you see a better way to solve this ??  Thanks")* was created by *[dyvel](/forum/user/39996-dyvel "View dyvel's Profile")*

-- HikaShop version -- : 4.0.1

Hi

Hikashop allow a product to be displayed in all categories, even if the product is not published in more than one category.
I would like to prevent this, so I'm looking to modify the product/show_default.php file.

I can get an array of the categories, the product belong to with this code:
Code:

$productClass = hikashop_get('class.product'); $categories = $productClass-&gt;getCategories($this-&gt;element-&gt;product_id);

My problem is finding the category that I'm currently "in". The best way I could come up with, is access the active menu items hikashop parameters, like this:

Code:

// Using current menu item to find current hika category params $app = JFactory::getApplication(); $currentMenuItem = $app-&gt;getMenu()-&gt;getActive(); $params = $currentMenuItem-&gt;params; $currentCategory = $params-&gt;get('hk_category')-&gt;category; // Check if product is published in current hika category $productClass = hikashop_get('class.product'); // $displayProduct now contains a boolean value we can test with $displayProduct = array_key_exists($currentCategory, $this-&gt;categories);

Can you see a better way to solve this ??

Thanks

Last edit: 7 years 11 months ago by [dyvel](/forum/user/39996-dyvel "View dyvel's Profile").

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

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86541
- Thank you received: 14304
-
-

7 years 11 months ago -  7 years 11 months ago [\#301382](#301382) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Prevent product from being displayed in categories it's not published in](/forum/31-development/896408-prevent-product-from-being-displayed-in-categories-its-not-published-in#301382 "-- HikaShop version -- : 4.0.1  Hi  Hikashop allow a product to be displayed in all categories, even if the product is not published in more than one category. I would like to prevent this, so I'm looking to modify the product/show&#95;default.php file.  I can get an array of the categories, the product belong to with this code:  My problem is finding the category that I'm currently &quot;in&quot;. The best way I could come up with, is access the active menu items hikashop parameters, like this:  Can you see a better way to solve this ??  Thanks")*

Hi,

Another to do it could be to directly look at the URL and its parameters in $_SERVER
There you'll have the alias of the category somewhere and you should be able to extract it and then load the category id based on that alias with a MySQL query to the hikashop_category table.
But your solution is better as far as I can see.

Last edit: 7 years 11 months ago by [nicolas](/forum/user/63-nicolas "View nicolas's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50Lzg5NjQwOC1wcmV2ZW50LXByb2R1Y3QtZnJvbS1iZWluZy1kaXNwbGF5ZWQtaW4tY2F0ZWdvcmllcy1pdHMtbm90LXB1Ymxpc2hlZC1pbj90bXBsPW1hcmtkb3du) 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.040 seconds

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