2015-03-19 25 views
0

我創建了custom module to add Land Phone field in registration page。該form display the field but in database the Land Phone number is not inserted。但在eav_attribute table中添加了landphone屬性。唯一的問題是Land Phone的價值並未插入到客戶表中。我遵循本教程:http://www.fontis.com.au/blog/magento/know-more-about-your-customers-adding-custom-signup-attributes使用定製模塊進行註冊時,數據未插入到magento數據庫中

我會給你詳細的代碼,我做了什麼。

我的模塊名稱是TCreg_Customer

應用程序的/ etc /模塊/ TCreg_Customer.xml

<?xml version="1.0"?> 
<config> 
    <modules> 
     <TCreg_Customer> 
     <codePool>local</codePool> 
     <active>true</active> 
     </TCreg_Customer> 
    </modules> 
</config> 

應用程序/代碼/本地/ TCreg /客戶的/ etc/config.xml中

I copy app/code/core/Mage/Customer/etc/config.xml file and make 2 changes

<modules> 
     <TCreg_Customer> 
      <version>1.0.0</version> 
     </TCreg_Customer> 
    </modules> 

,並添加

<landphone><create>1</create><update>1</update></landphone> 

<customer_account>標籤

應用程序/代碼/本地/ TCreg /客戶/型號/實體/ Setup.php

<?php 
class TCreg_Customer_Model_Entity_Setup extends Mage_Customer_Model_Entity_Setup 
{ 
    public function getDefaultEntities(){ 

     return array(

       'landphone'=>array(
         'type'=> 'varchar', 
         'label'=> 'Land Phone', 
         'visiable' => true, 
         'sort_order' => 80, 
       ) 
     ); 
    } 
} 
?> 

土地電話場設置在register.phtml位於app/design/frontend/mytheme/template/persistent/customer/form/registe r.phtml

<!--landphone field begin--> 
    <div class="field"> 
    <label for="landphone"><?php echo $this->__('Land Phone') ?></label> 
    <div class="input-box"> 
    <input type="text" name="landphone" id="landphone" value="<?php echo $this->escapeHtml($this->getFormData()->getLandphone()) ?>" title="<?php echo $this->__('Land Phone') ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('landphone') ?>" /> 
    </div> 
</div> 
<!--landphone field end--> 

應用程序/設計/前端/ mytheme的/模板/永久/客戶/地址/ edit.phtml需要添加

<!--Landphone field begin--> 
    <div class="field"> 
    <label for="landphone"><?php echo $this->__('Land Phone') ?></label> 
    <div class="input-box"> 
    <input type="text" name="landphone" value="<?php echo $this->htmlEscape($this->getAddress()->getLandphone()) ?>" title="<?php echo $this->__('Land Phone') ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('landphone') ?>" id="landphone" /> 

</div> 
</div> 
<!--Landphone field end--> 

新的屬性(土地電話)到Magento數據庫。所以我加了這些代碼位register.phtml

$setup = new Mage_Eav_Model_Entity_Setup('core_setup'); 
$setup->addAttribute('customer', 'landphone', array(
    'label'  => 'Land Phone', 
    'type'  => 'varchar', 
    'input'  => 'text', 
    'visible' => true, 
    'position' => 1, 
    )); 

我認爲唯一的問題是客戶表中沒有插入手機土地的價值。但我找不到解決方案。所以請幫助我..我該如何解決這個問題?任何幫助真的是可觀..

Magento的版本是1.9.1.0

+0

看一看以下職位爲同一目的:HTTP://phpmagento.blogspot.in/2012/02/custom-field-in-customer-registration。 html 希望你會得到一些想法以另一種方式做到這一點...不要忘了將核心文件複製到本地代碼池文件夾 – 2015-03-19 11:55:44

+0

@VinodKumar,它是什麼? '不要忘記將核心文件複製到本地代碼池文件夾中' – next2u 2015-03-20 04:39:11

+0

我提到你的鏈接直接顯示核心文件中的所有代碼修改...所以我建議你複製所有文件將編輯,進入本地/法師目錄... – 2015-03-20 05:18:00

回答

0

您需要確保該屬性在表中的條目customer_form_attribute這將告訴Magento的什麼客戶應該提供的屬性在每個客戶和地址表單上。

您可以通過以下腳本代碼片段執行此操作。構建一個新的設置腳本,您已經提到過您可以執行該操作並設置該屬性需要使用的所有表單的數組。

Mage::getSingleton('eav/config') 
     ->getAttribute('customer', 'attribute_code') 
     ->setData('used_in_forms', array('adminhtml_customer', 'checkout_register', 'customer_account_create')) 
     ->save(); 

形式代碼的選項如下:

  • adminhtml_checkout,
  • adminhtml_customer,
  • adminhtml_customer_address,
  • checkout_register,
  • customer_account_create,
  • customer_account_edit,
  • customer_address_edit,
  • customer_register_address
+0

我很困惑,請更具體。什麼是 - > setData('used_in_forms',array('adminhtml_customer'))中的'used_in_forms'。在哪裏放這個代碼? 'form code options'是什麼意思? – next2u 2015-04-21 04:52:30

+0

添加了一個簡短說明,基本上你需要一個新的設置腳本,並將used_in_forms設置爲屬性應該在其中的所有表單的數組。 – dmanners 2015-04-21 07:15:38