Wednesday, November 25, 2009

Import Simple Products (for barrmy)

You don't need to import the data directly in the into the tables. My suggestion is to use the models provided by magento (that's why it's a MVC).

Create an product instance like this:

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

set the data you need
$product->setName('PRODUCT NAME');
$product->setDescription('PRODUCT DESCRIPTION');
and so on.
To add stock to this:
'use_config_manage_stock' => 1,
'qty' => 998,
'min_qty' => 0,
'min_sale_qty' => 0,
'max_sale_qty' => 9999,
'is_qty_decimal' => 0,
'backorders' => 0,
'notify_stock_qty' => 0,
'is_in_stock' => 1

If you have more that 1 website you must specify on which website to appear
To add categories:
Set status
$product->setStatus(1);//1=Enabled; 2=Disabled;
Set visibility
$product->setVisibility(4);//4 = catalog & search.
For photos:
$product->addImageToMediaGallery('path/to/photo', array('image', 'small_image', 'thumbnail'), false, false);

second parameter can be replaced by null for a regular image. You can test the difference :)

After all the attributes are set just call
and Magento will put all the attributes in the right table.
If you want to update a product, do the same but instead of creating an "empty" instance of a product, load one.
$product = Mage::getModel('catalog/product')->load(PRODUCT ID);

This will work if you want to modify the default values. If you want to modify the values for a specific store do this.
$product = Mage::getModel('catalog/product')->setStoreId(STORE ID)->load(PRODUCT ID);
These are the basics. If you want a "fine tuned" product creation you just have to play around with the attributes setData() method.

It's not easy. You need some programming skills, but it can be done.

You can find an update to this post here:

1 comment:

  1. Hi,

    Thank you for linking my site here :), I will also do the same for you lol :) Would you like to become an editor on my site? helping people around with Magento? Reply me back at if you would like to help a hand.