This is an overview of extension development for AbanteCart
How extensions are processed?
Once AbanteCart page/response load starts (init.php), all enabled extensions are loaded. At this time, system has created instances of all extensions classes responsible for hooks processing. These are core hook files located inside of each extension core directory.
Now, control is passed to Action class which is trying to define controller and method based on route (rt) requested in URL. Action class checks the requested route, and if it is matching the existing extension. If there is a match, extension controller class is loaded.
After extension controller is loaded, requested method is executed and it is ready to render template. System is looking for template file specified.
- first it looks for an override file - it will be named as template.override.tpl - any extensions can override template file. But if several extensions tries to override one file, file from extension with higher priority will be used.
- if override is not found it is looking for template.pre.tpl and template.post.tpl - their content added before and after original template - any extensions can use pre and post files. if several extensions contain pre or postfiles - they all will be rendered according to extension priority
- at last it is looking for template.tpl
How to develop extensions?
Let us show how to develop extension based on the example that will apply discount on all products
Extension unique id name will be - discount
- create directory ../extensions/discount
- create config file ../extensions/discount/config.xml
At minimum we need to add following settings
- discount_status - enabled/disabled
- discount_percent - percent of discount
- discount message - message that will be shown on cart page
- discount message for every product - how much you save
create main driver PHP file ../extensions/discount/main.php
create language setting file ../extensions/discount/admin/language/english/discount/discount.xml
create extension class to handle the work: ../extensions/discount/core/discount.php
add a message about discounts to CheckoutCart step/page 1. Edit file add this function below: