AbanteCart Development > Development Help Needed

How to extend controllers and model for new template.

(1/2) > >>

Hi,i'm currently trying to convert html template to abantecart themes,i have used developer tools to create new theme,what i would like to ask is how to extend the controller and the model from new template.I have tried to copy the controller and the model for the storefront from default_html5 theme to the new theme,but it doesn't work.Hopefully abantecart would teach how to extend it.Thanks a lot.

I doubt that you need to extend controllers or models heavily for the template. Possibly something small.

You can do one of the following:
1. Create a hook to controller
2. Create "pre" or "post" controller
Note: You can not override controller completely.

For #1. You need to create an Extension type class with "magic" hook method inside of main.php of your extension.
(This can be done in included file of cause)


--- Code: ---class ExtensionTestName extends Extension {

 public function onControllerPagesCheckoutPayment_InitData() {
      $that = $this->baseObject;


--- End code ---

This class name should consist of Extension[extension text id] and shoudl extend Extension base class
To hook to specific controller, you need to create a "magic" method that id constructed as following:
onController[controller name path]_InitData()
onController[controller name path]_UpdateData()

InitData() is before main controller is executed and UpdateData() after main controller is executed.

To access and change main controller objects and data use $this->baseObject;

For #2.
You need to create a new controller with the same relative path as main controller starting from [ext dir]/[storefront oe admin]/controllers/....

Name of the controller should end with .pre or .post.
Example:  ../checkout/payment.pre.php

As for model. You can not extend model easily. You can always create your own model and get data what you need for your controller or hook.

This document covers extension dev in details:

If you have suggestions how to improve this document, please let us know. Help us to improve it.

I have another question.Is it possible to get variables from controller via hook?Thanks

Yes. You can access anything that is present in view with t_UpdateData hook. See below example:

--- Code: ---        public function onControllerPagesCheckoutPayment_UpdateData() {
                $that = $this->baseObject;


--- End code ---

You can try

--- Code: --- echo_array($that->data);

--- End code ---

Hi abantecart,does hook can only access the view objects only and not able to access the base controller objects? Like get $results=$this->model_catalog_product->getProductsByCategoriesId(),what i would like to do is add isotope filter to category page and display products that belong to category and subcategory,so customer doesn't to click the subcategory and redirect to other page.Thanks


[0] Message Index

[#] Next page

Go to full version
Powered by SMFPacks Social Login Mod