1.要覆盖原生验证类,先定义在config文件里:
<models> <customer_address> <rewrite> <abstract>Bysoft_Mycustomer_Model_Address_Abstract</abstract> </rewrite> </customer_address> </models>
2.把文件/app/code/core/Mage/Customer/Model/Address/Abstract.php
复制到自己的模块之后类定义这样写:
class Bysoft_Mycustomer_Model_Address_Abstract extends Mage_Customer_Model_Address_Abstract
{
3.注释掉验证lastname的地方
/*
if (!Zend_Validate::is($this->getLastname(), 'NotEmpty')) {
$errors[] = Mage::helper('customer')->__('Please enter the last name.');
}
*/
4.注释掉checkout模板文件里填写lastname的字段
<!--
<div class="field name-lastname">
<label for="<?php echo $this->getFieldId('lastname')?>" class="required"><em>*</em><?php echo $this->__('Last Name') ?></label>
<div class="input-box">
<input type="text" id="<?php echo $this->getFieldId('lastname')?>" name="<?php echo $this->getFieldName('lastname')?>" value="<?php echo $this->htmlEscape($this->getObject()->getLastname()) ?>" title="<?php echo $this->__('Last Name') ?>" class="input-text required-entry absolute-advice" <?php echo $this->getFieldParams() ?> />
</div>
</div>
-->
5.覆盖后台订单列表的billing name 和shipping name 展示
<blocks> <adminhtml> <rewrite> <sales_order_grid>Bysoft_Mycustomer_Block_Adminhtml_Sales_Order_Grid</sales_order_grid> </rewrite> </adminhtml> </blocks>
6.撰写覆盖类
class Bysoft_Mycustomer_Block_Adminhtml_Sales_Order_Grid extends Mage_Adminhtml_Block_Sales_Order_Grid
{
protected function _prepareCollection()
{
$collection = Mage::getResourceModel($this->_getCollectionClass());
$collection ->getSelect()
->joinLeft(array('t2'=>'sales_flat_order_grid'),
't2.entity_id=main_table.entity_id',
array(
't2_shipping_name'=>"SUBSTRING(t2.shipping_name,1,LOCATE(' ', t2.shipping_name))",
)
);
$this->setCollection($collection);
if ($this->getCollection()) {
$this->_preparePage();
$columnId = $this->getParam($this->getVarNameSort(), $this->_defaultSort);
$dir = $this->getParam($this->getVarNameDir(), $this->_defaultDir);
$filter = $this->getParam($this->getVarNameFilter(), null);
if (is_null($filter)) {
$filter = $this->_defaultFilter;
}
if (is_string($filter)) {
$data = $this->helper('adminhtml')->prepareFilterString($filter);
$this->_setFilterValues($data);
}
else if ($filter && is_array($filter)) {
$this->_setFilterValues($filter);
}
else if(0 !== sizeof($this->_defaultFilter)) {
$this->_setFilterValues($this->_defaultFilter);
}
if (isset($this->_columns[$columnId]) && $this->_columns[$columnId]->getIndex()) {
$dir = (strtolower($dir)=='desc') ? 'desc' : 'asc';
$this->_columns[$columnId]->setDir($dir);
$this->_setCollectionOrder($this->_columns[$columnId]);
}
if (!$this->_isExport) {
$this->getCollection()->load();
$this->_afterLoadCollection();
}
}
//return parent::_prepareCollection();
return ;
}
protected function _prepareColumns()
{
$this->addColumn('real_order_id', array(
'header'=> Mage::helper('sales')->__('Order #'),
'width' => '80px',
'type' => 'text',
'index' => 'increment_id',
));
if (!Mage::app()->isSingleStoreMode()) {
$this->addColumn('store_id', array(
'header' => Mage::helper('sales')->__('Purchased From (Store)'),
'index' => 'store_id',
'type' => 'store',
'store_view'=> true,
'display_deleted' => true,
));
}
$this->addColumn('created_at', array(
'header' => Mage::helper('sales')->__('Purchased On'),
'index' => 'created_at',
'type' => 'datetime',
'width' => '100px',
));
$this->addColumn('t2_shipping_name', array(
'header' => Mage::helper('sales')->__('Bill to Name'),
'index' => 't2_shipping_name',
'filter_index' => "SUBSTRING(t2.shipping_name,1,LOCATE(' ', t2.shipping_name))",
));
$this->addColumn('shipping_name', array(
'header' => Mage::helper('sales')->__('Ship to Name'),
'index' => 't2_shipping_name',
'filter_index' => "SUBSTRING(t2.shipping_name,1,LOCATE(' ', t2.shipping_name))",
));
$this->addColumn('base_grand_total', array(
'header' => Mage::helper('sales')->__('G.T. (Base)'),
'index' => 'base_grand_total',
'type' => 'currency',
'currency' => 'base_currency_code',
));
$this->addColumn('grand_total', array(
'header' => Mage::helper('sales')->__('G.T. (Purchased)'),
'index' => 'grand_total',
'type' => 'currency',
'currency' => 'order_currency_code',
));
$this->addColumn('status', array(
'header' => Mage::helper('sales')->__('Status'),
'index' => 'status',
'type' => 'options',
'width' => '70px',
'options' => Mage::getSingleton('sales/order_config')->getStatuses(),
));
if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
$this->addColumn('action',
array(
'header' => Mage::helper('sales')->__('Action'),
'width' => '50px',
'type' => 'action',
'getter' => 'getId',
'actions' => array(
array(
'caption' => Mage::helper('sales')->__('View'),
'url' => array('base'=>'*/sales_order/view'),
'field' => 'order_id'
)
),
'filter' => false,
'sortable' => false,
'index' => 'stores',
'is_system' => true,
));
}
$this->addRssList('rss/order/new', Mage::helper('sales')->__('New Order RSS'));
$this->addExportType('*/*/exportCsv', Mage::helper('sales')->__('CSV'));
$this->addExportType('*/*/exportExcel', Mage::helper('sales')->__('Excel XML'));
return $this;
}
}
值得注意的是两个方法均返回$this才能正确展示
数据库中并没有正正删除lastname字段。
此方法仅仅在展示的时候做了隐藏