`
kirenenko04
  • 浏览: 152237 次
  • 性别: Icon_minigender_2
  • 来自: 上海
社区版块
存档分类
最新评论

remove lastname validation in checkout

 
阅读更多

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

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

 

分享到:
评论

相关推荐

    struts2中两种validation.xml的配置方式

    在Struts2框架中,`validation.xml`是用于定义验证规则的重要配置文件。根据所提供的信息,我们可以了解到文章主要探讨了Struts2中两种不同的`validation.xml`配置方式,并且通过一个具体的例子进行了说明。下面将对...

    extjs动态生成树,绝对能运行产生

    INSERT INTO Employee(FirstName, LastName, SupervisorID) VALUES('Cheung','Carin',201); INSERT INTO Employee(FirstName, LastName, SupervisorID) VALUES('Cheung','Geoffrey C',201); INSERT INTO Employee...

    js中for in的用法示例解析.docx

    在这个例子中,`for...in`循环会依次输出`firstName`、`lastName`和`age`这三个属性及其对应的值。注意,它并不会区分对象自身和从原型链继承的属性。 然而,有时候我们可能只想获取对象自身的属性,而不包括从原型...

    use-model-validation:将数据存储在模型中并在任何地方验证数据

    使用模式 将数据存储在模型中并在任何地方验证数据 ... lastName : [ R . max ( 20 , "Too long, must be :max characters or less" ) ] , email : [ R . required ( "Email is required" ) ] , } , } ) ; // Upda

    split-human-name:将一个人的名字分为firstName和lastName字段

    将名称精确地划分为两个字段{ firstName, lastName } 修复了大写字母,小写字母,iNVERSE大写字母和其他错误样式的情况 处理情侣(“ John and Jane Doe”) 如果存在多个姓氏,则正常降级以将整个字符串放在...

    DbfDotNet_version_1.0_Source

    indiv.LASTNAME = lastname; indiv.DOB = dob; indiv.STATE = state; indiv.SaveChanges(); } Collapse Copy Codevoid InsertNewIndividual( int id, string firstname, string middlename, string ...

    SQL经典语法SQL经典语法

    例如,`SELECT * FROM Persons WHERE LastName IN ('Adams','Gates')`选取LastName为Adams或Gates的记录。 13. **BETWEEN...AND运算符**:`BETWEEN`用于选取在两个值之间的记录。例如,`SELECT * FROM Persons ...

    微软内部资料-SQL性能优化5

    For example, if the clustered index is on (lastname, firstname) and a nonclustered index is on firstname, the firstname value will not be duplicated in the nonclustered index leaf rows. Note The ...

    DB2 solutions

    SELECT LASTNAME, SALARY, BONUS, COMM FROM EMPLOYEE WHERE SALARY &gt; 22000 AND BONUS IN (400, 500) AND COMM &lt; 1900 ORDER BY LASTNAME ``` 使用IN关键字可以简化多个OR条件。 9. 查找活动号为10、80或180,...

    SQL语句大全

    - **示例**: `SELECT * FROM Persons WHERE LastName IN ('Adams', 'Carter');` —— 从Persons表中选择LastName为Adams或Carter的记录。 **3.4 BETWEEN操作符** - **语法**: `SELECT * FROM table_name WHERE ...

    SQLServer2000到Oracle11G存储过程转换技术探究.pdf

    (lastname IN VARCHAR2, firstname OUT VARCHAR2) AS BEGIN SELECT Firstname INTO firstname FROM Authors WHERE Lastname = lastname; END; ``` 转换过程中,需要注意以下几点: 1. **参数声明**:SQLServer...

    son-flowe-father.zip_Father

    self.lastName = lastName self.age = age def getFullName(self): return self.firstName + " " + self.lastName # 其他getter和setter方法... ``` 接着,我们可以创建一个`Family`类来存储家庭成员,包括...

    SQL Server存储过程入门......

    WHERE LastName = @LastName ``` 调用此存储过程有两种方式: ```sql EXEC uspGetContact 'Alberts' EXEC uspGetContact @LastName='Alberts' ``` 进一步扩展,存储过程可以有输入和输出参数。例3展示了如何在...

    ORACLE的SQL语句脚本

    p_lastname IN Employees.LastName%TYPE, p_jobtitle IN Employees.JobTitle%TYPE, p_hiredate IN Employees.HireDate%TYPE) AS BEGIN INSERT INTO Employees VALUES(p_employeeID, p_firstname, p_lastname, p_...

    SQL语法手册.pdf

    例如,从 "Persons" 表中选出字段名 "LastName" 和 "FirstName" 的数据: SELECT LastName, FirstName FROM Persons 返回结果: LastName FirstName Hansen Ola Svendson Tove Pettersen Kari 二、WHERE 语句 ...

    SqlServer语法

    SELECT * FROM Persons WHERE LastName IN ('Adams', 'Carter') ``` 五、BETWEEN 操作符 BETWEEN 操作符用于选取介于两个值之间的数据范围。基本语法为: ``` SELECT column_name(s) FROM table_name WHERE column_...

    SQL Server存储过程入门案例详解

    WHERE LastName = @LastName ``` 调用时,可以传入参数值,如`EXEC uspGetContact 'Alberts'`,或者指定参数名和值,如`EXEC uspGetContact @LastName='Alberts'`。 **带有输入和输出参数的存储过程** 例3展示了一...

    学习SQL Server存储过程入门例子详解

    WHERE LastName = @LastName ``` 执行该存储过程的命令如下: ```sql EXEC uspGetContact 'Alberts' ``` 或 ```sql EXEC uspGetContact @LastName='Alberts' ``` 查询的结果将显示与传入参数匹配的记录。 例 3:带...

Global site tag (gtag.js) - Google Analytics