kelvindereus Posted December 26, 2022 Share Posted December 26, 2022 Hi. I just started with Prestashop modules. Now i'm wondering how i can make it so some code get's triggered when a user sends a message in the contact form. I searched: https://devdocs.prestashop-project.org/8/modules/concepts/hooks/list-of-hooks/actionmoduleregisterhookafter/ but could't find the right hook. Greets, Kelvin Link to comment Share on other sites More sharing options...
JBW Posted December 27, 2022 Share Posted December 27, 2022 Contact from is a module and does not have any hooks afaik. You can either create an override for the module or use hook actionEmailSendBefore in Mail function e.g. filtering for $template to identify that it's coming from contact form. Link to comment Share on other sites More sharing options...
kelvindereus Posted December 30, 2022 Author Share Posted December 30, 2022 So i have this: // Mail hook trigger public function actionEmailSendBefore($param) { // Webhook code (working) $url = "WEBHOOK_URL_HERE"; $headers = [ 'Content-Type: application/json; charset=utf-8' ]; $POST = [ 'username' => 'Testing BOT', 'content' => 'Testing message' ]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($POST)); $response = curl_exec($ch); } but it doesn't run the code. What is a easy way to check if "actionEmailSendBefore" gets triggerd? Link to comment Share on other sites More sharing options...
JBW Posted December 30, 2022 Share Posted December 30, 2022 Is your module properly registered on that hook? It's triggered in Mail::send function so you could debug from there 1 Link to comment Share on other sites More sharing options...
kelvindereus Posted December 30, 2022 Author Share Posted December 30, 2022 (edited) I did register the webhook as seen below here but with no result // Gets called when module gets installed public function install() { // Register actionEmailSendBefore hook return parent::install() && $this->registerHook("actionEmailSendBefore"); } Hmm, gonna look into Hook::exec! Also i see online everywhere "hook" before public funtion hookhere. Edited December 30, 2022 by kelvindereus (see edit history) Link to comment Share on other sites More sharing options...
kelvindereus Posted December 30, 2022 Author Share Posted December 30, 2022 It works! 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