我創建了一個非常大的導入腳本,它將CSV導入到magento。我還有一個問題需要解決。設置產品的Magento下拉(選擇)值
我使用屬性下拉菜單。不幸的是,我無法爲單個產品的這些屬性設置值。 我所做的:
- 創建的屬性設置[PHP],
- 添加值的下拉列表屬性這一套[PHP],
- 中設置適當的屬性增加了新的產品,並試圖設置屬性值我創造了。
我試過一些方法,這裏是one好看我:
private function setOrAddOptionAttribute($product, $arg_attribute, $arg_value) {
$attribute_model = Mage::getModel('eav/entity_attribute');
$attribute_options_model = Mage::getModel('eav/entity_attribute_source_table');
$attribute_code = $attribute_model->getIdByCode('catalog_product', $arg_attribute);
$attribute = $attribute_model->load($attribute_code);
$attribute_options_model->setAttribute($attribute);
$options = $attribute_options_model->getAllOptions(false);
// determine if this option exists
$value_exists = false;
foreach($options as $option) {
if ($option['label'] == $arg_value) {
$value_exists = true;
break;
}
}
// if this option does not exist, add it.
if (!$value_exists) {
$attribute->setData('option', array(
'value' => array(
'option' => array($arg_value,$arg_value)
)
));
$attribute->save();
}
$product->setData($arg_attribute, $arg_value);
$product->save();
}
不幸的是,不工作。有任何想法嗎?我使用的Magento 1.7.0.2
檢查這一點,也許會有所幫助。 http://magento.stackexchange.com/a/7146/146 – Marius
嘗試分離2個操作:首先創建所需的所有屬性選項,然後將選項屬性分配給產品。 – OSdave