Magento 2 event/observer for create shipment

半城伤御伤魂 提交于 2021-02-19 06:05:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!