xbenjii Posted October 23, 2014 Share Posted October 23, 2014 Is there any such thing in PrestaShop? By which I mean, is there anywhere I can set a pre-defined URL to POST data upon a PrestaShop action such as creating a new order. Scenario: User places order Webhook is fired and POSTS the order data to a pre-defined URL such as http://www.example.com/incoming Data is then parsed and synchronised with our stock control services. The only way I can think of doing this is extending the OrderDetailCore class and adding in the hook manually using cURL. Something like: class OrderDetail extends OrderDetailCore { public function create(Order $order, Cart $cart, $product, $id_order_state, $id_order_invoice, $use_taxes = true, $id_warehouse = 0) { parent::create($order, $cart, $product, $id_order_state, $id_order_invoice, $use_taxes, $id_warehouse); $ch=curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://www.example.com/incoming'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $product); $reply=curl_exec($ch); curl_close($ch); } } Link to comment Share on other sites More sharing options...
xbenjii Posted October 27, 2014 Author Share Posted October 27, 2014 Bump Link to comment Share on other sites More sharing options...
PrestaShopDeveloper Posted October 27, 2014 Share Posted October 27, 2014 Yes, it is called just hooks and you need actionValidateOrder. http://doc.prestashop.com/display/PS15/Creating+a+PrestaShop+module#CreatingaPrestaShopmodule-Implementinghooks Link to comment Share on other sites More sharing options...
vekia Posted October 27, 2014 Share Posted October 27, 2014 i don't understand your expectactions well but i think that you're talking about webservice (?) it's a kind of API to manage store based on something like "SOAP" http://doc.prestashop.com/display/PS16/Using+the+PrestaShop+Web+Service Link to comment Share on other sites More sharing options...
xbenjii Posted October 27, 2014 Author Share Posted October 27, 2014 (edited) i don't understand your expectactions well but i think that you're talking about webservice (?) it's a kind of API to manage store based on something like "SOAP" http://doc.prestashop.com/display/PS16/Using+the+PrestaShop+Web+Service No I'm not talking about the SOAP Webservice. I want a method to be called whenever another method is called. The method I want calling will fire off some data via a POST request. Something like the Github webhooks. https://developer.github.com/webhooks/ A good definition of a webhook can be seen here: http://en.wikipedia.org/wiki/Webhook Webhooks are "user-defined HTTP callbacks".[2] They are usually triggered by some event, such as pushing code to a repository[3] or a comment being posted to a blog.[4] When that event occurs, the source site makes an HTTP request to the URI configured for the webhook. Users can configure them to cause events on one site to invoke behaviour on another. Yes, it is called just hooks and you need actionValidateOrder. http://doc.prestashop.com/display/PS15/Creating+a+PrestaShop+module#CreatingaPrestaShopmodule-Implementinghooks Don't those just hook into the views? Edited October 27, 2014 by xbenjii (see edit history) Link to comment Share on other sites More sharing options...
PrestaShopDeveloper Posted October 28, 2014 Share Posted October 28, 2014 Don't those just hook into the views? No. http://doc.prestashop.com/display/PS15/Hooks+in+PrestaShop+1.5 Link to comment Share on other sites More sharing options...
xbenjii Posted October 28, 2014 Author Share Posted October 28, 2014 No. http://doc.prestashop.com/display/PS15/Hooks+in+PrestaShop+1.5 Ah, I see. Thanks for the help. Came up with something like this, will be expanded later. <?PHP if (!defined("_PS_VERSION_")) exit; class orderHook extends Module { public function __construct() { $this->name = "orderHook"; $this->tab = "checkout"; $this->version = "0.1"; $this->author = "Benjamin Fortune"; $this->need_instance = 0; $this->ps_versions_compliancy = array('min' => '1.6', 'max' => '1.6'); $this->dependencies = array(); parent::__construct(); $this->displayName = $this->l("Order Hook"); $this->description = $this->l("Fires a POST request to a pre-defined URL upon order creation."); $this->confirmUninstall = $this->l("Are you sure you want to uninstall?"); if (!Configuration::get('orderHook')) $this->warning = $this->l('No name provided.'); } public function install() { if (Shop::isFeatureActive()) Shop::setContext(Shop::CONTEXT_ALL); return parent::install() && $this->registerHook('actionValidateOrder') && Configuration::updateValue('ORDER_HOOK_URL', 'http://localhost/orders/incoming'); } public function uninstall() { return parent::uninstall() && $this->unregisterHook('actionValidateOrder'); } public function hookactionValidateOrder($params) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, Configuration::get('ORDER_HOOK_URL')); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params)); curl_exec($ch); curl_close($ch); } } Link to comment Share on other sites More sharing options...
solvire Posted July 12, 2015 Share Posted July 12, 2015 Did this webhook module ever get added to the store? I really need one for slack. Basically on the exact same scenario as you. This really should be build into the system IMO. Link to comment Share on other sites More sharing options...
xbenjii Posted July 12, 2015 Author Share Posted July 12, 2015 Did this webhook module ever get added to the store? I really need one for slack. Basically on the exact same scenario as you. This really should be build into the system IMO. Not as such, I did end up creating a little module which should do the job though. It hasn't been updated so I don't know how it'll work with the latest version. Let me know if you have any problems. https://www.prestashop.com/forums/topic/375015-webhook-module/ 1 Link to comment Share on other sites More sharing options...
solvire Posted July 12, 2015 Share Posted July 12, 2015 Awesome. Thanks for that man. I just inherited a project and I have never used this cart before. Link to comment Share on other sites More sharing options...
radialpoint.sqa Posted October 16, 2015 Share Posted October 16, 2015 Hello, I tried uploading the webhook.zip that you provided and got the following errors in prestashop: webhook (parse error in /modules/webhook/webhook.php) webhook (class missing in /modules/webhook/webhook.php) I was wondering if you could help since I really want to be able to use webhooks in the form you have implemented. I am also surprised such a standard feature isn't available. Link to comment Share on other sites More sharing options...
bpoller Posted May 10, 2016 Share Posted May 10, 2016 Hi, I encountered the same problem. In webhook.php, replacing <?PHP by <?php did the trick for me. Hope this helps someone... Link to comment Share on other sites More sharing options...
stweet Posted November 29, 2017 Share Posted November 29, 2017 up Link to comment Share on other sites More sharing options...
selectshop.at Posted November 29, 2017 Share Posted November 29, 2017 40 minutes ago, stweet said: up This is very old module. Don't think it is working in latest Prestashop versions. Which PS version are you using ? The hack mentioned here before does not work ? On 10.5.2016 at 6:01 PM, bpoller said: Hi, I encountered the same problem. In webhook.php, replacing <?PHP by <?php did the trick for me. Hope this helps someone... Link to comment Share on other sites More sharing options...
stweet Posted November 30, 2017 Share Posted November 30, 2017 looking for similar that works with 1.7 Link to comment Share on other sites More sharing options...
gajofe Posted August 2, 2019 Share Posted August 2, 2019 x2 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