How can I add a new module position for opencart?

Create a file name content_footer.php and past the code from here

class ControllerCommonContentFooter extends Controller {
    public function index() {
        $this->load->model('design/layout');
        $this->load->model('catalog/category');
        $this->load->model('catalog/product');
        $this->load->model('catalog/information');

        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'])) {
            $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'])) {
            $layout_id = $this->model_catalog_product->getProductLayoutId($this->request->get['product_id']);
        }

        if ($route == 'information/information' && isset($this->request->get['information_id'])) {
            $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');
        }

        $module_data = array();

        $this->load->model('setting/extension');

        $extensions = $this->model_setting_extension->getExtensions('module');

        foreach ($extensions as $extension) {
            $modules = $this->config->get($extension['code'] . '_module');

            if ($modules) {
                foreach ($modules as $module) {
                    if ($module['layout_id'] == $layout_id && $module['position'] == 'content_footer' && $module['status']) {
                        $module_data[] = array(
                            'code'       => $extension['code'],
                            'setting'    => $module,
                            'sort_order' => $module['sort_order']
                        );
                    }
                }
            }
        }

        $sort_order = array();

        foreach ($module_data as $key => $value) {
            $sort_order[$key] = $value['sort_order'];
        }

        array_multisort($sort_order, SORT_ASC, $module_data);

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

        foreach ($module_data as $module) {
            $module = $this->getChild('module/' . $module['code'], $module['setting']);

            if ($module) {
                $this->data['modules'][] = $module;
            }
        }

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

        $this->render();
    }
}
?>

Step#1: Go to catalog/controller/common/ paste the file content_footer.php

Step#2: We will need to create a template file for this new module position. Create a file name content_footer.tpl. Go to catalog/view/theme/default/template/common/ paste the file content_footer.tpl

<?php foreach ($modules as $module) { ?>
   <?php echo $module; ?>
<?php } ?>

Step#3: Edit for link up catalog/controller/common/footer.php and find

$this->render();

Before it, add

$this->children = array(
   'common/content_footer'
);

Step#4: Edit catalog/view/theme/default/template/common/footer.tpl and find

<div id="powered"><?php echo $powered; ?></div>

Before it, add

<?php echo $content_footer; ?>

Assigning Positions To Modules

Open up the template files of any modules that you would like to display at the new position. Let’s say I would like to display the Featured Module at Content Footer, I will open up admin/view/template/module/featured.tpl and find

<?php if ($module['position'] == 'content_top') { ?>
   <option value="content_top" selected="selected"><?php echo $text_content_top; ?></option>
<?php } else { ?>
   <option value="content_top"><?php echo $text_content_top; ?></option>
<?php } ?>

Before it, add

<?php if ($module['position'] == 'content_footer') { ?>
   <option value="content_footer" selected="selected">Content Footer</option>
<?php } else { ?>
   <option value="content_footer">Content Footer</option>
<?php } ?>

Now, find

html += '      <option value="content_top"><?php echo $text_content_top; ?></option>';

and before it add

html += '      <option value="content_footer">Content Footer</option>';

By adding those codes, you have a new position ‘Content Footer’ for the Featured module.

Enjoy it 🙂

Download Source Code: 1st you need to backup your all source code then apply with this.

Module Position Downlaod
Opencart Module Position

8 Replies to “How can I add a new module position for opencart?”

  1. I follow your step and get this error. Helo !!

    Fatal error: Class ‘Controllercommoncontentfooter’ not found in /home/redbirdo/public_html/vqmod/vqcache/vq2-system_engine_controller.php on line 42

    1. Hi Sandeep,

      What’s your version?. This tutorial is tested for version 1.4.x – 1.5.4. I have no test with latest new version. I saw your folder path. It’s a cache folder please clear your cache and try again. I think, it’ll be work.

      Thanks.

  2. I clear all the cache files. Still its showing error.

    Fatal error: Class ‘Controllercommoncontentfooter’ not found in /home/redbirdo/public_html/vqmod/vqcache/vq2-system_engine_controller.php on line 42

    I think it means I am declare contentfooter class in vq2-system_engine_controller.php

    Help plz…

    1. I have check it’s okay I think you was mistake to apply. I have upload extension for this so, you can apply it fresh default code for understand purpose then try to your working theme.

  3. Hai i copy my new template files,that the template name displayed in dropdown,but template not reflected any suggetions

Leave a Reply

Your email address will not be published. Required fields are marked *


*