Common/Listener/ShipmentNotifyListener.php
protected function watch(OrderShipmentInterface $shipment)
    {
        $order = $shipment->getOrder();

        // Abort if notify disabled
        if (!$order->isAutoNotify()) {
            return;
        }

        if ($shipment->isReturn()) {
            // If state is 'PENDING'
            if ($shipment->getState() === ShipmentStates::STATE_PENDING) {
                // Abort if shipment state has not changed for 'PENDING'
                if (!$this->didStateChangeTo($shipment, ShipmentStates::STATE_PENDING)) {
                    return;
                }

                // Abort if sale has notification of type 'RETURN_PENDING' with same shipment number
                if ($this->hasNotification($order, NotificationTypes::RETURN_PENDING, $shipment->getNumber())) {
                    return;
                }

                $this->notify(NotificationTypes::RETURN_PENDING, $shipment);

                return;
            }

            // Else if state has changed for 'RETURNED'
            if ($shipment->getState() === ShipmentStates::STATE_RETURNED) {
                // Abort if shipment state has not changed for 'RETURNED'
                if (!$this->didStateChangeTo($shipment, ShipmentStates::STATE_RETURNED)) {
                    return;
                }

                // Abort if sale has notification of type 'RETURN_RECEIVED' with same shipment number
                if ($this->hasNotification($order, NotificationTypes::RETURN_RECEIVED, $shipment->getNumber())) {
                    return;
                }

                $this->notify(NotificationTypes::RETURN_RECEIVED, $shipment);
            }

            return;
        }

        // Abort if shipment state has not changed for 'SHIPPED'
        if (!$this->didStateChangeTo($shipment, ShipmentStates::STATE_SHIPPED)) {
            return;
        }

        // Abort if sale has notification of type 'SHIPMENT_SHIPPED' with same shipment number
        if ($this->hasNotification($order, NotificationTypes::SHIPMENT_SHIPPED, $shipment->getNumber())) {
            return;
        }
        // Abort if sale has notification of type 'SHIPMENT_PARTIAL' with same shipment number
        if ($this->hasNotification($order, NotificationTypes::SHIPMENT_SHIPPED, $shipment->getNumber())) {
            return;
        }

        $type = NotificationTypes::SHIPMENT_SHIPPED;
        if ($order->getShipmentState() !== ShipmentStates::STATE_COMPLETED) {
            $type = NotificationTypes::SHIPMENT_PARTIAL;
        }

        $this->notify($type, $shipment);
    }
protected function watch(OrderShipmentInterface $shipment)
    {
        $order = $shipment->getOrder();

        // Abort if notify disabled
        if (!$order->isAutoNotify()) {
            return;
        }

        if ($shipment->isReturn()) {
            // If state is 'PENDING'
            if ($shipment->getState() === ShipmentStates::STATE_PENDING) {
                // Abort if shipment state has not changed for 'PENDING'
                if (!$this->didStateChangeTo($shipment, ShipmentStates::STATE_PENDING)) {
                    return;
                }

                // Abort if sale has notification of type 'RETURN_PENDING' with same shipment number
                if ($this->hasNotification($order, NotificationTypes::RETURN_PENDING, $shipment->getNumber())) {
                    return;
                }

                $this->notify(NotificationTypes::RETURN_PENDING, $shipment);

                return;
            }

            // Else if state has changed for 'RETURNED'
            if ($shipment->getState() === ShipmentStates::STATE_RETURNED) {
                // Abort if shipment state has not changed for 'RETURNED'
                if (!$this->didStateChangeTo($shipment, ShipmentStates::STATE_RETURNED)) {
                    return;
                }

                // Abort if sale has notification of type 'RETURN_RECEIVED' with same shipment number
                if ($this->hasNotification($order, NotificationTypes::RETURN_RECEIVED, $shipment->getNumber())) {
                    return;
                }

                $this->notify(NotificationTypes::RETURN_RECEIVED, $shipment);
            }

            return;
        }

        // Abort if shipment state has not changed for 'SHIPPED'
        if (!$this->didStateChangeTo($shipment, ShipmentStates::STATE_SHIPPED)) {
            return;
        }

        // Abort if sale has notification of type 'SHIPMENT_SHIPPED' with same shipment number
        if ($this->hasNotification($order, NotificationTypes::SHIPMENT_SHIPPED, $shipment->getNumber())) {
            return;
        }
        // Abort if sale has notification of type 'SHIPMENT_PARTIAL' with same shipment number
        if ($this->hasNotification($order, NotificationTypes::SHIPMENT_SHIPPED, $shipment->getNumber())) {
            return;
        }

        $type = NotificationTypes::SHIPMENT_SHIPPED;
        if ($order->getShipmentState() !== ShipmentStates::STATE_COMPLETED) {
            $type = NotificationTypes::SHIPMENT_PARTIAL;
        }

        $this->notify($type, $shipment);
    }
Shipment watcher.

@param OrderShipmentInterface $shipment