Default value is required on State/Province

We are running a store that doesn’t use state/province settings (for Denmark) and it is not included in the fields for checkout because the standard Magento setting “Allow to Choose State if It is Optional for Country” is set to “No”.

The checkout does not display the field, as it shouldn’t.

However, in the UB One Step Checkout settings under “Default values” the field “State / Province” is required and the settings can’t be saved without a selection. This selection that we are forced to make is now included in all orders – even if the field isn’t part of the checkout, resulting in our customers having faulty address data with a wrong region.

We have Recently upgraded the module to v. 1.1.4 and before that the “State / Province” was not included in order data.

I’m aware of the possibility to remove region from various template data, but we don’t want orders to exist with wrong data, even if it isn’t displayed.

How can we ensure that the default value for “State / Province” isn’t added to orders at all?

Regards
 

23 answers

Profile photo of Mall Staff 184060.00 $tone December 12, 2022
Public

Hi there,

How can we ensure that the default value for “State / Province” isn’t added to orders at all?

Can you clarify if you want to mention the ‘State/Province on the shipping and billing addresses in a Sales Order?
For testing purposes only: Please check to see what would happen if you disabled UB Checkout and then placed an order with Magento’s core checkout module.
 

Regards,
Mall.
 

#1
Profile photo of Kasper Brandt Hansen 510.00 $tone December 12, 2022
Public

We have disabled “State/Province” and it should not appear anywhere.

I have tested with UB Checkout disabled and the result is that “State/Province” is not added when UB Checkout is disabled. 

When re-enabling UB Checkout the value of “State/Province” selected in UB Checkout is again “forced” on the order.

#2
Profile photo of Mall Staff 184060.00 $tone December 13, 2022
Public

Hi there,

I have tested with UB Checkout disabled and the result is that “State/Province” is not added when UB Checkout is disabled. 
When re-enabling UB Checkout the value of “State/Province” selected in UB Checkout is again “forced” on the order.

So you can apply the same configuration again as you did to the last version of our module.

If you still need further assistance, please provide me with information about your instance and I will check further:
+ Admin credentials and URL to the backend
+ SSH credentials and the path to the M2 folder
 

Regards,
Mall.

#3
Profile photo of Kasper Brandt Hansen 510.00 $tone December 13, 2022
Public

No, that’s not the issue here. The configuration that creates the problem is that in you module, under “Default values” the field “State / Province” is required and the settings can’t be saved without a selection. This selection that we are forced to make is included in all orders – even if the field isn’t part of the checkout, resulting in our customers having faulty address data with a wrong region.

Even if the configurations are the same your new version of the module adds “State / Province” to the order. Regardless of what Magentos settings are, and regardless of what the previous version of the module does.
Regrds
 

#4
Profile photo of Kasper Brandt Hansen 510.00 $tone December 13, 2022
Public

This is the setting in UB Checkout causing the problem 
https://paste.pics/445910473ff120e6fa90b14506ae16fa

The field is part of your module and it is NOT possible to saveUB Checkout  configuration without selecting a value. This value is forced on all orders regardless of “State / province” settings in Magento.

I have tested with a clean Magento install running Luma

Scenario without UB Checkout installed
-- Magento is configured not to require “State / province”
-- checkout does not show “State / province” in checkout
-- checkout does not add “State / province” to order data when order is placed

Scenario WITH UB Checkout installed
-- Magento is configured not to require “State / province”
-- checkout with UB Checkout does not show “State / province” in checkout
-- checkout with UB Checkout adds “State / province” to order data when order is placed

#5
Profile photo of Kasper Brandt Hansen 510.00 $tone December 13, 2022
Public

Furthermore -- this is the code of the config field “UB One Step Checkout” -> “Default Values” -> “State / Province”

<select name=”groups[default_values][fields][region_id][value]” title=”” id=”ubertheme_checkout_default_values_region_id” class=”required-entry select”><option value=””>Please select a region, state or province.</option><option value=”908″ selected=””>Hovedstaden</option><option value=”909″>Midtjylland</option><option value=”910″>Nordjylland</option><option value=”911″>Sjælland</option><option value=”912″>Syddanmark</option></select>

As you can see it has the class “required-entry”
I can remove this class in the code by using the browser developer tools as a hack, and this allow me to save the config without a selected value in this field. Until the page reloads and the class is added again.
When the config is saved without a value in “UB One Step Checkout” -> “Default Values” -> “State / Province” the “State / province” is not forced on orders.

I hope you can see that the issue is simply the fact that there is no way around the default value for “State / province” as long as your module requires a value in the field.

#6
Profile photo of Mall Staff 184060.00 $tone December 13, 2022
Public

Hi there,

As you can see it has the class “required-entry”
I can remove this class in the code by using the browser developer tools as a hack, and this allow me to save the config without a selected value in this field. Until the page reloads and the class is added again.

To handle your case, please try with steps:
+ Open the XML file at path: app/code/Ubertheme/Checkout/etc/adminhtml/system.xml
and find the code lines:

<field id="region_id" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
<label>State / Province</label>
<depends>
<field id="country_id" negative="1"><![CDATA[]]></field>
</depends>
</field>
<field id="city" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
<label>City</label>
<depends>
<field id="country_id" negative="1"><![CDATA[]]></field>
</depends>
</field>

and replace by code lines:

<field id="region_id" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
<label>State / Province</label>
<depends>
<field id="country_id" negative="1"><![CDATA[]]></field>
</depends>
<can_be_empty>1</can_be_empty>
</field>
<field id="city" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
<label>City</label>
<depends>
<field id="country_id" negative="1"><![CDATA[]]></field>
</depends>
<can_be_empty>1</can_be_empty>
</field>

+ Once done, clean the M2 cache. And check the issue you mentioned again.
Regards,
Mall.
 

#7
Profile photo of Kasper Brandt Hansen 510.00 $tone December 13, 2022
Public

<can_be_empty>1</can_be_empty> only applies to multiselect.
https://experienceleague.adobe.com/docs/commerce-operations/configuration-guide/files/config-reference-systemxml.html

Also, there is a secondary rendering of the field happening after settings from system.xml are applied because it is depending on country_id and populated according to selection made in country_id. Settings applied to “region_id” will always be overridden if made in system.xml.

So, your suggestion will not make it possible to save the configs without selecting a value.

#8
Profile photo of Kasper Brandt Hansen 510.00 $tone December 13, 2022
Public

It seems that omitting the class “countries” you add to the field removes the dependency so “region_id” isn’t populated according to “country_id” selection and isn’t rendered as a select field
<frontend_class>countries</frontend_class>
Changed to:
<!-- <frontend_class>countries</frontend_class> -->

…in the file app/code/Ubertheme/Checkout/etc/adminhtml/system.xml
Can you confirm that this does not break anything?
What is your position on the issue in general.
Will it be better handled in a future release?

#9
Profile photo of Mall Staff 184060.00 $tone December 14, 2022
Public

Hi there,

<frontend_class>countries</frontend_class>
Changed to:
<!-- <frontend_class>countries</frontend_class> -->
…in the file app/code/Ubertheme/Checkout/etc/adminhtml/system.xml
Can you confirm that this does not break anything?

It’s not recommended to do that.

It seems that omitting the class “countries” you add to the field removes the dependency so “region_id” isn’t populated according to “country_id” selection and isn’t rendered as a select field

Yes that is correct. Please discard my suggested workaround in reply #7.
Can you try with the blank option for Country? http://prntscr.com/N7cT7h_CpmfI
Or select one country which does not require region input: http://prntscr.com/Y2B-2XkXLsrs
And you can manage the countries and regions depending on the Magentos’ system configuration: http://prntscr.com/3CYlTlim6YNh
 

Regards,
Mall.
 
 
 

#10
Profile photo of Kasper Brandt Hansen 510.00 $tone December 14, 2022
Public

Leaving country blank results in this error when completing an order:

[2022-12-14T09:11:53.386420+00:00] main.CRITICAL: Magento\Framework\Validator\Exception: Invalid country code in /public_html/vendor/magento/framework/Model/AbstractModel.php:720
Stack trace:
#0 /public_html/vendor/magento/framework/Model/ResourceModel/Db/AbstractDb.php(389): Magento\Framework\Model\AbstractModel->validateBeforeSave()
#1 /public_html/vendor/magento/framework/Model/AbstractModel.php(658): Magento\Framework\Model\ResourceModel\Db\AbstractDb->save()
#2 /public_html/vendor/magento/module-quote/Model/ShippingAddressManagement.php(117): Magento\Framework\Model\AbstractModel->save()
#3 /public_html/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Quote\Model\ShippingAddressManagement->assign()
#4 /public_html/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Quote\Model\ShippingAddressManagement\Interceptor->___callParent()
#5 /public_html/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Quote\Model\ShippingAddressManagement\Interceptor->Magento\Framework\Interception\{closure}()
#6 /public_html/generated/code/Magento/Quote/Model/ShippingAddressManagement/Interceptor.php(23): Magento\Quote\Model\ShippingAddressManagement\Interceptor->___callPlugins()
#7 /public_html/vendor/magento/module-quote/Model/Quote/ShippingAssignment/ShippingProcessor.php(66): Magento\Quote\Model\ShippingAddressManagement\Interceptor->assign()
#8 /public_html/vendor/magento/module-quote/Model/Quote/ShippingAssignment/ShippingAssignmentProcessor.php(106): Magento\Quote\Model\Quote\ShippingAssignment\ShippingProcessor->save()
#9 /public_html/vendor/magento/module-quote/Model/Quote/ShippingAssignment/ShippingAssignmentPersister.php(34): Magento\Quote\Model\Quote\ShippingAssignment\ShippingAssignmentProcessor->save()
#10 /public_html/vendor/magento/module-quote/Model/QuoteRepository/SaveHandler.php(145): Magento\Quote\Model\Quote\ShippingAssignment\ShippingAssignmentPersister->save()
#11 /public_html/vendor/magento/module-quote/Model/QuoteRepository/SaveHandler.php(120): Magento\Quote\Model\QuoteRepository\SaveHandler->processShippingAssignment()
#12 /public_html/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Quote\Model\QuoteRepository\SaveHandler->save()
#13 /public_html/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Quote\Model\QuoteRepository\SaveHandler\Interceptor->___callParent()
#14 /public_html/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Quote\Model\QuoteRepository\SaveHandler\Interceptor->Magento\Framework\Interception\{closure}()
#15 /public_html/generated/code/Magento/Quote/Model/QuoteRepository/SaveHandler/Interceptor.php(23): Magento\Quote\Model\QuoteRepository\SaveHandler\Interceptor->___callPlugins()
#16 /public_html/vendor/magento/module-quote/Model/QuoteRepository.php(202): Magento\Quote\Model\QuoteRepository\SaveHandler\Interceptor->save()
#17 /public_html/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Quote\Model\QuoteRepository->save()
#18 /public_html/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Quote\Model\QuoteRepository\Interceptor->___callParent()
#19 /public_html/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Quote\Model\QuoteRepository\Interceptor->Magento\Framework\Interception\{closure}()
#20 /public_html/generated/code/Magento/Quote/Model/QuoteRepository/Interceptor.php(50): Magento\Quote\Model\QuoteRepository\Interceptor->___callPlugins()
#21 /public_html/app/code/Ubertheme/Checkout/Controller/Index/Index.php(125): Magento\Quote\Model\QuoteRepository\Interceptor->save()
#22 /public_html/app/code/Ubertheme/Checkout/Controller/Index/Index.php(66): Ubertheme\Checkout\Controller\Index\Index->initDefaultValues()
#23 /public_html/vendor/magento/framework/Interception/Interceptor.php(58): Ubertheme\Checkout\Controller\Index\Index->execute()
#24 /public_html/vendor/magento/framework/Interception/Interceptor.php(138): Ubertheme\Checkout\Controller\Index\Index\Interceptor->___callParent()
#25 /public_html/vendor/magento/framework/Interception/Interceptor.php(153): Ubertheme\Checkout\Controller\Index\Index\Interceptor->Magento\Framework\Interception\{closure}()
#26 /public_html/generated/code/Ubertheme/Checkout/Controller/Index/Index/Interceptor.php(23): Ubertheme\Checkout\Controller\Index\Index\Interceptor->___callPlugins()
#27 /public_html/vendor/magento/framework/App/Action/Action.php(111): Ubertheme\Checkout\Controller\Index\Index\Interceptor->execute()
#28 /public_html/vendor/magento/module-checkout/Controller/Onepage.php(161): Magento\Framework\App\Action\Action->dispatch()
#29 /public_html/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Checkout\Controller\Onepage->dispatch()
#30 /public_html/vendor/magento/framework/Interception/Interceptor.php(138): Ubertheme\Checkout\Controller\Index\Index\Interceptor->___callParent()
#31 /public_html/vendor/magento/framework/Interception/Interceptor.php(153): Ubertheme\Checkout\Controller\Index\Index\Interceptor->Magento\Framework\Interception\{closure}()
#32 /public_html/generated/code/Ubertheme/Checkout/Controller/Index/Index/Interceptor.php(32): Ubertheme\Checkout\Controller\Index\Index\Interceptor->___callPlugins()
#33 /public_html/vendor/magento/framework/App/FrontController.php(245): Ubertheme\Checkout\Controller\Index\Index\Interceptor->dispatch()
#34 /public_html/vendor/magento/framework/App/FrontController.php(212): Magento\Framework\App\FrontController->getActionResponse()
#35 /public_html/vendor/magento/framework/App/FrontController.php(147): Magento\Framework\App\FrontController->processRequest()
#36 /public_html/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\App\FrontController->dispatch()
#37 /public_html/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\App\FrontController\Interceptor->___callParent()
#38 /public_html/vendor/magento/module-store/App/FrontController/Plugin/RequestPreprocessor.php(99): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}()
#39 /public_html/vendor/magento/framework/Interception/Interceptor.php(135): Magento\Store\App\FrontController\Plugin\RequestPreprocessor->aroundDispatch()
#40 /public_html/vendor/magento/module-page-cache/Model/App/FrontController/BuiltinPlugin.php(75): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}()
#41 /public_html/vendor/magento/framework/Interception/Interceptor.php(135): Magento\PageCache\Model\App\FrontController\BuiltinPlugin->aroundDispatch()
#42 /public_html/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}()
#43 /public_html/generated/code/Magento/Framework/App/FrontController/Interceptor.php(23): Magento\Framework\App\FrontController\Interceptor->___callPlugins()
#44 /public_html/vendor/magento/framework/App/Http.php(116): Magento\Framework\App\FrontController\Interceptor->dispatch()
#45 /public_html/generated/code/Magento/Framework/App/Http/Interceptor.php(23): Magento\Framework\App\Http->launch()
#46 /public_html/vendor/magento/framework/App/Bootstrap.php(264): Magento\Framework\App\Http\Interceptor->launch()
#47 /public_html/pub/index.php(30): Magento\Framework\App\Bootstrap->run()
#48 {main} [] []

We can’t select a wrong country and hope it doesn’t show up somewhere else. Data has to be correct in the config. 

I’m sorry to say, but this part of the module seems very buggy and simply not tested.

#11
Profile photo of Mall Staff 184060.00 $tone December 15, 2022
Public

Hi there,

Leaving country blank results in this error when completing an order:

You should set a default country with that setting (which should be the same as the default country at Stores > Settings > Configuration > General > General > Country Options > Default Country)
Then you can set to not require of the region for that default country on the Magentos’ system configuration: http://prntscr.com/3CYlTlim6YNh

In case you need further assistance, please provide me with information about your instance:
+ Admin credentials and URL to the backend
+ SSH credentials and the path to M2 folder
I will be able to check further for you then.
 

Regards,
Mall.
 

#12
Profile photo of Kasper Brandt Hansen 510.00 $tone December 15, 2022
Public

That is exactly what was done from the beginning, and as I described – in the very first message, your module adds the value selected in your default values – even if the field “State / region” isn’t shown during checkout.

This is a bug in your module. There is not need to access our site.
You can recreate it on a blank installation running only you module.
The error happening with blank country in your default values is caused by your code not handling an empty value in country. It’s happening in Ubertheme\Checkout\Controller that intercepts the order save.

#13
Profile photo of Mall Staff 184060.00 $tone December 16, 2022
Public

Hi there,

your module adds the value selected in your default values – even if the field “State / region” isn’t shown during checkout.
This is a bug in your module. There is not need to access our site.

Please consider applying settings on your site with the steps suggested in reply #12.
And you can try to disable the following default values of the related configuration in the config file at the path: app/code/Ubertheme/Checkout/etc/config.xml 

 <default_values>
<country_id>US</country_id>
<region_id>3</region_id>
</default_values>

Hopes that helps.

We will consider reviewing the issues you mentioned further for future release.
Regards,
Mall.

#14
Profile photo of Kasper Brandt Hansen 510.00 $tone December 16, 2022
Public

As mentioned, that is exactly what was done from the beginning. As I described – in the very first message. The description from your reply #12 are the settings we have had from the beginning.
Removing the default_values node from Ubertheme/Checkout/etc/config.xml does not change the cause of the problem. The data is fetched from the the DB and handled in your code that fails. 
I have tested and it doesn’t work. 

#15
Profile photo of ubdev Staff 98150.00 $tone December 21, 2022
Public

Hi Kasper Brandt Hansen,
 
Sorry for the inconvenience that you encountered. 
Currently our team is unable to look into this fully as we’re occupied with other tasks. As mentioned in reply #14, we will consider reviewing the issue further in future. 

 
Best regards,
 

#16
Profile photo of ubdev Staff 98150.00 $tone December 22, 2022
Public

Hi Kasper,

Are you saying that you don’t have time to fix an obvious and very simple bug in your module?

Sorry if there was a misunderstanding. Our team will be checking the issue of course, however it might take a while so we want to let you know.

We will try to work on this asap and notify you once there’s an update.

 
Best regards,

#18
Profile photo of ubdev Staff 98150.00 $tone February 16, 2023
Public

Hi there,

As our team is currently occupied with other tasks right now, we haven’t been able to upgrade the module yet.

What is your position on the situation that our download/support period has expired in the period were this reported bug hasn’t been fixed?

Please rest assured that we will provide you with the fix after the upgrade, even if your membership has expired by then.

#20
Profile photo of Kasper Brandt Hansen 510.00 $tone February 16, 2023
Public

It has been more than two months since I reported the bug and the module hasn’t been updated since May 17, 2022 – and given the fact that your deleted that from my post…. can you give me an estimate of the timeframe? Days, weeks, months? I don’t think that’s unfair to ask for.

#21
Profile photo of ubdev Staff 98150.00 $tone February 17, 2023
Public

Hi

can you give me an estimate of the timeframe? Days, weeks, months? I don’t think that’s unfair to ask for.

I’m sorry that our team hasn’t been able to work on the upgrade for the module. The team has priorities in other tasks right now so it is not possible to give an estimate.
 

#22

This question is now closed

Written By

Comments