AbanteCart Community

AbanteCart Development => Development Help Needed => Topic started by: yonghan on June 26, 2014, 07:13:03 AM

Title: Is it possible to hook functions in controller?
Post by: yonghan on June 26, 2014, 07:13:03 AM
Hi,i would like to ask if it's possible to hook functions in controller?i.e i would like to extend add function in customer manage address controller to use other styles.insted of directly edit the controller or using javascript.thanks a lot.
Title: Re: Is it possible to hook functions in controller?
Post by: abantecart on June 27, 2014, 08:08:37 AM
You can hook to any controller in the beginning and at the end. You can also have pre and post controllers

Check this manual:
http://www.abantecart.com/document_wiki/index.php/AbanteCart_Extension’s_Developer_Guide#Hooks
Title: Re: Is it possible to hook functions in controller?
Post by: abolabo on June 27, 2014, 08:14:40 AM
Hi,i would like to ask if it's possible to hook functions in controller?i.e i would like to extend add function in customer manage address controller to use other styles.insted of directly edit the controller or using javascript.thanks a lot.

of cource.

read this first
http://www.abantecart.com/document_wiki/index.php/AbanteCart_Extension%E2%80%99s_Developer_Guide#Hooks (http://www.abantecart.com/document_wiki/index.php/AbanteCart_Extension%E2%80%99s_Developer_Guide#Hooks)
and also you can open some extension's file with hooks for ex. default_pp_pro/core/default_pp_pro.php to look...
Also we have developer tools to generate extension https://github.com/abantecart/developer_tools_extension (https://github.com/abantecart/developer_tools_extension)
You can build your own extension very fast.
Title: Re: Is it possible to hook functions in controller?
Post by: yonghan on June 27, 2014, 08:59:30 AM
Thanks a lot for the replies,i'll take a look at the pre and post controller example from existing extensions.
Title: Re: Is it possible to hook functions in controller?
Post by: yonghan on July 26, 2014, 09:41:19 AM
Hi abolabo,my question is not clear enough.What i would like to do is hook function i.e insert function in storefront/controller/pages/account/address.Is it possible to do that?Thanks
Title: Re: Is it possible to hook functions in controller?
Post by: abolabo on July 26, 2014, 09:46:49 AM
every method of core-controller contain 2 hook calls:
//init controller data
$this->extensions->hk_InitData($this, __FUNCTION__);

and
//update controller data
$this->extensions->hk_UpdateData($this, __FUNCTION__);

You just should to add methods
public function onControllerPagesAccountAddress_InitData(){
    //write your code here
}

and

public function onControllerPagesAccountAddress_UpdateData(){
    //write your code here
}

Title: Re: Is it possible to hook functions in controller?
Post by: yonghan on July 26, 2014, 10:09:10 AM
I've tried using Update_Data() to hook before,but when i run the code,the rest of the core function didn't work.
Title: Re: Is it possible to hook functions in controller?
Post by: abolabo on July 26, 2014, 10:11:45 AM
I've tried using Update_Data() to hook before,but when i run the code,the rest of the core function didn't work.

i guess you call hook on all methods on core-controller.
use condition if($this->baseObject_method='name of method')  to define place when your hook must work
Title: Re: Is it possible to hook functions in controller?
Post by: yonghan on July 26, 2014, 10:20:45 AM
I will try it again,thanks a lot.