Magento – How to Parse Billing Address

billing-addressmagento-1.8magento-1.9pdf

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?

Best Answer

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

see below enter image description here

Related Topic