- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2017
05:30 AM
06-13-2017
05:30 AM
Add new customer > only 1 name required
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
1 REPLY 1
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2017
05:46 AM
06-16-2017
05:46 AM
Re: Add new customer > only 1 name required
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();
Please try below code to remove required field from customer Address "Last Name"
$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"
But from frontend need to change
1. Rewrite app/code/core/Mage/Customer/Helper/Address.php
Change Code from
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; }
And in name.phtml file line 82
app/design/frontend/base/default/template/customer/widget/name.phtml
Change From
<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() ?> />
Change To
<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() ?> />
Elsner Technologies