Posted By

ericmuyser on 02/04/11


Tagged

ls


Versions (?)

ls create products via api


 / Published in: PHP
 

  1. $session_key = time();
  2. // Create the product object and initialize its fields
  3. $product = Shop_Product::create();
  4. $product->categories = array(1);
  5. $product->price = 100;
  6. $product->product_type_id = Shop_ProductType::create()->find_by_name('Goods')->id;
  7. $product->url_name = 'test_product';
  8. $product->name = 'Test product';
  9. $product->sku = 'test_product_01';
  10. $product->tax_class_id = Shop_TaxClass::get_default_class_id();
  11. // Create price tier and save
  12. $price_tier = Shop_PriceTier::create();
  13. $price_tier->customer_group_id = 1;
  14. $price_tier->quantity = 1;
  15. $price_tier->price = 50;
  16. $price_tier->save();
  17. // Add the price tier to the product
  18. $product->price_tiers->add($price_tier, $session_key);
  19. // Save the product
  20. $product->save(null, $session_key);

Report this snippet  

You need to login to post a comment.