Reputation: 309
Im making a module to import products from another system, but I cant find a way to actually save the product. This is what i have tried:
$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();
But this does not seem to work :(
Could anybody help me on the right track?
BR/Sune
Upvotes: 0
Views: 1911
Reputation: 309
I found a solution:
$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();
where $product is an array with new product information.
This works just perfect!
Upvotes: 3