3

I am planing to create a web hook in Magento through which Magento will send a alert to the destination upon placing an order using web hook.

  • did you got any solution ? – Pawan Sep 14 '18 at 16:26
  • no I still searching :( – Magento Learner Sep 14 '18 at 16:56
  • Please my answer – Pawan Sep 15 '18 at 2:52
  • how can open module in ui of admin magento 2 – user77182 Feb 19 at 13:07
  • If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review – Mohit Kumar Arora Feb 19 at 13:36
1

First thing there is no web hooks available in Magento. Magento call them Event Observer.

What is an Event: An event can be any action Or state in magento like customer_register_success, sales_order_place_after etc.

What is an Observer: An Observer is a PHP class which listen to events, when events get fire Observer class get activated.

For example we need order details when order get placed.We are going to create a custom module for this say Pawanist_Orderdata

Create following files for module:

app/code/Pawanist/Orderdata/registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Pawanist_Orderdata',
__DIR__
);

app/code/Pawanist/Orderdata/etc/module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Pawanist_Orderdata" setup_version="1.0.1">
   </module>
</config>

app/code/Pawanist/Orderdata/etc/events.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="sales_order_place_after">
    <observer name="sales_pawanist_orderdata" instance="Pawanist\Orderdata\Observer\GetOrderData" />
</event>
</config>

app/code/Pawanist/Orderdata/Observer/GetOrderData.php

<?php

namespace Pawanist\Orderdata\Observer;

use Magento\Framework\Event\ObserverInterface;
use Psr\Log\LoggerInterface;

class GetOrderData implements ObserverInterface
{
 protected $logger;

 public function __construct(LoggerInterface$logger) {
 $this->logger = $logger;
 }

 public function execute(\Magento\Framework\Event\Observer $observer)
 {
    try {
        $order = $observer->getEvent()->getOrder();

        $total = $order->getGrandTotal();//this will log order total
        $this->logger->info($total);

    }catch (\Exception $e) {
        $this->logger->info($e->getMessage());
    }
 }
}

After creating module, you need to activate module using:

- php bin/magento setup:upgrade
- php bin/magento cache:flush
- php bin/magento setup:static-content:deploy (only required in production mode)

Hope above will help!

0

You have to use the Magento Observer feature here and use event sales_order_place_after

You can follow this link to implement this https://meetanshi.com/blog/get-order-data-from-magento-2-sales_order_place_after-event/

0

Try this Webhook module https://www.mageplaza.com/magento-2-webhook/ After creating order, it will send a hook request to any endpoints.

  • but its not support with order status with multiple endpoints. – Anas Mansuri Aug 22 at 12:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.