3

I'd like to override the address layout defined in Magento\Customer\etc\config.xml -> default | customer | address_templates | oneline | html

In Magento 1, we could re-define a config.xml file in the local pool or in a module, and everything got mashed together and our new values over-rode it.

However, this doesn't seem to work in Magento 2, assuming from the documentation that config.xml only affects the scope of the module? So, I've tried adding:

Vendor/Namespace/etc/config.xml or Vendor/Namespace/etc/frontend/config.xml with the following content:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
    <customer>
        <address_templates>
            <html><![CDATA[{{depend prefix}}{{var prefix}} {{/depend}}{{var firstname}} {{depend middlename}}{{var middlename}} {{/depend}}{{var lastname}}{{depend suffix}} {{var suffix}}{{/depend}}{{depend firstname}}<br/>{{/depend}}
                    {{depend company}}{{var company}}<br />{{/depend}}
                    {{if street1}}{{var street1}}<br />{{/if}}
                    {{depend street2}}{{var street2}}<br />{{/depend}}
                    {{depend street3}}{{var street3}}<br />{{/depend}}
                    {{depend street4}}{{var street4}}<br />{{/depend}}
                    {{if city}}{{var city}},  {{/if}}{{if region}}{{var region}}, {{/if}}{{if postcode}}{{var postcode}}{{/if}}<br/>
                    {{var country}}<br/>
                    {{depend telephone}}Telephone: {{var telephone}}{{/depend}}
                    {{depend fax}}<br/>F: {{var fax}}{{/depend}}
                    {{depend vat_id}}<br/>VAT: {{var vat_id}}{{/depend}}]]>
            </html>
        </address_templates>
    </customer>
</default>
</config>

However, I don't get the change (Telephone: instead of T: in this quick example).

EDIT: module.xml looks like this:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Vendor_Namespace" setup_version="0.1.0">
    <sequence>
        <module name="Magento_Customer"/>
    </sequence>
</module>

Do I need to create my own renderer for this and add a preference to use it, or am I missing something?

2

It is possible to change this in the admin of Magento. At Stores > Configuration > Customers > Customer Configuration, you can find the 'Address Templates'. You can change the T: to Telephone: for HTML and PDF over there.

1

Create your module and add the sequence so it runs after Magento_Customer

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="MyModule_Customer" >
        <sequence>
            <module name="Magento_Customer"/>
        </sequence>
    </module>
</config>

Add the config.xml in app/code/MyModule/Customer/etc/config.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
    <default>
        <customer>
            <address_templates>
                <text>{{depend prefix}}{{var prefix}} {{/depend}}{{var firstname}} {{depend middlename}}{{var middlename}} {{/depend}}{{var lastname}}{{depend suffix}} {{var suffix}}{{/depend}}
                    {{depend company}}{{var company}}{{/depend}}
                    {{if street1}}{{var street1}}
                    {{/if}}
                    {{depend street2}}{{var street2}}{{/depend}}
                    {{depend street3}}{{var street3}}{{/depend}}
                    {{depend street4}}{{var street4}}{{/depend}}
                    {{if city}}{{var city}},  {{/if}}{{if region}}{{var region}}, {{/if}}{{if postcode}}{{var postcode}}{{/if}}
                    {{var country}}
                    {{depend telephone}}T: {{var telephone}}{{/depend}}
                    {{depend fax}}F: {{var fax}}{{/depend}}
                    {{depend vat_id}}VAT: {{var vat_id}}{{/depend}}</text>
                <oneline>{{depend prefix}}{{var prefix}} {{/depend}}{{var firstname}} {{depend middlename}}{{var middlename}} {{/depend}}{{var lastname}}{{depend suffix}} {{var suffix}}{{/depend}}, {{var street}}, {{var city}}, {{var region}} {{var postcode}}, {{var country}}</oneline>
                <html><![CDATA[{{depend prefix}}{{var prefix}} {{/depend}}{{var firstname}} {{depend middlename}}{{var middlename}} {{/depend}}{{var lastname}}{{depend suffix}} {{var suffix}}{{/depend}}{{depend firstname}}<br />{{/depend}}
{{depend company}}{{var company}}<br />{{/depend}}
{{if street1}}{{var street1}}<br />{{/if}}
{{depend street2}}{{var street2}}<br />{{/depend}}
{{depend street3}}{{var street3}}<br />{{/depend}}
{{depend street4}}{{var street4}}<br />{{/depend}}
{{if city}}{{var city}},  {{/if}}{{if region}}{{var region}}, {{/if}}{{if postcode}}{{var postcode}}{{/if}}<br />
{{var country}}<br />
{{depend telephone}}T: {{var telephone}}{{/depend}}
{{depend fax}}<br />F: {{var fax}}{{/depend}}
{{depend vat_id}}<br />VAT: {{var vat_id}}{{/depend}}]]></html>
                <pdf><![CDATA[{{depend prefix}}{{var prefix}} {{/depend}}{{var firstname}} {{depend middlename}}{{var middlename}} {{/depend}}{{var lastname}}{{depend suffix}} {{var suffix}}{{/depend}}|
{{depend company}}{{var company}}|{{/depend}}
{{if street1}}{{var street1}}|{{/if}}
{{depend street2}}{{var street2}}|{{/depend}}
{{depend street3}}{{var street3}}|{{/depend}}
{{depend street4}}{{var street4}}|{{/depend}}
{{if city}}{{var city}}, {{/if}}{{if region}}{{var region}}, {{/if}}{{if postcode}}{{var postcode}}{{/if}}|
{{var country}}|
{{depend telephone}}T: {{var telephone}}|{{/depend}}
{{depend fax}}F: {{var fax}}|{{/depend}}|
{{depend vat_id}}VAT: {{var vat_id}}{{/depend}}|]]></pdf>
            </address_templates>
        </customer>
    </default>
</config>

In the above I have removed the telephone link, which is on the default XML template in /vendor/magento/module-customer/etc/config.xml

Run grunt refresh and do a cache:clean and/or static content deployment.

0

In the module.xml file of your M2 module you can set a sequence node which is basically the same as the depends node present in M1 app/etc/company_mymodule.xml file for the module company_mymodule. Have you set this sequence in your M2 module's config.xml?

1
  • Hi! The sequence node is currently <sequence> <module name="Magento_Customer"/> </sequence> – Douglas Radburn Jan 4 '17 at 19:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.