Skip to content

Commit

Permalink
RATESWSX-310: prevent bidirectionality if manual deliver/return/cance…
Browse files Browse the repository at this point in the history
…l has been processed
  • Loading branch information
rommelfreddy committed Sep 12, 2024
1 parent 6733ab0 commit 713aa05
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## WIP

* RATESWSX-310: prevent bidirectionality if manual deliver/return/cancel has been processed

## Version 7.0.1 - Released on 2024-06-07

RATESWSX-303: fix admin-session logout endless redirect & make admin-session urls more unified
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ public function onItemsOperationDone(OrderItemOperationDoneEvent $event): void
$canceledItemQty += $position->getCanceled();
}

$event->getContext()->addArrayExtension('ratepay', [
TransitionSubscriber::PREVENT_BIDIRECTIONALITY => true,
]);

try {
if ($fullCanceled && $canceledItemQty > 0) {
$this->onFullCancel($event);
Expand All @@ -108,6 +112,8 @@ public function onItemsOperationDone(OrderItemOperationDoneEvent $event): void
}
} catch (IllegalTransitionException) {
// do nothing.
} finally {
$event->getContext()->removeExtension('ratepay');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

class TransitionSubscriber implements EventSubscriberInterface
{
public const PREVENT_BIDIRECTIONALITY = 'prevent_bidirectionality';

public function __construct(
private readonly EntityRepository $orderDeliveryRepository,
private readonly EntityRepository $orderRepository,
Expand All @@ -58,6 +60,12 @@ public function onTransition(StateMachineTransitionEvent $event): void
return;
}

/** @var ArrayStruct|null $struct */
$struct = $event->getContext()->getExtension('ratepay');
if ($struct?->get(self::PREVENT_BIDIRECTIONALITY) === true) {
return;
}

/** @var OrderDeliveryEntity $orderDelivery */
$orderDelivery = $this->orderDeliveryRepository->search(new Criteria([$event->getEntityId()]), $event->getContext())->first();
/** @var OrderEntity $order */
Expand Down

0 comments on commit 713aa05

Please sign in to comment.