OpenCart: hook module to all pages

I needed to make my module appear on all pages by default in OpenCart. The layout/route system was kinda tricky and it looked like the user needs to do it manually after installing the module.

What I did was check what parameters are sent when a module gets hooked to every route and what happens afterwards. Then I added a piece of code to the install() function of my module that mirrors that behavior without user needing to do it all manually.

You'll need to load the setting model, replace modulename with the actual name of your module and change the position to the one you need. I wanted to hook it to content_top.

For 1.5.0.x
[raw]

[/raw]

For 1.5.1.x
[raw]

[/raw]
That should do it.

 

UPD:

This works for default layouts (ids 1-11). If you've got custom layouts in your installation, you'll want to retrieve corresponding layout ids from the layout table instead.

Martin Boze

Martin Boze

About the authorMartin Boze is the Founder of MultiMerch Marketplace. I also love skydiving, motorcycles and space. And other cool things.
Martin Boze

Latest posts by Martin Boze (see all)

Share this post on: Share on LinkedInTweet about this on TwitterShare on FacebookShare on Google+ 105 shares
  • Hello, where do I place this code? Sorry I'm new at using open cart

  • affect

    I put it inside install() function of module's controller in the admin part so that it gets executed during module installation.

  • Hmm. what if i've already installed it? It's not really a module I created, I just downloaded a free module from opencart extension and installed it.

  • affect

    Then you'd have to either hook it to every possible layout via edit screen manually (if it has positions part on the edit screen) or put this code somewhere where you can execute it (you'd have to load settings model first) or insert the serialized $settings string to the setting table.

    I'd say second possibility would be the easiest if you don't want to modify the extension itself.

  • @affect, sorry for trouble. would you like to tell me how can I modify it?

    like

    go to which file, and find which line, and add code before or after.

    thank you.

    David

    • I receive this error in step two of check out.PHP Notice: Undefined index: comanpy_no in /home/hgs/public_html/catalog/model/account/address.php on line 59 PHP Notice: Undefined index: comanpy_tax in /home/hgs/public_html/catalog/model/account/address.php on line 60I also receive this error in admin when editing costumer information.PHP Notice: Undefined index: comanpy_no in /home/hgs/public_html/admin/model/sale/customer.php on line 225PHP Notice: Undefined index: comanpy_tax in /home/hgs/public_html/admin/model/sale/customer.php on line 226Any help would be appreciated. Thanks!

  • affect

    It depends on what do you want to hook.

    I put it to the install() function of the module I need hooked, i.e. admin/controller/module/modulename.php, public function install().

    If the function doesn't exist you can add it.

    That way the code gets executed when the module is installed.

  • Looking so i think you could help me.. I need to insert the shipping calculator 1.5.1 on the product page, you know how to do?

    • affect

      Yeah if it's the one that's in the cart you'd need to copy that part from checkout/cart controller and insert it to product controller.

      If it's some external sidebar module you could just hook it to product layout.

  • Hi i was wondering if this can be done in the latest opencart version 1.5.3.1 please? and if so if any1 knew how to do it as i couldn't get the above to work

    Thanks
    Aaron

  • Kin

    There is a VQMod can do exactly what you want.
    http://www.opencart.com/index.php?route=extension/extension/info&extension_id=11843

    This VQmod works great. It allows you to have a dedicated layout to show modules on every pages on your Opencart website.

  • OC version 1.5.2 the prebolm happen in the checkout process, step two. it does not let you continue any farther along only when registered. when checking out not logged it works past step 2 in checkout. them is store opencart 1.5x template. Compatible with: Opencart 1.5.0.x 1.5.1.x 1.5.2 1.5.2.1I hope that helps. I have only been using OC for about two months and still learning. I did a fresh install with the new OC version not thinking about all the glitches it still might have. To late now to much time invested in it. I do like the softare thought. Any help would be cool. Thanks again Jeff