Your shopping cart is empty. Browse our Store

Magento

Open Source eCommerce Evolved

Adding a new product

Last modified by Bojan Hrnkas on Wed, May 14, 2008 07:49
Source|Old Revisions  

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.




 

Popular Wiki Tags  |  View all

Professional Services from the Magento Team

Professional Installation from the Magento Team

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs
Sales: Call 877.832.5289 (North America) 310.295.4144 (International) to request a call-back.
© Copyright 2008 Varien. Magento is a trademark of Irubin Consulting Inc. DBA Varien
Privacy Policy|Terms of Service
Magento Community Count
28391 users|505 users currently online|64543 forum posts