【发布时间】:2011-04-05 10:39:07
【问题描述】:
我正在使用 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();
但是当我点击这个模块的 url 时,我没有看到任何错误,但这些属性不在我的数据库中。
我还创建了 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 嘿,你能告诉我你在我的帖子中编辑了什么,它可能会有所帮助。
-
没什么,只是加了php标签。
标签: php magento entity-attribute-value