Do you like AbanteCart? Please rate AbanteCart or share your experience with other eCommerce entrepreneurs. Go to Softaculous rating page to add your rating or write a review

How to extend controllers and model for new template.

Started by yonghan, June 03, 2014, 08:20:22 AM

Previous topic - Next topic

yonghan

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.

abantecart

#1
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)

Example:


class ExtensionTestName extends Extension {

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

}


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()
or
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:
https://abantecart.atlassian.net/wiki/spaces/DOC/pages/17727622/Extension+s+Developer+Guide

If you have suggestions how to improve this document, please let us know. Help us to improve it.
Please  rate your experience or leave your review
We need your help to build better free open source ecommerce platform for everyone. See how you can help

yonghan

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

abantecart

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


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

                echo_array($that->data['payment_methods']);
        }


You can try

echo_array($that->data);

Please  rate your experience or leave your review
We need your help to build better free open source ecommerce platform for everyone. See how you can help

yonghan

#4
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

jamesardolf

Expanding the functionality of controllers and models for new templates is a critical task in software development. At our Software Development Company in California, we understand the importance of this process. Our skilled team of developers has mastered the art of seamless template integration, ensuring that your software remains flexible and scalable. Let's elevate your software together!

Forum Rules Code of conduct
AbanteCart.com 2010 -