-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor #488 [Cart] Simplify cart recalculation after customer cart …
…assignment (lchrusciel) This PR was merged into the 1.0-dev branch. Discussion ---------- Closing #401, #259 and #406 Commits ------- f80d609 [Customer] Refactor customer assignment to command bf72278 [Cart] Simplify cart recalculation after customer cart assignment e97cd65 [Cart] Auto assign customer to cart during cart pick up
- Loading branch information
Showing
14 changed files
with
219 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace spec\Sylius\ShopApiPlugin\Event; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
|
||
final class CartPickedUpSpec extends ObjectBehavior | ||
{ | ||
function let(): void | ||
{ | ||
$this->beConstructedWith('ORDERTOKEN'); | ||
} | ||
|
||
function it_has_order_token(): void | ||
{ | ||
$this->orderToken()->shouldReturn('ORDERTOKEN'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace spec\Sylius\ShopApiPlugin\EventListener\Messenger; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
use Prophecy\Argument; | ||
use Sylius\Component\Core\Model\CustomerInterface; | ||
use Sylius\Component\Core\Model\ShopUserInterface; | ||
use Sylius\ShopApiPlugin\Command\Cart\AssignCustomerToCart; | ||
use Sylius\ShopApiPlugin\Event\CartPickedUp; | ||
use Sylius\ShopApiPlugin\Provider\LoggedInShopUserProviderInterface; | ||
use Symfony\Component\Messenger\Envelope; | ||
use Symfony\Component\Messenger\MessageBusInterface; | ||
|
||
final class CartPickedUpListenerSpec extends ObjectBehavior | ||
{ | ||
function let(LoggedInShopUserProviderInterface $loggedInShopUserProvider, MessageBusInterface $bus): void | ||
{ | ||
$this->beConstructedWith($loggedInShopUserProvider, $bus); | ||
} | ||
|
||
function it_assigns_customer_to_cart_when_user_is_logged_in( | ||
LoggedInShopUserProviderInterface $loggedInShopUserProvider, | ||
MessageBusInterface $bus, | ||
ShopUserInterface $shopUser, | ||
CustomerInterface $customer | ||
): void { | ||
$loggedInShopUserProvider->isUserLoggedIn()->willReturn(true); | ||
|
||
$loggedInShopUserProvider->provide()->willReturn($shopUser); | ||
$shopUser->getCustomer()->willReturn($customer); | ||
$customer->getEmail()->willReturn('peter@parker.com'); | ||
|
||
$assignCustomerToCart = new AssignCustomerToCart('ORDERTOKEN', 'peter@parker.com'); | ||
|
||
$bus->dispatch($assignCustomerToCart)->willReturn(new Envelope($assignCustomerToCart))->shouldBeCalled(); | ||
|
||
$this(new CartPickedUp('ORDERTOKEN')); | ||
} | ||
|
||
function it_does_nothing_if_user_is_not_logged_in( | ||
LoggedInShopUserProviderInterface $loggedInShopUserProvider, | ||
MessageBusInterface $bus | ||
): void { | ||
$loggedInShopUserProvider->isUserLoggedIn()->willReturn(false); | ||
|
||
$bus->dispatch(Argument::any())->shouldNotBeCalled(); | ||
|
||
$this(new CartPickedUp('ORDERTOKEN')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\ShopApiPlugin\Event; | ||
|
||
class CartPickedUp | ||
{ | ||
/** @var string */ | ||
protected $orderToken; | ||
|
||
public function __construct(string $orderToken) | ||
{ | ||
$this->orderToken = $orderToken; | ||
} | ||
|
||
public function orderToken(): string | ||
{ | ||
return $this->orderToken; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\ShopApiPlugin\EventListener\Messenger; | ||
|
||
use Sylius\ShopApiPlugin\Command\Cart\AssignCustomerToCart; | ||
use Sylius\ShopApiPlugin\Event\CartPickedUp; | ||
use Sylius\ShopApiPlugin\Provider\LoggedInShopUserProviderInterface; | ||
use Symfony\Component\Messenger\MessageBusInterface; | ||
|
||
final class CartPickedUpListener | ||
{ | ||
/** @var LoggedInShopUserProviderInterface */ | ||
private $loggedInShopUserProvider; | ||
|
||
/** @var MessageBusInterface */ | ||
private $bus; | ||
|
||
public function __construct(LoggedInShopUserProviderInterface $loggedInShopUserProvider, MessageBusInterface $bus) | ||
{ | ||
$this->loggedInShopUserProvider = $loggedInShopUserProvider; | ||
$this->bus = $bus; | ||
} | ||
|
||
public function __invoke(CartPickedUp $cartPickedUp): void | ||
{ | ||
if (!$this->loggedInShopUserProvider->isUserLoggedIn()) { | ||
return; | ||
} | ||
|
||
$shopUser = $this->loggedInShopUserProvider->provide(); | ||
$email = $shopUser->getCustomer()->getEmail(); | ||
|
||
$this->bus->dispatch(new AssignCustomerToCart($cartPickedUp->orderToken(), $email)); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.