Adding a new product
Here is how you can add a product using Magento backend.
//create a new product
try {
$newProduct = Mage::getModel('catalog/product')
->setStoreId('default')
->setCategoryIds('4')
->setAttributeSetId(41)
->setPrice(15.49)
->setSku('4you')
->setName('4You T Shirt')
->setManufacturer(20)
->save();
echo 'OK Product ID: '.$newProduct->getId();
}
catch (Mage_Core_Exception $e) {
echo $e->getMessage();
}
catch (Exception $e) {
echo $e;
}
You can set any other attribute by using universal setter function setData($attribute_code, $value) or for example for shirt size: setShirtSize($value). Varian object translates it automatically into setData(’shirt_size’, $value).
If you want to update existing product, call $newProduct→load($id) before setting any attributes.




