Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Defining the zip attributes based on the xsd schema #4530

Merged
merged 3 commits into from
May 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions guides/v2.1/howdoi/checkout/checkout_zip.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,34 @@ When a shopper specifies the country and ZIP code in the shipping address during
In Magento the input masks for the **ZIP code** field are specified in the `<Magento_Directory_module_dir>/etc/zip_codes.xml`. Input masks are specified per country, and are entered in the form of regular expressions.
The syntax of defined by the [zip_code.xsd]({{ site.mage2bloburl }}/{{ page.guide_version }}/app/code/Magento/Directory/etc/zip_codes.xsd) scheme.

The following table defines the `zip` node attributes:

Attribute name | Required | Description
--- | --- | ---
`countryCode` | Yes | The country code (Alpha-2 format) for which the zip is defined

```xml
<zip countryCode="US">
<!-- Here we add the zip codes -->
</zip>
```

The following table defines the `code` node attributes:

Attribute name | Required | Description
--- | --- | ---
`id` | Yes | A random unique name within the same list.
`example` | Yes | An example of the allowed pattern.
`active` | No | Defines if this zip pattern is active or not.

You can define several zip `code` patterns for the same country, by passing a list of `codes`.
```xml
<codes>
<code id="pattern_1" active="true" example="12345">^[0-9]{5}$</code>
<code id="pattern_2" active="true" example="AB1234">^[a-zA-z]{2}[0-9]{4}$</code>
</codes>
```

For the sake of compatibility, upgradability, and easy maintenance, do not edit the default Magento code. Add your customizations in a separate, custom module. For your ZIP code input mask customization to be applied correctly, your custom module should depend on the `Magento_Directory` module. Do not use `Ui` for your custom module name, because `%Vendor%_Ui` notation, required when specifying paths, might cause issues.

## Add custom ZIP code input masks {#add}
Expand Down