How to check if a product is in a certain category

  • Posts: 151
  • Thank you received: 9
11 years 5 months ago #102866

Hi,

I have a category called 'New'.

I have customized the file listing_table.php and I want to automatically display a 'New' icon near the product title.

So when I have a new product, I put them in the final category AND in the 'New' category. This should diplay the 'new' icon.
When I remove the 'New' category from the product, the icon should not be displayed anymore.

Does anyone have a code snippet for me that I can use in listing_table.php to see if the product is in the 'New' category?

Thank you!

Kind regards,
Maurice

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

  • Posts: 82760
  • Thank you received: 13346
  • MODERATOR
11 years 5 months ago #102923

Hi,

Why not simply use the badge system to add your new icon as a badge which would display on the image of all the products from that category ?

Anyway, you can use that code to get all the categories of the current product:
$productClass = hikashop_get('class.product');
$loadedCategories = $productClass->getCategories($row->product_id);

And then to see if the product is in the new category (id 18) :
foreach($loadedCategories as $cat){
if($cat == 18) echo "it's a new product";
}

The following user(s) said Thank You: Maurice

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

  • Posts: 151
  • Thank you received: 9
11 years 5 months ago #102983

I could use that indeed, however I also have a tab on our front page that shows the content of the New group and I am doing a little bit more than only showing the icon. For the readability of this topic I just asked what was really needed. And voilá it works like a charm.

Thank you Nicolas!

Last edit: 11 years 5 months ago by Maurice.

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

Time to create page: 0.054 seconds
Powered by Kunena Forum