When we created the customer_profile inline form, we ported the default_country handling from the previous commerce_profile_select element. Callers are responsible for passing the default_country, and they get it from $store->getAddress()->getCountryCode(). This is both verbose and not flexible enough.

Commerce actually has a CurrentCountry service, which invokes country resolvers, and the StoreCountryResolver sets the country to $store->getAddress()->getCountryCode(). However, other sites might use geoip or a domain to determine the customer's country, or some other logic (previous profile, for example). Basically, it allows the "current country" to be altered.
This is the country we'd expect to see preselected at checkout.

So, we want to remove the default_country setting and stop passing it. The CustomerProfile form should inject the CurrentCountry service and get the default country from there. We also need to compare that value against the list of available countries, and skip the default if that country is not available. This is needed because by default the Address/Country form elements ensure that the default country is always available, and that is not advisable here because it would allow the customer to order to a country to which the store might not ship to (or is forbidden from billing to).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bojanz created an issue. See original summary.

bojanz’s picture

Status: Active » Needs review
FileSize
11.69 KB

First try. Let's see what the existing tests say.

bojanz’s picture

Issue summary: View changes
bojanz’s picture

Now with additional test coverage.

  • bojanz committed 24ece25 on 8.x-2.x
    Issue #3024878 by bojanz: Rework the customer profile default_country...
bojanz’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.