Sometimes we need to add sub sub categories in opencart header with the product images. One of my client wanted a similar layout, I did it with the following code.
Add the following code to header controller.
$categories_1 = $this->model_catalog_category->getCategories(0);
foreach ($categories_1 as $category_1) {
$level_2_data = array();
$categories_2 = $this->model_catalog_category->getCategories($category_1['category_id']);
foreach ($categories_2 as $category_2) {
/*Incase level 3 not available*/
$level_5_data = array();
$categories_5 = $this->model_catalog_product->getProducts($data = array('filter_category_id' => $category_2['category_id']));
foreach ($categories_5 as $category_5 ) {
$level_5_data [] = array(
'name' => $category_5['name'],
'image' => $server . 'image/' . $category_5['image'],
'href' => $this->url->link('product/product', 'product_id=' . $category_5['product_id']),
);
}
/*Incase level 3 not available*/
$level_3_data = array();
$categories_3 = $this->model_catalog_category->getCategories($category_2['category_id']);
foreach ($categories_3 as $category_3) {
// Custum code for for products by Diwakar Mishra (Appealsoft)
$level_4_data = array();
$categories_4 = $this->model_catalog_product->getProducts($data = array('filter_category_id' => $category_3['category_id']));
foreach ($categories_4 as $category_4 ) {
$level_4_data [] = array(
'name' => $category_4['name'],
'image' => $server . 'image/' . $category_4['image'],
'href' => $this->url->link('product/product', 'product_id=' . $category_4['product_id']),
);
}
// Custum code for for products by Diwakar Mishra (Appealsoft)
$level_3_data[] = array(
'name' => $category_3['name'],
'children' => $level_4_data,
'column' => $category_3['column'] ? $category_3['column'] : 1,
'href' => $this->url->link('product/category', 'path=' . $category_1['category_id'] . '_' . $category_2['category_id'] . '_' . $category_3['category_id'])
);
}
$level_2_data[] = array(
'name' => $category_2['name'],
'children' => $level_3_data,
'children_else' => $level_5_data,
'href' => $this->url->link('product/category', 'path=' . $category_1['category_id'] . '_' . $category_2['category_id'])
);
}
$this->data['categories'][] = array(
'name' => $category_1['name'],
'children' => $level_2_data,
'column' => $category_1['column'] ? $category_1['column'] : 1,
'href' => $this->url->link('product/category', 'path=' . $category_1['category_id'])
);
}
you will need to change the header.tpl file and create a loop of the above arrays to get the final result.