Calling Developers!
We are reenergizing our code contribution process! Learn More

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

Options
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
    Options

    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
    Options

    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
    Options

    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
    Options

    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
    Options

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

  • sebastian.larisch
    sebastian.larisch Spryker Customer Posts: 143 🧑🏻‍🚀 - Cadet
    Options

    so u probably extended the right form in the wrong place

  • U04F4JUC0UT
    U04F4JUC0UT Posts: 35 🧑🏻‍🚀 - Cadet
    edited December 2022
    Options

    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
    Options

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

  • U04F4JUC0UT
    U04F4JUC0UT Posts: 35 🧑🏻‍🚀 - Cadet
    Options

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

  • sebastian.larisch
    sebastian.larisch Spryker Customer Posts: 143 🧑🏻‍🚀 - Cadet
    Options

    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
    Options

    Okay got it thanks.

  • U04F4JUC0UT
    U04F4JUC0UT Posts: 35 🧑🏻‍🚀 - Cadet
    Options

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

  • sebastian.larisch
    sebastian.larisch Spryker Customer Posts: 143 🧑🏻‍🚀 - Cadet
    Options

    should 🤔

  • sebastian.larisch
    sebastian.larisch Spryker Customer Posts: 143 🧑🏻‍🚀 - Cadet
    Options

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

  • U04F4JUC0UT
    U04F4JUC0UT Posts: 35 🧑🏻‍🚀 - Cadet
    Options

    Okay thanks for the help 🙂
    Let me move it to the correct structure.

  • U04F4JUC0UT
    U04F4JUC0UT Posts: 35 🧑🏻‍🚀 - Cadet
    edited December 2022
    Options

    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
    Options

    where’s your RegisterForm class located?

  • sebastian.larisch
    sebastian.larisch Spryker Customer Posts: 143 🧑🏻‍🚀 - Cadet
    Options

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

  • U04F4JUC0UT
    U04F4JUC0UT Posts: 35 🧑🏻‍🚀 - Cadet
    Options

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

  • U04F4JUC0UT
    U04F4JUC0UT Posts: 35 🧑🏻‍🚀 - Cadet
    Options

    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
    Options

    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
    Options

    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
    Options

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

  • sebastian.larisch
    sebastian.larisch Spryker Customer Posts: 143 🧑🏻‍🚀 - Cadet
    Options

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

  • U04F4JUC0UT
    U04F4JUC0UT Posts: 35 🧑🏻‍🚀 - Cadet
    Options

    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
    Options

    try composer dump-autoload

  • sebastian.larisch
    sebastian.larisch Spryker Customer Posts: 143 🧑🏻‍🚀 - Cadet
    Options

    but no spryker console commands are needed

  • U04F4JUC0UT
    U04F4JUC0UT Posts: 35 🧑🏻‍🚀 - Cadet
    Options

    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
    Options

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

  • sebastian.larisch
    sebastian.larisch Spryker Customer Posts: 143 🧑🏻‍🚀 - Cadet
    Options
    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