Adding the magento product from the interface with attributes


How to add product from frontend with custom attributes ? I have this code form another stack question

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

$product->setName('Some cool product name');
$product->setDescription('Full description here');
$product->setShortDescription('Short description here');

$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";

But i have custom attributes also , and how to add them from that code.

For each attribute you have you need to call:

$product->setData('attribute_code_here', 'Value here');


For yes/no attributes do it like this:

$product->setData('attribute_code_here', 1); //1 for Yes, 0 for No

For multiple selects

$product->setData('attribute_code_here', "4,6,12"); //the ids of the values concatenated by comma.