2011-11-05 30 views
2

我已經創建了一個新的字段調用子名,這是一個帳戶註冊表單上的一個重要字段。無法將Magento 1.6商店註冊頁面上的自定義字段導入到mysql數據庫中。

我:

新增形式進入register.phtml確定並顯示在表格上。

把這個代碼放到/local/Mage/Customer/etc/config.xml

   <childname> 
       <create>1</create> 
       <update>1</update> 
       </childname> 

將此添加到/local/Mage/Customer/Model/Resource/Setup.php

    'childname'   => array( 
      'type'    => 'varchar',      
        'label'    => 'Please Enter Childs Name', 
        'input'    => 'text', 
        'required'   => true, 
        'visible'   => true, 

我已經在eav_attribute表中添加了attribute_code子類名設置爲varchar

我已經運行了註冊頁面並查看了customer_entity_varchar,但它沒有被存儲?

我錯過了一些代碼的地方,不知道哪個文件發送數據到數據庫?

任何幫助將不勝感激!

在此先感謝

運行Magento的1.6

回答

5

一件事,我認爲缺少的是,你需要告訴這個屬性在形式使用Magento的,所以它會被處理。基本上,您需要以各種形式包含它,如'customer_account_create','customer_account_edit','checkout_register','adminhtml_customer'。 所以,你需要把升級「SQL文件」是這樣的:

$usedInForms = array('customer_account_create', 'customer_account_edit', 'checkout_register', 'adminhtml_customer'); 
$oAttribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'childname'); 
$oAttribute->setData('used_in_forms', $usedInForms); 
$oAttribute->save(); 

所以,我只是做我自己對我的一個客戶,這是actaully很簡單。你只需要在你的模塊中的3個文件,並編輯幾個phtml。

  1. etc/config.xml,一如既往在Magento中,您需要配置您的模塊。在我們的例子中,我們只需要配置資源。這裏是我的整個config.xml文件:

    <config> 
        <modules> 
         <Osdave_Custattr> 
          <version>0.1.0</version> 
         </Osdave_Custattr> 
        </modules> 
    
        <global> 
         <resources> 
          <custattr_setup> 
           <setup> 
            <module>Osdave_Custattr</module> 
            <class>Mage_Customer_Model_Entity_Setup</class> 
           </setup> 
           <connection> 
            <use>core_setup</use> 
           </connection> 
          </custattr_setup> 
          <custattr_write> 
           <connection> 
            <use>core_write</use> 
           </connection> 
          </custattr_write> 
          <custattr_read> 
           <connection> 
            <use>core_read</use> 
           </connection> 
          </custattr_read> 
         </resources> 
        </global> 
    </config> 
    
  2. SQL/custattr_setup/mysql4安裝-0.1.0.php,這是它增加了屬性到EAV屬性表文件。正如你在config.xml中看到的那樣,它延伸到Mage_Customer_Model_Entity_Setup。同樣,整個文件:

    <?php 
    
    $installer = $this; 
    
    $installer->startSetup(); 
    
    $this->addAttribute('customer', 'erp_customer_id', array(
        'type' => 'varchar', 
        'input' => 'text', 
        'label' => 'ERP Customer ID', 
        'global' => 1, 
        'visible' => 1, 
        'required' => 0, 
        'user_defined' => 1, 
        'default' => null, 
        'visible_on_front' => 1 
    )); 
    
    
    if (version_compare(Mage::getVersion(), '1.6.0', '<=')) { 
        $customer = Mage::getModel('customer/customer'); 
        $attrSetId = $customer->getResource()->getEntityType()->getDefaultAttributeSetId(); 
        $this->addAttributeToSet('customer', $attrSetId, 'General', 'erp_customer_id'); 
    } 
    
    if (version_compare(Mage::getVersion(), '1.4.2', '>=')) { 
        Mage::getSingleton('eav/config') 
          ->getAttribute('customer', 'erp_customer_id') 
          ->setData('used_in_forms', array('adminhtml_customer', 'customer_account_create', 'customer_account_edit', 'checkout_register')) 
          ->save(); 
    } 
    
    $installer->endSetup(); 
    
  3. 激活xml文件,應用程序的/ etc /模塊/ Osdave_Custattr.xml:

    <?xml version="1.0"?> 
    <config> 
        <modules> 
         <Osdave_Custattr> 
          <active>true</active> 
          <codePool>local</codePool> 
         </Osdave_Custattr> 
        </modules> 
    </config> 
    
  4. ,現在我只需要編輯,我想了PHTML文件顯示新的字段,即註冊,編輯和結賬註冊。以下是我在我的應用程序/設計/前端/ mypackage中/ mydesign /永久/客戶/表格/ register.phtml已經添加:

    <div class="fieldset"> 
        <h2 class="legend"><?php echo $this->__('ERP Account Information') ?></h2> 
        <ul class="form-list"> 
         <li> 
          <label for="erp_customer_id" class="required"><em>*</em><?php echo $this->__('ERP Customer ID') ?></label> 
          <div class="input-box"> 
           <input type="text" name="erp_customer_id" id="erp_customer_id" value="<?php echo $this->htmlEscape($this->getFormData()->getErpCustomerId()) ?>" title="<?php echo $this->__('ERP Customer ID') ?>" class="input-text" /> 
          </div> 
         </li> 
        </ul> 
    </div> 
    

    很重要的字段的名稱屬性的名稱相匹配。

vo il,,當我註冊該字段庫存在分貝。
經過這個,可能對您來說最好的解決方案是獲得您在開始編輯之前所做的db-and-files備份,並重現我的步驟。您必須更改名稱以符合您的要求。

HTH

+0

@OSDdave非常感謝,wheres最好的地方放這段代碼? – Ledgemonkey

+0

@Ledgemonkey最好的地方是app/code/local-or-community/YourNamespace/YourModule/sql/yourmodule_setup/mysql4-upgrade-0.1.0-0.1.1.php假設你的模塊目前版本爲0.1.0,而你的第一次安裝將一行插入到core_resource中。但我並不完全確定,因爲您對整個模塊的信息很少。 – OSdave

+0

再次非常感謝您的幫助,我使用本地/法師/客戶 - sql/customer_setup mysql4-upgrade-1.6.0.0-1.6.1.0.php我應該在本地創建一個新模塊嗎? – Ledgemonkey

相關問題