diff --git a/Observer/OrderAddressObserver.php b/Observer/OrderAddressObserver.php index 992dab1..1b1738d 100644 --- a/Observer/OrderAddressObserver.php +++ b/Observer/OrderAddressObserver.php @@ -35,11 +35,6 @@ class OrderAddressObserver implements ObserverInterface */ private $transformService; - /** - * @var OrderService - */ - private $orderService; - /** * @param SeQuraTranslationProvider $translationProvider * @param TransformEntityService $transformService @@ -94,7 +89,11 @@ private function handleAddressUpdate(MagentoAddress $magentoAddress): void $isShippingAddress = $magentoAddress->getAddressType() === 'shipping'; $address = $this->transformService->transformAddressToSeQuraOrderAddress($magentoAddress); - StoreContext::doWithStore($magentoOrder->getStoreId(), [$this->getOrderService(), 'updateOrder'], [ + $orderService = StoreContext::doWithStore($magentoOrder->getStoreId(), function () { + return ServiceRegister::getService(OrderService::class); + }); + + StoreContext::doWithStore($magentoOrder->getStoreId(), [$orderService, 'updateOrder'], [ new OrderUpdateData( $magentoOrder->getIncrementId(), null, null, $isShippingAddress ? $address : null, @@ -103,20 +102,6 @@ private function handleAddressUpdate(MagentoAddress $magentoAddress): void ]); } - /** - * Returns an instance of Order service. - * - * @return OrderService - */ - private function getOrderService(): OrderService - { - if (!isset($this->orderService)) { - $this->orderService = ServiceRegister::getService(OrderService::class); - } - - return $this->orderService; - } - /** * Handles the update address errors. * diff --git a/Observer/OrderCancellationObserver.php b/Observer/OrderCancellationObserver.php index 70c686b..7d40ff5 100644 --- a/Observer/OrderCancellationObserver.php +++ b/Observer/OrderCancellationObserver.php @@ -30,11 +30,6 @@ class OrderCancellationObserver implements ObserverInterface */ private $translationProvider; - /** - * @var OrderService - */ - private $orderService; - /** * @param SeQuraTranslationProvider $translationProvider */ @@ -79,7 +74,11 @@ private function handleCancellation(MagentoOrder $orderData): void throw new LocalizedException($this->translationProvider->translate('sequra.error.cannotCancel')); } - StoreContext::doWithStore($orderData->getStoreId(), [$this->getOrderService(), 'updateOrder'], [ + $orderService = StoreContext::doWithStore($orderData->getStoreId(), function () { + return ServiceRegister::getService(OrderService::class); + }); + + StoreContext::doWithStore($orderData->getStoreId(), [$orderService, 'updateOrder'], [ new OrderUpdateData( $orderData->getIncrementId(), new SeQuraCart($orderData->getOrderCurrencyCode()), @@ -89,20 +88,6 @@ private function handleCancellation(MagentoOrder $orderData): void ]); } - /** - * Returns an instance of Order service. - * - * @return OrderService - */ - private function getOrderService(): OrderService - { - if (!isset($this->orderService)) { - $this->orderService = ServiceRegister::getService(OrderService::class); - } - - return $this->orderService; - } - /** * Handles the order cancellation errors. * diff --git a/Observer/OrderShipmentObserver.php b/Observer/OrderShipmentObserver.php index dfa3130..0ed06da 100644 --- a/Observer/OrderShipmentObserver.php +++ b/Observer/OrderShipmentObserver.php @@ -34,11 +34,6 @@ class OrderShipmentObserver implements ObserverInterface */ private $transformService; - /** - * @var OrderService - */ - private $orderService; - /** * @param SeQuraTranslationProvider $translationProvider * @param TransformEntityService $transformService @@ -89,7 +84,11 @@ private function handleShipment(MagentoShipment $shipmentData): void $unshippedCart = $this->transformService->transformOrderCartToSeQuraCart($orderData, false); $shippedCart = $this->transformService->transformOrderCartToSeQuraCart($orderData, true); - StoreContext::doWithStore($orderData->getStoreId(), [$this->getOrderService(), 'updateOrder'], [ + $orderService = StoreContext::doWithStore($orderData->getStoreId(), function () { + return ServiceRegister::getService(OrderService::class); + }); + + StoreContext::doWithStore($orderData->getStoreId(), [$orderService, 'updateOrder'], [ new OrderUpdateData( $orderData->getIncrementId(), $shippedCart, @@ -100,20 +99,6 @@ private function handleShipment(MagentoShipment $shipmentData): void ]); } - /** - * Returns an instance of Order service. - * - * @return OrderService - */ - private function getOrderService(): OrderService - { - if (!isset($this->orderService)) { - $this->orderService = ServiceRegister::getService(OrderService::class); - } - - return $this->orderService; - } - /** * Handles the order shipment errors. *