Magento 1.4.2 - Make Registration Fields Not Required
I have tried a very commonly used method to make the telephone field not required during registration, but it doesn't seem to work with Magento 1.4.2
I've made a copy of
magento/app/code/core/Mage/Customer/Model/Address/Abstract.php
to
magento/app/code/local/Mage/Customer/Model/Address/Abstract.php
and removed the following code from the validate function in that file
if (!Zend_Validate::is($this->getTelephone(), 'NotEmpty')) {
$errors[] = $helper->__('Please enter telephone.');
}
I have also removed the
class="input-text required-entry"
from the register.phtml file, but I can't get past the validation. I keep getting the error
"Telephone" is a required val开发者_StackOverflow社区ue. "Telephone" length must be equal or greater than 1 characters.
Thanks
The default telephone attribute is set to required in the database. See is_required
column of eav_attribute
table, search for attribute_code = 'telephone'
.
Alternatively you can run this code just once, such as with an install script.
$telephone = Mage::getModel('eav/entity_attribute')
->loadByCode('customer_address', 'telephone')
->setIsRequired(false)
->save();
Also you have to remove the asterisk * from the from in you template checkout\onepage\billing.phtml
Change (Line ~120) from
<label for="billing:telephone" class="required"><em>*</em><?php echo $this->__('Telephone') ?></label>
to
<label for="billing:telephone"><?php echo $this->__('Telephone') ?></label>
Delete cache to view changes.
There are a few steps to take (version 1.7.0.2).
As mentioned above: change database table
eav_attribute
.Phpmyadmin
is one easy way to do that.Comment out these 3 lines:
if (!Zend_Validate::is($this->getTelephone(), 'NotEmpty')) { $errors[] = Mage::helper('customer')->__('Please enter the telephone number.'); }
in files:
App/code/core/Mage/Customer/Model/Address/Abstract.php
includes/src/Mage_Customer_Model_Address_Abstract.php
includes/src/_checkout.php
You can also remove the
*
in theregister.phtml
andbilling.phtml
files in the onepage folders of theapp/design/frontend/base/default/template/persistent
andapp/design/frontend/base/default/template/customer
folders.
Make no mistake, Magento REALLY wanted to make that a required entry!
That should do it.
I am aware of all the suggested solutions of copying and editing core-files but this will be upgrade-suicide.
For now (Magento 1.9 and older) the only method that does not require modifying Magento core files is to use a dummy value for the telephone field.
A simple mock-up solution is to add to the bottom of the 'address/edit.phtml' file:
jQuery(function($){
$('#form-validate').submit(function(){
var telephone = $('#telephone');
if( !telephone.val().length )
telephone.val("<?= $this->__('Not supplied') ?>");
});
});
精彩评论