Magento - make the field "company" required
Asked Answered
Y

5

9

for a B2B Magento site, when registering a new client, I want to make the field "company" required.

Which file should I edit?

Thanks a lot.

Yaakov answered 28/3, 2011 at 9:8 Comment(3)
When you are registering/creating customers manually or customers registering themselves? which one?Naara
On customers registering themselves, thanksYaakov
I don't even see "company" as an optional field. Where is that configuration?Lightfingered
P
22

You should as well add it in your attribute on the server side.

If you're using Magento Entreprise Edition, you can simply edit the company attribute through back end, and set it to "required".

If you're working with a Community Edition, you'll have to manually change this value with SQL. It's in eav_attribute table, the attribute_code is company and you just need to set is_required to 1.

Picayune answered 28/3, 2011 at 13:3 Comment(4)
I am trying to make "telephone" not required. I changed is_required to 0 in eav_attribute. The frontend still shows the "required" asterisk. So I edit the frontend as per Oguz's answer below. Now the form POSTs, but the result of the POST is "Please enter the telephone number". What further steps should I take?Fakir
I don't have a Magento install at hand, so I can't really help, but my advice would be not to change the template. You should be able to change that only through the DB. Are you sure you've chnaged the right EAV attribute? Maybe you've changed it for another entity...Picayune
I actually had to override the form controller - there is another test in there for the presence of telephone.Fakir
@RobertOnslow Hi Rober, How exactly do you override the form controller?Atchley
E
12

Additionally to haltabush answer (which is the correct one) here is the SQL for lazy developers:

UPDATE eav_attribute SET is_required = 1 WHERE attribute_code = 'company';
Excise answered 30/8, 2013 at 9:47 Comment(2)
no. it is just what the enterprise edition does when you edit the attribute in the backend. But what you are doing is to fix it for the frontend but not for the backend... anyway, hacking magento is not a good idea. really.Excise
Why was this undervote? This is one of the correct answers. If not the most completed.Schellens
F
5

For Customer Address Book Section (registered customers ) :

/app/design/frontend/base/default/template/customer/address/edit.phtml

For checkout billing section :

/app/design/frontend/base/default/template/checkout/onepage/billing.phtml

For checkout shipping section :

/app/design/frontend/base/default/template/checkout/onepage/shipping.phtml

For registration section :

/app/design/frontend/base/default/template/customer/form/register.phtml

/app/design/frontend/base/default/template/customer/form/address.phtml

Find looks like following line for required fields :

class="input-text validate-email required-entry"
Frear answered 28/3, 2011 at 10:44 Comment(3)
Do you know that you've set (hardcoded!) the field as required just for the frontend and not for the backend?Excise
Besnik, it's not my problem. I just referenced where it is. If you have a serious developer you should know how it is override the function. If not, you need a simple solution. As you might guess, nobody like you, especially small site owners! Besides, I used many times and haven't seen any problem. Of course, if you don't need those fields!Naara
Although it has a similar effect, this is definitely not the way to do it.Schellens
S
2

This is how to do it using installer. The proper way to do it in magento. This works for enterprise edition and comunity edition. But you will have to have the module configured to understand a file under sql folder

<?php
    $installer = new Mage_Customer_Model_Entity_Setup('core_setup');;

    $installer->startSetup();


    $installer->run("UPDATE eav_attribute SET is_required = 1 WHERE attribute_code = 'company';");


    $installer->endSetup();

This is how is my module xml file looks like.

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Package_Customer>
            <version>1.1.0.4</version>
        </Package_Customer>
    </modules>
    <global>
      ....
       <resources>
        <package_customer_setup>
            <setup>
                <module>Package_Customer</module>
            </setup>
        </package_customer_setup>
         </resources>
       ....
     </global>

This is what I did to edit.phtml to make it dynamic

    <li class="wide">
        <?php 
            $validation_class = $this->helper('customer/address')->getAttributeValidationClass('company') ;
            $required = strstr($validation_class, 'required-entry');
        ?>
        <label for="company" class=<?php echo $required?"required":""?>><?php echo $this->__('Company') ?> <?php echo $required?"<em>*</em>":""?> </label>
        <div class="input-box">
            <input type="text" name="company" id="company" title="<?php echo $this->__('Company') ?>" value="<?php echo $this->escapeHtml($this->getAddress()->getCompany()) ?>" class="input-text <?php echo $validation_class ?>" />
        </div>
    </li>
Schellens answered 13/3, 2015 at 14:39 Comment(0)
I
0

There is a backend setting you can set (version 2.4.5-p1).

You can find it in Stores > Settings > Configuration, then under Customers > Customer Configuration you will find the option "Show Company" under the tab "Name and Address Options".

It looks like this:

enter image description here

Setting the option to required will make the company a required field in all address forms.

Increate answered 12/4, 2023 at 13:44 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.