https://github.com/magesuite/order-failure-notification
The module sends emails notifying about order failures. The email contains data that can be useful when debugging the cause of failed order.
Installation
This module is optional.
composer require "creativestyle/magesuite-order-failure-notification" ^1.0.0
Admin settings
Admin settings can be found under Stores -> Configuration -> MageSuite -> Order Failure Notification
Settings:
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
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 metioned event will be triggered.
vendor/magento/module-quote/Model/QuoteManagement.php
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
<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
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
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:
Order data
Quote data
Exception message
Exception track
The template is located in: order-failure-notification/view/adminhtml/email/order_failure_notification.html