我正在使用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
),
),
)
);
}
}
但我什麼也看不到,而不是在數據庫中的任何新的屬性。
你們可以幫助這裏什麼是錯? 謝謝
@Sasquiha嗨,哥們u能告訴我你在我的後它可能已編輯有幫助。 – SAM 2011-05-18 04:46:49
沒什麼,只是添加了php標籤。 – ColWhi 2011-05-18 07:45:56