9

Please could some one post a guide on the removal of 'required' telephone field in checkout based on the magento layout Version 1.8.0.0, the majority of current googled resources are out of date and no longer work. This would seem the perfect place to keep an updated how-to / guide.

It would be helpful if some one could confirm the working solution by downloading Magento 1.8.0.0 and providing proof of it's removal, these code snippets are sometimes helpful, but we have yet to find a working solution in an easy to read / documented fashion.

8
+150

Before 1.8.1 I'm not aware of any ways to make this work, you have to either override the abstract core class in the local code pool or rewrite every single child class (ugly, I know).

From 1.8.1 on, they introduced the event customer_address_validation_after. I got rid of the validation by using reflexion, even if I'm not too proud of it. Might not solve your problem, but I thought I'd post it anyway.

/**
 * Validate address ignoring phone-related errors
 *
 * Internally uses reflexion. Maybe not the most
 * efficient or clean implementation, but allows
 * this functionality to be implemented without
 * the need to rewrite 3 core classes.
 *
 * Listens to:
 * - customer_address_validation_after
 *
 * @param Varien_Event_Observer $observer Event observer
 */
public function validateAddress(Varien_Event_Observer $observer)
{
    /* @var $address Mage_Customer_Model_Address_Abstract */
    $address = $observer->getAddress();
    if (!$address) {
        return;
    }

    $prop = new ReflectionProperty('Mage_Customer_Model_Address_Abstract', '_errors');
    if (!$prop) {
        return;
    }
    $prop->setAccessible(true);
    $errors = $prop->getValue($address);
    $prop->setValue($address, array());

    $errorMessage = $this->getErrorMessage();
    foreach ($errors as $error) {
        if ($error !== $errorMessage) {
            $address->addError($error);
        }
    }
}

/**
 * Get standard error message
 *
 * @return string
 */
protected function getErrorMessage()
{
    return Mage::helper('customer')->__('Please enter the telephone number.');
}

I also wrote an update script to define the filed as not required, and edited all forms to remove the frontend validation. Like I said, it might not be the best solution, but it's better than rewriting 3-4 classes IMHO.

UPDATE The core team wrapped the event customer_address_validation_after in a conditional starting from 1.9.0 through 1.9.1.1 (I really wonder why, makes no sense to me...) so my solution won't work for these versions, unfortunately. The conditional was luckily removed in 1.9.2.

6

You will need to modify the Mage_Customer_Model_Address_Abstract class* on line 375-377 commenting the Zend Validation of the phone number.

//if (!Zend_Validate::is($this->getTelephone(), 'NotEmpty')) {
//   $errors[] = Mage::helper('customer')->__('Please enter the telephone number.');
//}

as well as the telephone attribute itself in the database removing the required class. This can be done with the following query

UPDATE `eav_attribute` SET `is_required` = 0 WHERE `attribute_code` = 'telephone';

This will take care of the frontend (Javascript) validation of the telephone fields.

**Make sure to copy the class file to your local code directory*

  • Note that you cannot extend (rewrite) an abstract class from a custom extension. You can only copy the whole file to app/code/local and customize it there. Also note that this answer works for Magento versions lower than 1.8 as well. – Mark van der Sanden Oct 22 '13 at 12:20
  • You're absolutely right. I'll edit right away – Sander Mangel Oct 22 '13 at 12:27
  • As suggested answers show I have copied the Abstract.php from /public_html/app/code/core/Mage/Customer/Model/Address to public_html/app/code/local/Mage/Customer/Model/Address commented out the lines regarding the telephone number and run UPDATE eav_attribute SET is_required =0 WHERE attribute_code = 'telephone' LIMIT 1; 1 row affected. ( Query took 0.0506 sec ) Cleared all caches ( my magento compile is always off ) Howevert customers still required to give a number before they can checkout. Can some one please confirm this solution works on 1.8.0.0 , because it does not work on mine. – Alistair Oct 23 '13 at 15:33
  • 2
    There's a small error in Sander's query: omit the LIMIT 1 in the query. In a default CE 1.8 installation, there are 4 entries in eav_attribute with code 'telephone', so you can't tell which one has been updated. Then the code should work (have just tested it). For the visual part, you then still need to remove <em>*</em> in the label of the field in all forms (checkout / address edit). Of course, if you have some kind of one step checkout installed, it could override some of the default Magento functionality and this answer may not work. – Mark van der Sanden Nov 8 '13 at 8:15
  • 1
    Hi Mark: Thanks for your comment, i did check to see if that was the case on my store, but i only have one eav_atribute with code'telephone' "SELECT * FROM eav_attribute WHERE attribute_code = 'telephone'" Showing rows 0 - 0 ( 1 total, Query took 0.0005 sec), so my store only has one of these, unlike yours.. and it is currently set to "is_required=0" – Alistair Nov 10 '13 at 16:28
5

I would suggest to change the address template for the site theme and make the phone a hidden field with as default value a space or dash. This will require no rewrites/overwrites.

2

Could you not simply rewrite the classes that use the abstract using a custom extension and config rewrites.

  • Mage_Sales_Model_Quote_Address,
  • Mage_Customer_Model_Address,
  • Mage_Sales_Model_Order_Address,

Then you can make your own validate function that will exclude the telephone check, or better yet checks for all required attributes and validates that they are set.

  • 1
    True, but unfortunately every second payment or shipping module is trying to rewrite those classes (I could name a few). Often it is not an option, or it ends up being very messy. – fmrng Nov 19 '15 at 11:11
  • but you have solved those multiple rewrites? cause then you could use that solution and inject your validation there. – David Manners Nov 19 '15 at 11:54
  • Of course you can do that, but you have to do it for every single project, since you don't know who else is going to rewrite those classes. Unfortunately, customers always ask to remove the phone validation. The only standard and "clean" solution I came up with is the one I described in my answer, and it doesn't even work for all Magento versions. If that can't be applied, the easiest is to copy the abstract class to the local code pool and comment out the validation... not the best, but it's fine if you don't abuse it. – fmrng Nov 19 '15 at 14:42
2

I just encountered a nice little extension "Webguys_Telefonkeinpflicht" by Tobi, which basically follows David's approach. It rewrites the respective subclasses. What I like pretty much is the fact that it only dispatches an event in the rewritten classes and all the further customisation is then done in an event observer. It also observes the core_block_abstract_to_html_after event in order to remove the star and the required class from the input field with some regex black magic. And it of course comes with a setup script, which makes the telephone attribute not required in the eav_attribute table. You can check the extension on GitHub.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.