Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The module sends emails notifying about order failures. The email contains data that can be useful when debugging the cause of failed order.

Table of Contents
minLevel1
maxLevel7

Installation

Info

This module is optional.

...

Field

Options

Comment

Enable notifications for order failure

Yes/No

Default value: No

E-mail address

Multiple e-mail addresses shall be separated with comma

Backend

Note

To be added

There is observer vendor/creativestyle/magesuite-order-failure-notification/Observer/QuoteSubmitFailure.php which observers event sales_model_service_quote_submit_failure

This event is triggered while submitting quote.

If exception appears, addresses will be rollback and after it mentioned event will be triggered.

vendor/magento/module-quote/Model/QuoteManagement.php

Code Block
class QuoteManagement implements CartManagementInterface
{
    public function submit(QuoteEntity $quote, $orderData = [])
    {
        .....

        return $this->submitQuote($quote, $orderData);
    }
    
    protected function submitQuote(QuoteEntity $quote, $orderData = [])
    {
        try {
            $order = $this->orderManagement->place($order);
            .....
        } catch (\Exception $e) {
            $this->rollbackAddresses($quote, $order, $e);
            throw $e;
        }
    }
    
    private function rollbackAddresses(
        QuoteEntity $quote,
        OrderInterface $order,
        \Exception $e
    ): void {
        .....
            $this->eventManager->dispatch(
                'sales_model_service_quote_submit_failure',
                [
                    'order' => $order,
                    'quote' => $quote,
                    'exception' => $e,
                ]
            );
        ......
    }
}

vendor/creativestyle/magesuite-order-failure-notification/etc/events.xml

Code Block
breakoutModewide
<event name="sales_model_service_quote_submit_failure">
    <observer name="quote_submit_failure_notification" instance="MageSuite\OrderFailureNotification\Observer\QuoteSubmitFailure" shared="true" />
</event>

Observer notify about order failure and there email will be send:

vendor/creativestyle/magesuite-order-failure-notification/Observer/QuoteSubmitFailure.php

Code Block
class QuoteSubmitFailure implements \Magento\Framework\Event\ObserverInterface
{
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        if ($this->config->isNotificationEnabled()) {
            $this->notification->orderFailure(
                $this->config->getNotificationRecipients(),
                $observer->getEvent()->getException(),
                $observer->getEvent()->getQuote(),
                $observer->getEvent()->getOrder()
            );
        }
    }
}

vendor/creativestyle/magesuite-order-failure-notification/Service/Notification.php

Code Block
breakoutModewide
class Notification implements NotificationInterface
{
    public function orderFailure($recipients, $exception, $quote, $order)
    {
        try {
            $this->transportBuilder
                ->setTemplateIdentifier(self::EMAIL_TEMPLATE)
                ->setTemplateOptions(
                    [
                        'area' => \Magento\Framework\App\Area::AREA_ADMINHTML,
                        'store' => $this->getStoreId()
                    ]
                )
                ->setTemplateVars(['exception' => $exception, 'quote' => $quote, 'order' => $order])
                ->setFromByScope('general', $this->getStoreId())
                ->addTo($recipients);

            $transport = $this->transportBuilder->getTransport();
            $transport->sendMessage();
        } catch (\Exception $e) {
            $this->logger->error($e->getMessage());
        }
    }
}

Frontend

The notification email contains the following data:

...