Magento 用户创建的产品属性未保存
我现在正在为一件看似简单的事情而奋斗大约两天。我希望有人能提供帮助。
我创建了 myUpdate EAV 属性
class Company_Module_Model_Resource_Eav_Mysql4_Setup extends Mage_Eav_Model_Entity_Setup
{
public function getDefaultEntities()
{
return array(
'catalog_product' => array(
'entity_model' => 'catalog/product',
'attribute_model' => 'catalog/resource_eav_attribute',
'table' => 'catalog/product',
'additional_attribute_table' => 'catalog/eav_attribute',
'entity_attribute_collection' => 'catalog/product_attribute_collection',
'attributes' => array(
'my_update' => array(
'label' => 'My timestamp',
'type' => 'datetime',
'input' => 'date',
'default' => '',
'class' => 'validate-date',
'backend' => 'eav/entity_attribute_backend_datetime',
'frontend' => '',
'table' => '',
'source' => '',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => true,
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'visible_in_advanced_search' => false,
'unique' => false,
'apply_to' => 'simple',
)
)
)
);
}
}
该属性创建正常,并且在安装时正确显示在属性列表中。
后来我这样做了
// for product 1
$product->setMyUpdate($stringDate); // string this format: yyyy-MM-dd HH:mm:ss
$product->save(); // and saves without issues * in admin module
但是后来当我这样做时:
$product = Mage::getModel('catalog/product')->load(1);
var_dump($product->getMyUpdate()); // returns null
不知何故,数据没有真正保存..或者我没有正确检索它。 请建议如何获取数据以及数据在数据库中的保存位置,以便我可以检查插入是否正确完成。
谢谢。
I am fighting an apparently simple thing for about two days now. I hope somebody can help.
I created the myUpdate EAV attribute
class Company_Module_Model_Resource_Eav_Mysql4_Setup extends Mage_Eav_Model_Entity_Setup
{
public function getDefaultEntities()
{
return array(
'catalog_product' => array(
'entity_model' => 'catalog/product',
'attribute_model' => 'catalog/resource_eav_attribute',
'table' => 'catalog/product',
'additional_attribute_table' => 'catalog/eav_attribute',
'entity_attribute_collection' => 'catalog/product_attribute_collection',
'attributes' => array(
'my_update' => array(
'label' => 'My timestamp',
'type' => 'datetime',
'input' => 'date',
'default' => '',
'class' => 'validate-date',
'backend' => 'eav/entity_attribute_backend_datetime',
'frontend' => '',
'table' => '',
'source' => '',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => true,
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'visible_in_advanced_search' => false,
'unique' => false,
'apply_to' => 'simple',
)
)
)
);
}
}
The attribute is created OK and on install appears correctly in the list of attributes.
Later I do
// for product 1
$product->setMyUpdate($stringDate); // string this format: yyyy-MM-dd HH:mm:ss
$product->save(); // and saves without issues * in admin module
But later when I do:
$product = Mage::getModel('catalog/product')->load(1);
var_dump($product->getMyUpdate()); // returns null
Somehow the data is not really saved.. or I am not retrieving it correctly.
Please advice on how to get the data and where the data is saved in the DB so I can check at if the insert is done correctly.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在数据库中,属性应保存在按其 attribute_id 组织的表
catalog_product_entity_datetime
中。首先获取entity_type_id(因为我的显然与你的不同):我在最后一个上得到4,但可以根据情况进行替换。以下查询应列出所有已保存的值:
为了确保您实际上已将属性添加到数据库中:
如果您在该空间中看到值,则问题可能是您尚未选择要加载的属性。例如,如果您要从目录产品集合中加载产品,则需要一种加载属性的方法:
如果您看到数据实际上已保存,请提供有关产品加载的更多上下文。
希望有帮助。
谢谢!乔
In the database, the attribute should be saved in the table
catalog_product_entity_datetime
organized by its attribute_id. First get the entity_type_id (since mine is apparently different than yours):I get 4 on that last one, but substitute as applicable. The following query should list any saved values:
To make sure that you have actually added the attribute to the database:
If you see values in that space, your problem may be that you haven't selected the attribute to be loaded. For instance, if you are loading products from a catalog product collection, there is a method necessary to load attributes:
Please give more context on your product loading if you see that the data is actually saved.
Hope that helps.
Thanks! Joe
默认情况下不保存您的属性。您可以使用:
$product->getResource()->saveAttribute($product, "name_of_your_attribute");
Your attributes are not saved by default. You can use:
$product->getResource()->saveAttribute($product, "name_of_your_attribute");