Reputation: 13
I am doing a first job on prestashop 1.7 I am currently trying to display a list of product categories
$root_category_id = Context::getContext()->shop->getCategory();
$category_tree = Category::getNestedCategories($root_category_id);
$category_array = [];
foreach ($category_tree[2]["children"] as $cat) {
array_push($category_array, $cat);
}
So far, it works. But, my problem is that I will also want to retrieve the number of products in each of the associated categories to display them with the name of the category
Upvotes: 0
Views: 940
Reputation: 397
Check function getProducts() in classes/Category.php
public function getProducts(
$idLang,
$p,
$n,
$orderyBy = null,
$orderWay = null,
$getTotal = false, // To return count of products, pass this parameter as true
$active = true,
$random = false,
$randomNumberProducts = 1,
$checkAccess = true,
Context $context = null
)
Upvotes: 0