Skip to content

Commit

Permalink
PLUG-105: Create new quote for customers and set it as active after d…
Browse files Browse the repository at this point in the history
…eleting the previously active quote.
  • Loading branch information
lighe committed May 9, 2024
1 parent 631ef30 commit 6d12cd5
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Service/Order/ProcessReturn.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Sales\Model\Order;
use Magento\Quote\Api\CartManagementInterface;
use TrueLayer\Connect\Api\Log\RepositoryInterface as LogRepository;
use TrueLayer\Connect\Api\Transaction\RepositoryInterface as TransactionRepository;
use TrueLayer\Connect\Service\Api\GetClient;
Expand Down Expand Up @@ -58,6 +59,10 @@ class ProcessReturn
* @var LogRepository
*/
private $logger;
/**
* @var CartManagementInterface
*/
private $cartManagement;

/**
* ProcessReturn constructor.
Expand All @@ -76,6 +81,7 @@ public function __construct(
CartRepositoryInterface $quoteRepository,
OrderInterface $orderInterface,
OrderRepositoryInterface $orderRepository,
CartManagementInterface $cartManagement,
TransactionRepository $transactionRepository,
LogRepository $logger
) {
Expand All @@ -84,6 +90,7 @@ public function __construct(
$this->quoteRepository = $quoteRepository;
$this->orderInterface = $orderInterface;
$this->orderRepository = $orderRepository;
$this->cartManagement = $cartManagement;
$this->transactionRepository = $transactionRepository;
$this->logger = $logger;
}
Expand Down Expand Up @@ -139,7 +146,7 @@ public function execute(string $transactionId): array
/**
* @param CartInterface $quote
* @param Order $order
* @return void
* @throws \Magento\Framework\Exception\CouldNotSaveException
*/
private function updateCheckoutSession(CartInterface $quote, Order $order): void
{
Expand All @@ -150,6 +157,7 @@ private function updateCheckoutSession(CartInterface $quote, Order $order): void
try {
$activeQuote = $this->quoteRepository->getActiveForCustomer($customerId);
$this->quoteRepository->delete($activeQuote);
$this->cartManagement->createEmptyCartForCustomer($customerId);
} catch (NoSuchEntityException $e) {
$this->logger->addErrorLog('Remove customer quote', $e->getMessage());
}
Expand Down

0 comments on commit 6d12cd5

Please sign in to comment.