Hi,
when I add a new customer in my magento, the fields of Prename and Surname are required.
I often work with tradecustomer and only want to use the company name.
How can I make one of the names optional, so I have to fill only one name?
How can I do this.
Thank you in advance.
Regards
Please try below code to remove required field from customer "Last Name" using sql installation script
$installer = $this;
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$installer->startSetup();
/*** Update customer address attributes*/
$setup->updateAttribute('customer', 'lastname', 'is_required', 0);
$installer->endSetup();$installer = $this;
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$installer->startSetup();
/*** Update customer address attributes*/
$setup->updateAttribute('customer_address', 'lastname', 'is_required', 0);
$installer->endSetup();Using above code Required Option removed from Customer and Customer Address "Last Name"public function getAttributeValidationClass($attributeCode)
{
/** @var $attribute Mage_Customer_Model_Attribute */
$attribute = isset($this->_attributes[$attributeCode]) ? $this->_attributes[$attributeCode]
: Mage::getSingleton('eav/config')->getAttribute('customer_address', $attributeCode);
$class = $attribute ? $attribute->getFrontend()->getClass() : '';
if (in_array($attributeCode, array('firstname', 'middlename', 'lastname', 'prefix', 'suffix', 'taxvat'))) {
if ($class && !$attribute->getIsVisible()) {
$class = ''; // address attribute is not visible thus its validation rules are not applied
}
/** @var $customerAttribute Mage_Customer_Model_Attribute */
$customerAttribute = Mage::getSingleton('eav/config')->getAttribute('customer', $attributeCode);
$class .= $customerAttribute && $customerAttribute->getIsVisible()
? $customerAttribute->getFrontend()->getClass() : '';
$class = implode(' ', array_unique(array_filter(explode(' ', $class))));
}
return $class;
}Change To public function getAttributeValidationClass($attributeCode ,$attributeEntity = 'customer_address')
{
/** @var $attribute Mage_Customer_Model_Attribute */
$attribute = isset($this->_attributes[$attributeCode]) ? $this->_attributes[$attributeCode]
: Mage::getSingleton('eav/config')->getAttribute($attributeEntity, $attributeCode);
$class = $attribute ? $attribute->getFrontend()->getClass() : '';
if (in_array($attributeCode, array('firstname', 'middlename', 'lastname', 'prefix', 'suffix', 'taxvat'))) {
if ($class && !$attribute->getIsVisible()) {
$class = ''; // address attribute is not visible thus its validation rules are not applied
}
/** @var $customerAttribute Mage_Customer_Model_Attribute */
$customerAttribute = Mage::getSingleton('eav/config')->getAttribute('customer', $attributeCode);
$class .= $customerAttribute && $customerAttribute->getIsVisible()
? $customerAttribute->getFrontend()->getClass() : '';
$class = implode(' ', array_unique(array_filter(explode(' ', $class))));
}
return $class;
}<input type="text" id="<?php echo $this->getFieldId('lastname')?>" name="<?php echo $this->getFieldName('lastname')?>" value="<?php echo $this->escapeHtml($this->getObject()->getLastname()) ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->getStoreLabel('lastname')) ?>" maxlength="255" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('lastname') ?>" <?php echo $this->getFieldParams() ?> /><input type="text" id="<?php echo $this->getFieldId('lastname')?>" name="<?php echo $this->getFieldName('lastname')?>" value="<?php echo $this->escapeHtml($this->getObject()->getLastname()) ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->getStoreLabel('lastname')) ?>" maxlength="255" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('lastname' , 'customer') ?>" <?php echo $this->getFieldParams() ?> />