Change standard address format on Magento Frontend
I want to change Magento's standard address format on the customer address page. How can I do that?
For those who don't know the address format, it is the method in wich we write the address. For example, the english format for France is this:
Addressee (Natural person/Organization) More detailed description of addressee (optional) Housenumber + Streetname Postal code + uppercase town Country (if other than France)
The address format for the USA is this:
Name of address Street number and name Name of town, State abbreviation + ZIP code (typical handwritten format)
You can read 开发者_运维问答more at wikipedia. Thanks a lot.
It seems that the config.xml file is no longer used (or just to load the default values into the database).
Go to:
System->Configuration->Customer->Customer Configuration and scroll down to Address Templates.
There you find the same code as in the XML file.
Generally speaking the address formats are contained in app/code/core/Mage/Customer/config.xml look for some markup like this:
...
<default>
<customer>
<address_formats>
<text><![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}}
T: {{var telephone}}
{{depend fax}}F: {{var fax}}{{/depend}}}]]></text>
</address_templates>
</customer>
</default>
...
Magento Render Address as it is defined in magento admin Configuration. You can manage address format by changing address template.
Go to System/Configuration/Customer Configuration/Address Template/Html/ Edit the content as you wish to show.
Similarly you can edit PDF template for changing the pdf view of address.
I have create module for define multiple address format base on county :
Below is simple way to create it.
Create admin module for insert update 'directory_country_format' table.
rewrite Mage_Customer_Block_Address_Renderer_Default class in you module.
override below function
public function getFormat(Mage_Customer_Model_Address_Abstract $address=null)
{
$countryFormat = is_null($address) ? parent::getFormat($address) :
$address->getCountryModel()->getFormat($this->getType()->getCode());
if (is_object($countryFormat)) {
$cFormat = $countryFormat->getFormat();
}
$format = $countryFormat ?
(!empty($cFormat)?$cFormat:$this->getType()->getDefaultFormat()) :
$this->getType()->getDefaultFormat();
return $format;
}
Here is my module which help you for define address formats base on customer country.
http://magentosolution.com/index.php/2014/08/27/magento-address-formats-base-of-country/
精彩评论