I am trying to override the ZIP code validation xml file in Magento's Directory module. I'm doing this because I want to enforce a space in UK postcodes. The path of the file I'm attempting to override is:
/vendor/magento/module-directory/etc/zip_codes.xml
I'm attempting to override this by creating a file in my theme with the same name:
/app/design/frontend/[Company]/[Theme]/Magento_Directory/etc/zip_codes.xml
This hasn't had the desired effect, I presume I'm missing a key step but I've not been able to figure out what else is required. Any help would be greatly appreciated.
Best Answer
You cannot overwrite an existing XML file from the
etc
directory. What you are trying to do is working for files in theview
directory only.What you can do is extend an existing XML file with your own module which will be loaded after the
Magento_Directory
module (controlled by the<sequence>
tag in the module.xml). This module can have aetc/zip_codes.xml
file too. Don't copy all of the original file, just the header and the footer:So let's assume you want to change the zip range for Australia (AU) which is as follows by default:
You can add a second range in your own module:
Or disable an existing pattern:
Or change an existing entry:
You can access an existing entry by using the same main identifier
id
.For your case the zip_codes.xml will probably look as follows (
+
removed):