how to Programmatically create bundle products in Magento external file external file
In this post we will show you, how to Programmatically create bundle products in Magento external file. hear we are going to show you code how to create bundle products Programmatically in Magento external file.
Pass you data link name, sku, color, weight, etc information to create Easily a bundle product programmatically in Magento external file.
// include file for Mage and config // file for run ern external ".php" file require_once('includes/config.php'); require_once('app/Mage.php'); // add store id $add_store_id = 1; // add website id $add_website_id = array(1); // add category id $add_category_id = array(5); Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); /** * @var $product_check Mage_Catalog_Model_Product */ $product_check = Mage::getModel('catalog/product'); // add your product data $add_product_data = array( 'sku_type' => 0, 'sku' => 'onlinecode', 'name' => "onlinecode name", 'description' => 'onlinecode description', 'short_description' => 'onlinecode shor description', 'type_id' => 'bundle', 'attribute_set_id' => 4, 'weight_type' => 0, 'visibility' => 4, 'price_type' => 0, 'price_view' => 0, 'status' => 1, 'created_at' => strtotime('now'), 'category_ids' => $add_category_id, 'store_id' => $add_store_id, 'website_ids' => $add_website_id ); // save product in db $product_check->setData($add_product_data); Mage::register('product', $product_check); $option_raw_data = array(); $option_raw_data[0] = array( 'required' => 1, 'option_id' => '', 'position' => 0, 'type' => 'select', 'title' => 'onlinecode title', 'default_title' => 'onlinecode default title', 'delete' => '', ); $selection_raw_data = array(); $selection_raw_data[0] = array(); $selection_raw_data[0][] = array( 'product_id' => 1, 'selection_qty' => 1, 'selection_can_change_qty' => 1, 'position' => 0, 'is_default' => 1, 'selection_id' => '', 'selection_price_type' => 0, 'selection_price_value' => 0.0, 'option_id' => '', 'delete' => '' ); Mage::register('productCheck', $product_check); Mage::register('current_product', $product_check); $product_check->setCanSaveConfigurableAttributes(false); $product_check->setCanSaveCustomOptions(true); // hear set the Bundle Options & Selection Data $product_check->setBundleOptionsData($option_raw_data); $product_check->setBundleSelectionsData($selection_raw_data); $product_check->setCanSaveBundleSelections(true); $product_check->setAffectBundleProductSelections(true); // save product in db $product_check->save();