J.K.A.
J.K.A.

Reputation: 7404

How to override prestashop's default front-office template and controller in module

I want to override prestashop's default front-office template and controller in my newly created module without modifying prestashop's internal code/structure.

Example :

I have created one module i.e. "mymodule" in /modules folder where I want use prestashop's address form (address.tpl).

see : http://demo-store.prestashop.com/en/address.

I want to enhance address form by providing some additional fields/functionality but without changing prestashop's core functionality.

So, How can I override its controller/themes/templates in my module? I have searched lot of about this on google but didn't found anything :(

Any help would be appreciated.

Upvotes: 1

Views: 8016

Answers (1)

kawashita86
kawashita86

Reputation: 1573

Modules can work like you ask only if there's an HOOK inside the template/controller that allow you to run your customized function. Look if you have a chance of hooking your module somewhere by watching on the list showed inside

backoffice > modules > position

the Address controllers hasn't got any Hook if i recall well, so you have 3 ways to edit its functionality:

  1. Go for an (imho) horrible client-side modification, by an heavy usage of jquery/ajax call to perform the action you need. Place the code by using a module that only add your js script in the header by using the hookHeader() function. Since this hook it's always called in all the site you can exploit the missing hook in the address template.

  2. add yourself an hook inside the Controller and the template by following this procedure: http://www.prestashop.com/forums/topic/218291-create-custom-and-new-hook-in-ps-15/

  3. use the amazing override features of the prestashop framework to modify what you need in the Controller file placed inside your prestashop_root/override/controllers/front/AddressController.php and inside your /prestashop_root/themes/my_theme/address.tpl. this way you can ovverride any function of the Controller withouth loosing the original functionality and if you'll need to upgrade your installation you will just need to check for the function you changed in the overrided file just as you would do for your module.

Upvotes: 1

Related Questions