Hi everyone, this is my first post
I can add new products like
$product ->setTypeId($type) ->setAttributeSetId(4) ->setSku($simpleproduct['code'])) ; $product ->setName($simpleproduct['name']) ->setDescription('Description')
;
etc.. When I save the product it shows in admin panel but I cannot set price, taxclass, and weight values like this way. After I set them manually from admin panel the product is shown in frontend. How can I set price, taxclass, and weight values like the codes above? Thank you.
Try it, below approach:
//Create product object $newproduct = new Mage_Catalog_Model_Product(); //Set the stock data $stock_data = array( 'use_config_manage_stock' => 1, 'original_inventory_qty' => 0, 'qty' => $paramData['qty_avail'], 'use_config_min_qty' => 1, 'use_config_min_sale_qty' => 1, 'use_config_max_sale_qty' => 1, 'is_qty_decimal' => 0, 'is_decimal_divided' => 0, 'use_config_backorders' => 1, 'use_config_notify_stock_qty' => 1, 'use_config_enable_qty_increments' => 1, 'use_config_qty_increments' => 1, 'is_in_stock' => '1', //1 -> In Stock and 0-> Out Of Stock ); //Define data array like the below one $dataProduct = array ( 'name' => '<Product_Title>', 'sku' => '<Product_Sku>', 'weight' => '', 'status' => '1', 'tax_class_id' => '0' , //Default tax class id is Zero 'url_key' => '', 'visibility' => '4', //Set the visibility 4 'price' => '<Set_Product_Price>' , 'cost' => 'Total of <Ship Cost + Product Price>', 'special_price' => '', //Optional 'special_from_date' => '', //Optional 'special_to_date' => '', //Optional 'enable_googlecheckout' => 1, 'msrp_enabled' => 2, 'msrp_display_actual_price_type' => 4, 'msrp' => htmlentities($paramData['msrp']), 'thumbnail' => 'no_selection', 'small_image' => 'no_selection', 'image' => 'no_selection', 'media_gallery' => array ( 'images' => '', 'values' => array("thumbnail"=>null,"small_image"=>null,"image"=>null) ), 'description' => '<Product_Description>', 'short_description' => '<Product_Short_Description>', 'custom_design' => '', 'custom_design_from' => '', 'custom_design_to' => '', 'custom_layout_update' => '', 'stock_data' => '<Pass Stock Data Array>', //See $stock_data array above 'options_container' => 'container2', 'page_layout' => '', 'is_recurring' => 0, 'recurring_profile' => '', 'use_config_gift_message_available' => 1, 'website_ids' => array ( '0' => 1 ), 'store_ids' =>array(0,1,2,3) , 'category_ids' => '<YOUR_CATEGORIES_IDS>', 'affect_product_custom_options' => 1, ); //Pass the above data to product object and call save method. $newproduct->setData($dataProduct); $newproduct->save();