public function onAuthenticationSuccess(AuthenticationEvent $event)
    {
        $loggedUser = $event
            ->getAuthenticationToken()
            ->getUser();

        $cart = $this
            ->cartWrapper
            ->get();

        if (
            ($loggedUser instanceof CustomerInterface) &&
            ($cart instanceof CartInterface && $cart->getId())
        ) {
            /*
             * We assume that a cart with an ID is
             * not a pristine entity coming from a
             * factory method. (i.e. has already been
             * flushed)
             */
            $cart->setCustomer($loggedUser);

            $this->cartManager->flush($cart);
        }
    }
public function onAuthenticationSuccess(AuthenticationEvent $event)
    {
        $loggedUser = $event
            ->getAuthenticationToken()
            ->getUser();

        $cart = $this
            ->cartWrapper
            ->get();

        if (
            ($loggedUser instanceof CustomerInterface) &&
            ($cart instanceof CartInterface && $cart->getId())
        ) {
            /*
             * We assume that a cart with an ID is
             * not a pristine entity coming from a
             * factory method. (i.e. has already been
             * flushed)
             */
            $cart->setCustomer($loggedUser);

            $this->cartManager->flush($cart);
        }
    }
public function onAuthenticationSuccess ( AuthenticationEvent $ event ) { $ loggedUser = $ event -> getAuthenticationToken ( ) -> getUser ( ) ; $ cart = $ this -> cartWrapper -> get ( ) ; if ( ( $ loggedUser instanceof CustomerInterface ) && ( $ cart instanceof CartInterface && $ cart -> getId ( ) ) ) { /*
             * We assume that a cart with an ID is
             * not a pristine entity coming from a
             * factory method. (i.e. has already been
             * flushed)
             */ $ cart -> setCustomer ( $ loggedUser ) ; $ this -> cartManager -> flush ( $ cart ) ; } }
Assign the Cart stored in session to the logged Customer.

When a user has successfully logged in, a check is needed
to see if a Cart was created in session when she was not
logged.

@param AuthenticationEvent $event Event
Assign the Cart stored in session to the logged Customer .