我正在做一个以编程方式添加Magento产品的项目。以下是代码段以编程方式创建Magento产品
try{
//create new product
$newProduct = new Mage_Catalog_Model_Product();
$newProduct->setAttributeSetId(9)
->setTypeId('simple')
->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)
->setTaxClassId(2)
->setCreatedAt(strtotime('now'))
->setName($data[0])
->setSku($data[1])
->setWeight($data[2])
->setStatus($data[3])
->setPrice($data[4])
->setCategoryIds(explode(',',$data[5]))
->setWebsiteIds(explode(',',$data[6]))
->setDescription($data[7])
->setShortDescription($data[8])
....
->setFreeGroundShipping($data[18])
->setMetaTitle($data[19])
->setMetaKeyword($data[20])
->setMetaDescription($data[21])
->setStockData(array(
'manage_stock'=>0,
'min_sale_qty'=>$data[22],
'max_sale_qty'=>$data[23]))
->setSetupFee($data[24])
->setsetupCost($data[25]);
$newProduct->save();
}catch(Exception $e){
$result['status'] = 3;
$result['message'] = 'There is an ERROR happened! NOT ALL products are created! Error:'.$e->getMessage();
echo json_encode($result);
return;
}
这里谈到的问题:执行代码后,我又回到了Magento的管理产品,该产品已经建立,但一些“存储视图”的属性是空的!我进入数据库,发现所有属性都有值。
有没有人有任何想法如何使属性显示?非常感谢!
属性是否填充在默认视图中?或者所有视图/网站的属性都是空的? –
它们对于默认存储视图为空。 – CharlesDou