What are the Slack Archives?

It’s a history of our time together in the Slack Community! There’s a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.

Because this space is not active, you won’t be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..

Hi Team , Hope you all are doing well ! I'm trying to add a new field mobile numbe

U04F4JUC0UT
U04F4JUC0UT Posts: 35 πŸ§‘πŸ»β€πŸš€ - Cadet

Hi Team ,

Hope you all are doing well !
I'm trying to add a new field mobile number on the signUp page, and enable users to log in with their mobile number and email.

Need your help in understanding how I can do that.

Thanks

Β«1

Comments

  • Alberto Reyer
    Alberto Reyer Lead Spryker Solution Architect / Technical Director Posts: 690 πŸͺ - Explorer

    For the login part you can have a look at \Spryker\Zed\Customer\Business\Customer\Customer::tryAuthorizeCustomerByEmailAndPassword.

    For the registration you need to extend the \SprykerShop\Yves\CustomerPage\Form\RegisterForm to include the mobile number

    In addition you will need to extend the CustomerTransfer to add the new mobile phone number field.

    If it's possible to register only with mobile and without email you might want to consider the whole password reset process as well, as this is build with the expectation that there is always an email to send a password reset mail too.
    Also registration confirmation might be something you will need to adapt if registration without any email is a valid case.

  • U04F4JUC0UT
    U04F4JUC0UT Posts: 35 πŸ§‘πŸ»β€πŸš€ - Cadet
    edited December 2022

    Hi @UL6DGRULR, Thanks for the reply.

    Below are the changes which I have added can you please have a look,

    Extended registration form in pyz/yves/form

    <?php
    
    /**
     * Copyright Β© 2016-present Spryker Systems GmbH. All rights reserved.
     * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
     */
    
    namespace Pyz\Yves\Form;
    
    use SprykerShop\Yves\CustomerPage\Form\RegisterForm as SignUpForm;
    use Symfony\Component\Form\Extension\Core\Type\TextType;
    use Symfony\Component\Form\FormBuilderInterface;
    
    /**
     * @method \SprykerShop\Yves\CustomerPage\CustomerPageConfig getConfig()
     */
    class RegisterForm extends SignUpForm
    {
        /**
         * @var string
         */
        public const FIELD_MOBILE_NUMBER = 'mobile_number';
    
        /**
         * @param \Symfony\Component\Form\FormBuilderInterface $builder
         * @param array $options
         *
         * @return void
         */
        public function buildForm(FormBuilderInterface $builder, array $options)
        {
            parent::buildForm($builder, $options);
            $builder->addMobileNumberField($builder);
        }
    
        /**
         * @param \Symfony\Component\Form\FormBuilderInterface $builder
         *
         * @return $this
         */
        protected function addMobileNumberField(FormBuilderInterface $builder)
        {
            $builder->add(self::FIELD_MOBILE_NUMBER, TextType::class, [
                'label' => 'customer.mobile_number',
                'required' => true,
                'constraints' => [
                    parent::createNotBlankConstraint(),
                ],
            ]);
    
            return $this;
        }
    }
    

    And I have also extended the FormFactory in pyz/yves/form

    <?php
    
    /**
     * Copyright Β© 2016-present Spryker Systems GmbH. All rights reserved.
     * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
     */
    
    namespace Pyz\Yves\Form;
    
    use Pyz\Yves\Form\RegisterForm;
    use SprykerShop\Yves\CustomerPage\Form\FormFactory as SignUpFormFactory;
    
    
    /**
     * @method \SprykerShop\Yves\CustomerPage\CustomerPageConfig getConfig()
     */
    class FormFactory extends SignUpFormFactory
    {
    
        /**
         * @return \Symfony\Component\Form\FormInterface
         */
        public function getRegisterForm()
        {
            return parent::getFormFactory()->create(RegisterForm::class);
        }
    
    }
    

    And also I have updated the twig file

  • sebastian.larisch
    sebastian.larisch Spryker Customer Posts: 143 πŸ§‘πŸ»β€πŸš€ - Cadet
    edited December 2022

    looks like u extended the wrong FormFactory. Try to extend Pyz\Yves\CustomerPage\Form\FormFactory.php instead and override your getRegisterForm there

  • U04F4JUC0UT
    U04F4JUC0UT Posts: 35 πŸ§‘πŸ»β€πŸš€ - Cadet

    Hi @UNGMX0012, thanks for the reply
    I have extended this form factory

    SprykerShop\Yves\CustomerPage\Form\FormFactory
    
  • sebastian.larisch
    sebastian.larisch Spryker Customer Posts: 143 πŸ§‘πŸ»β€πŸš€ - Cadet

    yes but your namespace says namespace Pyz\Yves\Form;

  • sebastian.larisch
    sebastian.larisch Spryker Customer Posts: 143 πŸ§‘πŸ»β€πŸš€ - Cadet

    so u probably extended the right form in the wrong place

  • U04F4JUC0UT
    U04F4JUC0UT Posts: 35 πŸ§‘πŸ»β€πŸš€ - Cadet
    edited December 2022

    Okay, here I have created a new file name FormFactory and added the above mentioned code

    src\Pyz\Yves\Form\FormFactory.php
    

    Here is the path for the same
    Thats why I have added that namespace

  • sebastian.larisch
    sebastian.larisch Spryker Customer Posts: 143 πŸ§‘πŸ»β€πŸš€ - Cadet

    the FormFactory should be here: src/Pyz/Yves/CustomerPage/Form/FormFactory.php

  • U04F4JUC0UT
    U04F4JUC0UT Posts: 35 πŸ§‘πŸ»β€πŸš€ - Cadet

    Okay, and the registerForm also should be there only right?

  • sebastian.larisch
    sebastian.larisch Spryker Customer Posts: 143 πŸ§‘πŸ»β€πŸš€ - Cadet

    if u want to extend the RegisterForm put it there as well: src/Pyz/Yves/CustomerPage/Form/RegisterForm.php .. same structure as in vendor

  • U04F4JUC0UT
    U04F4JUC0UT Posts: 35 πŸ§‘πŸ»β€πŸš€ - Cadet

    Okay got it thanks.

  • U04F4JUC0UT
    U04F4JUC0UT Posts: 35 πŸ§‘πŸ»β€πŸš€ - Cadet

    And once these changes are done that field will be visible on frontend?

  • sebastian.larisch
    sebastian.larisch Spryker Customer Posts: 143 πŸ§‘πŸ»β€πŸš€ - Cadet

    should πŸ€”

  • sebastian.larisch
    sebastian.larisch Spryker Customer Posts: 143 πŸ§‘πŸ»β€πŸš€ - Cadet

    btw: I can recommend the β€œPYZ” PhpStorm plugin which is helping u when extending spryker stuff in pyz.

  • U04F4JUC0UT
    U04F4JUC0UT Posts: 35 πŸ§‘πŸ»β€πŸš€ - Cadet

    Okay thanks for the help πŸ™‚
    Let me move it to the correct structure.

  • U04F4JUC0UT
    U04F4JUC0UT Posts: 35 πŸ§‘πŸ»β€πŸš€ - Cadet
    edited December 2022

    Hi @UNGMX0012, I have moved the code to the correct folder. Still, the field is not coming up on the front end.

    Path: src\Pyz\Yves\CustomerPage\Form\FormFactory.php

    <?php
    
    /**
     * Copyright Β© 2016-present Spryker Systems GmbH. All rights reserved.
     * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
     */
    
    namespace Pyz\Yves\CustomerPage\Form;
    
    use Pyz\Yves\CustomerPage\Form\RegisterForm;
    use SprykerShop\Yves\CustomerPage\Form\FormFactory as SignUpFormFactory;
    
    
    /**
     * @method \SprykerShop\Yves\CustomerPage\CustomerPageConfig getConfig()
     */
    class FormFactory extends SignUpFormFactory
    {
    
        /**
         * @return \Symfony\Component\Form\FormInterface
         */
        public function getRegisterForm()
        {
            return parent::getFormFactory()->create(RegisterForm::class);
        }
    
    }
    
  • sebastian.larisch
    sebastian.larisch Spryker Customer Posts: 143 πŸ§‘πŸ»β€πŸš€ - Cadet

    where’s your RegisterForm class located?

  • sebastian.larisch
    sebastian.larisch Spryker Customer Posts: 143 πŸ§‘πŸ»β€πŸš€ - Cadet

    should: src/Pyz/Yves/CustomerPage/Form/RegisterForm.php

  • U04F4JUC0UT
    U04F4JUC0UT Posts: 35 πŸ§‘πŸ»β€πŸš€ - Cadet

    Its in the same folder
    \src\Pyz\Yves\CustomerPage\Form\RegisterForm.php

  • U04F4JUC0UT
    U04F4JUC0UT Posts: 35 πŸ§‘πŸ»β€πŸš€ - Cadet

    Yes its there only
    And here is the code for that

    <?php
    
    /**
     * Copyright Β© 2016-present Spryker Systems GmbH. All rights reserved.
     * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
     */
    
     namespace Pyz\Yves\CustomerPage\Form;
    
    use SprykerShop\Yves\CustomerPage\Form\RegisterForm as SignUpForm;
    use Symfony\Component\Form\Extension\Core\Type\TextType;
    use Symfony\Component\Form\FormBuilderInterface;
    
    /**
     * @method \SprykerShop\Yves\CustomerPage\CustomerPageConfig getConfig()
     */
    class RegisterForm extends SignUpForm
    {
        /**
         * @var string
         */
        public const FIELD_MOBILE_NUMBER = 'mobile_number';
    
        /**
         * @param \Symfony\Component\Form\FormBuilderInterface $builder
         * @param array $options
         *
         * @return void
         */
        public function buildForm(FormBuilderInterface $builder, array $options)
        {
            die("Died here in the form ");
            parent::buildForm($builder, $options);
            $builder->addMobileNumberField($builder);
        }
    
        /**
         * @param \Symfony\Component\Form\FormBuilderInterface $builder
         *
         * @return $this
         */
        protected function addMobileNumberField(FormBuilderInterface $builder)
        {
            $builder->add(self::FIELD_MOBILE_NUMBER, TextType::class, [
                'label' => 'customer.mobile_number',
                'required' => true,
                'constraints' => [
                    parent::createNotBlankConstraint(),
                ],
            ]);
    
            return $this;
        }
    }
    
  • sebastian.larisch
    sebastian.larisch Spryker Customer Posts: 143 πŸ§‘πŸ»β€πŸš€ - Cadet

    one more thing … did u override the CustomerPageFactory as well?
    add:

    use Pyz\Yves\CustomerPage\Form\FormFactory;
    
    ...
    
    public function createCustomerFormFactory(): FormFactory
    {
        return new FormFactory();
    }
    
  • U04F4JUC0UT
    U04F4JUC0UT Posts: 35 πŸ§‘πŸ»β€πŸš€ - Cadet

    Yes I did
    Path: src\Pyz\Yves\CustomerPage\CustomerPageFactory.php
    here is the code

    <?php
    
    /**
     * Copyright Β© 2016-present Spryker Systems GmbH. All rights reserved.
     * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
     */
    
    namespace Pyz\Yves\CustomerPage;
    
    use SprykerShop\Yves\CustomerPage\CustomerPageFactory;
    use Pyz\Yves\CustomerPage\Form\FormFactory;
    
    
    /**
     * @method \SprykerShop\Yves\CustomerPage\CustomerPageConfig getConfig()
     */
    class SignUpPageFactory extends CustomerPageFactory
    {
        /**
         * @return \Pyz\Yves\Form\FormFactory
         */
        public function createCustomerFormFactory()
        {
            return new FormFactory();
        }
    
    }
    
  • sebastian.larisch
    sebastian.larisch Spryker Customer Posts: 143 πŸ§‘πŸ»β€πŸš€ - Cadet

    wrong return type: remove docblock and change it to: public function createCustomerFormFactory(): FormFactory

  • sebastian.larisch
    sebastian.larisch Spryker Customer Posts: 143 πŸ§‘πŸ»β€πŸš€ - Cadet

    or fix docblock and use correct FormFactory -> Pyz\Yves\CustomerPage\Form\FormFactory

  • U04F4JUC0UT
    U04F4JUC0UT Posts: 35 πŸ§‘πŸ»β€πŸš€ - Cadet

    Done, after doing these changes do I need to run any command to load the new changes or it will take it automatically

  • sebastian.larisch
    sebastian.larisch Spryker Customer Posts: 143 πŸ§‘πŸ»β€πŸš€ - Cadet

    try composer dump-autoload

  • sebastian.larisch
    sebastian.larisch Spryker Customer Posts: 143 πŸ§‘πŸ»β€πŸš€ - Cadet

    but no spryker console commands are needed

  • U04F4JUC0UT
    U04F4JUC0UT Posts: 35 πŸ§‘πŸ»β€πŸš€ - Cadet

    Okay, still it's not coming up on frontend, do we have to add more changes

    Sorry for asking so many questions

  • sebastian.larisch
    sebastian.larisch Spryker Customer Posts: 143 πŸ§‘πŸ»β€πŸš€ - Cadet

    pls rename SignUpPageFactoryto CustomerPageFactory and the origin one gets an alias like VendorCustomerPageFactory or SprykerCustomerPageFactory..

  • sebastian.larisch
    sebastian.larisch Spryker Customer Posts: 143 πŸ§‘πŸ»β€πŸš€ - Cadet
    namespace Pyz\Yves\CustomerPage;
    
    use SprykerShop\Yves\CustomerPage\CustomerPageFactory as SprykerCustomerPageFactory;
    use Pyz\Yves\CustomerPage\Form\FormFactory;
    
    
    /**
     * @method \SprykerShop\Yves\CustomerPage\CustomerPageConfig getConfig()
     */
    class CustomerPageFactory extends SprykerCustomerPageFactory