vivek_23 Posted July 14, 2017 Share Posted July 14, 2017 (edited) 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 July 14, 2017 by vivek_23 (see edit history) Link to comment Share on other sites More sharing options...
joseantgv Posted July 14, 2017 Share Posted July 14, 2017 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 More sharing options...
vivek_23 Posted July 14, 2017 Author Share Posted July 14, 2017 Can you explain a bit more as to which function I need to override? Link to comment Share on other sites More sharing options...
joseantgv Posted July 14, 2017 Share Posted July 14, 2017 Can you explain a bit more as to which function I need to override? Do you want that your function is called when you go an URL, don't you? Which is this URL? Link to comment Share on other sites More sharing options...
vivek_23 Posted July 14, 2017 Author Share Posted July 14, 2017 (edited) Ok, let's say the URL is http://localhost/prestashop/my-checkout-url So, it will be a POST request to this URL with some parameters. Now, is it that we can't define our custom URLs and attach a functionality to it? Edited July 14, 2017 by vivek_23 (see edit history) Link to comment Share on other sites More sharing options...
joseantgv Posted July 16, 2017 Share Posted July 16, 2017 Ok, let's say the URL is http://localhost/prestashop/my-checkout-url So, it will be a POST request to this URL with some parameters. Now, is it that we can't define our custom URLs and attach a functionality to it? If "my-checkout-url" is a custom URL, not a PS page, then you have to create this controller and include there all the logic. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now