使用Prestashop 1.7检索类别中的产品数量

问题描述

我正在prestashop 1.7上做第一份工作 我目前正在尝试显示产品类别列表

   $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);
        }

到目前为止,它有效。 但是,我的问题是,我还将希望检索每个关联类别中的产品数量,以使用类别名称显示它们

解决方法

检查class / Category.php中的getProducts()函数

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
    )