Skip to content

Commit

Permalink
fixes token being seen as already used when not completing order
Browse files Browse the repository at this point in the history
  • Loading branch information
kingjia90 committed Sep 1, 2023
1 parent ace8119 commit 08b4e57
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/OrderManager/V7/OrderManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,9 @@ public function recreateOrder(CartInterface $cart): AbstractOrder
$sourceOrder = $this->getOrderFromCart($cart);

if ($sourceOrder) {
$tokens = $sourceOrder->getVoucherTokens();
$tokenVersionNote = '';

//create new order object
$tempOrdernumber = $this->createOrderNumber();
$order = $this->getNewOrderObject();
Expand All @@ -307,10 +310,21 @@ public function recreateOrder(CartInterface $cart): AbstractOrder
$order->setOrderdate(new Carbon());
$order->setCartId($sourceOrder->getCartId());

if ($tokens) {
$tokenVersionNote = ' Token previously added but removed: ';
foreach ($tokens as $token) {
$this->voucherService->removeAppliedTokenFromOrder($token, $sourceOrder);
$this->voucherService->applyToken($token->getToken(), $cart, $order);
$tokenVersionNote .= '"' . $token->getToken() . '"';
}
}

$order->save(['versionNote' => 'OrderManager::recreateOrder.']);

$sourceOrder->setSuccessorOrder($order);
$sourceOrder->save(['versionNote' => 'OrderManager::recreateOrder - save successor order.']);
$sourceOrder->save([
'versionNote' => 'OrderManager::recreateOrder - save successor order.'. $tokenVersionNote
]);
}

return $this->getOrCreateOrderFromCart($cart);
Expand Down

0 comments on commit 08b4e57

Please sign in to comment.