調整姓名顯示順序

edited 十一月 -1 in Magento
表單的部份可以透過 template 修改,顯示的部份就比較麻煩了

因為不想要直接動手修改核心程式,所以試著透過模組來覆寫

需要處理的 model 如下(放在 etc/config.xml 中的)
<models>
<customer>
<rewrite>
<customer>Namespace_ModuleName_Model_Customer</customer>
<address>Namespace_ModuleName_Model_Address</address>
</rewrite>
</customer>

<sales>
<rewrite>
<order_address>Namespace_ModuleName_Model_Order_Address</order_address>
<quote_address>Namespace_ModuleName_Model_Quote_Address</quote_address>
</rewrite>
</sales>
</models>


依據上面設定需要放入下面這些檔案:
Model/Order/Address.php
Model/Quote/Address.php
Model/Customer.php
Model/Address.php

檔案內容都長的像這樣:
<?php

class Namespace_ModuleName_Model_Order_Address extends Mage_Sales_Model_Order_Address {

/**
* Get full customer name
*
* @return string
*/
public function getName() {
$name = '';
$config = Mage::getSingleton('eav/config');
if ($config->getAttribute('customer_address', 'prefix')->getIsVisible() && $this->getPrefix()) {
$name .= $this->getPrefix() . ' ';
}
$name .= $this->getLastname();
if ($config->getAttribute('customer_address', 'middlename')->getIsVisible() && $this->getMiddlename()) {
$name .= ' ' . $this->getMiddlename();
}
$name .= $this->getFirstname();
if ($config->getAttribute('customer_address', 'suffix')->getIsVisible() && $this->getSuffix()) {
$name .= ' ' . $this->getSuffix();
}
return $name;
}

}


其中 Namespace_ModuleName 是自己的命名空間與模組名稱,需要 extends 的對象如下
Model/Order/Address.php => Mage_Sales_Model_Order_Address
Model/Quote/Address.php => Mage_Sales_Model_Quote_Address
Model/Customer.php => Mage_Customer_Model_Customer
Model/Address.php => Mage_Customer_Model_Address

到這裡還沒結束,還需要進入系統的後台,在 "系統 -> 設定 -> 客戶 -> 客戶設定 -> 地址樣板" 裡面每個欄位都需要調整

到這裡其實後台還是有些地方會看到姓名顛倒的情況,但前台看起來已經 OK 了

Magento 版本 1.8.0.0-alpha1

原始討論: http://twpug.net/x/modules/newbb/viewtopic.php?topic_id=7550
Sign In or Register to comment.