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); + } } }