Last active
February 16, 2016 11:37
-
-
Save syammohanmp/bd5f17206277493e555f to your computer and use it in GitHub Desktop.
Add Product Programatically in Magento
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//$product = Mage::getModel('catalog/product'); | |
$product = new Mage_Catalog_Model_Product(); | |
echo time(); | |
// Build the product | |
$product->setAttributeSetId(9);// #4 is for default | |
$product->setTypeId('simple'); | |
$product->setName('Some cool product name'); | |
$product->setDescription('Full description here'); | |
$product->setShortDescription('Short description here'); | |
$product->setSku(time()); | |
$product->setWeight(4.0000); | |
$product->setStatus(1); | |
$product->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);//4 | |
print_r(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH); | |
$product->setPrice(39.99);// # Set some price | |
$product->setTaxClassId(0);// # default tax class | |
$product->setStockData(array( | |
'is_in_stock' => 1, | |
'qty' => 99999 | |
)); | |
$product->setCategoryIds(array(27));// # some cat id's, | |
$product->setWebsiteIDs(array(1));// # Website id, 1 is default | |
//Default Magento attribute | |
$product->setCreatedAt(strtotime('now')); | |
//print_r($product); | |
try { | |
$product->save(); | |
echo "Product Created"; | |
} | |
catch (Exception $ex) { | |
//Handle the error | |
echo "Product Creation Failed"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment