Post by Ladi » Fri Jul 29, 2016 9:47 pm

Hello people,

Need to show number of product in category in third level menu.

This is code

Code: Select all

 foreach ($categories as $category) {
        if ($category['top']) {
            // Level 2
            $children_data = array();
            $children = $this->model_catalog_category->getCategories($category['category_id']);
            foreach ($children as $child) {
              // Level 3
                $children_data2 = array();
                $children2 = $this->model_catalog_category->getCategories($child['category_id']);
                foreach ($children2 as $child2) {
                    $children_data2[] = array(
					'name'  => $child2['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''), //new
                    'href'  => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'].'_'.$child2['category_id'])
                    );
                }

                $filter_data = array(
                    'filter_category_id'  => $child['category_id'],
                    'filter_sub_category' => true
                );

                $children_data[] = array(
                    'children'=>$children_data2,
                    'name'  => $child['name'],
                    'href'  => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
                );
            }
            // Level 1
            $data['categories'][] = array(
                'name'     => $category['name'],
                'children' => $children_data,
                'column'   => $category['column'] ? $category['column'] : 1,
                'href'     => $this->url->link('product/category', 'path=' . $category['category_id'])
            );
        }
    }
Issue is here I suppose (...not sure)

Code: Select all

'name'  => $child2['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''), //new
But don`t know what is wrong.

Thanks for help!

Newbie

Posts

Joined
Thu Jul 21, 2016 10:17 pm

Post by straightlight » Fri Jul 29, 2016 9:54 pm

There are also 3 other solutions from this page: http://www.opencart.com/index.php?route ... load_id=44 you could try. The first three results demonstrates the third-level categories for sub-categories (free). :)

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Ladi » Fri Jul 29, 2016 10:33 pm

Thanks again straightlight!

This one do the job perfectly :)
http://www.opencart.com/index.php?route ... load_id=44

Regards!

Newbie

Posts

Joined
Thu Jul 21, 2016 10:17 pm
Who is online

Users browsing this forum: No registered users and 7 guests