Author Topic: How to extend controllers and model for new template.  (Read 20603 times)

yonghan

  • Guest
How to extend controllers and model for new template.
« on: June 03, 2014, 08:20:22 AM »
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.
« Last Edit: July 25, 2014, 02:44:17 AM by yonghan »

Offline abantecart

  • Administrator
  • Hero Member
  • *****
  • Posts: 4363
  • Karma: +301/-10
    • View Profile
    • Ideal Open Source Ecommerce Solution
Re: How to extend contollers and model for new template.
« Reply #1 on: June 03, 2014, 09:07:13 AM »
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:

Code: [Select]
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.
« Last Edit: November 19, 2020, 03:08:38 AM by Basara »
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

  • Guest
Re: How to extend contollers and model for new template.
« Reply #2 on: June 04, 2014, 06:03:41 AM »
I have another question.Is it possible to get variables from controller via hook?Thanks

Offline abantecart

  • Administrator
  • Hero Member
  • *****
  • Posts: 4363
  • Karma: +301/-10
    • View Profile
    • Ideal Open Source Ecommerce Solution
Re: How to extend contollers and model for new template.
« Reply #3 on: June 05, 2014, 09:02:27 PM »
Yes. You can access anything that is present in view with t_UpdateData hook. See below example:

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

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

You can try
Code: [Select]
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

  • Guest
Re: How to extend contollers and model for new template.
« Reply #4 on: June 05, 2014, 09:07:34 PM »
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
« Last Edit: June 05, 2014, 09:27:03 PM by yonghan »

Offline jamesardolf

  • Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Re: How to extend controllers and model for new template.
« Reply #5 on: November 06, 2023, 07:49:52 AM »
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!

 

Powered by SMFPacks Social Login Mod