Post by ahmedatwa » Wed Mar 01, 2017 6:45 pm

Hi Guys,
i'm trying to display the subcategories related to parent only what i have achieved sofar is
here is the category.php controller

Code: Select all

$categories = $this->model_catalog_category->getCategories(0);
		$category_info = $this->model_catalog_category->getCategory($data['category_id']);
		
			$data['parent_name'] = $category_info['name'];
			$data['parent_id']   = $category_info['parent_id'];
			$data['category_id']   = $category_info['category_id'];
			$data['category_name']   = $category_info['name'];
			$data['parent_href'] = $this->url->link('product/category', 'path=' . $this->request->get['path']);
			$data['child_href_parent'] = $this->url->link('product/category', 'path=' . $category_info['parent_id']);
		
		var_dump($category_info['parent_id']);
		var_dump($category_info['category_id']);
		var_dump($category_info['name']);
		foreach ($categories as $category) {

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

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

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

					$data['children'][] = array(
						'category_id' => $child['category_id'],
						'name'        => $child['name'],
						'parent_id'   => $child['parent_id'],
						'href'        => $this->url->link('product/category', 'path=' . $child['category_id'])
					);
				}

[code]

and the category.tpl 
[code]<div class="list-group">
  <?php foreach ($categories as $category) { ?>
  <?php } ?>
  <?php if (!empty($children)) { ?>
  <a href="<?php echo $parent_href; ?>" class="list-group-item active"><i class="fa fa-arrow-circle-o-right" aria-hidden="true"></i> <?php echo $parent_name; ?></a>
  <?php foreach ($children as $child) { ?>
  <?php if ($category_id == $child['parent_id']) { ?>
  <a href="<?php echo $child['href']; ?>" class="list-group-item active">&nbsp;&nbsp;&nbsp;- <?php echo $child['name']; ?></a>
  <?php } ?>
  <?php } ?>
  <?php } else { ?>
  <?php } ?>
</div>
[code]

it displays perfectly as expected however if i reach the last category i get no subcategory because it doesn't have childs, hat i need is to stop or display the last level i'm in check the images 
[attachment=]https://forum.opencart.com/download/file.php?mode=view&id=31558[/attachment]

now if i click on any subcategory it returns empty i need to stop the loop till this level or break it if empty and display same results

Attachments

Capture.PNG

Capture.PNG (6.11 KiB) Viewed 637 times


New member

Posts

Joined
Sat Mar 05, 2016 5:22 pm
Who is online

Users browsing this forum: No registered users and 8 guests