我正在编写一个导入模块,将可配置的产品导入到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();
两个代码都很好地创建了属性,但是我不能用它来创建可配置的属性。我试图手动运行索引脚本,但这对我没有帮助。
我做错什么了?创造新的属性是不是魔法师的魔法?:-D个