Skip to content

Commit

Permalink
Moved order retrieval logic to repository
Browse files Browse the repository at this point in the history
  • Loading branch information
JevgenijVisockij committed Apr 17, 2024
1 parent 6eddc30 commit c75fc72
Show file tree
Hide file tree
Showing 2 changed files with 19 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 \ObjectModel[]|null
*
* @throws \PrestaShopException
*/
public function findAllByCartId($id_cart)
{
return $this->findAllBy(['id_cart' => (int) $id_cart]);

Check failure on line 49 in src/Repository/OrderRepository.php

View workflow job for this annotation

GitHub Actions / PHPStan (1.7.6.8)

Method Mollie\Repository\OrderRepository::findAllByCartId() should return array<ObjectModel>|null but returns PrestaShopCollection|null.

Check failure on line 49 in src/Repository/OrderRepository.php

View workflow job for this annotation

GitHub Actions / PHPStan (1.7.7.0)

Method Mollie\Repository\OrderRepository::findAllByCartId() should return array<ObjectModel>|null but returns PrestaShopCollection|null.
}
}
18 changes: 7 additions & 11 deletions src/Service/OrderStatusService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit c75fc72

Please sign in to comment.