Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* add new product */
- $product = new Mage_Catalog_Model_Product();
- //------- settings
- $product->setAttributeSetId('4'); // Attribute Set
- $product->setTypeId('downloadable'); // Product Type
- /* Product Information */
- //------- general
- $product->setName('Test Product');
- $product->setDescription('');
- $product->setShortDescription('');
- $product->setSku('TEST');
- $product->setNewsFromDate('11/27/2014'); //product set as new from
- $product->setNewsToDate('12/27/2014'); //product set as new to
- $product->setWeight('');
- $product->setStatus(1); // Enabled
- $product->setVisibility(4); // Catalog, Search
- /* Multi-Select Attribute Sets */
- $product->setData('cdb_list_type', '42, 43');
- /* Text Attribute Sets */
- $product->setNumber_of_total_entries('1000');
- //------- Prices
- $product->setPrice('100');
- $product->setTaxClassId(0); // None
- //------- Inventories
- $product->setStockData(array(
- 'use_config_manage_stock' => 0, //'Use config settings' checkbox
- 'manage_stock' => 0
- )); // not work 'is_in_stock' if qty is 0
- //------- Categories
- $product->setCategoryIds(array(2, 4)); // 2 is main, category id
- //------- Dowmloadable Information
- $product->setLinksTitle('Test Product');
- $product->setLinksPurchasedSeparately('0'); // No
- $downloadData = array();
- $downloadData['link'][0] = array(
- 'is_delete' => '',
- 'link_id' => '0',
- 'title' => 'test', // <----------- NOT WORKING
- 'price' => '',
- 'number_of_downloads' => '3', // Unlimited
- 'is_shareable' => '2',
- 'sample' => array( // sample if have
- 'file' => '[]',
- 'type' => 'url',
- 'url' => 'http://test.com/file.zip'
- ),
- 'file' => '[]',
- 'type' => 'url',
- 'link_url' => 'http://test.com/file.zip',
- 'sort_order' => ''
- );
- $product->setDownloadableData($downloadData);
- /* Others */
- $product->setWebsiteIDs(array(1)); # Website id, 1 is default
- $product->setCreatedAt(strtotime('now'));
- /* Save */
- try {
- $product->save();
- }
- catch (Exception $ex) {
- //Handle the error
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement