/** * @param GenericEvent $event */ public function ensureReviewHasAuthor(GenericEvent $event) { if (!($subject = $event->getSubject()) instanceof ReviewInterface) { throw new UnexpectedTypeException($subject, ReviewInterface::class); } if (null !== $subject->getAuthor()) { return; } $subject->setAuthor($this->customerContext->getCustomer()); }
/** * {@inheritdoc} */ public function getCart() { try { $channel = $this->channelContext->getChannel(); } catch (ChannelNotFoundException $exception) { throw new CartNotFoundException('Sylius was not able to find the cart, as there is no current channel.'); } $customer = $this->customerContext->getCustomer(); if (null === $customer) { throw new CartNotFoundException('Sylius was not able to find the cart, as there is no logged in user.'); } $cart = $this->orderRepository->findLatestCartByChannelAndCustomer($channel, $customer); if (null === $cart) { throw new CartNotFoundException('Sylius was not able to find the cart for currently logged in user.'); } return $cart; }
function it_gets_current_customer_from_context(CustomerContextInterface $customerContext, CustomerInterface $customer) { $customerContext->getCustomer()->willReturn($customer); $this->getCustomer()->shouldReturn($customer); }
function it_throws_exception_if_there_is_no_logged_in_customer(CustomerContextInterface $customerContext) { $customerContext->getCustomer()->willReturn(null); $this->shouldThrow(new CartNotFoundException('Sylius was not able to find the cart, as there is no logged in user.'))->during('getCart', []); }
/** * {@inheritdoc} */ public function getCustomer() { return $this->customerContext->getCustomer(); }