我在Magento中以编程方式创建了一个可配置的产品,除了当我浏览产品时,我要求一切正常工作,它要求我为产品选择一个可配置的属性。
我似乎无法找到可添加可配置属性的代码。我的代码如下:
$parentProduct->setAttributeSetId(4)
->setTypeId('configurable')
->setStockData(array(
'manage_stock' => 0,
'is_in_stock' => 1,
'qty' => 99999,
'min_sale_qty' => 0,
'max_sale_qty' => 0,
))
->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)
->setTaxClassId(12) // P0000000
->setCreatedAt(time())
->setName($row['name'])
->setSku($sku)
->setPrice($row['price'])
->setCategoryIds(array(2, 3))
->setStatus(1)
->setWeight(1)
->setWebsiteIDs(array(1))
->setDescription($row['description'])
->setShortDescription($row['short_desc'])
->setHasOptions(true)
->setRequiredOptions(true);
$parentProduct->save();
答案 0 :(得分:3)
找到我最终想要的东西。
$parentProduct->setUsedProductAttributeIds(array(80)); // where 80 is color
$data = array(
'0' => array(
'id' => NULL,
'label' => 'Color',
'position' => NULL,
'values' => array(
'0' => array(
'value_index' => 4,
'label' => 'Silver',
'is_percent' => 0,
'pricing_value' => '0',
'attribute_id' =>'80',
),
'1' => array(
'value_index' => 3,
'label' => 'Gold',
'is_percent' => 0,
'pricing_value' => '0',
'attribute_id' =>'80',
),
),
'attribute_id' => 80,
'attribute_code' => 'color',
'frontend_label' => 'Color',
'html_id' => 'config_super_product__attribute_0',
),
);
$parentProduct->setConfigurableAttributesData($data);
现在,当我访问该产品时,它不再要求我指定可配置属性。