3

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 value. "Telephone" length must be equal or greater than 1 characters.

Thanks

3 Answers 3

8

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.

2
  • I second this method. The install script should be placed in your own plugin directory in your company's namespace so that it's reproduceable across other installs (say, if you move servers, hosting, or promote code to staging/production)
    – philwinkle
    Feb 11, 2011 at 17:32
  • thanks guys! Worked perfectly. I was initially wary of editing the database, but if that's the only way, then cool.
    – bonhommie
    Feb 11, 2011 at 18:30
6

There are a few steps to take (version 1.7.0.2).

  1. As mentioned above: change database table eav_attribute. Phpmyadmin is one easy way to do that.

  2. 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
  3. You can also remove the * in the register.phtml and billing.phtml files in the onepage folders of the app/design/frontend/base/default/template/persistent and app/design/frontend/base/default/template/customer folders.

Make no mistake, Magento REALLY wanted to make that a required entry!

That should do it.

0

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') ?>");
    });
});

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

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.