Magento 用户姓名中文化

2016年3月9日 Edited 2022年12月6日 浏览量 21 2 min read
Magento 用户姓名中文化
因magento用的是西方的姓名规则,即前名firstname,后姓lastname,与我们国内姓名规则相反;这里通过修改后姓lastname为非必填,并隐藏,将前名firstname作为姓名整体使用,用这个方法来解决magento的中文姓名颠倒问题。

一、修改数据库字段属性
  

      
    UPDATE `eav_attribute` SET `is_required` = '0' WHERE `eav_attribute`.`attribute_id` =22;
  UPDATE `eav_attribute` SET `is_required` = '0' WHERE `eav_attribute`.`attribute_id` =7;
  UPDATE `customer_eav_attribute` SET `validate_rules` = 'a:2:{s:15:"max_text_length";i:255;s:15:"min_text_length";i:0;}' WHERE `customer_eav_attribute`.`attribute_id` =7;
  UPDATE `customer_eav_attribute` SET `validate_rules` = 'a:2:{s:15:"max_text_length";i:255;s:15:"min_text_length";i:0;}' WHERE `customer_eav_attribute`.`attribute_id` =22;
      
    


  执行以上两条sql,把字段属性先设置为非必填。
  注意:以上代码非普遍适用,最好打开数据库手工修改!


  二、去掉验证代码  修改文件app/code/core/Mage/Customer/Model/Address/Abstract.php,找到这个并注释掉:

      
  if (!Zend_Validate::is($this->getLastname(), 'NotEmpty')) {
            $this->addError(Mage::helper('customer')->__('Please enter the last name.'));
        }
  
    


  修改文件app/code/core/Mage/Customer/Model/Customer.php,找到这个并注释掉:

      
  if (!Zend_Validate::is( trim($this->getLastname()) , 'NotEmpty')) {
            $errors[] = Mage::helper('customer')->__('The last name cannot be empty.');
        }
  
    


  三、新问题  将lastname修改为非必填后,当lastname输入为空值时,网站后台的客户管理列表中不显示用户名,解决方法如下:
  修改文件:/app/code/core/Mage/Adminhtml/Block/Customer/Grid.php,将:

      
  /*$this->addColumn('firstname', array(
  'header' => Mage::helper('customer')->__('First Name'),
  'index' => 'firstname'
  ));
  $this->addColumn('lastname', array(
  'header' => Mage::helper('customer')->__('Last Name'),
  'index' => 'lastname'
  ));*/
  $this->addColumn('name', array(
  'header' => Mage::helper('customer')->__('Name'),
  'index' => 'name'
  ));
  
    


  改为:

      
  $this->addColumn('firstname', array(
  'header' => Mage::helper('customer')->__('First Name'),
  'index' => 'firstname'
  ));
  /*$this->addColumn('lastname', array(
  'header' => Mage::helper('customer')->__('Last Name'),
  'index' => 'lastname'
  ));
  $this->addColumn('name', array(
  'header' => Mage::helper('customer')->__('Name'),
  'index' => 'name'
  ));*/
  
    


  以上更改启用了firstname栏目,禁用了lastname和name栏目。


  四、magento前端隐藏后姓lastname(可选)
  使用css将mangeto前端的lastname输入栏目隐藏掉,在style.css后加入:

      
  div.name-lastname{display:none;}/*注:magento modern theme适用。*/
  
    


  五、完成。

Previous article:
Next article:
Comments
发表评论,留下你的足迹
我们不会公开你的邮箱地址

是否允许我们在发布新内容或者进行促销活动向您发送消息?

Remind me later

Thank you! Please check your email inbox to confirm.

Oops! Notifications are disabled.

© 2014-2023 www.magease.com. All Rights Reserved. 寰云网络 版权所有    鲁ICP备 14014975号-1