/** * @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 setCurrencyCode($currencyCode) { if (null === ($customer = $this->customerContext->getCustomer())) { $channel = $this->channelContext->getChannel(); return $this->storage->setData($this->getStorageKey($channel->getCode()), $currencyCode); } $customer->setCurrencyCode($currencyCode); $this->customerManager->persist($customer); $this->customerManager->flush(); }
/** * @param array $rawData * @param FormInterface $form * * @return CustomerInterface|null */ protected function getCustomerFromProperSource(array $rawData, FormInterface $form) { if (null !== ($customer = $this->customerContext->getCustomer())) { $form->remove('email'); return $customer; } if (!isset($rawData['email'])) { return null; } return $this->createCustomerIfNecessary($rawData['email']); }
/** * @param GenericEvent $event */ public function setCustomer(GenericEvent $event) { $resource = $event->getSubject(); if (!$resource instanceof CustomerAwareInterface) { throw new UnexpectedTypeException($resource, CustomerAwareInterface::class); } if (null === ($customer = $this->customerContext->getCustomer())) { return; } $resource->setCustomer($customer); }
/** * @param GenericEvent $event */ public function setCustomer(GenericEvent $event) { if ($event instanceof CartEvent) { $resource = $event->getCart(); } else { $resource = $event->getSubject(); } if (!$resource instanceof CustomerAwareInterface) { throw new UnexpectedTypeException($resource, 'Sylius\\Component\\User\\Model\\CustomerAwareInterface'); } if (null === ($customer = $this->customerContext->getCustomer())) { return; } $resource->setCustomer($customer); }
/** * {@inheritdoc} */ public function getCustomer() { return $this->customerContext->getCustomer(); }
function it_gets_current_customer_from_context(CustomerContextInterface $customerContext, CustomerInterface $customer) { $customerContext->getCustomer()->willReturn($customer); $this->getCustomer()->shouldReturn($customer); }