I have created a customer attribute to capture the company name on registration, not as part of the address field.
The field is created in eav_attribute
//add Company Name to customer attributes
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$entityTypeId = $setup->getEntityTypeId('customer');
$attributeSetId = $setup->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);
$installer->addAttribute("customer", "company_name", array(
"type" => "varchar",
"backend" => "",
"label" => "Company Name",
"input" => "text",
"source" => "",
"visible" => true,
"required" => true,
"default" => "",
"frontend" => "",
"unique" => false
));
$attribute = Mage::getSingleton("eav/config")->getAttribute("customer", "company_name");
$setup->addAttributeToGroup(
$entityTypeId,
$attributeSetId,
$attributeGroupId,
'tamper_company_name',
'3' //sort_order
);
$used_in_forms=array();
$used_in_forms[]="adminhtml_customer";
$used_in_forms[]="checkout_register";
$used_in_forms[]="customer_account_create";
$used_in_forms[]="customer_account_edit";
$used_in_forms[]="adminhtml_checkout";
$attribute->setData("used_in_forms", $used_in_forms)
->setData("is_used_for_customer_segment", true)
->setData("is_system", 0)
->setData("is_user_defined", 1)
->setData("is_visible", 1)
->setData("sort_order", 3)
;
$attribute->save();
$installer->endSetup();
The field displays and populates properly from the account creation page: \app\design\frontend\base\default\template\MYMODULE\customer\widget\name.phtml Which I overwrote using config.xml
<div class="field name-companyname">
<label for="<?php echo $this->getFieldId('company_name')?>" class="required"><em>*</em><?php echo $this->getStoreLabel('company_name') ?></label>
<div class="input-box">
<input type="text" id="<?php echo $this->getFieldId('company_name')?>" name="<?php echo $this->getFieldName('company_name')?>" value="<?php echo $this->escapeHtml($this->getObject()->getTamper_company_name()) ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->getStoreLabel('company_name')) ?>" maxlength="255" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('company_name') ?>" <?php echo $this->getFieldParams() ?> />
</div>
</div>
I have two issues:
- In the customer dashboard, create address does not return anything for the above code, even through it uses the same template. Name and surname work, but Company Name does not - it does not return any value or labels.
$this->getObject()->getFirstname()
returns the name$this->getObject()->getCompany_name()
returns nothing. getAttributeValidationClass also does not work. - In the address templates, using
{{depend company_name}}{{var company_name}}{{/depend}}
does not return anything.
If i Mage::Log $this->getObject() from the address entry screen, I get a data array including name, pre/post fix, initial but no company_name.
Do I need to override when of the helpers to add this field in?