/** * Get the customer. * * @throws \RuntimeException * * @return \Sonata\Component\Customer\CustomerInterface */ public function get() { $customer = null; $user = null; if (true === $this->securityContext->isGranted('IS_AUTHENTICATED_FULLY')) { // user is authenticated $user = $this->securityContext->getToken()->getUser(); if (!$user instanceof UserInterface) { throw new \RuntimeException('User must be an instance of FOS\\UserBundle\\Model\\UserInterface'); } $customer = $this->customerManager->findOneBy(array('user' => $user->getId())); } if (!$customer) { $basket = $this->getBasket(); if ($basket && $basket->getCustomer()) { $customer = $basket->getCustomer(); } } if (!$customer) { $customer = $this->customerManager->create(); } if (!$customer->getLocale()) { $customer->setLocale($this->locale); } if ($user && $customer) { $customer->setUser($user); } return $customer; }