Extension Process Overview

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

  1. discount_status - enabled/disabled
  2. discount_percent - percent of discount 
  3. discount message - message that will be shown on cart page 
  4. 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:
../extensions/discount/core/discount.php


Extension will need to override default cart template to add discount message copy
storefront/view/default/template/pages/checkout/cart.tpl
to
extensions/discount/storefront/view/default/template/pages/checkout/

edit cart.tpl


now lets apply a discount to each product in cart

1. edit core\lib\cart.php

2. edit extensions\discount\core\discount.php

 

3. edit storefront\controller\checkout\cart.php add these lines

4. edit extensions\discount\core\discount.php

Use updateData hook. Each controller has this hook and can update its data before render output


5. edit extensions/discount/storefront/view/default/template/pages/checkout/cart.tpl