1

Magento 2.3.3

When the shipment is created from the admin (see https://i.stack.imgur.com/nII0M.png), a shipment mail is sent out to the customer. I tried searching for that mail sending part in the code in Magento\Shipping\Controller\Adminhtml\Order\Shipment\Save.php but wasnt able to find it.

Any idea where the mail is being sent to the customer when the "submit shipment" button is clicked?

Thanks!

2
  • Since the 'Email Copy' button is unchecked in the screenshot, it should not send any shipment email. This means probably you have a custom code written for the shipment email. Try to check if there is any observer written for sales_order_shipment_save_after event or similar ones. Jul 6, 2020 at 10:54
  • Yes, right, but I need the code anyway, because I want to send the mail at another place. So do you have any idea where I can find the actual code?
    – EOB
    Jul 6, 2020 at 21:16

1 Answer 1

0

Please go to your admin panel.

in the left menu select Stores and under the Settings submenu select Configuration

Under Sales select "Sales Emails" enter image description here

Scroll down until you find the "Shipment" sction in here disable it like the image below:

enter image description here

This should solve your issue ;)

UPDATE: Place where email is sent

The code that will send the email is in: CLASS: Magento\Sales\Model\Order\Email\Sender

Path to file: \vendor\magento\module-sales\Model\Order\Email\Sender\ShipmentSender.php

public function send(Shipment $shipment, $forceSyncMode = false)
    {
        $shipment->setSendEmail($this->identityContainer->isEnabled());

        if (!$this->globalConfig->getValue('sales_email/general/async_sending') || $forceSyncMode) {
            $order = $shipment->getOrder();
            $this->identityContainer->setStore($order->getStore());

            $transport = [
                'order' => $order,
                'shipment' => $shipment,
                'comment' => $shipment->getCustomerNoteNotify() ? $shipment->getCustomerNote() : '',
                'billing' => $order->getBillingAddress(),
                'payment_html' => $this->getPaymentHtml($order),
                'store' => $order->getStore(),
                'formattedShippingAddress' => $this->getFormattedShippingAddress($order),
                'formattedBillingAddress' => $this->getFormattedBillingAddress($order),
                'order_data' => [
                    'customer_name' => $order->getCustomerName(),
                    'is_not_virtual' => $order->getIsNotVirtual(),
                    'email_customer_note' => $order->getEmailCustomerNote(),
                    'frontend_status_label' => $order->getFrontendStatusLabel()
                ]
            ];
            $transportObject = new DataObject($transport);

            /**
             * Event argument `transport` is @deprecated. Use `transportObject` instead.
             */
            $this->eventManager->dispatch(
                'email_shipment_set_template_vars_before',
                ['sender' => $this, 'transport' => $transportObject->getData(), 'transportObject' => $transportObject]
            );

            $this->templateContainer->setTemplateVars($transportObject->getData());

            if ($this->checkAndSend($order)) {
                $shipment->setEmailSent(true);
                $this->shipmentResource->saveAttribute($shipment, ['send_email', 'email_sent']);
                return true;
            }
        } else {
            $shipment->setEmailSent(null);
            $this->shipmentResource->saveAttribute($shipment, 'email_sent');
        }

        $this->shipmentResource->saveAttribute($shipment, 'send_email');

        return false;
    }
2
  • Yes, right, but I need the code anyway, because I want to send the mail at another place. So do you have any idea where I can find the actual code?
    – EOB
    Jul 6, 2020 at 21:16
  • updated my answer with the path / code that sends the shipment email. let me know if you need any further asistance ;) Oh and don't forget to upvote/mark as answer if this solved your problem :)
    – Joao71
    Jul 7, 2020 at 10:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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