Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. <?php
  2. /* add new product */
  3. $product = new Mage_Catalog_Model_Product();
  4. //------- settings
  5. $product->setAttributeSetId('4'); // Attribute Set
  6. $product->setTypeId('downloadable'); // Product Type
  7.  
  8. /* Product Information */
  9. //------- general
  10. $product->setName('Test Product');
  11. $product->setDescription('');
  12. $product->setShortDescription('');
  13. $product->setSku('TEST');
  14. $product->setNewsFromDate('11/27/2014'); //product set as new from
  15. $product->setNewsToDate('12/27/2014'); //product set as new to
  16. $product->setWeight('');
  17. $product->setStatus(1); // Enabled
  18. $product->setVisibility(4); // Catalog, Search
  19.  
  20.  
  21. /* Multi-Select Attribute Sets */
  22. $product->setData('cdb_list_type', '42, 43');
  23.  
  24. /* Text Attribute Sets */
  25. $product->setNumber_of_total_entries('1000');
  26.  
  27. //------- Prices
  28. $product->setPrice('100');
  29. $product->setTaxClassId(0); // None
  30.  
  31. //------- Inventories
  32.  
  33. $product->setStockData(array(
  34. 'use_config_manage_stock' => 0, //'Use config settings' checkbox
  35. 'manage_stock' => 0
  36. )); // not work 'is_in_stock' if qty is 0
  37.  
  38.  
  39. //------- Categories
  40. $product->setCategoryIds(array(2, 4)); // 2 is main, category id
  41.  
  42. //------- Dowmloadable Information
  43. $product->setLinksTitle('Test Product');
  44. $product->setLinksPurchasedSeparately('0'); // No
  45. $downloadData = array();
  46.  
  47. $downloadData['link'][0] = array(
  48. 'is_delete' => '',
  49. 'link_id' => '0',
  50. 'title' => 'test', // <----------- NOT WORKING
  51. 'price' => '',
  52. 'number_of_downloads' => '3', // Unlimited
  53. 'is_shareable' => '2',
  54. 'sample' => array( // sample if have
  55. 'file' => '[]',
  56. 'type' => 'url',
  57. 'url' => 'http://test.com/file.zip'
  58. ),
  59. 'file' => '[]',
  60. 'type' => 'url',
  61. 'link_url' => 'http://test.com/file.zip',
  62. 'sort_order' => ''
  63. );
  64.  
  65.  
  66. $product->setDownloadableData($downloadData);
  67.  
  68. /* Others */
  69. $product->setWebsiteIDs(array(1)); # Website id, 1 is default
  70. $product->setCreatedAt(strtotime('now'));
  71.  
  72. /* Save */
  73. try {
  74. $product->save();
  75. }
  76. catch (Exception $ex) {
  77. //Handle the error
  78. }
  79. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement