Magento结账页面显示国家大洲地址缩写

本教程适用于Magento1.9.X

首先创建模型文件:

app/code/community/Magentochina/Stateabrv/Model/Region.php

填充文件:

<?php
class Magentochina_Stateabrv_Model_Region extends Mage_Directory_Model_Region {
	//继承于Mage_Directory_Model_Region类并重写
	public function getName()
	{
		$name = $this->getData('name');

		if (!is_null($name)) {

			/*
			* 获取国家ID,如果国家为美国,则返回code缩写
			*/

			$regionCountry = $this->getData('country_id');

			if($regionCountry && $regionCountry=='US') {

				$name = $this->getData('code')."-".$name;

			}

			unset($regionCountry);

		}

		/*
		* 如果 $name 为空, 返回默认值
		*/

		if (is_null($name)) {
			$name = $this->getData('default_name');
		}
		return $name;
	}
}

创建配置文件

app/code/community/Magentochina/Stateabrv/etc/config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
	<Magentochina_Stateabrv>
		<version>0.1.0</version>
	</Magentochina_Stateabrv>
</modules>
<global>
	<models>
		<directory>
			<rewrite>
				<region>Magentochina_Stateabrv_Model_Region</region>
			</rewrite>
		</directory>
	</models>
</global>
</config>

实际效果图: