I am trying to add a product to my Magento store programmatically. Basically I'm duplicating a template and editing it:
$storeId = Mage::app()->getStore()->getId(); // get store id
$product = Mage::getModel('catalog/product')->load(186);
$new = $product->duplicate();
$new->setSku(date('YmdHis'));
$new->setData("url_path", "$name.html");
$new->setEnableGooglecheckout(0);
$new->setIsImported(0);
$new->setLinksExist(false);
$new->setDescription($desc);
$new->setMetaKeyword($desc);
$new->setCustomLayoutUpdate(NULL);
$new->setName($name);
$new->setMetaTitle($desc);
$new->setMetaDescription($desc);
$new->setLinksTitle("Visitenkarten");
$new->setWebsiteIds(array(1));
$new->setData("links_exist", "1");
$new->setStockData(array(
'use_config_manage_stock' => 0,
'manage_stock'=>1,
'min_sale_qty'=>1,
'max_sale_qty'=>2,
'is_in_stock' => 1,
'qty' => 999
)
);
$new->setState(1);
$new->save();
In my admin panel, the new product does show up, but the "Quantity" is empty. When I edit the product in the admin panel and save it, a "0" shows up in the Quantity field.
Can anyone help me with this?
EDIT: The question my answer has been marked a duplicate of isn't describing the same error. The code in this question is already throwing an error on execution, but my code is just creating a product only showing up on the admin panel.