Php 创建新属性不会更新产品平面数据
我正在编写一个导入模块,将可配置产品导入到magento中,效果非常好。我已经调整了导入,以便它可以创建创建可配置产品所需的所有必要属性集、属性和属性选项。到目前为止一切正常。。。一切都很好 导入创建新属性时,无法创建可配置产品。当我在后端编辑新属性并保存它而不做任何更改时,会出现一条消息,告诉我更新一些索引。更新产品平面数据索引后,我可以再次运行导入,一切正常 我尝试了几种创建新属性的方法:Php 创建新属性不会更新产品平面数据,php,magento,import,entity-attribute-value,Php,Magento,Import,Entity Attribute Value,我正在编写一个导入模块,将可配置产品导入到magento中,效果非常好。我已经调整了导入,以便它可以创建创建可配置产品所需的所有必要属性集、属性和属性选项。到目前为止一切正常。。。一切都很好 导入创建新属性时,无法创建可配置产品。当我在后端编辑新属性并保存它而不做任何更改时,会出现一条消息,告诉我更新一些索引。更新产品平面数据索引后,我可以再次运行导入,一切正常 我尝试了几种创建新属性的方法: $setup = new Mage_Catalog_Model_Resource_Eav_Mysql4
$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我忘记将新属性的后端类型设置为“int”,因此它会自动设置为static(这意味着magento会在实体表中查找它) 另一件事是我不能像这样设置属性值:
$model->setData("newattributecode", 123);
Magento只是没有保存属性。相反,我必须使用未记录的函数Mage\u Catalog\u Model\u Product::addAttributeUpdate()
来保存此模型的属性值:
$model->addAttributeUpdate("newattributecode", 123, 0);
若要对此进行添加,请不要在之后调用$model->save()。我这样做了,让他们疑惑属性值(例如123)是否被重置回null。