|
11 | 11 | use Magento\Framework\Event\Observer;
|
12 | 12 | use Magento\Framework\Event\ObserverInterface;
|
13 | 13 | use Psr\Log\LoggerInterface;
|
14 |
| -use Throwable; |
| 14 | +use Exception; |
15 | 15 |
|
16 | 16 | /**
|
17 | 17 | * Save order extension data.
|
@@ -72,27 +72,27 @@ public function __construct(
|
72 | 72 | */
|
73 | 73 | public function execute(Observer $observer)
|
74 | 74 | {
|
| 75 | + $order = $observer->getEvent()->getOrder(); |
| 76 | + if ($order->getPayment()->getMethod() !== Service::CODE) { |
| 77 | + return; |
| 78 | + } |
| 79 | + $orderId = (int)$order->getEntityId(); |
| 80 | + $publicOrderId = $this->checkoutSession->getBoldCheckoutData()['data']['public_order_id'] ?? null; |
| 81 | + $this->checkoutSession->setBoldCheckoutData(null); |
| 82 | + if (!$publicOrderId) { |
| 83 | + $this->logger->error('Public order id for order ID = ' . $order->getId() . 'is missing.'); |
| 84 | + return; |
| 85 | + } |
| 86 | + $orderExtensionData = $this->orderExtensionDataFactory->create(); |
| 87 | + $orderExtensionData->setOrderId($orderId); |
| 88 | + $orderExtensionData->setPublicId($publicOrderId); |
| 89 | + $this->eventManager->dispatch( |
| 90 | + 'checkout_save_order_extension_data_before', |
| 91 | + ['order' => $order, 'orderExtensionData' => $orderExtensionData] |
| 92 | + ); |
75 | 93 | try {
|
76 |
| - $order = $observer->getEvent()->getOrder(); |
77 |
| - if ($order->getPayment()->getMethod() !== Service::CODE) { |
78 |
| - return; |
79 |
| - } |
80 |
| - $orderId = (int)$order->getEntityId(); |
81 |
| - $publicOrderId = $this->checkoutSession->getBoldCheckoutData()['data']['public_order_id'] ?? null; |
82 |
| - $this->checkoutSession->setBoldCheckoutData(null); |
83 |
| - if (!$publicOrderId) { |
84 |
| - $this->logger->error('Public order id for order ID = ' . $order->getId() . 'is missing.'); |
85 |
| - return; |
86 |
| - } |
87 |
| - $orderExtensionData = $this->orderExtensionDataFactory->create(); |
88 |
| - $orderExtensionData->setOrderId($orderId); |
89 |
| - $orderExtensionData->setPublicId($publicOrderId); |
90 |
| - $this->eventManager->dispatch( |
91 |
| - 'checkout_save_order_extension_data_before', |
92 |
| - ['order' => $order, 'orderExtensionData' => $orderExtensionData] |
93 |
| - ); |
94 | 94 | $this->orderExtensionDataResource->save($orderExtensionData);
|
95 |
| - } catch (Throwable $e) { |
| 95 | + } catch (Exception $e) { |
96 | 96 | $this->logger->error($e->getMessage());
|
97 | 97 | return;
|
98 | 98 | }
|
|
0 commit comments