Skip to content

Commit

Permalink
Fixing case where with payment fee and multiple orders order status w…
Browse files Browse the repository at this point in the history
…asn't correct
  • Loading branch information
JevgenijVisockij committed Apr 17, 2024
1 parent 243afb2 commit 6eddc30
Showing 1 changed file with 40 additions and 11 deletions.
51 changes: 40 additions & 11 deletions src/Service/OrderStatusService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}

Expand Down

0 comments on commit 6eddc30

Please sign in to comment.