views:

28

answers:

1

Hi guys,

How have I to add a product into Magento using a php function? I have used the API but it is very slow. I have to import about 100.000 records and check the stock everynight.

Regards

+1  A: 

Programmatically adding a product is easy. You start with creating a blank model

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

Then fill it in...

$product->setSku('XXXX')    // must be a unique value
    ->setName('Your product\'s name')
    ->setWebsiteIds(array(1))    // should have at least one website to show
    ->setCategoryIds('1,2,3')    // comma-separated list
    ->setStatus(true);

...and so on for the attributes you want. (Values here are examples only.) Remember to include all required attributes like description, price, tax class, visibility, etc.
Finally add it to the database.

$product->save();

Have you tried using the import/export profiles?

clockworkgeek