Skip to main content

How to get all products from category (PHP)

More
4 years 1 month ago #344078 by dyvel
-- HikaShop version -- : 4.6.1
-- Joomla version -- : 4.x
-- PHP version -- : 8.0

I'm working on an integration to YOOtheme Pro. Currently on the category with products listing.
I wonder if a function exists to get all products of a given category, like how we can get a product with:
Code:
$productClass = hikashop_get('class.product'); $product = $productClass->getProduct($id);

Or do I need to get them manually using a mysql query?

Thanks

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

More
4 years 1 month ago #344079 by dyvel
I could do something like this:
Code:
$db = JFactory::getDbo(); $sql = 'SELECT product_id FROM #__hikashop_product_category WHERE category_id = '.$params->category.''; $db->setQuery($sql); $product_ids = $db->loadColumn(); $productClass = hikashop_get('class.product'); foreach ($product_ids as $product_id) { $products[] = $productClass->getProduct($product_id); }

But is this the best way?

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

More
4 years 1 month ago #344080 by nicolas
Hi,

There is no function for that.
You have the function getProductsIn in class.category which is quite close to what you need. But you would need to remove the $products parameter and the code using it. I think this function is a good base even if you just want to get the MySQL query.
The following user(s) said Thank You: dyvel

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

Time to create page: 0.157 seconds
Powered by Kunena Forum