diff --git a/spec/ViewRepository/Cart/CartViewRepositorySpec.php b/spec/ViewRepository/Cart/CartViewRepositorySpec.php new file mode 100644 index 000000000..909d29814 --- /dev/null +++ b/spec/ViewRepository/Cart/CartViewRepositorySpec.php @@ -0,0 +1,39 @@ +beConstructedWith($cartRepository, $cartViewFactory); + } + + function it_is_cart_query(): void + { + $this->shouldImplement(CartViewRepositoryInterface::class); + } + + function it_provides_cart_view( + OrderRepositoryInterface $cartRepository, + CartViewFactoryInterface $cartViewFactory, + OrderInterface $cart, + CartSummaryView $cartView + ): void { + $cartRepository->findOneBy(['tokenValue' => 'ORDERTOKEN', 'state' => 'cart'])->willReturn($cart); + $cart->getLocaleCode()->willReturn('en_GB'); + + $cartViewFactory->create($cart, 'en_GB')->willReturn($cartView); + + $this->getOneByToken('ORDERTOKEN')->shouldReturn($cartView); + } +} diff --git a/src/ViewRepository/Cart/CartViewRepository.php b/src/ViewRepository/Cart/CartViewRepository.php index 5dea01085..e41c4f327 100644 --- a/src/ViewRepository/Cart/CartViewRepository.php +++ b/src/ViewRepository/Cart/CartViewRepository.php @@ -29,13 +29,8 @@ public function __construct( public function getOneByToken(string $token): CartSummaryView { - /** @var OrderInterface $cart */ - $cart = $this->cartRepository->createCartQueryBuilder() - ->andWhere('o.tokenValue = :tokenValue') - ->setParameter('tokenValue', $token) - ->getQuery() - ->getOneOrNullResult(); - + /** @var OrderInterface|null $cart */ + $cart = $this->cartRepository->findOneBy(['tokenValue' => $token, 'state' => OrderInterface::STATE_CART]); Assert::notNull($cart, 'Cart with given id does not exists'); return $this->cartViewFactory->create($cart, $cart->getLocaleCode());