Last active
June 7, 2024 09:03
-
-
Save vasilii-b/3dcac2fc66c78bd7f805d3c90d9c7962 to your computer and use it in GitHub Desktop.
Magento 2 (adobe commerce) find customers with wrong region ID in the address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select | |
cae.entity_id as "Address ID", | |
cae.parent_id as "Customer ID", | |
c.firstname, | |
c.lastname, | |
c.email, | |
cae.country_id, | |
cae.city, | |
cae.postcode, | |
cae.region as "Current Address Region", | |
cae.region_id as "Current Address Region ID", | |
r.default_name as "Proper Region", | |
r.region_id as "Proper Region ID" | |
from customer_address_entity as cae | |
left join customer_entity as c | |
on cae.parent_id = c.entity_id | |
left join directory_country_region as r | |
on cae.region = r.default_name and cae.country_id = r.country_id | |
where | |
(cae.region_id is not null OR cae.region_id != 0 or cae.region is not null) AND # region for country is required | |
cae.region in ( | |
select name from directory_country_region_name | |
) AND | |
cae.region_id != r.region_id | |
order by cae.country_id ASC | |
-- limit 100; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The fix for the region ID mismatch (customer address vs country region table)