Cannot setPrice, setTaxClassId and setWeight when creating a product programmatically

I am using Magento Community Edition ver.

I am trying to add a simple product using Varien data collection model (not Api).

The product is created, but the price, ID, and tax class are not set.

I would be grateful if anyone can advise why these specific product attributes are not set.

Here is my code:

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

    $product->setType('Simple Product');
    $product->setName('Product Name6');
    $product->setDescription('The Product Description');
    $product->setShortDescription('Brief Description');


    $stockItem = Mage::getModel('cataloginventory/stock_item');
    if (! $stockItem->getId()) {
    $stockItem->setData('inventory_manage_stock_default', 1);
    $stockItem->setData('is_in_stock', 1);
    $stockItem->setData('qty', 10000);



Any help is greatly appreciated!




source to share

3 answers

Mistake in

$product->setType('Simple Product');





now the price is isset. Because the price in magento depends on the type of product.



Do not use:

$product->setType('Simple Product');


it doesn't actually install the product ... it hasn't worked for a while ... as above, use:



This will actually set the type ... since "simple" was defined as a constant in the magic / directory ... but not "simple product" ...



As stated above, tweaking $product->setType('Simple');

will solve your problem. How did mine.



All Articles