创建新属性不会更新产品平面数据

发布于 2024-09-26 19:36:29 字数 2606 浏览 2 评论 0原文

我正在编写一个导入模块来将可配置产品导入到magento 中,效果非常好。我已经调整了导入,以便它可以创建创建可配置产品所需的所有必要属性集、属性和属性选项。到目前为止,一切正常……一切正常。

当导入创建新属性时,无法创建可配置产品。当我在后端编辑新属性并保存它而不进行更改时,会出现一条消息,告诉我更新一些索引。更新产品平面数据索引后,我可以再次运行导入,一切正常。

我尝试过创建新属性的方法:

$setup = new Mage_Catalog_Model_Resource_Eav_Mysql4_Setup('core_setup');    
$setup->addAttribute(
                $this->getEntityTypeId(),
                $code,
                array(
                    'attribute_code'            => $code,
                    'label'                     => ucfirst($code),
                    //'group'                   => $attributeSet->getId(),
                    'user_defined'              => 1,
                    'global'                    => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
                    'input'                     => 'select',
                    'unique'                    => 0,
                    'required'                  => 0,
                    'configurable'              => 1,
                    'filterable'                => 1,
                    'visible_on_front'          => 1,
                    'used_in_product_listing'   => 1,
                    'frontend_label'            => array(
                        $code
                    )
                )
            );

另一种方法是:

$attribute = Mage::getModel("catalog/resource_eav_attribute");
        $attribute->addData(
            array(
                'entity_type_id'            => $this->getEntityTypeId(),
                'attribute_code'            => $code,
                'label'                     => ucfirst($code),
                //'group'                   => $attributeSet->getId(),
                'is_user_defined'           => 1,
                'is_global'                 => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
                'frontend_input'            => 'select',
                'is_unique'                 => 0,
                'is_required'               => 0,
                'is_configurable'           => 1,
                'is_filterable'             => 1,
                'is_visible_on_front'       => 1,
                'is_used_in_product_listing'=> 1,
                'frontend_label'            => array(
                    $code
                )
            )
        );

        $attribute->save();

两个代码都很好地创建了该属性,但我无法使用它来创建可配置的属性。我尝试手动运行索引脚本,但这对我没有帮助。

我做错了什么?创建新属性是否是magento 的黑魔法? :-D

I'm writing an import module to import configurable products into magento, which works quite fine. I've tweaked the import so that it can create all necessary attribute sets, attributes and attribute options needed for creating the configurable products. So far everything works ... quite everything.

When the import creates a new attribute, it can not create the configurable product. When I edit the new attribute in the backend and save it without changes, a message appears which tells me to update some indexes. After I have updated the product flat data index, I can run the import again and everything works fine.

I've tried to ways to create a new attribute:

$setup = new Mage_Catalog_Model_Resource_Eav_Mysql4_Setup('core_setup');    
$setup->addAttribute(
                $this->getEntityTypeId(),
                $code,
                array(
                    'attribute_code'            => $code,
                    'label'                     => ucfirst($code),
                    //'group'                   => $attributeSet->getId(),
                    'user_defined'              => 1,
                    'global'                    => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
                    'input'                     => 'select',
                    'unique'                    => 0,
                    'required'                  => 0,
                    'configurable'              => 1,
                    'filterable'                => 1,
                    'visible_on_front'          => 1,
                    'used_in_product_listing'   => 1,
                    'frontend_label'            => array(
                        $code
                    )
                )
            );

The other way is:

$attribute = Mage::getModel("catalog/resource_eav_attribute");
        $attribute->addData(
            array(
                'entity_type_id'            => $this->getEntityTypeId(),
                'attribute_code'            => $code,
                'label'                     => ucfirst($code),
                //'group'                   => $attributeSet->getId(),
                'is_user_defined'           => 1,
                'is_global'                 => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
                'frontend_input'            => 'select',
                'is_unique'                 => 0,
                'is_required'               => 0,
                'is_configurable'           => 1,
                'is_filterable'             => 1,
                'is_visible_on_front'       => 1,
                'is_used_in_product_listing'=> 1,
                'frontend_label'            => array(
                    $code
                )
            )
        );

        $attribute->save();

Both codes create the attribute well but I can't use it to create configurable Attributes. I've tried to manually run the index scripts but this does not help me.

What am I doing wrong? Is creating new attributes somehow the black magic of magento? :-D

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

风吹短裙飘 2024-10-03 19:36:29

我忘记将新属性的后端类型设置为“int”,因此它被自动设置为静态(这意味着magento 在实体表中查找它)。

另一件事是我无法像这样设置属性值:

$model->setData("newattributecode", 123);

Magento 只是没有保存属性。相反,我必须使用未记录的函数 Mage_Catalog_Model_Product::addAttributeUpdate() 来保存该模型的属性值:

$model->addAttributeUpdate("newattributecode", 123, 0);

I forgot to set the backend type for the new attribute to "int" so it was automatically set to static (which means magento looks for it in the entity table).

The other thing is that i couldn't set the attribute value like this:

$model->setData("newattributecode", 123);

Magento just didn't save the attribute. Instead I had to use the undocumented function Mage_Catalog_Model_Product::addAttributeUpdate() to save the attribute value of this model:

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