I simply would like to make the field "company" on the onepage checkout a required field. Would be happy for some help? I tried it already but it didn't work, so probably I have to change or add some more data in another file.
2 Answers
In magento by default customer address attribute "company" is not required.If you need required then update company attribute to bellow php script.
Run bellow script to update attribute
$installer = new Mage_Customer_Model_Entity_Setup('core_setup');
$installer->startSetup();
/*** Update customer address attributes*/
$installer->updateAttribute('customer_address', 'company', 'is_required', 1);
$installer->endSetup();
Ok so the following code is only valid for the base/default template you may have to adapt it if you're using a custom theme.
Replace the following code under app/design/frontend/base/default/template/checkout/onepage/billing.phtml
:
<div class="field">
<label for="billing:company"><?php echo $this->__('Company') ?></label>
<div class="input-box">
<input type="text" id="billing:company" name="billing[company]" value="<?php echo $this->escapeHtml($this->getAddress()->getCompany()) ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Company')) ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('company') ?>" />
</div>
</div>
With the following:
<div class="field">
<label for="billing:company" class="required"><em>*</em><?php echo $this->__('Company') ?></label>
<div class="input-box">
<input type="text" id="billing:company" name="billing[company]" value="<?php echo $this->escapeHtml($this->getAddress()->getCompany()) ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Company')) ?>" class="input-text required-entry <?php echo $this->helper('customer/address')->getAttributeValidationClass('company') ?>" />
</div>
</div>
Repeat the process with the app/design/frontend/base/default/template/checkout/onepage/shipping.phtml
template:
<div class="fields">
<label for="shipping:company"><?php echo $this->__('Company') ?></label>
<div class="input-box">
<input type="text" id="shipping:company" name="shipping[company]" value="<?php echo $this->escapeHtml($this->getAddress()->getCompany()) ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Company')) ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('company') ?>" onchange="shipping.setSameAsBilling(false);" />
</div>
</div>
With:
<div class="fields">
<label for="shipping:company" class="required"><em>*</em><?php echo $this->__('Company') ?></label>
<div class="input-box">
<input type="text" id="shipping:company" name="shipping[company]" value="<?php echo $this->escapeHtml($this->getAddress()->getCompany()) ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Company')) ?>" class="input-text required-entry <?php echo $this->helper('customer/address')->getAttributeValidationClass('company') ?>" onchange="shipping.setSameAsBilling(false);" />
</div>
</div>