From 6eddc30c69a1df23b0c0ecbd40d2f4265194cce3 Mon Sep 17 00:00:00 2001 From: jevgenijvisockij Date: Wed, 17 Apr 2024 13:29:52 +0300 Subject: [PATCH 1/3] Fixing case where with payment fee and multiple orders order status wasn't correct --- src/Service/OrderStatusService.php | 51 +++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/src/Service/OrderStatusService.php b/src/Service/OrderStatusService.php index bfa1dab0a..3b6a90657 100644 --- a/src/Service/OrderStatusService.php +++ b/src/Service/OrderStatusService.php @@ -13,6 +13,8 @@ namespace Mollie\Service; use Configuration; +use Db; +use DbQuery; use Mollie\Api\Types\OrderStatus; use Mollie\Api\Types\PaymentStatus; use Mollie\Config\Config; @@ -102,20 +104,47 @@ public function setOrderStatus($orderId, $statusId, $useExistingPayment = null, $useExistingPayment = !$order->hasInvoice(); } - $history = new OrderHistory(); - $history->id_order = $order->id; - $history->changeIdOrderState($statusId, $orderId, $useExistingPayment); + $orders = Db::getInstance()->executeS( + (new DbQuery()) + ->select('id_order') + ->from('orders') + ->where('id_cart = ' . (int) $order->id_cart) + ); + if (count($orders) > 1) { + foreach ($orders as $orderData) { + $subOrder = new Order($orderData['id_order']); + $history = new OrderHistory(); + $history->id_order = $subOrder->id; + $history->changeIdOrderState($statusId, $subOrder->id, $useExistingPayment); + + $status = OrderStatusUtility::transformPaymentStatusToPaid($status, Config::STATUS_PAID_ON_BACKORDER); + + if ($this->checkIfOrderConfNeedsToBeSend($statusId)) { + $this->mailService->sendOrderConfMail($subOrder, $statusId); + } - $status = OrderStatusUtility::transformPaymentStatusToPaid($status, Config::STATUS_PAID_ON_BACKORDER); + if ('0' === Configuration::get('MOLLIE_MAIL_WHEN_' . Tools::strtoupper($status))) { + $history->add(); + } else { + $history->addWithemail(true, $templateVars); + } + } + } else { + $history = new OrderHistory(); + $history->id_order = $order->id; + $history->changeIdOrderState($statusId, $orderId, $useExistingPayment); - if ($this->checkIfOrderConfNeedsToBeSend($statusId)) { - $this->mailService->sendOrderConfMail($order, $statusId); - } + $status = OrderStatusUtility::transformPaymentStatusToPaid($status, Config::STATUS_PAID_ON_BACKORDER); - if ('0' === Configuration::get('MOLLIE_MAIL_WHEN_' . Tools::strtoupper($status))) { - $history->add(); - } else { - $history->addWithemail(true, $templateVars); + if ($this->checkIfOrderConfNeedsToBeSend($statusId)) { + $this->mailService->sendOrderConfMail($order, $statusId); + } + + if ('0' === Configuration::get('MOLLIE_MAIL_WHEN_' . Tools::strtoupper($status))) { + $history->add(); + } else { + $history->addWithemail(true, $templateVars); + } } } From c75fc72f390f0b38f5841e2b4726844d0f987e96 Mon Sep 17 00:00:00 2001 From: jevgenijvisockij Date: Wed, 17 Apr 2024 13:49:04 +0300 Subject: [PATCH 2/3] Moved order retrieval logic to repository --- src/Repository/OrderRepository.php | 12 ++++++++++++ src/Service/OrderStatusService.php | 18 +++++++----------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/Repository/OrderRepository.php b/src/Repository/OrderRepository.php index 82d43d1f4..281c297f8 100644 --- a/src/Repository/OrderRepository.php +++ b/src/Repository/OrderRepository.php @@ -36,4 +36,16 @@ public function findOneByCartId($id_cart) { return $this->findOneBy(['id_cart' => (int) $id_cart]); } + + /** + * @param int $id_cart + * + * @return \ObjectModel[]|null + * + * @throws \PrestaShopException + */ + public function findAllByCartId($id_cart) + { + return $this->findAllBy(['id_cart' => (int) $id_cart]); + } } diff --git a/src/Service/OrderStatusService.php b/src/Service/OrderStatusService.php index 3b6a90657..47fe0d11c 100644 --- a/src/Service/OrderStatusService.php +++ b/src/Service/OrderStatusService.php @@ -13,11 +13,10 @@ namespace Mollie\Service; use Configuration; -use Db; -use DbQuery; use Mollie\Api\Types\OrderStatus; use Mollie\Api\Types\PaymentStatus; use Mollie\Config\Config; +use Mollie\Repository\OrderRepository; use Mollie\Utility\OrderStatusUtility; use Order; use OrderDetail; @@ -38,9 +37,12 @@ class OrderStatusService */ private $mailService; - public function __construct(MailService $mailService) + private $orderRepository; + + public function __construct(MailService $mailService, OrderRepository $orderRepository) { $this->mailService = $mailService; + $this->orderRepository = $orderRepository; } /** @@ -104,15 +106,9 @@ public function setOrderStatus($orderId, $statusId, $useExistingPayment = null, $useExistingPayment = !$order->hasInvoice(); } - $orders = Db::getInstance()->executeS( - (new DbQuery()) - ->select('id_order') - ->from('orders') - ->where('id_cart = ' . (int) $order->id_cart) - ); + $orders = $this->orderRepository->findAllByCartId($order->id_cart); if (count($orders) > 1) { - foreach ($orders as $orderData) { - $subOrder = new Order($orderData['id_order']); + foreach ($orders as $subOrder) { $history = new OrderHistory(); $history->id_order = $subOrder->id; $history->changeIdOrderState($statusId, $subOrder->id, $useExistingPayment); From f225c3cd0c977386f3732ac23521b4dccc4b1303 Mon Sep 17 00:00:00 2001 From: jevgenijvisockij Date: Tue, 14 May 2024 15:11:30 +0300 Subject: [PATCH 3/3] Stan fix --- src/Repository/OrderRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Repository/OrderRepository.php b/src/Repository/OrderRepository.php index 281c297f8..bca48c021 100644 --- a/src/Repository/OrderRepository.php +++ b/src/Repository/OrderRepository.php @@ -40,7 +40,7 @@ public function findOneByCartId($id_cart) /** * @param int $id_cart * - * @return \ObjectModel[]|null + * @return \PrestaShopCollection * * @throws \PrestaShopException */