Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Sep 16th, 2012  |  syntax: None  |  size: 1.34 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # My Magento Snippets #
  2.  
  3. ## Create Simple Product ##
  4.  
  5. ```php
  6. <?php
  7.  
  8. require_once '../app/Mage.php';
  9.  
  10. Varien_Profiler::enable();
  11. Mage::setIsDeveloperMode(true);
  12. ini_set('display_errors', 1);
  13.  
  14. umask(0);
  15. Mage::app();
  16.  
  17. /**
  18.  * Adding Product
  19.  */
  20.  
  21. /** @TODO HACK */
  22. Mage::app()->getStore()->setWebsiteId(1);
  23.  
  24. for ($i=0; $i<25; $i++) {
  25.  
  26.     $data = array(
  27.         'name'                => 'Simple Product '.$i,
  28.         'sku'                 => 'skusimple'.$i,
  29.         'attribute_set_id'    => 4,
  30.         'type_id'             => 'simple',
  31.         'website_ids'         => array(1),
  32.         'description'         => 'Simple Product Description '.$i,
  33.         'short_description'   => 'Simple Product Short Description '.$i,
  34.         'price'               => 25,
  35.         'tax_class_id'        => 0,
  36.         'visibility'          => Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
  37.         'status'              => Mage_Catalog_Model_Product_Status::STATUS_ENABLED,
  38.         'category_ids'        => array(),
  39.         'is_scope_store'      => 0,
  40.         'has_options'         => 1,
  41.         'required_options'    => 1,
  42.         'stock_data'          => array(
  43.             'manage_stock'    => 0,
  44.             'is_in_stock'     => 1,
  45.             'qty'             => 50,
  46.         )
  47.     );
  48.  
  49.     $product = Mage::getModel('catalog/product');
  50.     $product->setData($data)->save();
  51.  
  52. }
  53. ```