Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento - make the field "company" required

Tags:

magento

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.

like image 629
Ahmed Ala Dali Avatar asked Mar 28 '11 09:03

Ahmed Ala Dali


4 Answers

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.

like image 162
haltabush Avatar answered Dec 12 '22 12:12

haltabush


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';
like image 25
Besnik Avatar answered Dec 12 '22 11:12

Besnik


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"
like image 42
Oğuz Çelikdemir Avatar answered Dec 12 '22 11:12

Oğuz Çelikdemir


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>
like image 36
Jose Areas Avatar answered Dec 12 '22 11:12

Jose Areas