2012-07-17 87 views
0

我想添加一個屬性mobilecustomer_address實體。當我從前端創建用戶時,Magento沒有保存這個屬性值,但是當我從admin創建用戶時它的工作原理。Magento自定義客戶地址屬性不保存

下面是代碼片段

$installer->addAttribute('customer_address','trading2_mobile',array(
    'type'    => 'varchar', 
    'label'    => 'Mobile 2', 
    'input'    => 'text', 
    'global' => 1, 
    'visible' => 1, 
    'required' => 0, 
    'visible_on_front' => 1, 
)); 

$trading2_mobile = Mage::getSingleton('eav/config')->getAttribute('customer_address', 'trading2_mobile'); 
$trading2_mobile->setData('used_in_forms',array('customer_register_address','customer_address_edit','adminhtml_customer_address'))->save(); 

前端代碼輸入字段的

<div class="field"> 
    <label for="mobile2" class="required"><em>*</em><?php echo $this->__('Mobile 2') ?></label> 
    <div class="input-box"> 
    <input type="text" name="mobile2" id="mobile2" value="<?php echo $this->htmlEscape($this->getFormData()->getTrading2Mobile()) ?>" title="<?php echo $this->__('Mobile 2') ?>" class="input-text required-entry" /> 
</div> 
        </div> 

回答

1

名稱和ID(對於JS驗證)屬性應該是 'trading2_mobile':

<input type="text" name="trading2_mobile" id="trading2_mobile" value="<?php echo $this->htmlEscape($this->getFormData()->getTrading2Mobile()) ?>" title="<?php echo $this->__('Mobile 2') ?>" class="input-text required-entry" /> 
相關問題