Adding New Modules Positions to OpenCart 2

前端 未结 2 1843
野性不改
野性不改 2021-01-28 18:39

I want to add more Positions for modules. How can I add a new module position in opencart 2?

Here, I like this information. but, it is work only for OpenCart older vers

2条回答
  •  失恋的感觉
    2021-01-28 19:08

    I know it is bit late , but it might be helpful to others , also the above answer helped me but for newbie to understand easily i am writing this.

    I am inserting the new position content_footer in it.

    Tested For 2.3.0.2

    We will edit the files for admin side first

    1] Go to admin/view/template/design/layout_form.tpl

    By Default opencart gives 4 position for modules find the below code

      

    so after copy this whole section from start of the table to the table closing and paste it below and change the content_bottom to content_footer

      

    2] Now find the function addModule() and find the below line

    $('#module-column-left, #module-column-right, #module-content-top, #module-content-bottom ').delegate
    

    Now add #module-content-footer

    $('#module-column-left, #module-column-right, #module-content-top, #module-content-bottom , #module-content-footer').delegate(
    

    Same way below line for trigger

    $('#module-column-left, #module-column-right, #module-content-top, #module-content-bottom , #module-content-footer' ).trigger
    

    3] In admin/controller/design/layout.php find the below function

    protected function getForm()
    

    and this line in it

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

    4] Now add following line in admin/language/en-gb/layout.php

    $_['text_content_footer'] = 'Content Footer';
    

    Front Side Files Changing

    1] Create a new template file in catalog/view/theme/themename/template/common/content_footer.tpl

    
    

    2] Create a new controller file in Catalog/controller/common/content_footer.php and place the below code

        load->model('design/layout');
    
        if (isset($this->request->get['route'])) {
            $route = (string)$this->request->get['route'];
        } else {
            $route = 'common/home';
        }
    
        $layout_id = 0;
    
        if ($route == 'product/category' && isset($this->request->get['path'])) {
            $this->load->model('catalog/category');
    
            $path = explode('_', (string)$this->request->get['path']);
    
            $layout_id = $this->model_catalog_category->getCategoryLayoutId(end($path));
        }
    
        if ($route == 'product/product' && isset($this->request->get['product_id'])) {
            $this->load->model('catalog/product');
    
            $layout_id = $this->model_catalog_product->getProductLayoutId($this->request->get['product_id']);
        }
    
        if ($route == 'information/information' && isset($this->request->get['information_id'])) {
            $this->load->model('catalog/information');
    
            $layout_id = $this->model_catalog_information->getInformationLayoutId($this->request->get['information_id']);
        }
    
        if (!$layout_id) {
            $layout_id = $this->model_design_layout->getLayout($route);
        }
    
        if (!$layout_id) {
            $layout_id = $this->config->get('config_layout_id');
        }
    
        $this->load->model('extension/module');
    
        $data['modules'] = array();
    
        $modules = $this->model_design_layout->getLayoutModules($layout_id, 'content_footer');
    
        foreach ($modules as $module) {
            $part = explode('.', $module['code']);
    
            if (isset($part[0]) && $this->config->get($part[0] . '_status')) {
                $module_data = $this->load->controller('extension/module/' . $part[0]);
    
                if ($module_data) {
                    $data['modules'][] = $module_data;
                }
            }
    
            if (isset($part[1])) {
                $setting_info = $this->model_extension_module->getModule($part[1]);
    
                if ($setting_info && $setting_info['status']) {
                    $output = $this->load->controller('extension/module/' . $part[0], $setting_info);
    
                    if ($output) {
                        $data['modules'][] = $output;
                    }
                }
            }
        }
    
        return $this->load->view('common/content_footer', $data);
    }}
    

    3] Now add the following line in catalog/controller/common/home.php

    $data['content_footer'] = $this->load->controller('common/content_footer');
    

    4] Finally , to show the position on the home page, you'll add

    
    

    to catalog/view/theme/themename/template/common/home.tpl

提交回复
热议问题