Skip to content

Commit

Permalink
Fix order cancellation when source items have been removed
Browse files Browse the repository at this point in the history
  • Loading branch information
convenient committed Jul 14, 2023
1 parent 9a95e10 commit 9cbfbb7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Observer/CancelOrderItemObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ public function execute(EventObserver $observer): void
return;
}

$this->executeSourceDeductionForItems->executeSourceDeductionForItems($orderItem, $itemsToCancel);
$this->executeSourceDeductionForItems->executeSourceDeductionForItems($orderItem, $itemsToCancel, true);
}
}
11 changes: 9 additions & 2 deletions src/Service/ExecuteSourceDeductionForItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,10 @@ public function __construct(
/**
* @param OrderItem $orderItem
* @param array $itemsToCancel
* @param bool $graceful
* @throws NoSuchEntityException
*/
public function executeSourceDeductionForItems(OrderItem $orderItem, array $itemsToCancel)
public function executeSourceDeductionForItems(OrderItem $orderItem, array $itemsToCancel, bool $graceful = false)
{
$order = $orderItem->getOrder();

Expand Down Expand Up @@ -163,7 +164,13 @@ public function executeSourceDeductionForItems(OrderItem $orderItem, array $item
'salesEvent' => $salesEvent
]);

$this->sourceDeductionService->execute($sourceDeductionRequest);
try {
$this->sourceDeductionService->execute($sourceDeductionRequest);
} catch (NoSuchEntityException $noSuchEntityException) {
if (!$graceful) {
throw $noSuchEntityException;
}
}
}
}

Expand Down

0 comments on commit 9cbfbb7

Please sign in to comment.