public function createAction()
    {
        $this->checkAuth();

        $addressCreate = $this->createForm(FrontForm::ADDRESS_CREATE);

        try {
            /** @var Customer $customer */
            $customer = $this->getSecurityContext()->getCustomerUser();

            $form = $this->validateForm($addressCreate, "post");
            $event = $this->createAddressEvent($form);
            $event->setCustomer($customer);

            $this->dispatch(TheliaEvents::ADDRESS_CREATE, $event);

            return $this->generateSuccessRedirect($addressCreate);
        } catch (FormValidationException $e) {
            $message = $this->getTranslator()->trans("Please check your input: %s", ['%s' => $e->getMessage()], Front::MESSAGE_DOMAIN);
        } catch (\Exception $e) {
            $message = $this->getTranslator()->trans("Sorry, an error occured: %s", ['%s' => $e->getMessage()], Front::MESSAGE_DOMAIN);
        }

        Tlog::getInstance()->error(sprintf("Error during address creation process : %s", $message));

        $addressCreate->setErrorMessage($message);

        $this->getParserContext()
            ->addForm($addressCreate)
            ->setGeneralError($message)
        ;

        // Redirect to error URL if defined
        if ($addressCreate->hasErrorUrl()) {
            return $this->generateErrorRedirect($addressCreate);
        }
    }
public function createAction()
    {
        $this->checkAuth();

        $addressCreate = $this->createForm(FrontForm::ADDRESS_CREATE);

        try {
            /** @var Customer $customer */
            $customer = $this->getSecurityContext()->getCustomerUser();

            $form = $this->validateForm($addressCreate, "post");
            $event = $this->createAddressEvent($form);
            $event->setCustomer($customer);

            $this->dispatch(TheliaEvents::ADDRESS_CREATE, $event);

            return $this->generateSuccessRedirect($addressCreate);
        } catch (FormValidationException $e) {
            $message = $this->getTranslator()->trans("Please check your input: %s", ['%s' => $e->getMessage()], Front::MESSAGE_DOMAIN);
        } catch (\Exception $e) {
            $message = $this->getTranslator()->trans("Sorry, an error occured: %s", ['%s' => $e->getMessage()], Front::MESSAGE_DOMAIN);
        }

        Tlog::getInstance()->error(sprintf("Error during address creation process : %s", $message));

        $addressCreate->setErrorMessage($message);

        $this->getParserContext()
            ->addForm($addressCreate)
            ->setGeneralError($message)
        ;

        // Redirect to error URL if defined
        if ($addressCreate->hasErrorUrl()) {
            return $this->generateErrorRedirect($addressCreate);
        }
    }
public function createAction ( ) { $ this -> checkAuth ( ) ; $ addressCreate = $ this -> createForm ( FrontForm :: ADDRESS_CREATE ) ; try { /** @var Customer $customer */ $ customer = $ this -> getSecurityContext ( ) -> getCustomerUser ( ) ; $ form = $ this -> validateForm ( $ addressCreate , "post" ) ; $ event = $ this -> createAddressEvent ( $ form ) ; $ event -> setCustomer ( $ customer ) ; $ this -> dispatch ( TheliaEvents :: ADDRESS_CREATE , $ event ) ; return $ this -> generateSuccessRedirect ( $ addressCreate ) ; } catch ( FormValidationException $ e ) { $ message = $ this -> getTranslator ( ) -> trans ( "Please check your input: %s" , [ '%s' => $ e -> getMessage ( ) ] , Front :: MESSAGE_DOMAIN ) ; } catch ( \ Exception $ e ) { $ message = $ this -> getTranslator ( ) -> trans ( "Sorry, an error occured: %s" , [ '%s' => $ e -> getMessage ( ) ] , Front :: MESSAGE_DOMAIN ) ; } Tlog :: getInstance ( ) -> error ( sprintf ( "Error during address creation process : %s" , $ message ) ) ; $ addressCreate -> setErrorMessage ( $ message ) ; $ this -> getParserContext ( ) -> addForm ( $ addressCreate ) -> setGeneralError ( $ message ) ; // Redirect to error URL if defined if ( $ addressCreate -> hasErrorUrl ( ) ) { return $ this -> generateErrorRedirect ( $ addressCreate ) ; } }
Create controller.
Check if customer is logged in

Dispatch TheliaEvents::ADDRESS_CREATE event
Create controller . Check if customer is logged in