Wednesday 1 July 2015

Magento Remove firstname and lastname for registration

Set the firstname and lastname fields in database not required

SELECT * FROM `eav_entity_type`;#find the customer entity_type_id
SELECT * FROM `eav_attribute` WHERE `attribute_code` IN ('lastname','firstname') and `entity_type_id`=1; #find firstname and lastname attributes;#find firstname and lastname attributes
UPDATE `eav_attribute` SET `is_required`=0  WHERE `attribute_code` IN ('lastname','firstname') and `entity_type_id`=1; #set is_required 0 which means it's not necessary

Copy and modify template file to remove the classes related to validation

Copy \app\design\frontend\base\default\template\customer\widget\name.phtml to your theme folder
Remove the following code for firstname and lastname field:
class='required'
<?php echo $this->helper('customer/address')->getAttributeValidationClass

Create a custom extension to override Mage_Customer_Model_Customer

Create a custom extension.
Add the following xml in config.xml
     <global>
        <models>
            <customer>
              <rewrite>
               <customer>Yourcompany_Yourmodule_Model_Customer</customer>
              </rewrite>
            </customer>
        </models>
     </global>
Copy the validate method from magento core to your module and remove the validation code of firstname and lastname

Hide firstname and lastname in registration form if needed

Add the following code in less file:
//hide first name and last name in registration form by bargainoverseas dev
.customer-account-create {
    .customer-name{
         display: none;
    }
}

1 comment:

  1. hi iam a newbie can u please help where to copy thename.phtml and how to form the extension

    ReplyDelete