问题
I'm trying to send an SMS notification to the client after creating a shipment.
In M1 I can do that with this event:
<sales_order_shipment_save_after>
But in Magento 2 there is no event triggering after creating the shipment.
Can anyone advise me, please?
回答1:
you can use sales_order_shipment_save_after event
for this you need to create etc/events.xml file to define your event
<?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_shipment_save_after">
<observer name="emizentechshipment" instance="Emizentech\MyModule\Observer\ProcessShipment" />
</event>
</config>
than you need to create Observer\ProcessShipment.php file
<?php
namespace Emizentech\MyModule\Observer;
use Magento\Framework\Event\ObserverInterface;
class ProcessShipment implements ObserverInterface
{
/**
*
* @param \Magento\Framework\Event\Observer $observer
* @return $this
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
$shipment = $observer->getEvent()->getShipment();
$order = $shipment->getOrder();
// your code for sms here
}
}
来源:https://stackoverflow.com/questions/37371650/magento-2-event-observer-for-create-shipment