Skip to content

Commit

Permalink
minor #591 [Cart] Dispatch CartPickedUp after doctrine transaction (l…
Browse files Browse the repository at this point in the history
…chrusciel)

This PR was merged into the 1.0-dev branch.

Discussion
----------



Commits
-------

93bd29a [Cart] Dispatch CartPickedUp after doctrine transaction
  • Loading branch information
Zales0123 authored Nov 23, 2019
2 parents dd9bdd7 + 93bd29a commit 7b03034
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
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

0 comments on commit 7b03034

Please sign in to comment.