magento 為使用者註冊增加一個欄位(轉)

來源:互聯網
上載者:User

標籤:

步驟 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 為使用者註冊增加一個欄位(轉)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.