2

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.

5
  • Did you clear all cache? Try to check source code in browser if your changes are applied. Jan 26, 2014 at 11:56
  • Hi Oleksii. I've cleared all cache. However, I didn't manually delete folder var/cache. Will try it again but I suspect Magento groups the names (first & last) together during checkout.
    – user4928
    Jan 26, 2014 at 12:10
  • Did you remove class 'required-entry' on input field? By this class javascript knows which field to validate. Jan 26, 2014 at 12:14
  • In file widget/name.phtml remove css class 'require-entry' which belongs to last name input field. After please test for all your other cases. Maybe this will help you too. Jan 26, 2014 at 12:24
  • I can confirm that after manually deleting all cache I can pass last name validation during checkout. Now I'm stuck when creating address for customer in the backend only.
    – user4928
    Jan 26, 2014 at 12:54

4 Answers 4

2

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');
2
  • How Can I run a direct queries in phpmyadmin? I'm a Web Designer unfortunately
    – user4928
    Jan 26, 2014 at 15:47
  • UPDATE eav_attribute SET is_required = 0 WHERE attribute_code = 'lastname' After clean cache. Jan 26, 2014 at 16:21
8

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>
6
  • 1
    Additionally for Magento 1.9 - I found that customer_eav_attribute had keys referencing lastname fields and has validation rules against ID 7 and 22 in my default installation - UPDATE customer_eav_attribute SET validate_rules = 'a:1:{s:15:"max_text_length";i:255;}' WHERE customer_eav_attribute.attribute_id = 22; - to just leave a max length. May 27, 2015 at 14:31
  • i followed your step but it still showing lastname required
    – Magento 2
    Sep 14, 2015 at 12:56
  • @Manojkothari can you be a little bit more specific? Where's is the prompt for lastname displayed when what actions are taken? Are there any logs in system.log or your apache server error logs?
    – versedi
    Sep 14, 2015 at 13:59
  • Create account and billing address for that time it will through the error
    – Magento 2
    Sep 14, 2015 at 14:00
  • Check if your template file is not covered with required="required" or required in INPUT tag responsible for that name field. What version are you using? In last patch there were changes in function getCustomerName
    – versedi
    Sep 14, 2015 at 14:01
0

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'
0

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';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.