从自定义模块创建新产品

时间:2011-02-06 17:16:59

标签: magento

我正在制作一个模块来从另一个系统导入产品,但我找不到实际保存产品的方法。这就是我的尝试:

$new_product    = Mage::getModel('catalog/product');

$productInfoData['sku'] = 'mySKU';
$productInfoData['price'] = '10';
$productInfoData['name'] = 'The name';
$productInfoData['status'] = 1;

// then set product's general info to update
$new_product->setData($productInfoData);

// call save() method to save your product with updated data
$new_product->save();

但这似乎不起作用:(

有人能帮助我走上正轨吗?

BR /淑娜

1 个答案:

答案 0 :(得分:3)

我找到了解决方案:

                    $new_product    = Mage::getModel('catalog/product');

                $new_product->setWebsiteIds(array(1));
                $new_product->setSku('lu-'.$product['sku']);
                $new_product->setPrice((($product['price'])*$e_rate));
                $new_product->setCategoryIds(array(1152));
                $new_product->setAttributeSetId(4); 
                $new_product->setVisibility(1);             
                $new_product->setType('Simple Product');
                $new_product->setName($product['name']);
                $new_product->setDescription('');
                $new_product->setShortDescription('');
                $new_product->setStatus(2); 
                $new_product->setTaxClassId(2);
                $new_product->setWeight(0);             
                $new_product->setCreatedAt(strtotime('now'));                   


                // call save() method to save your product with updated data
                $new_product->save();

其中$ product是包含新产品信息的数组。

这非常完美!

相关问题