i am trying to display third level of category in open cart.Following is array when i display $data['categories'][0]['children']
Array
(
[0] => Array
(
[name] => HTC
[href] => http://127.0.0.1/oc/mobile_phones/HTC
[sec_children] => Array
(
[0] => Array
(
[name] => Desire
[href] => http://127.0.0.1/oc/HTC/HTC_Desire
)
[1] => Array
(
[name] => One
[href] => http://127.0.0.1/oc/HTC/HTC_One
)
[2] => Array
(
[name] => Windows
[href] => http://127.0.0.1/oc/HTC/HTC_Windows
)
)
)
[1] => Array
(
[name] => iPhone
[href] => http://127.0.0.1/oc/mobile_phones/iPhone
[sec_children] => Array
(
)
)
)
Following is code in header.php
foreach ($categories as $category) {
if ($category['top']) {
// Level 2
$children_data = array();
$cat = $this->model_catalog_category->getCategories($category['category_id']);
//'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
foreach ($cat as $child) {
//3rd level begin
$sec_children_data = array();
$sec_children = $this->model_catalog_category->getCategories($child['category_id']);
foreach ($sec_children as $sec_child) {
$sec_children_data[] = array(
'name' => $sec_child['name'],// . ($this->config->get('config_product_count') ? ' (' . $product_total . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $child['category_id'] . '_' . $sec_child['category_id'])
);
}
//3rd level end
$filter_data = array(
'filter_category_id' => $child['category_id'],
'filter_sub_category' => true
);
$kids_data[] = array(
'name' => $child['name'],
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id']),
'sec_children' => $sec_children_data //level 3
);
//$this->load->test($kids_data);
}
// Level 1
$data['categories'][] = array(
'name' => $category['name'],
'children' => $kids_data,
'column' => $category['column'] ? $category['column'] : 1,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
}
Code in category.tpl
<li class="level0<?php if($category['category_id'] == $category_id){ echo " active";} ?>"><a href="<?php echo $category['href']; ?>" <?php if($category['children']){ echo "class='parent'";} ?>><?php echo $category['name']; ?></a>
<?php if ($category['children']) { ?>
<ul>
<?php foreach ($category['children'] as $child) { ?>
<?php if ($child['category_id'] == $child_id) { ?>
<li><a href="<?php echo $child['href']; ?>" class="active"><?php echo $child['name']; ?></a></li>
<?php } else { ?>
<li><a href="<?php echo $child['href']; ?>"><i class="fa fa-chevron-right"></i><?php echo $child['name']; ?></a></li>
<?php } ?>
<!-- level 3 -->
<?php if ($child['sec_children']) { ?>
<ul>
<?php foreach ($child['sec_children'] as $subChild) { ?>
<li><a href="<?php echo $subChild['href']; ?>" class="active"><?php echo $subChild['name']; ?></a></li>
<?php } ?>
</ul>
<?php } ?>
<!-- level 3 -->
<?php } ?>
</ul>
<?php } ?>
</li>
<?php } ?>
following error is being displayed ->Undefined index: sec_children . Though it is clearly displayed in the array... i am unable to sort it .... kindly suggest