2

I am having a little trouble with Magento's invoice PDF. Specifically, I want to change the address formatting. For example, currently Magento outputs names and addresses under the Billing Address heading like this:

John Doe  
123 Fake Street Los Angeles,  
California, 90210  
T: (310) 555-5555  

I want the output to have the following format:

John Doe  
123 Fake Street  
Los Angeles, California, 90210  
T: (310) 555-5555  

Where the city is on the same line as the State and Zip.

I have found how Magento formats the first example. I am trying to figure out how to modify Magento's code so that I get the second output.

In /app/code/core/Mage/Sales/Model/Order/Pdf/ -> Abstract.php there is a function _formatAddress() that takes in a string with the that looks like:

"John Doe| 123 Fake Street Los Angeles,| California, 90210| T: (310) 555-5555"

and parses the string with respect to the vertical bars ("|"). I've noticed that I need to place a vertical bar right after the Street in order to produce my desired output but I don't know what function inserts these vertical bars.

Also, _formatAddress() gets called like this:

$billingAddress = $this->_formatAddress($order->getBillingAddress()->format('pdf'));

I have tried tracing the getBillingAddress() and format('pdf') but have had no luck.

Does anyone know where the vertical bars get inserted?

3

You can customise the format via the back-end under System > Configuration > Customer Configuration > Address Templates > Pdf

see below enter image description here

  • Thanks! This worked for me. I moved the pipe from after "{{if city}}{{var city}}," to right before it. Thanks guys much appreciated! – Ivan Alvarado Jun 12 '15 at 17:25
0

This is the file you are looking for app/code/core/Mage/Customer/etc/config.xml

around line 562,

<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}}<br/>F: {{var fax}}{{/depend}}|
{{depend vat_id}}<br/>VAT: {{var vat_id}}{{/depend}}|]]></pdf>

Notice the pipes in it.

It's not recommended to edit it directly there as it's core file, you can edit it in your own module config.xml, something like this:

<default>
    <customer>
        <address_templates>
            <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}}<br/>F: {{var fax}}{{/depend}}|
{{depend vat_id}}<br/>VAT: {{var vat_id}}{{/depend}}|]]></pdf>
        </address_templates>
    </customer>
</default>

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.