Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ASD-1227]: Order in status cancelled on Magento2 (ver. 2.4.6-p5) #1258

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cron/CleanUpIncompleteSessions.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ protected function processTransaction(array $transactionData)
$this->logger->info(self::LOG_PREFIX . 'Cleaning up checkout session id: ' . $checkoutSessionId);

try {

// Check current state of Amazon checkout session
$amazonSession = $this->amazonPayAdapter->getCheckoutSession(null, $checkoutSessionId);
$state = $amazonSession['statusDetails']['state'] ?? false;
Expand All @@ -126,7 +125,8 @@ protected function processTransaction(array $transactionData)
$logMessage = 'Checkout session Canceled, cancelling order and closing transaction: ';
$logMessage .= $checkoutSessionId;
$this->logger->info(self::LOG_PREFIX . $logMessage);
$this->cancelOrder($orderId);
$cancelledMessage = $this->checkoutSessionManagement->getCanceledMessage($amazonSession);
$this->cancelOrder($orderId, $cancelledMessage);
$this->transactionHelper->closeTransaction($transactionData['transaction_id']);
break;
case self::SESSION_STATUS_STATE_OPEN:
Expand All @@ -153,12 +153,12 @@ protected function processTransaction(array $transactionData)
* @param int $orderId
* @return void
*/
protected function cancelOrder($orderId)
protected function cancelOrder($orderId, $reasonMessage = '')
{
$order = $this->loadOrder($orderId);

if ($order) {
$this->checkoutSessionManagement->cancelOrder($order);
$this->checkoutSessionManagement->cancelOrder($order, null, $reasonMessage);
} else {
$this->logger->error(self::LOG_PREFIX . 'Order not found for ID: ' . $orderId);
}
Expand Down
17 changes: 10 additions & 7 deletions Model/CheckoutSessionManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -704,11 +704,6 @@ public function cancelOrder($order, $quote = null, $reasonMessage = '')
// decrement coupon usages if applicable
$this->updateCouponUsages->execute($order, false);

// delete order comments and add new one
foreach ($order->getStatusHistories() as $history) {
$history->delete();
}

if (!$reasonMessage) {
$reasonMessage = __('Something went wrong. Choose another payment method for checkout and try again.');
}
Expand Down Expand Up @@ -790,7 +785,9 @@ public function completeCheckoutSession($amazonSessionId, $cartId = null, $order
} catch (\Exception $e) {
if (isset($order)) {
$this->closeChargePermission($amazonSessionId, $order, $e);
$this->cancelOrder($order, $quote);
$session = $this->getAmazonSession($amazonSessionId);
$cancelledMessage = $this->getCanceledMessage($session);
$this->cancelOrder($order, $quote, $cancelledMessage);
$this->magentoCheckoutSession->restoreQuote();
}

Expand Down Expand Up @@ -1315,7 +1312,13 @@ private function handlePayment($amazonSessionId, $amazonCheckoutResult, $order,
} catch (\Exception $e) {
$this->closeChargePermission($amazonSessionId, $order, $e);

$this->cancelOrder($order, $quote);
$session = $this->amazonAdapter->getCheckoutSession(
$order->getStoreId(),
$amazonSessionId
);

$cancelledMessage = $this->getCanceledMessage($session);
$this->cancelOrder($order, $quote, $cancelledMessage);
$this->magentoCheckoutSession->restoreQuote();

$logEntryDetails = 'amazonSessionId: ' . $amazonSessionId
Expand Down