Skip to content

Commit

Permalink
Merge pull request #906 from mollie/PIPRES-363
Browse files Browse the repository at this point in the history
PIPRES-363: Fixed case with split orders where status wasn't correct
  • Loading branch information
JevgenijVisockij authored May 14, 2024
2 parents d70f454 + f225c3c commit 8436ac1
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 11 deletions.
12 changes: 12 additions & 0 deletions src/Repository/OrderRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,16 @@ public function findOneByCartId($id_cart)
{
return $this->findOneBy(['id_cart' => (int) $id_cart]);
}

/**
* @param int $id_cart
*
* @return \PrestaShopCollection
*
* @throws \PrestaShopException
*/
public function findAllByCartId($id_cart)
{
return $this->findAllBy(['id_cart' => (int) $id_cart]);
}
}
47 changes: 36 additions & 11 deletions src/Service/OrderStatusService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
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;
Expand All @@ -36,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;
}

/**
Expand Down Expand Up @@ -102,20 +106,41 @@ public function setOrderStatus($orderId, $statusId, $useExistingPayment = null,
$useExistingPayment = !$order->hasInvoice();
}

$history = new OrderHistory();
$history->id_order = $order->id;
$history->changeIdOrderState($statusId, $orderId, $useExistingPayment);
$orders = $this->orderRepository->findAllByCartId($order->id_cart);
if (count($orders) > 1) {
foreach ($orders as $subOrder) {
$history = new OrderHistory();
$history->id_order = $subOrder->id;
$history->changeIdOrderState($statusId, $subOrder->id, $useExistingPayment);

$status = OrderStatusUtility::transformPaymentStatusToPaid($status, Config::STATUS_PAID_ON_BACKORDER);
$status = OrderStatusUtility::transformPaymentStatusToPaid($status, Config::STATUS_PAID_ON_BACKORDER);

if ($this->checkIfOrderConfNeedsToBeSend($statusId)) {
$this->mailService->sendOrderConfMail($order, $statusId);
}
if ($this->checkIfOrderConfNeedsToBeSend($statusId)) {
$this->mailService->sendOrderConfMail($subOrder, $statusId);
}

if ('0' === Configuration::get('MOLLIE_MAIL_WHEN_' . Tools::strtoupper($status))) {
$history->add();
if ('0' === Configuration::get('MOLLIE_MAIL_WHEN_' . Tools::strtoupper($status))) {
$history->add();
} else {
$history->addWithemail(true, $templateVars);
}
}
} else {
$history->addWithemail(true, $templateVars);
$history = new OrderHistory();
$history->id_order = $order->id;
$history->changeIdOrderState($statusId, $orderId, $useExistingPayment);

$status = OrderStatusUtility::transformPaymentStatusToPaid($status, Config::STATUS_PAID_ON_BACKORDER);

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 8436ac1

Please sign in to comment.