2011-04-05 30 views
0

我正在使用magento V1.5。我正在致力於客戶EAV &已嘗試創建另一個EAV模塊。在表單中添加自定義屬性

我在客戶實體中添加了一些屬性。現在我的要求是這些屬性必須可以從前端以及後端進行編輯。

請告訴我如何在forntend表單中添加這些屬性(客戶編輯表單)。 &告訴我在後端要做些什麼來讓這些選項可編輯。 我在想,如果在我們的Form.php中有一種管理方式,我們會爲其添加元素以準備表單。那麼我們不需要編寫一個代碼來創建實際的html。 Magento自動做到這一點。所以它的想法是它也必須加載剛剛添加的新屬性。 (就像它們在產品編輯中出現的一樣)。

第二個問題是,你們能告訴我應該在我的Grid.php >> prepareCollection(用於其他EAV模塊)中寫什麼。因此,它必須得到所有的屬性以及它們的值(或可能是少數)

這裏的東西,我在我的Grid.php,但它不工作

protected function _prepareCollection() 
{ 
    $collection = Mage::getModel('pincodes/eavpincodes')->getCollection(); 

    $this->setCollection($collection); 
    return parent::_prepareCollection(); 
} 

&這是我收集的文件

class Namespace_Pincodes_Model_Resource_Eav_Mysql4_Eavpincodes_Collection extends Mage_Eav_Model_Entity_Collection_Abstract 
{ 
    protected function _construct() 
    { 
     $this->_init('pincodes/eavpincodes'); 
    } 
} 

但它不是我的格子返回任何東西

&這裏是我的屬性集合文件

class Inkfruit_Pincodes_Model_Resource_Eav_Mysql4_Attribute_Collection extends Mage_Eav_Model_Mysql4_Entity_Attribute_Collection 
{ 
public function _construct() 
{ 
    $this->_init('pincodes/resource_eav_attribute', 'eav/entity_attribute'); 
} 

protected function _initSelect() 
{ 

    $this->getSelect()->from(array('main_table' => $this->getResource()->getMainTable())) 
     ->where('main_table.entity_type_id=?', Mage::getModel('eav/entity')->setType('pincodes_eavpincodes')->getTypeId()) 
     ->join(
     array('additional_table' => $this->getTable('pincodes/eavpincodes')), 
     'additional_table.attribute_set_id=main_table.attribute_id' // I think this sql need to be changed but I have no idea what it'll be 
     ); 
    return $this; 
} 

}

傢伙太感謝你了。本次論壇是專門對我很有幫助,我創建一個單獨的模塊有一個mysql4_install文件&不言而喻如下

$installer = $this; 
$installer->startSetup(); 
$setup = new Mage_Eav_Model_Entity_Setup('core_setup'); 

$setup->addAttribute('customer', 'profile_image', array(
        'label'  => 'Profile Image', 
        'type'  => 'varchar', 
        'input'  => 'file', 
        'visible' => true, 
        'required' => false, 
        'user_defined' => true, 
      )); 

$setup->addAttribute('customer', 'mobile', array(
        'label'  => 'Mobile Number', 
        'type'  => 'int', 
        'input'  => 'text', 
        'visible' => true, 
        'required' => false, 
        'user_defined' => true, 
      )); 


$installer->endSetup(); 
$installer->installEntities(); 

但是,當我的客戶

問候 SAM

玉傢伙打這個模塊的網址我沒有看到錯誤,但這些屬性不在我的數據庫中。

我也創建了Entity_Setup文件&不言而喻如下我認爲它不正確,但我給它一個嘗試

<?php 

class Namespace_Customer_Entity_Setup extends Mage_Eav_Model_Entity_Setup 
{ 
public function getDefaultEntities() 
    {   
    return array (
     'customer' => array(
      'entity_model'  => 'customer/customer', 
      'attribute_model' => 'customer/attribute', 
      'table'    => 'customer/entity', 
      'attributes'  => array(
       'profile_image' => array(
        //the EAV attribute type, NOT a mysql varchar 
        'type'    => 'varchar', 
        'backend'   => '', 
        'frontend'   => '', 
        'label'    => 'Profile Image', 
        'input'    => 'file', 
        'class'    => '', 
        'source'   => '', 
        // store scope == 0 
        // global scope == 1 
        // website scope == 2       
        'global'   => 0, 
        'visible'   => true, 
        'required'   => false, 
        'user_defined'  => true, 
        'default'   => '', 
        'searchable'  => true, 
        'filterable'  => true, 
        'comparable'  => false, 
        'visible_on_front' => false, 
        'unique'   => false 
       ), 

       'mobile' => array(

        'type'    => 'varchar', 
        'backend'   => '', 
        'frontend'   => '', 
        'label'    => 'Mobile Number', 
        'input'    => 'text', 
        'class'    => '', 
        'source'   => '',       

        'global'   => 0, 
        'visible'   => true, 
        'required'   => true, 
        'user_defined'  => true, 
        'default'   => '', 
        'searchable'  => true, 
        'filterable'  => true, 
        'comparable'  => false, 
        'visible_on_front' => false, 
        'unique'   => false 
       ), 

      ), 
     ) 
    ); 
    } 
} 

但我什麼也看不到,而不是在數據庫中的任何新的屬性。

你們可以幫助這裏什麼是錯? 謝謝

+0

@Sasquiha嗨,哥們u能告訴我你在我的後它可能已編輯有幫助。 – SAM 2011-05-18 04:46:49

+0

沒什麼,只是添加了php標籤。 – ColWhi 2011-05-18 07:45:56

回答

-1

在這裏有同樣的問題。在1.5.0.1中使用addAttribute似乎將其添加到數據庫中,但客戶管理員不會呈現它。

此方法適用於產品和類別屬性。在1.4.0.0中它也適用於客戶。

在Magento chagelog中,有關於客戶屬性渲染的改進項目中有一點。接下來我會開始檢查它。

+0

其實我最近通過我的mysql_install文件向產品添加了一些屬性,並猜測它們在管理屬性和產品編輯中都沒有顯示在管理區中。看起來像我的代碼是非常錯誤的:) – SAM 2011-05-18 04:49:31

0

這爲我工作,注意附加線:

<?php 

class Millena_CustomerExportAdditions_Model_Resource_Eav_Mysql4_Setup extends Mage_Eav_Model_Entity_Setup 
{ 
    public function getDefaultEntities() 
    { 
     return array(
      'customer' => array(
       'entity_model'   =>'customer/customer', 
       'attribute_model'  => 'customer/attribute', 
       'table'     => 'customer/entity', 
       'additional_attribute_table' => 'customer/eav_attribute', 
       'entity_attribute_collection' => 'customer/attribute_collection', 
       'attributes' => array(
        'export_status' => array(
         //'group'    => 'Group/Tab', 
         'label'    => 'Customer Export Status', 
         'type'    => 'int', 
         'input'    => 'select', 
         'default'   => '0', 
         'class'    => '', 
         'backend'   => '', 
         'frontend'   => '', 
         'source'   => 'millena_customerExportAdditions/customer_attribute_source_exportStatus', 
         'global'   => 2, //global scope 
         'visible'   => true, 
         'required'   => false, 
         'user_defined'  => false, 
         'searchable'  => false, 
         'filterable'  => false, 
         'comparable'  => false, 
         'visible_on_front' => false, 
         'visible_in_advanced_search' => false, 
         'unique'   => false 
        ) 


       ) 
      ) 

    ); 
    } 
} 

安裝腳本是:

<?php 
$installer = $this; 
$installer->installEntities(); 
1

夥計們,這裏是我的解決方案。上面的答案適用於添加屬性到數據庫只有 我的問題有三個部分。

1.將屬性添加到數據庫中的實體。

Ans。上述安裝腳本起作用。使用一個Setup.php & mysql_install/mysql_upgrade腳本。

2.屬性應該是從前端

答案編輯。我們需要修改文件的應用程序/設計/ fontend /默認模板// /客戶/表格/ edit.phtml

3.屬性必須是可編輯從後端

答案。爲此,我們需要在我們的config.xml中添加此片段

<global> 
     <fieldsets> 
      <customer_account> 
       <create>1</create><update>1</update> 
      </customer_account> 
     </fieldsets> 
</global> 

這將盡一切 希望這會幫助別人