Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate a Magento product programmatically in the 1.7 version
    text
    copied!<p>why this snipped of code doesn't create a product in magento 1.7?</p> <pre><code>class MyCompany_Catalogimporter_Model_Mysql4_Importer extends Mage_Core_Model_Mysql4_Abstract { public function _construct() { $this-&gt;_init('catalogimporter/catalogimporter', 'catalogimporter_id'); } public function uploadAndImport(Varien_Object $object){ $product = Mage::getModel('catalog/product'); $product-&gt;setSku('pro12'); $product-&gt;setAttributeSetId(9); $product-&gt;setTypeId('simple'); $product-&gt;setName('Product title'); $product-&gt;setCategoryIds(array(7)); $product-&gt;setWebsiteIDs(array(1)); $product-&gt;setDescription('Product Full description'); $product-&gt;setShortDescription('Product Short description'); $product-&gt;setPrice(250.00); $product-&gt;setWeight(30.00); $product-&gt;setVisibility(4); $product-&gt;setStatus(1); $product-&gt;setTaxClassId(0); $product-&gt;setStockData(array( 'is_in_stock' =&gt; 1, 'qty' =&gt; 20 )); $product-&gt;setCreatedAt(strtotime('now')); try { $product-&gt;save(); } catch (Exception $e) { Mage::log($e-&gt;getMessage()); //check your var/log/system.log for error } echo "saved"; die(); } } </code></pre> <p>There are NO Errors!</p> <p><strong>UPDATE</strong></p> <p>If I create a simple file in the magento root with this following code, it works as well:</p> <pre><code>require_once('app/Mage.php'); Mage::app(); $product = Mage::getModel('catalog/product'); $product-&gt;setSku('pro111'); $product-&gt;setAttributeSetId(9); $product-&gt;setTypeId('simple'); $product-&gt;setName('Product title'); $product-&gt;setCategoryIds(array(7)); $product-&gt;setWebsiteIDs(array(1)); $product-&gt;setDescription('Product Full description'); $product-&gt;setShortDescription('Product Short description'); $product-&gt;setPrice(250.00); $product-&gt;setWeight(30.00); $product-&gt;setVisibility(4); $product-&gt;setStatus(1); $product-&gt;setTaxClassId(0); $product-&gt;setStockData(array( 'is_in_stock' =&gt; 1, 'qty' =&gt; 20 )); $product-&gt;setCreatedAt(strtotime('now')); $product-&gt;save(); </code></pre> <p><strong>WHY?!?!?</strong></p> <p>thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload