开发者

magento: Add product from front end

Can anyone help me by some idea that how can I Add products from the front end with most of the attributes of the products in Magento?

Tha开发者_如何学Cnks in Advance.


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

I have used this and it worked. I also found this from a site but forgotten the link :(


You could use the frontend with 'custom product attributes' to collect the information (and image) needed to add a product.

Then you can have your own backend code to take an 'order' and build products from those custom product attributes.


Products can be uploaded and managed from magento frontend using magento Rest/Soap api. .This extension also does the same.Have a look at: Frontend Products Upload


Magento uses the backend for adding products to your store.Adding it from frontend changes the whole scope from security and integrity point of view. Why the need for adding from frontend when you can do the same from backend with full priviliges?


It is not possible out-of-the-box. But you can write your own custom module for this, it will not be very big and complicated.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜