The language file variable names need to relate properly to their counterparts in $full_menu, template file needs $menu_items in the appropriate place as well.
Code: Select all
class ControllerCommonMenu extends Controller {
protected function index() {
$this->load->language('common/menu');
$this->data['text_help'] = $this->language->get('text_help');
$this->data['text_support'] = $this->language->get('text_support');
$this->data['text_documentation'] = $this->language->get('text_documentation');
$this->data['text_opencart'] = $this->language->get('text_opencart');
$full_menu = array(
'admin' => array(
'common/home',
'shop',
'configuration' => array(
'setting/setting',
'users' => array(
'user/user',
'user/user_permission'
),
'localisation' => array(
'localisation/language',
'localisation/currency',
'localisation/stock_status',
'localisation/order_status',
'localisation/country',
'localisation/zone',
'localisation/geo_zone',
'localisation/tax_class',
'localisation/measurement_class',
'localisation/weight_class'
),
'tool/error_log',
'tool/backup'
),
'common/logout'
),
'catalog' => array(
'catalog/category',
'catalog/product',
'catalog/manufacturer',
'catalog/download',
'catalog/review',
'catalog/information',
'catalog/featured'
),
'extension' => array(
'extension/module',
'extension/shipping',
'extension/payment',
'extension/total',
'extension/feed'
),
'customers' => array(
'customer/customer',
'customer/customer_group',
'customer/order',
'customer/coupon',
'customer/contact'
),
'reports' => array(
'report/sale',
'report/viewed',
'report/purchased'
)
);
$this->data['menu_items'] = $this->outputMenu($full_menu);
$this->data['logged'] = $this->user->isLogged();
$this->id = 'menu';
$this->template = 'common/menu.tpl';
$this->render();
}
function outputMenu($array, $level = 1, $output = "") {
if (is_array($array)) {
foreach ($array as $key => $value) {
if (is_array($value)) {
if ($level == 1) {
$parent = '<li id="' . $key . '"><a class="top">' . $this->language->get('text_' . $key) . '</a><ul>' . "\n";
}
else {
$parent = '<li><a class="parent">' . $this->language->get('text_' . $key) . '</a><ul>' . "\n";
}
$newoutput = $this->outputMenu($value, 2, $output);
if ($newoutput != $output) {
$output .= $parent;
$output = $this->outputMenu($value, 2, $output);
$output .= "</ul></li>" . "\n";
}
}
elseif ($value == 'shop') {
$output .= '<li><a href="' . HTTP_CATALOG . '">' . $this->language->get('text_shop') . '</a></li>' . "\n";
}
elseif ($value == 'common/home' || $value == 'common/logout') {
$part = explode('/', $value);
$output .= '<li><a href="' . $this->url->http($value) . '">' . $this->language->get('text_' . @$part[1]) . '</a></li>' . "\n";
}
else {
$part = explode('/', $value);
if ($this->user->hasPermission('access', @$part[0] . '/' . @$part[1])) {
$output .= '<li><a href="' . $this->url->http($value) . '">' . $this->language->get('text_' . @$part[1]) . '</a></li>' . "\n";
}
}
}
}
return $output;
}
}