From 50ecf7a66fa80666b95ef0161ad434a34fb13cf9 Mon Sep 17 00:00:00 2001 From: cjohannsen Date: Tue, 3 Nov 2020 17:19:17 +0100 Subject: [PATCH 1/4] CHANGE OrderStatusService.php - prevent loading the statuses with id lower than 1 --- src/Services/OrderStatusService.php | 41 ++++++++++++++++++----------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/src/Services/OrderStatusService.php b/src/Services/OrderStatusService.php index ed3b00acb..1a820d14b 100644 --- a/src/Services/OrderStatusService.php +++ b/src/Services/OrderStatusService.php @@ -38,7 +38,7 @@ public function __construct(AuthHelper $authHelper, OrderStatusRepositoryContrac $this->orderStatusRepo = $orderStatusRepo; $this->statusHistoryRepo = $statusHistoryRepo; } - + /** * @param int $orderId * @param float $orderStatusId @@ -49,16 +49,17 @@ public function getOrderStatus($orderId, $orderStatusId) $lang = Utils::getLang(); $orderStatusRepo = $this->orderStatusRepo; $statusHistoryRepo = $this->statusHistoryRepo; - $logger = $this->getLogger(__CLASS__); + $logger = $this->getLogger(__CLASS__)->addReference('orderId', $orderId); $orderStatus = $this->authHelper->processUnguarded( function() use ($orderId, $orderStatusId, $lang, $orderStatusRepo, $statusHistoryRepo, $logger) { + $statusHistory = $statusHistoryRepo->getStatusHistoryByOrderId($orderId); $orderStatus = $orderStatusRepo->get($orderStatusId); - if ( !is_null($orderStatus) && $orderStatus->isFrontendVisible ) + if (!is_null($orderStatus) && $orderStatus->isFrontendVisible) { return str_replace('['.$orderStatus->statusId.']', '', $orderStatus->names->get($lang)); } - elseif( !is_null($orderStatus) ) + elseif(!is_null($orderStatus)) { $statusHistory = $statusHistoryRepo->getStatusHistoryByOrderId($orderId); if(count($statusHistory)) @@ -66,16 +67,24 @@ public function getOrderStatus($orderId, $orderStatusId) $statusHistoryNew = []; foreach($statusHistory as $entryKey => $entry) { - try - { - $statusHistoryNew[$entryKey] = $orderStatusRepo->get($entry->statusId); - }catch(\Exception $e) - { - $logger->error("IO::Debug.OrderStatusService_getOrderSatus", [ - 'code' => $e->getCode(), - 'message' => $e->getMessage() - ]); + // status with 0 means the creation of an order is not completed, caused by an error + if ($statusHistory[0]->statusId > 0) { + try + { + $newStatus = $orderStatusRepo->get($entry->statusId); + if ($newStatus->isFrontendVisible) { + $statusHistoryNew[$entryKey] = $newStatus; + } + }catch(\Exception $e) + { + $logger->error("IO::Debug.OrderStatusService_getOrderSatus", [ + 'code' => $e->getCode(), + 'message' => $e->getMessage(), + 'entryKey' => $entryKey + ]); + + } } } @@ -92,10 +101,10 @@ public function getOrderStatus($orderId, $orderStatusId) } } } - + return ''; }); - + return $orderStatus; } -} \ No newline at end of file +} From dc2e7d25a829352b76e86f61aadde98ab891c5a6 Mon Sep 17 00:00:00 2001 From: cjohannsen Date: Tue, 3 Nov 2020 17:19:51 +0100 Subject: [PATCH 2/4] CHANGE OrderStatusService.php - reformat code --- src/Services/OrderStatusService.php | 60 ++++++++++++++--------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/src/Services/OrderStatusService.php b/src/Services/OrderStatusService.php index 1a820d14b..66bcb63d5 100644 --- a/src/Services/OrderStatusService.php +++ b/src/Services/OrderStatusService.php @@ -32,8 +32,11 @@ class OrderStatusService * @param OrderStatusRepositoryContract $orderStatusRepo * @param StatusHistoryRepositoryContract $statusHistoryRepo */ - public function __construct(AuthHelper $authHelper, OrderStatusRepositoryContract $orderStatusRepo, StatusHistoryRepositoryContract $statusHistoryRepo) - { + public function __construct( + AuthHelper $authHelper, + OrderStatusRepositoryContract $orderStatusRepo, + StatusHistoryRepositoryContract $statusHistoryRepo + ) { $this->authHelper = $authHelper; $this->orderStatusRepo = $orderStatusRepo; $this->statusHistoryRepo = $statusHistoryRepo; @@ -46,38 +49,37 @@ public function __construct(AuthHelper $authHelper, OrderStatusRepositoryContrac */ public function getOrderStatus($orderId, $orderStatusId) { - $lang = Utils::getLang(); - $orderStatusRepo = $this->orderStatusRepo; - $statusHistoryRepo = $this->statusHistoryRepo; - $logger = $this->getLogger(__CLASS__)->addReference('orderId', $orderId); + $lang = Utils::getLang(); + $orderStatusRepo = $this->orderStatusRepo; + $statusHistoryRepo = $this->statusHistoryRepo; + $logger = $this->getLogger(__CLASS__)->addReference('orderId', $orderId); - $orderStatus = $this->authHelper->processUnguarded( function() use ($orderId, $orderStatusId, $lang, $orderStatusRepo, $statusHistoryRepo, $logger) - { + $orderStatus = $this->authHelper->processUnguarded(function () use ( + $orderId, + $orderStatusId, + $lang, + $orderStatusRepo, + $statusHistoryRepo, + $logger + ) { $statusHistory = $statusHistoryRepo->getStatusHistoryByOrderId($orderId); $orderStatus = $orderStatusRepo->get($orderStatusId); - if (!is_null($orderStatus) && $orderStatus->isFrontendVisible) - { - return str_replace('['.$orderStatus->statusId.']', '', $orderStatus->names->get($lang)); - } - elseif(!is_null($orderStatus)) - { + if (!is_null($orderStatus) && $orderStatus->isFrontendVisible) { + return str_replace('[' . $orderStatus->statusId . ']', '', $orderStatus->names->get($lang)); + } elseif (!is_null($orderStatus)) { $statusHistory = $statusHistoryRepo->getStatusHistoryByOrderId($orderId); - if(count($statusHistory)) - { + if (count($statusHistory)) { $statusHistoryNew = []; - foreach($statusHistory as $entryKey => $entry) - { + foreach ($statusHistory as $entryKey => $entry) { // status with 0 means the creation of an order is not completed, caused by an error if ($statusHistory[0]->statusId > 0) { - try - { + try { $newStatus = $orderStatusRepo->get($entry->statusId); if ($newStatus->isFrontendVisible) { - $statusHistoryNew[$entryKey] = $newStatus; + $statusHistoryNew[$entryKey] = $newStatus; } - }catch(\Exception $e) - { + } catch (\Exception $e) { $logger->error("IO::Debug.OrderStatusService_getOrderSatus", [ 'code' => $e->getCode(), 'message' => $e->getMessage(), @@ -88,14 +90,12 @@ public function getOrderStatus($orderId, $orderStatusId) } } - if(count($statusHistoryNew)) - { - for($i = count($statusHistoryNew)-1; $i >= 0; $i--) - { + if (count($statusHistoryNew)) { + for ($i = count($statusHistoryNew) - 1; $i >= 0; $i--) { $statusEntry = $statusHistoryNew[$i]; - if($statusEntry instanceof OrderStatus && $statusEntry->statusId < $orderStatusId && $statusEntry->isFrontendVisible) - { - return str_replace('['.$statusEntry->statusId.']', '', $statusEntry->names->get($lang)); + if ($statusEntry instanceof OrderStatus && $statusEntry->statusId < $orderStatusId && $statusEntry->isFrontendVisible) { + return str_replace('[' . $statusEntry->statusId . ']', '', + $statusEntry->names->get($lang)); } } } From fe6c88fdd2bb0e73ea2cd3b592b19d522ea514e3 Mon Sep 17 00:00:00 2001 From: cjohannsen Date: Tue, 3 Nov 2020 17:23:13 +0100 Subject: [PATCH 3/4] CHANGE OrderStatusService.php - correct debug log --- resources/lang/en/Debug.properties | 3 +++ src/Services/OrderStatusService.php | 8 ++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/resources/lang/en/Debug.properties b/resources/lang/en/Debug.properties index 8a641346f..1977c71e2 100644 --- a/resources/lang/en/Debug.properties +++ b/resources/lang/en/Debug.properties @@ -88,6 +88,9 @@ OrderService_orderValidationError = "Error while create new order." OrderService_placeOrder = "New order created." OrderService_returnStatusNotFound = "Status for new return orders does not exist. Created return order with status 9.0" +; OrderStatusService +OrderStatusService_getOrderStatus = "Cannot load status with given id." + ; PlaceOrderController PlaceOrderController_cannotCompleteOrder = "Cannot complete checkout process: An error occurred after creating the order." PlaceOrderController_cannotPlaceOrder = "Cannot place order." diff --git a/src/Services/OrderStatusService.php b/src/Services/OrderStatusService.php index 66bcb63d5..cbfcfae7c 100644 --- a/src/Services/OrderStatusService.php +++ b/src/Services/OrderStatusService.php @@ -74,13 +74,9 @@ public function getOrderStatus($orderId, $orderStatusId) // status with 0 means the creation of an order is not completed, caused by an error if ($statusHistory[0]->statusId > 0) { try { - $newStatus = $orderStatusRepo->get($entry->statusId); - - if ($newStatus->isFrontendVisible) { - $statusHistoryNew[$entryKey] = $newStatus; - } + $statusHistoryNew[$entryKey] = $orderStatusRepo->get($entry->statusId); } catch (\Exception $e) { - $logger->error("IO::Debug.OrderStatusService_getOrderSatus", [ + $logger->error("IO::Debug.OrderStatusService_getOrderStatus", [ 'code' => $e->getCode(), 'message' => $e->getMessage(), 'entryKey' => $entryKey From 8e1a241cb21c7e8765852464a8cf966a91b7c359 Mon Sep 17 00:00:00 2001 From: cjohannsen Date: Tue, 3 Nov 2020 17:36:37 +0100 Subject: [PATCH 4/4] CHANGE OrderStatusService - remove testing code --- src/Services/OrderStatusService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Services/OrderStatusService.php b/src/Services/OrderStatusService.php index cbfcfae7c..0ea985880 100644 --- a/src/Services/OrderStatusService.php +++ b/src/Services/OrderStatusService.php @@ -72,7 +72,7 @@ public function getOrderStatus($orderId, $orderStatusId) $statusHistoryNew = []; foreach ($statusHistory as $entryKey => $entry) { // status with 0 means the creation of an order is not completed, caused by an error - if ($statusHistory[0]->statusId > 0) { + if ($entry->statusId > 0) { try { $statusHistoryNew[$entryKey] = $orderStatusRepo->get($entry->statusId); } catch (\Exception $e) {