- Posts: 88
- Thank you received: 20
How to get all products from category (PHP)
4 years 1 month ago #344078
by dyvel
How to get all products from category (PHP) was created 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:
Or do I need to get them manually using a mysql query?
Thanks
-- 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.
4 years 1 month ago #344079
by dyvel
Replied by dyvel on topic How to get all products from category (PHP)
I could do something like this:
But is this the best way?
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.
4 years 1 month ago #344080
by nicolas
Replied by nicolas on topic How to get all products from category (PHP)
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.
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.193 seconds