Author Topic: Is it possible to hook functions in controller?  (Read 5295 times)

yonghan

  • Guest
Is it possible to hook functions in controller?
« 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.

Offline abantecart

  • Administrator
  • Hero Member
  • *****
  • Posts: 4139
  • Karma: +250/-9
    • View Profile
    • Ideal Open Source Ecommerce Solution
Re: Is it possible to hook functions in controller?
« Reply #1 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
We need your help to build better free open source eCommerce platform for everyone.
See how you can help

Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 1768
  • Karma: +246/-11
  • web for all, all for web!
    • View Profile
    • AbanteCart
Re: Is it possible to hook functions in controller?
« Reply #2 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
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
You can build your own extension very fast.
“No one is useless in this world who lightens the burdens of another.”
― Charles Dickens

yonghan

  • Guest
Re: Is it possible to hook functions in controller?
« Reply #3 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.

yonghan

  • Guest
Re: Is it possible to hook functions in controller?
« Reply #4 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

Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 1768
  • Karma: +246/-11
  • web for all, all for web!
    • View Profile
    • AbanteCart
Re: Is it possible to hook functions in controller?
« Reply #5 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
}

“No one is useless in this world who lightens the burdens of another.”
― Charles Dickens

yonghan

  • Guest
Re: Is it possible to hook functions in controller?
« Reply #6 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.

Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 1768
  • Karma: +246/-11
  • web for all, all for web!
    • View Profile
    • AbanteCart
Re: Is it possible to hook functions in controller?
« Reply #7 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
“No one is useless in this world who lightens the burdens of another.”
― Charles Dickens

yonghan

  • Guest
Re: Is it possible to hook functions in controller?
« Reply #8 on: July 26, 2014, 10:20:45 AM »
I will try it again,thanks a lot.

 

Powered by SMFPacks Social Login Mod