<?php
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$product = Mage::getModel('catalog/product');
    if(!$product->getIdBySku('testsku11')){

try {
   $product
   ->setStoreId(2) //you can set data in store scope
   //website ID the product is assigned to, as an array
   ->setWebsiteIds(array(2))
   ->setAttributeSetId(9)//ID of a attribute set named 'default'
   ->setTypeId('simple')//product type
   ->setCreatedAt(strtotime('now'))//product creation time
   ->setUpdatedAt(strtotime('now')) //product update time

   ->setSku('testsku11')//SKU
   ->setName('test product11')//product name
   ->setWeight(20.0000)
   ->setStatus(1)//product status (1 - enabled, 2 - disabled)
   //tax class (0 - none, 1 - default, 2 - taxable, 4 - shipping)
   ->setTaxClassId(2)
   //catalog and search visibility
   ->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)
   ->setManufacturer(261)//manufacturer id
   //->setColor(24)
   ->setNewsFromDate('')//product set as new from (MM-DD-YYYY)
   ->setNewsToDate('')//product set as new to (MM-DD-YYYY)
   //country of manufacture (2-letter country code)
   ->setCountryOfManufacture('GB')

   ->setPrice(11.22)//price in form 11.22
   ->setCost(22.33)//price in form 11.22
   ->setSpecialPrice()//special price in form 11.22
   ->setSpecialFromDate('')//special price from (MM-DD-YYYY)
   ->setSpecialToDate('')//special price to (MM-DD-YYYY)
   ->setMsrpEnabled(0)//enable MAP 1 - enable, 0 - disable 
   //display actual price (1 - on gesture, 2 - in cart, 
   //3 - before order confirmation, 4 - use config)
   ->setMsrpDisplayActualPriceType(4)
   ->setMsrp()//Manufacturer's Suggested Retail Price

   ->setMetaTitle('test meta title 2')
   ->setMetaKeyword('test meta keyword 2')
   ->setMetaDescription('test meta description 2')
   ->setDescription('This is a long description')
   ->setShortDescription('This is a short description')
   //media gallery initialization
   ->setMediaGallery(array('images' => array(), 'values' => array()))
   //assigning image, thumb and small image to media gallery
   ->addImageToMediaGallery('', array(
              'image', 'thumbnail', 'small_image'), false, false)

   ->setStockData(array(
      'use_config_manage_stock' => 0, //'Use config settings' checkbox
      'manage_stock' => 1, //manage stock
      'min_sale_qty' => 1, //Minimum Qty Allowed in Shopping Cart
      'max_sale_qty' => 2, //Maximum Qty Allowed in Shopping Cart
      'is_in_stock' => 1, //Stock Availability
      'qty' => 999 //qty
     )
   )
   ->setCategoryIds(array(73)); //assign product to categories
   $product->save();

    }catch(Exception $e){
        echo Mage::log($e->getMessage());
    }

    }

 

Categorized in: