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..
Hello everyone, On the CheckoutAddressCollectionForm, I'm trying to change the defaults for the Sal
Hello everyone,
On the CheckoutAddressCollectionForm, I'm trying to change the defaults for the Salutation and the Country of the billing address. On the billing form (and only there), they are set to Mr. and Albania (the first country in the available countries array). Could someone point me to the FormBuilder option to change these?
Comments
-
I had the same problem a few months ago, changing the order of the countries array for our store on the file config/Shared/stores.php did the trick
0 -
The first country on the array will be the default
0 -
Now, for the salutation you have to extend the method
addSalutationField
of the classCheckoutAddressForm
0 -
For example:
/** * @param \Symfony\Component\Form\FormBuilderInterface $builder * @param array $options * * @return \SprykerShop\Yves\CustomerPage\Form\AddressForm */ public function addSalutationField(FormBuilderInterface $builder, array $options) { $builder->add(self::FIELD_SALUTATION, ChoiceType::class, [ 'choices' => array_flip([ 'Ms' => '[customer.salutation.ms](http://customer.salutation.ms)', 'Mr' => '[customer.salutation.mr](http://customer.salutation.mr)', ]), 'label' => 'profile.form.salutation', 'required' => true, 'trim' => true, 'constraints' => [ $this->createNotBlankConstraint($options), ], ]); return $this; }
0 -
Thank you, @U01K43ADW5N. It's funny, I did what you suggested and it seems that I ran into some kind of client side caching issue earlier.
Now it does pre-select the first value with an implementation that mimics your code.
0 -
Here's my addSalutationField method:
/** * @param \Symfony\Component\Form\FormBuilderInterface $builder * @param array $options * * @return $this */ public function addSalutationField(FormBuilderInterface $builder, array $options) { $builder->add(self::FIELD_SALUTATION, ChoiceType::class, [ 'choices' => array_flip([ '' => 'global.select.placeholder.value', 'Mr' => '[customer.salutation.mr](http://customer.salutation.mr)', 'Ms' => '[customer.salutation.ms](http://customer.salutation.ms)', 'Mrs' => 'customer.salutation.mrs', 'Dr' => 'customer.salutation.dr', ]), 'label' => 'profile.form.salutation', 'required' => true, 'trim' => true, 'constraints' => [$this->createNotBlankConstraint($options)], ]); return $this; }
And here the custom placeholder for the country selector (since I need an empty selector field, I could not use the store config):
/** * @param \Symfony\Component\Form\FormBuilderInterface $builder * @param array $options * * @return $this */ protected function addIso2CodeField(FormBuilderInterface $builder, array $options) { // Add blank preselect to address selector $choices = ['global.select.placeholder.value' => '']; $choices += array_flip($options[self::OPTION_COUNTRY_CHOICES]); $builder->add(self::FIELD_ISO_2_CODE, ChoiceType::class, [ 'label' => 'customer.address.country', 'required' => true, 'choices' => $choices, 'constraints' => [$this->createNotBlankConstraint($options)], ]); return $this; }
0 -
-
Hi @UK7KBE2JW, I think that's what I was looking for. Thank you!
0 -
your welcome
0
Categories
- All Categories
- 42 Getting Started & Guidelines
- 7 Getting Started in the Community
- 8 Additional Resources
- 7 Community Ideas and Feedback
- 75 Spryker News
- 924 Developer Corner
- 783 Spryker Development
- 88 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
- 25 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