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

[Cart] Dispatch CartPickedUp after doctrine transaction #591

Merged
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
3 changes: 2 additions & 1 deletion spec/Handler/Cart/PickupCartHandlerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Sylius\ShopApiPlugin\Handler\Cart\PickupCartHandler;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Messenger\Stamp\DispatchAfterCurrentBusStamp;

final class PickupCartHandlerSpec extends ObjectBehavior
{
Expand Down Expand Up @@ -66,7 +67,7 @@ function it_handles_cart_pickup_for_not_logged_in_user(

$cartPickedUp = new CartPickedUp('ORDERTOKEN');

$eventBus->dispatch($cartPickedUp)->willReturn(new Envelope($cartPickedUp))->shouldBeCalled();
$eventBus->dispatch($cartPickedUp, [new DispatchAfterCurrentBusStamp()])->willReturn(new Envelope($cartPickedUp))->shouldBeCalled();

$this(new PickupCart('ORDERTOKEN', 'CHANNEL_CODE'));
}
Expand Down
3 changes: 2 additions & 1 deletion src/Handler/Cart/PickupCartHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Sylius\ShopApiPlugin\Command\Cart\PickupCart;
use Sylius\ShopApiPlugin\Event\CartPickedUp;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Messenger\Stamp\DispatchAfterCurrentBusStamp;
use Webmozart\Assert\Assert;

final class PickupCartHandler
Expand Down Expand Up @@ -56,6 +57,6 @@ public function __invoke(PickupCart $pickupCart): void

$this->cartRepository->add($cart);

$this->eventBus->dispatch(new CartPickedUp($pickupCart->orderToken()));
$this->eventBus->dispatch(new CartPickedUp($pickupCart->orderToken()), [new DispatchAfterCurrentBusStamp()]);
}
}
1 change: 1 addition & 0 deletions src/Resources/config/app/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ framework:
sylius_shop_api_plugin.command_bus:
middleware:
- doctrine_transaction
- messenger.middleware.dispatch_after_current_bus
sylius_shop_api_plugin.event_bus:
default_middleware: allow_no_handlers

Expand Down