简体   繁体   English

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

[英]retrieve the number of products in a category with Prestashop 1.7

I am doing a first job on prestashop 1.7 I am currently trying to display a list of product categories我正在 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);
        }

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但是,我的问题是我还想检索每个关联类别中的产品数量,以使用类别名称显示它们

Check function getProducts() in classes/Category.php检查 classes/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
    )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM