Exemplo n.º 1
0
 /**
  * @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());
 }
Exemplo n.º 2
0
 /**
  * {@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']);
 }
Exemplo n.º 4
0
 /**
  * @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);
 }
Exemplo n.º 5
0
 /**
  * @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);
 }
Exemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 public function getCustomer()
 {
     return $this->customerContext->getCustomer();
 }
Exemplo n.º 7
0
 function it_gets_current_customer_from_context(CustomerContextInterface $customerContext, CustomerInterface $customer)
 {
     $customerContext->getCustomer()->willReturn($customer);
     $this->getCustomer()->shouldReturn($customer);
 }