Friday, December 23, 2011

Adding product from fornt-end with image in mangento programmatically


We can add a product from frond end in magneto Paste this code in file and place the file in root folder of project run this file in browser product will created and also give image correct path the image also uploaded

 define('MAGENTO', realpath(dirname(__FILE__)));
 require_once MAGENTO . '/app/Mage.php';

//$product = Mage::getModel('catalog/product');
$product = new Mage_Catalog_Model_Product();
echo time();
// Build the product
$product->setAttributeSetId(4);// #4 is for default

$product->setName('Some cool product name');
$product->setDescription('Full description here');
$product->setShortDescription('Short description here');
$mediaAttribute = array (
$product->addImageToMediaGallery($filepath_to_image, $mediaAttribute, true, false);

$product->setPrice(39.99);// # Set some price
$product->setTaxClassId(0);// # default tax class

'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


try {
    echo "Product Created";
catch (Exception $ex) {
    //Handle the error
    echo "Product Creation Failed";


No comments:

Post a Comment