为什么这段代码不能在 magento 1.7 中创建产品?
class MyCompany_Catalogimporter_Model_Mysql4_Importer extends Mage_Core_Model_Mysql4_Abstract
{
public function _construct()
{
$this->_init('catalogimporter/catalogimporter', 'catalogimporter_id');
}
public function uploadAndImport(Varien_Object $object){
$product = Mage::getModel('catalog/product');
$product->setSku('pro12');
$product->setAttributeSetId(9);
$product->setTypeId('simple');
$product->setName('Product title');
$product->setCategoryIds(array(7));
$product->setWebsiteIDs(array(1));
$product->setDescription('Product Full description');
$product->setShortDescription('Product Short description');
$product->setPrice(250.00);
$product->setWeight(30.00);
$product->setVisibility(4);
$product->setStatus(1);
$product->setTaxClassId(0);
$product->setStockData(array(
'is_in_stock' => 1,
'qty' => 20
));
$product->setCreatedAt(strtotime('now'));
try {
$product->save();
}
catch (Exception $e) {
Mage::log($e->getMessage()); //check your var/log/system.log for error
}
echo "saved";
die();
}
}
没有错误!
更新
如果我使用以下代码在 magento 根目录中创建一个简单文件,它也可以正常工作:
require_once('app/Mage.php');
Mage::app();
$product = Mage::getModel('catalog/product');
$product->setSku('pro111');
$product->setAttributeSetId(9);
$product->setTypeId('simple');
$product->setName('Product title');
$product->setCategoryIds(array(7));
$product->setWebsiteIDs(array(1));
$product->setDescription('Product Full description');
$product->setShortDescription('Product Short description');
$product->setPrice(250.00);
$product->setWeight(30.00);
$product->setVisibility(4);
$product->setStatus(1);
$product->setTaxClassId(0);
$product->setStockData(array(
'is_in_stock' => 1,
'qty' => 20
));
$product->setCreatedAt(strtotime('now'));
$product->save();
为什么?!?!?
谢谢