Jump to content

Execute Custom Hooks in a Module


Recommended Posts

Hello All, 

 

I am trying to figure out how to execute custom hooks attached to a module. Below is my code for install and hook function. 

public function install(){
   return parent::install() && $this->registerHook('actionMyCheckout');
}

public function hookActionMyCheckout($params){
   var_dump($params);
   exit;// just curious what's in the params for now.   
}

I will explain in a bit more detail-

  • I am making a checkout plugin for our Prestashop customers for a  different sales channel(not website). So, there will be a single checkout URL which our system will hit of a client's store, along with cart data. 
  • Once that particular URL is triggered, I want to execute my custom hook function and add all products to the cart on his/her website. 
  • I am aware of a hook function called actionCartSave, but don't want to hook my checkout function to it, as my function will also be called every time someone checks out on the client's website which is trivial and reduces efficiency of checkout process for client's visitors. 
  • Please guide me as to how to execute my custom hook ONLY on hitting a particular URL endpoint. 

Do I need to play around with Dispatcher?

Note: Since this will be a module, I don't have control over other files on the client's store backend. Checkout should work once our checkout module is installed by the client on his backend.

 

 

Edited by vivek_23 (see edit history)
Link to comment
Share on other sites

Hello All, 

 

I am trying to figure out how to execute custom hooks attached to a module. Below is my code for install and hook function. 

public function install(){
   return parent::install() && $this->registerHook('actionMyCheckout');
}

public function hookActionMyCheckout($params){
   var_dump($params);
   exit;// just curious what's in the params for now.   
}

I will explain in a bit more detail-

  • I am making a checkout plugin for our Prestashop customers for a  different sales channel(not website). So, there will be a single checkout URL which our system will hit of a client's store, along with cart data. 
  • Once that particular URL is triggered, I want to execute my custom hook function and add all products to the cart on his/her website. 
  • I am aware of a hook function called actionCartSave, but don't want to hook my checkout function to it, as my function will also be called every time someone checks out on the client's website which is trivial and reduces efficiency of checkout process for client's visitors. 
  • Please guide me as to how to execute my custom hook ONLY on hitting a particular URL endpoint. 

Do I need to play around with Dispatcher?

 

Note: Since this will be a module, I don't have control over other files on the client's store backend. Checkout should work once our checkout module is installed by the client on his backend.

 

So you need to override the function where you want to call your module function. Actually you don't need to create a hook but a function if you are not going to use PS hooks.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...