0

我正在使用 opencart 1.5.4。

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

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

我试图添加代码,但它看起来已经在控制器中(category/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 但它没有显示在前端。我是否在某个地方关闭了它,或者有没有办法重新打开它?

谢谢,

马特

4

1 回答 1

0

repalce 这个 foreach (不是 $children 整个 $categories ),让我知道它是否工作......

        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'])
        );  
    }
于 2013-09-24T07:18:16.623 回答