1. copy the following coding and insert the coding any module page and run the module page the product inserted manually .
$attributeSetId = 4;
//$newproduct = Mage::getModel('catalog/product');
$newproduct = new Mage_Catalog_Model_Product();
$newproduct->setTypeId('simple');
$newproduct->setWeight(100);
$newproduct->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
$newproduct->setStatus(1);
$newproduct->setSku('123456');
$newproduct->setShape(0.12);
$newproduct->setSeller('jaga2');
$newproduct->setCalarity('10');
$newproduct->setCutgrade('10');
$newproduct->setPolish('10');
$newproduct->setSymmetry('10');
$newproduct->setFluorescence('10');
$newproduct->setMeasurements('10');
$newproduct->setLab('0');
$newproduct->setFluorescence('10');
$newproduct->setFluorescence('10');
measurements
$newproduct->setColor('Red');
$newproduct->setTaxClassId(0);
$newproduct->setWebsiteIDs(array(1));
$newproduct->setStoreIDs(array(1));
$newproduct->setStockData(array(
'is_in_stock' => 1,
'qty' => 1000000000000,
'manage_stock' => 1
));
$newproduct->setAttributeSetId(4);
$newproduct->setName('Test_4_');
$newproduct->setCategoryIds(array(2,3)); // array of categories it will relate to
$newproduct->setDescription('producLongDescription');
$newproduct->setShortDescription('producescription');
$newproduct->setPrice(10000000000000000);
try {
if (is_array($errors = $newproduct->validate())) {
$strErrors = array();
foreach($errors as $code=>$error) {
$strErrors[] = ($error === true)? Mage::helper('catalog')->__('Attribute "%s" is invalid.', $code) : $error;
}
$this->_fault('data_invalid', implode("\n", $strErrors));
}
$newproduct->save();
} catch (Mage_Core_Exception $e) {
$this->_fault('data_invalid', $e->getMessage());
}
No comments:
Post a Comment