Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.x]: Discrepancy in UK administrative areas (County/Counties) #3363

Closed
emarthinsen opened this issue Jan 11, 2024 · 1 comment
Closed

[4.x]: Discrepancy in UK administrative areas (County/Counties) #3363

emarthinsen opened this issue Jan 11, 2024 · 1 comment
Assignees
Labels
bug commerce4 Issues related to Commerce v4

Comments

@emarthinsen
Copy link

emarthinsen commented Jan 11, 2024

What happened?

Description

This relates to craftcms/cms#13101, but is a bit different. I actually don't really care if our address form shows or doesn't show UK counties. However, I notice that when we call:

craft.commerce.store.getStore().getAdministrativeAreasListByCountryCode()

It returns a list of administrative areas for GB.

When we go to the Craft CP, navigate to a user with a United Kingdom address, and edit it, no administrative areas are available to be selected. Also, whatever the user originally entered into our form for their administrative area wasn't saved.

The output of getAdministrativeAreasListByCountryCode should match the list of administrative areas used by the Craft CP.

I'd love to know how to get these to match. I'm fine getting our form to match what the CP is doing. I don't have a horse in the race of counties vs. no counties in the UK. I'd also prefer to do this without resorting to custom code that is GB-specific, since I presume the issue is a specific case of a more general one and we could run into the same with other countries.

Expected behavior

Both the Craft CP and the getAdministrativeAreasListByCountryCode method should both use the same list (even an empty list) of administrative areas for GB.

Actual behavior

The Craft CP provides no administrative areas for GB. The method getAdministrativeAreasListByCountryCode returns 213 administrative areas for GB.

Craft CMS version

4.5.10 Pro

Craft Commerce version

4.3.2

PHP version

8.0.30

Operating system and version

Linux 5.3.0-7648-generic

Database type and version

MariaDB 10.4.32

Image driver and version

Imagick 3.7.0 (ImageMagick 6.9.11-60)

Installed plugins and versions

  • Amazon S3 2.0.3
  • Asset Rev 7.0.0
  • Craft Commerce 4_3_2
  • Inventory 3.1.1
  • Redactor 3.0.4
  • Redirect Manager 2.0.0
  • Sentry SDK 2.0.1
  • Stripe for Craft Commerce 4.0.1.1
  • Super Table 3.0.12
  • Typed link field 2.1.5
@emarthinsen emarthinsen added commerce4 Issues related to Commerce v4 bug labels Jan 11, 2024
@i-just
Copy link
Contributor

i-just commented Mar 28, 2024

Hi, thanks for reaching out!

The quickest way to match the control panel and front-end, and to allow the ADMINISTRATIVE_AREA value to save in the database is to add:

Event::on(
    Addresses::class,
    Addresses::EVENT_DEFINE_USED_SUBDIVISION_FIELDS,
    function(DefineAddressFieldsEvent $event) {
        if ($event->countryCode === 'GB') {
            $event->fields[] = AddressField::ADMINISTRATIVE_AREA;
        }
    }
);

to a module or a plugin.

If the above is not added, the subdivision field won't show for the GB in the control panel, and the value won't be saved in the database when added via the front-end. The list of subdivisions is still there if the field is not added via the event (hence it's returned via craft.commerce.store.getStore().getAdministrativeAreasListByCountryCode()), but not used.
So, theoretically, there should be no need to getAdministrativeAreasListByCountryCode() if you're not adding the the ADMINISTRATIVE_AREA field via event.

I hope this helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug commerce4 Issues related to Commerce v4
Projects
None yet
Development

No branches or pull requests

3 participants