opencart上的下拉菜单

时间:2016-04-04 15:51:02

标签: javascript php html

我在opencart上有一个下拉侧边栏菜单。当我点击category我想要的内容时,如何使该菜单不关闭?这是网站。 www.newopt.com.ua

以下是category.php控制器的代码:

<?php
  class ControllerModuleCategory extends Controller {
private $categoryList;

protected function index($setting) {
    $this->language->load('module/category');

    $this->data['heading_title'] = $this->language->get('heading_title');

    if (isset($this->request->get['path'])) {
        $parts = explode('_', (string)$this->request->get['path']);
    } else {
        $parts = array();
    }

    if (isset($parts[0])) {
        $this->data['category_id'] = $parts[0];
    } else {
        $this->data['category_id'] = 0;
    }

    if (isset($parts[1])) {
        $this->data['child_id'] = $parts[1];
    } else {
        $this->data['child_id'] = 0;
    }

    if (isset($parts[2])) {
        $this->data['ch3_id'] = $parts[2];
    } else {
        $this->data['ch3_id'] = 0;
    }

    $this->load->model('catalog/category');

    $this->load->model('catalog/product');

    $this->data['categories'] = array();

    $categories = $this->model_catalog_category->getCategories(0);

    $this->categoryList = $this->model_catalog_category->getCategoriesAll();


    foreach ($categories as $category) {
        $children_data = array();

            $children = $this->childCategory($category['category_id']);

            foreach ($children as $child) {

                $level3 = $this->childCategory($child['category_id']);
                $l3_data = array();

                foreach ($level3 as $l3) {
                    $data = array(
                    'filter_category_id'  => $l3['category_id'],
                    'filter_sub_category' => true
                );



                    $level4 = $this->childCategory($l3['category_id']);
                    $l4_data = array();

                    foreach ($level4 as $l4) {
                        $data = array(
                        'filter_category_id'  => $l4['category_id'],
                        'filter_sub_category' => true
                    );

                        $l4_data[] = array(
                            'category_id' => $l4['category_id'],
                            'name'        => $l4['name'],
                            'href'        => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id']. '_' . $l3['category_id']. '_' . $l4['category_id'])
                        );

                    }

                    $l3_data[] = array(
                        'category_id' => $l3['category_id'],
                        'name'        => $l3['name'],
                        'href'        => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id']. '_' . $l3['category_id']),
                        'children4'    => $l4_data
                    );

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

                    $children_data[] = array(
                        'category_id' => $child['category_id'],
                        'name'  => $child['name'],
                        'href'  => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id']),
                        'children3'    => $l3_data
                    );

            }
            // Level 1
            $data2 = array(
                    'filter_category_id'  => $category['category_id'],
                    'filter_sub_category' => true
                );

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

        }

    if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/category.tpl')) {
        $this->template = $this->config->get('config_template') . '/template/module/category.tpl';
    } else {
        $this->template = 'default/template/module/category.tpl';
    }

    $this->render();
}

protected function childCategory($cat_id) {
    $child = array();

    $numCategories = count($this->categoryList);

    $counter = 0;
    for ($i = 0; $i < $numCategories; $i++) {
        if($this->categoryList[$i]['parent_id'] == $cat_id){
            $child[$counter] = $this->categoryList[$i];
            $counter++;
        }
    }

    return $child;
}
}
?>

0 个答案:

没有答案