-
Notifications
You must be signed in to change notification settings - Fork 638
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
[5.x]: "City" field in address slideout is incorrectly labelled/populated for UK addresses #15551
Comments
@peteeveleigh can you confirm this is only happening with Commerce installed, or is it the same for addresses without Commerce? |
@lukeholder It's the same without Commerce. Just a Craft install with no plugins at all. |
Thank you for raising this with us. We have identified the cause of the bug and are now looking to create a solution to fix the issue. In the meantime, the following code provides a temporary solution to ensure that the counties are in the administrative area field and therefore leaving the "City" ( use CommerceGuys\Addressing\AddressFormat\AddressField;
use craft\events\DefineAddressFieldLabelEvent;
use craft\events\DefineAddressFieldsEvent;
use craft\events\DefineAddressSubdivisionsEvent;
use craft\services\Addresses;
// ...
// Add the 'administrativeArea' field to the list of fields used by the 'GB' country code
Event::on(
Addresses::class,
Addresses::EVENT_DEFINE_USED_FIELDS,
function(DefineAddressFieldsEvent $event) {
if ($event->countryCode === 'GB') {
$event->fields[] = AddressField::ADMINISTRATIVE_AREA;
}
}
);
// Change the label of the 'administrativeArea' field to "County" for the 'GB' country code
Event::on(
Addresses::class,
Addresses::EVENT_DEFINE_FIELD_LABEL,
function(DefineAddressFieldLabelEvent $event) {
if ($event->countryCode === 'GB' && $event->field === AddressField::ADMINISTRATIVE_AREA) {
$event->label = 'County';
}
}
);
// Add a blank option to 'GB' country code subdivisions to avoid accidental selection when resaving an address
Event::on(
Addresses::class,
Addresses::EVENT_DEFINE_ADDRESS_SUBDIVISIONS,
function (DefineAddressSubdivisionsEvent $event) {
if (!empty($event->parents) && $event->parents[0] === 'GB' && count($event->parents) === 1) {
$event->subdivisions = array_merge(['' => 'Select county'], $event->subdivisions);
}
}
); We will keep this issue open and updated with all future updates. Thanks! |
Nice! Thank you! |
Craft 4.11.5 and 5.3.6 are out now with a fix for this, via #15584. |
What happened?
Ran into this on a project site earlier today, but just confirmed the behaviour on a brand new, clean install with no plugins other than Commerce installed.
Description
For UK Addresses, the "City" dropdown field in the Address slideout is populated with a weird mix of counties and cities and there is no "County" field
For example, the dropdown contains both "Cardiff" which is a city, and "Worcestershire" which is a county.
Furthermore, many towns and cities are missing from the list, for example "Evesham" (a town in Worcestershire) so it's not possible to enter an accurate address.
As it is, it's pretty unusable.
It feels like a mix of 3 things.
Steps to reproduce
Expected behavior
Actual behavior
Craft CMS version
6.3.4
Craft Commerce version
5.0.16.2
PHP version
8.2.18
Operating system and version
Linux 6.6.32-linuxkit
Database type and version
MySQL 8.0.33
Image driver and version
No response
Installed plugins and versions
The text was updated successfully, but these errors were encountered: