標籤:
步驟 I. 加一個occupation/title欄位到使用者註冊頁,差不多在register.html的54行,在email下方加一個Occupation顯示代碼
-
代碼:
-
<li>
<div class="input-box">
<label for="email_address"><?php echo $this->__(‘Email Address‘) ?> <span class="required">*</span></label><br/>
<input type="text" name="email" id="email_address" value="<?php echo $this->htmlEscape($this->getFormData()->getEmail()) ?>" title="<?php echo $this->__(‘Email Address‘) ?>" class="validate-email required-entry input-text" />
</div>
<div class="input-box">
<label for="occupation"><?php echo $this->__(‘Occupation/Title‘) ?></label><br/>
<input type="text" name="occupation" id="occupation" value="<?php echo $this->htmlEscape($this->getFormData()->getOccupation()) ?>" title="<?php echo $this->__(‘Occupation‘) ?>" class="input-text" />
</div>
</li>
這是,如果進入使用者註冊頁, 就會看到新增的欄位。
步驟 2 同樣在edit.phtml中,加入Occupation顯示塊
-
代碼:
-
<li>
<div class="input-box">
<label for="email"><?php echo $this->__(‘Email Address‘) ?> <span class="required">*</span></label><br />
<input type="text" name="email" id="email" value="<?php echo $this->htmlEscape($this->getCustomer()->getEmail()) ?>" title="<?php echo $this->__(‘Email Address‘) ?>" class="required-entry validate-email input-text" />
</div>
</li>
<li>
<div class="input-box">
<label for="occupation"><?php echo $this->__(‘Occupation‘) ?> </label><br/>
<input type="text" name="occupation" id="occupation" value="<?php echo $this->htmlEscape($this->getCustomer()->getOccupation()) ?>" title="<?php echo $this->__(‘Occupation‘) ?>" class="input-text" />
</div>
</li>
步驟 3, 開啟Model/Entity/Setup.php差不多在93行,email的下方,加入occupation的相關代碼:
-
代碼:
-
‘email‘ => array(
‘type‘ => ‘static‘,
‘label‘ => ‘Email‘,
‘class‘ => ‘validate-email‘,
‘sort_order‘ => 60,
),
‘occupation‘ => array(
‘label‘ => ‘Occupation‘,
‘required‘ => false,
‘sort_order‘ => 65,
),
步驟4: 現在,代碼就基本寫好了 , 但是我們仍然需要執行一個資料庫操作將occupation這個屬性加入到eav_attribute表,把下面的代碼塊:
-
代碼:
-
<?php
$setup = new Mage_Eav_Model_Entity_Setup(‘core_setup‘);
$AttrCode = ‘occupation‘;
$settings = array (
‘position‘ => 1,
‘is_required‘=> 0
);
$setup->addAttribute(‘1‘, $AttrCode, $settings);
?>
放到合適的檔案裡執行一次。我建議把它放到register.html檔案的頂部,然後重新訪問register.html.查看資料庫eav_attribute表就能看到新增的條目。然後把上面的代碼從register.phtml中移除。
步驟 5: 最後需要編輯app/code/core/Mage/Customer/etc/config.xml 的<fieldsets>標籤下聲明該欄位如何處理插入和貴呢更新
-
代碼:
-
<fieldsets>
<customer_account>
.....
<occupation><create>1</create><update>1</update></occupation>
</customer_account>
</fieldsets>
magento 為使用者註冊增加一個欄位(轉)