我正在进行一个项目,需要通过编程的方式添加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管理产品页面,产品已经创建了,但是一些“商店视图”属性为空!我进入数据库发现所有属性都有值。
请问有人知道如何让属性显示出来吗?非常感谢!