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
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
Comments
-
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 numberIn 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.0 -
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
0 -
looks like u extended the wrong
FormFactory
. Try to extendPyz\Yves\CustomerPage\Form\FormFactory.php
instead and override yourgetRegisterForm
there0 -
Hi @UNGMX0012, thanks for the reply
I have extended this form factorySprykerShop\Yves\CustomerPage\Form\FormFactory
0 -
yes but your namespace says
namespace Pyz\Yves\Form;
0 -
so u probably extended the right form in the wrong place
0 -
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 namespace0 -
the FormFactory should be here:
src/Pyz/Yves/CustomerPage/Form/FormFactory.php
0 -
Okay, and the registerForm also should be there only right?
0 -
if u want to extend the RegisterForm put it there as well:
src/Pyz/Yves/CustomerPage/Form/RegisterForm.php
.. same structure as in vendor0 -
Okay got it thanks.
0 -
And once these changes are done that field will be visible on frontend?
0 -
should π€
0 -
btw: I can recommend the βPYZβ PhpStorm plugin which is helping u when extending spryker stuff in pyz.
0 -
Okay thanks for the help π
Let me move it to the correct structure.0 -
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); } }
0 -
whereβs your
RegisterForm
class located?0 -
should:
src/Pyz/Yves/CustomerPage/Form/RegisterForm.php
0 -
Its in the same folder
\src\Pyz\Yves\CustomerPage\Form\RegisterForm.php0 -
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; } }
0 -
one more thing β¦ did u override the
CustomerPageFactory
as well?
add:use Pyz\Yves\CustomerPage\Form\FormFactory; ... public function createCustomerFormFactory(): FormFactory { return new FormFactory(); }
0 -
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(); } }
0 -
wrong return type: remove docblock and change it to:
public function createCustomerFormFactory(): FormFactory
0 -
or fix docblock and use correct FormFactory -> Pyz\Yves\CustomerPage\Form\FormFactory
0 -
Done, after doing these changes do I need to run any command to load the new changes or it will take it automatically
0 -
try
composer dump-autoload
0 -
but no spryker console commands are needed
0 -
Okay, still it's not coming up on frontend, do we have to add more changes
Sorry for asking so many questions
0 -
pls rename
SignUpPageFactory
to CustomerPageFactory and the origin one gets an alias likeVendorCustomerPageFactory
orSprykerCustomerPageFactory
..0 -
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
0
Categories
- All Categories
- 42 Getting Started & Guidelines
- 7 Getting Started in the Community
- 8 Additional Resources
- 7 Community Ideas and Feedback
- 76 Spryker News
- 929 Developer Corner
- 787 Spryker Development
- 89 Spryker Dev Environment
- 362 Spryker Releases
- 3 Oryx frontend framework
- 35 Propel ORM
- 68 Community Projects
- 3 Community Ideation Board
- 30 Hackathon
- 3 PHP Bridge
- 6 Gacela Project
- 26 Job Opportunities
- 3.2K π Slack Archives
- 116 Academy
- 5 Business Users
- 370 Docker
- 551 Slack General
- 2K Help
- 75 Knowledge Sharing
- 6 Random Stuff
- 4 Code Testing
- 32 Product & Business Questions
- 70 Spryker Safari Questions
- 50 Random