public function get()
    {
        $customer = null;
        $user = null;

        if (true === $this->securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
            // user is authenticated
            $user = $this->securityContext->getToken()->getUser();

            if (!$user instanceof UserInterface) {
                throw new \RuntimeException('User must be an instance of Symfony\Component\Security\Core\User\UserInterface');
            }

            $customer = $this->customerManager->findOneBy([
                '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;
    }
public function get()
    {
        $customer = null;
        $user = null;

        if (true === $this->securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
            // user is authenticated
            $user = $this->securityContext->getToken()->getUser();

            if (!$user instanceof UserInterface) {
                throw new \RuntimeException('User must be an instance of Symfony\Component\Security\Core\User\UserInterface');
            }

            $customer = $this->customerManager->findOneBy([
                '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;
    }
public function get ( ) { $ customer = null ; $ user = null ; if ( true === $ this -> securityContext -> isGranted ( 'IS_AUTHENTICATED_REMEMBERED' ) ) { // user is authenticated $ user = $ this -> securityContext -> getToken ( ) -> getUser ( ) ; if ( ! $ user instanceof UserInterface ) { throw new \ RuntimeException ( 'User must be an instance of Symfony\Component\Security\Core\User\UserInterface' ) ; } $ customer = $ this -> customerManager -> findOneBy ( [ '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 ; }
Get the customer.

@throws \RuntimeException

@return \Sonata\Component\Customer\CustomerInterface
Get the customer .