I have created a script in magento which create the bundle product and it is working fine. But i want to also update the created bundle product with new products of selection. Here it is my code and it is not working:
public function updateBundleProduct($pro_id,$cPrdcts){
$bundleProduct = Mage::getModel('catalog/product');
$bundleProduct->load($pro_id);
$bundleProduct->setName('test product bundle bundlea');
$bundleSelections = array();
$bundleSelections = array(
'0' => array( //option ID
'0' => array(
'product_id' => '70',
'delete' => '',
'selection_price_value' => '10',
'selection_price_type' => 0,
'selection_qty' => 1,
'selection_can_change_qty' => 0,
'position' => 0,
'is_default' => 1,
'selection_id' => 71,
'option_id' => 14
),
'1' => array(
'product_id' => '84',
'delete' => '',
'selection_price_value' => '10',
'selection_price_type' => 0,
'selection_qty' => 1,
'selection_can_change_qty' => 0,
'position' => 0,
'is_default' => 1,
'selection_id' => 72,
'option_id' => 14
)
) //get all selected products list and data
);
$bundleOptions = array();
$bundleOptions = array(
'0' => array(
'title' => 'All Items2',
'option_id' => 14,
'delete' => '',
'type' => 'multi',
'required' => '1',
'position' => '1'
)
);
$bundleProduct->setData('_edit_mode', true);
//flags for saving custom options/selections
$bundleProduct->setCanSaveCustomOptions(true);
$bundleProduct->setCanSaveBundleSelections(true);
$bundleProduct->setAffectBundleProductSelections(true);
//registering a product because of Mage_Bundle_Model_Selection::_beforeSave
Mage::register('product', $bundleProduct);
//setting the bundle options and selection data
$bundleProduct->setBundleOptionsData($bundleOptions);
$bundleProduct->setBundleSelectionsData($bundleSelections);
// echo ''.print_r($bundleProduct,true).'
'; exit;
$bundleProduct->save();
}
But instead of adding the product items it is deleted my previous options.
$bundleProductset methods - scrowler