- Posts: 10
- Thank you received: 0
Getting all Products in a Category
11 years 8 months ago #185615
by philipp
Getting all Products in a Category was created by philipp
-- HikaShop version -- : latest
-- Joomla version -- : latest
-- PHP version -- : latest
-- Browser(s) name and version -- : ff latest
Hello Everybody,
Given a category ID, how can I get all the products in it?
I have tried this:
None of the methods returns the list of products or their ids…
How can I do that?
-- Joomla version -- : latest
-- PHP version -- : latest
-- Browser(s) name and version -- : ff latest
Hello Everybody,
Given a category ID, how can I get all the products in it?
I have tried this:
Code:
$category = hikashop_get('class.category');
//1.
$category->get(<cid>);
//2.
$category->getProductsIn(<cid>, array(<product>));
//3.
$category->getChildren(…)
None of the methods returns the list of products or their ids…
How can I do that?
Please Log in or Create an account to join the conversation.
11 years 8 months ago #185634
by nicolas
Replied by nicolas on topic Getting all Products in a Category
Hi,
There is no function to do that.
The best is to write a MySQL query and load the data yourself from the tables hikashop_product_category and hikashop_product.
Otherwise, you can use that code:
But I don't recommend that as it first loads all the data of all the products in the getProducts() function (which is used for products exports) before loading the products based on the category id and these products list.
There is no function to do that.
The best is to write a MySQL query and load the data yourself from the tables hikashop_product_category and hikashop_product.
Otherwise, you can use that code:
Code:
$productClass = hikashop_get('class.product');
$productClass->getProducts();
$categoryClass = hikashop_get('class.category');
$products_in_the_category = $category->getProductsIn($category_id, $productClass->products);
Please Log in or Create an account to join the conversation.
Time to create page: 0.144 seconds