Magento 用户创建的产品属性未保存

发布于 2024-08-24 19:16:12 字数 2567 浏览 4 评论 0原文

我现在正在为一件看似简单的事情而奋斗大约两天。我希望有人能提供帮助。

我创建了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

飞烟轻若梦 2024-08-31 19:16:12

在数据库中,属性应保存在按其 attribute_id 组织的表 catalog_product_entity_datetime 中。首先获取entity_type_id(因为我的显然与你的不同):

select entity_type_id from eav_entity_type where entity_type_code = 'catalog_product';

我在最后一个上得到4,但可以根据情况进行替换。以下查询应列出所有已保存的值:

select * from catalog_product_entity_datetime where attribute_id = (select attribute_id from eav_attribute where entity_type_id = 4 and attribute_code = 'my_update');

为了确保您实际上已将属性添加到数据库中:

select attribute_id from eav_attribute where entity_type_id = 4 and attribute_code = 'my_update'

如果您在该空间中看到值,则问题可能是您尚未选择要加载的属性。例如,如果您要从目录产品集合中加载产品,则需要一种加载属性的方法:

$collection->addAttributeToSelect("my_update");

如果您看到数据实际上已保存,请提供有关产品加载的更多上下文。

希望有帮助。

谢谢!乔

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):

select entity_type_id from eav_entity_type where entity_type_code = 'catalog_product';

I get 4 on that last one, but substitute as applicable. The following query should list any saved values:

select * from catalog_product_entity_datetime where attribute_id = (select attribute_id from eav_attribute where entity_type_id = 4 and attribute_code = 'my_update');

To make sure that you have actually added the attribute to the database:

select attribute_id from eav_attribute where entity_type_id = 4 and attribute_code = 'my_update'

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:

$collection->addAttributeToSelect("my_update");

Please give more context on your product loading if you see that the data is actually saved.

Hope that helps.

Thanks! Joe

如果没有 2024-08-31 19:16:12

默认情况下不保存您的属性。您可以使用:
$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");

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文