Skip to content

Allow opting countries out of states_required at seed time#6458

Open
shaggybelco wants to merge 1 commit intosolidusio:mainfrom
shaggybelco:fix/3803-germany-states-not-required
Open

Allow opting countries out of states_required at seed time#6458
shaggybelco wants to merge 1 commit intosolidusio:mainfrom
shaggybelco:fix/3803-germany-states-not-required

Conversation

@shaggybelco
Copy link
Copy Markdown

Carmen exposes German Bundesländer as subregions, so the default seeder marks Germany's Spree::Country#states_required as true. PayPal and Braintree do not return state data for German addresses, which then fails Solidus's address validation at checkout.

Introduce a countries_not_requiring_states preference (default ["DE"]) and consult it from both the country seeder and the country factory. The Spree::Country.iso == "DE" row will be seeded with states_required = false going forward, and host applications can extend the list (e.g. ["DE", "ES"]) without monkey-patching the seeder.

Existing seeded databases keep their current values; this only affects new installs and freshly created Spree::Country records.

Closes #3803

Summary

Checklist

Check out our PR guidelines for more details.

The following are mandatory for all PRs:

The following are not always needed:

  • 📖 I have updated the README to account for my changes.
  • 📑 I have documented new code with YARD.
  • 🛣️ I have opened a PR to update the guides.
  • ✅ I have added automated tests to cover my changes.
  • 📸 I have attached screenshots to demo visual changes.

Carmen exposes German Bundesländer as subregions, so the default
seeder marks Germany's `Spree::Country#states_required` as `true`.
PayPal and Braintree do not return state data for German addresses,
which then fails Solidus's address validation at checkout.

Introduce a `countries_not_requiring_states` preference (default
`["DE"]`) and consult it from both the country seeder and the country
factory. The `Spree::Country.iso == "DE"` row will be seeded with
`states_required = false` going forward, and host applications can
extend the list (e.g. `["DE", "ES"]`) without monkey-patching the
seeder.

Existing seeded databases keep their current values; this only affects
new installs and freshly created `Spree::Country` records.

Closes solidusio#3803
@shaggybelco shaggybelco requested a review from a team as a code owner April 25, 2026 14:00
@github-actions github-actions Bot added the changelog:solidus_core Changes to the solidus_core gem label Apr 25, 2026
Copy link
Copy Markdown
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. We already have a config for this. The list should be updated though.

We also have another issues that's a bit trickier to solve.

Carriers need subregions in certain European countries. Netherlands, Italy are two of them. But these countries don't need subregions for payment (PayPal).

We probably need to add a setting to payment and shipping methods instead of a global address setting to address the issue.

# the canonical case: PayPal/Braintree return no state for German addresses,
# which would otherwise fail address validation at checkout.
# (default: +['DE']+)
preference :countries_not_requiring_states, :array, default: ["DE"]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we already have the config above. we should use that instead

states_required { carmen_country.subregions? }
states_required do
carmen_country.subregions? &&
Spree::Config[:countries_not_requiring_states].exclude?(carmen_country.alpha_2_code)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the existing config

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog:solidus_core Changes to the solidus_core gem

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Set states_required to false for Germany

2 participants