remove lastname validation in checkout

本文介绍如何在Magento中修改顾客地址验证逻辑,移除对lastname字段的验证,并覆盖后台订单列表的billingname和shippingname展示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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字段。

此方法仅仅在展示的时候做了隐藏

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值