Forums › Forums › OroCRM › OroCRM – Programming Questions › Setting Default Country in Address to Primary Location
This topic contains 7 replies, has 4 voices, and was last updated by jakabadambalazs 9 years, 1 month ago.
Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.
- CreatorTopic
- October 14, 2014 at 4:15 am #24891
Hi,
Greetings!
Realise that when we set default country in the primary location field of System -> Configuration -> Localization, the changes are reflected in currency.
It would be ideal, if this also sets the default country in the Address Entity to the primary location. As of now, it shows ‘Choose a Country…’ .
Any idea how this can be implemented?
Thanks!
warm regards
Spurgeon - CreatorTopic
- AuthorReplies
- October 15, 2014 at 2:49 am #24892
Hi @spurgeonbj ! Sound like a good improvement for OroPlatform, thanks !
For now you can do this by form extension that will extend oro_country form type and set default data in options.
October 15, 2014 at 3:05 am #24893Hi Alex,
Greetings!
Thanks a lot for your kind response and tip and also for considering this for implementation.
Will check out the form extension option.
warm regards and gratitude,
SpurgeonOctober 29, 2014 at 12:57 am #24894Hi Spurgeon,
I’m looking into this as well. But cannot find the solution yet.
Have you solved this one?October 29, 2014 at 1:32 am #24895Hi Chang,
Greetings!
Not yet.
But I think we can extend / override or modify (only issue with modification is we need to incorporate these changes when we upgrade) oro_country form type in the Address Bundle.
I tried doing it by modifying and ended up getting the default country as a ‘Place Holder’ rather than the currently selected option, in my case it showed ‘India’ instead of ‘Choose a Country’ when i modified this file.
vendor/oro/platform/src/Oro/Bundle/AddressBundle/Form/Type/CountryType.php
1234567891011121314151617181920212223242526272829303132333435363738394041<?phpnamespace Oro\Bundle\AddressBundle\Form\Type;use Symfony\Component\Form\AbstractType;use Symfony\Component\OptionsResolver\OptionsResolverInterface;use Doctrine\ORM\EntityRepository;class CountryType extends AbstractType{public function setDefaultOptions(OptionsResolverInterface $resolver){$resolver->setDefaults(array('label' => 'oro.address.country.entity_label','class' => 'OroAddressBundle:Country','random_id' => true,'query_builder' => function (EntityRepository $er) {return $er->createQueryBuilder('c')->orderBy('c.name', 'ASC');},'configs' => array('allowClear' => true,'placeholder' => 'oro.address.form.choose_country'),'empty_value' => '','empty_data' => null));}public function getParent(){return 'genemu_jqueryselect2_translatable_entity';}public function getName(){return 'oro_country';}}I had set empty_value = ‘India’ and empty_data = ‘IN’ (dont remember whether it was the other way round). This does change the select2 control
Guess it might be to do something with setting default country id.
Hope Alex can help us here :-)
Do let me know if there’s any update.
Thanks!
warm regards
SpurgeonOctober 29, 2014 at 2:19 am #24896Ah, thank you for the response Spurgeon,
I think we should use a javascript solution here, as changing the country, should also trigger the state ajax.
Yes, sure hope Alex or someone from orocrm can help here :)
October 29, 2014 at 2:21 am #24897Hi Chang,
Greetings!
Thanks for the quick response.
That sounds great!
If you are comfortable in Javascript, you can check this file
1vendor/oro/platform/src/Oro/Bundle/AddressBundle/Resources/public/js/country/select2-handler.jswhich handles the events for the select2 control dealing with Country.
I’m not so conversant with JS, so was wondering how to go about…
Thanks!
warm regards
SpurgeonFebruary 7, 2015 at 2:52 am #24898Sounds good but too much hassle!
If it is agreed that we can use the system configuration “oro_locale.country” === “Primary Location” to be set as the selected country on the oro.address.form.choose_country field when there is no data set, I’ll try to make a PR for this.
a\
oro/platform(1.6.2) + oro/doctrine-extensions(1.0.7) + symfony/symfony(v2.3.27)
- AuthorReplies
The forum ‘OroCRM – Programming Questions’ is closed to new topics and replies.