Pergunta

I've updated database directly to make is_required on lastname = 0.

Removed the js validator for lastname in core.

Removed required field in frontend in widget/name.phtml.

However, The "Last name is required field" message still popups in 3 places:

During onepage checkout
When creating an order in admin for billing/shipping address
When inputing billing/shipping address for a customer in admin

Could some one help me please? We're doing wholesale and use only Purchase Order and COD. Thus, customer normally only puts in their outlet name in First Name field. Last Name is just optional for them.

Foi útil?

Solução

To make field Last Name none required for Customer editing in admin create sql upgrade script

/* @var $this Mage_Customer_Model_Resource_Setup */
$this->updateAttribute('customer_address','lastname','is_required','false');

Outras dicas

I was searching for an answer to that problem myself and I've merged both your answers as you have to do all these steps – so I'm undigging dead topic for future users.

1. First it's nice to run a SQL Query (i.e. in phpMyAdmin):

UPDATE eav_attribute SET is_required = 0 WHERE attribute_code = 'lastname'

2. Get rid of classes for JS validation

class="required" and class="required-entry" anywhere related with 'lastname' field where there are forms to save (i.e. customer/address/edit.phtml, persistent/checkout/billing.phtml)

3. Copy your core files from:

/app/code/core/Mage/customer/Model/Address/Abstract.php
/app/code/core/Mage/customer/Model/Customer.php
/app/code/core/Mage/customer/etc/config.xml

into:

/app/code/local/Mage/customer/Model/Address/Abstract.php
/app/code/local/Mage/customer/Model/Customer.php
/app/code/local/Mage/customer/etc/config.xml

And comment out everything related to Zend validation of Lastname.

/app/code/local/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/local/Mage/customer/Model/Customer.php

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

/app/code/local/Mage/customer/etc/config.xml

you have to search for:

 <lastname>
                <billing>1</billing>
                <shipping>1</shipping>
                **<required>0</required>** // change from 1 to 0
                <mapped>1</mapped>
 </lastname>

1. Remove the classes for JS validation from your templates.

customer/widget/name.phtml

Remove class="required" from the label relating to the lastname field at line 80

Remove <?php echo $this->helper('customer/address') ->getAttributeValidationClass('lastname') ?> from the input relating to lastname at line 82

2. Copy your core files from:

/app/code/core/Mage/customer/Model/Address/Abstract.php /app/code/core/Mage/customer/Model/Customer.php

into:

/app/code/local/Mage/customer/Model/Address/Abstract.php /app/code/local/Mage/customer/Model/Customer.php

And comment out everything related to Zend validation of Lastname.

/app/code/local/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/local/Mage/customer/Model/Customer.php

php code

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

3. Update the config.xml file for customer

/app/code/core/Mage/customer/etc/config.xml

copy to file

/app/code/local/Mage/customer/etc/config.xml

For last_name field, set required value "1" to "0"

4. At last update using row query in database

UPDATE eav_attribute SET is_required = 0 WHERE attribute_code = 'lastname'

For me, all that I did to solve this was this:

update eav_attribute set is_required=0 where attribute_code like 'firstname'; update eav_attribute set is_required=0 where attribute_code like 'lastname';

Licenciado em: CC-BY-SA com atribuição
Não afiliado a magento.stackexchange
scroll top