Making State Required? In Checkout?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
9 years ago
Thank you Andrei,
Just wanted to make sure it would work on 3.4.
Bob
9 years ago
Hello,
I am trying to make these changes in the nopCommerce 3.4 version but it does not work. I noticed that the changes suggested in src/Presentation/Nop.Web/Views/Shared/_CreateOrUpdateAddress.cshtml are missing something:

Following changes are suggested:

                        data: { "countryId": selectedItem, "addSelectStateItem": "false" },  
17                       data: { "countryId": selectedItem, "addSelectStateItem": "true" },  

However in Views/Shared/_CreateOrUpdateAddress.cshtml file has following line of code:
data: { "countryId": selectedItem, "addEmptyStateIfRequired": "true" },

If I replace this code with the suggested data: { "countryId": selectedItem, "addSelectStateItem": "true" }
I got the error messaged "Failed to retrieve the state"

Can someone please help.
9 years ago
I think I found the reason why suggested changes are not working in nopCommerce 3.4

Following method GetStatesByCountryId of CountryController has following condition - "(addEmptyStateIfRequired && result.Count == 0)" so "Select state" is not added if there are any state configured for a given country. I have made following changes and after that it worked great!

Current Code:
if (addEmptyStateIfRequired && result.Count == 0)
                    result.Insert(0, new { id = 0, name = _localizationService.GetResource("Address.OtherNonUS") });                    


Updated Code:
               if (addEmptyStateIfRequired)
                   if (result.Count == 0)
                        result.Insert(0, new { id = 0, name = _localizationService.GetResource("Address.OtherNonUS") });
                    else
                        result.Insert(0, new { id = 0, name = _localizationService.GetResource("Address.SelectState") });

Hope this will help someone. Please let me know if I am missing something!


thank you
3 years ago
Hello,

Using nopC 4.3. I just received a paid order from a customer who used guest checkout. The shipping state is missing from the order. State is enabled and required for "Customer" form fields in settings. State is also enabled for "Checkout" form fields but there is no requirement checkbox. This seems odd.

Why is there no requirement checkbox for state in "Checkout" form fields under customer settings?

With this current configuration, any customer who uses guest checkout, the state is not required and causes problems when charging taxes by state because the order can be completed without a shipping state.

Regards
3 years ago
Please check that you have States configured for the Country they selected.
3 years ago
50 out of 52 states were already configured for United States.

The customer managed to select a billing state just fine.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.