Opencart显示儿童类别列表中的总产品数量

时间:2013-09-24 01:54:36

标签: opencart

我正在使用opencart 1.5.4。

我想在此页面上的类别列表中显示子类别中有多少产品:

http://50.87.186.42/index.php?route=product/category&path=59_60

我尝试添加代码但看起来它已经在控制器中(类别/ controller / module / category.php)

以下是我正在查看的代码:

        foreach ($children as $child) {
            $data = array(
                'filter_category_id'  => $child['category_id'],
                'filter_sub_category' => true
            );

            $product_total = $this->model_catalog_product->getTotalProducts($data);

            $total += $product_total;

            $children_data[] = array(
                'category_id' => $child['category_id'],
                'name'        => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $product_total . ')' : ''),
                'href'        => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id']) 
            );      
        }

看起来它正在使用$ total或$ product_total但它没有显示在前端。我把它关掉了某个地方还是有办法把它重新打开?

谢谢,

马特

1 个答案:

答案 0 :(得分:0)

替换这个foreach(不是$ children的整个$类别),让我知道它的工作与否......

        foreach ($categories as $category) {
        $total = $this->model_catalog_product->getTotalProducts(array('filter_category_id' => $category['category_id']));

        $children_data = array();

        $children = $this->model_catalog_category->getCategories($category['category_id']);

        foreach ($children as $child) {



            $product_total = $this->model_catalog_product->getTotalProducts(array('filter_category_id'  => $child['category_id']));

            $total += $product_total;

            $children_data[] = array(
                'category_id' => $child['category_id'],
                'name'        => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $product_total . ')' : ''),
                'total'    => $product_total,
                'href'        => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id']) 
            );      
        }

        $this->data['categories'][] = array(
            'category_id' => $category['category_id'],
            'name'        => $category['name'] . ($this->config->get('config_product_count') ? ' (' . $total . ')' : ''),
            'children'    => $children_data,
            'href'        => $this->url->link('product/category', 'path=' . $category['category_id'])
        );  
    }