I\'m trying to get bundle options data. using this : $product->getBundleOptionsData
I need to use this, as I\'m trying to change data programmatically an
Finally I made it work to get bundle options data so I can manipulate it. I found the main code in magento's model bundle observer class duplicateProduct function: I needed however to add option_id (careful not to forget that)
here is the code in it's final stage.
$product->getTypeInstance(true)->setStoreFilter($product->getStoreId(), $product);
$optionCollection = $product->getTypeInstance(true)->getOptionsCollection($product);
$selectionCollection = $product->getTypeInstance(true)->getSelectionsCollection(
$product->getTypeInstance(true)->getOptionsIds($product),
$product
);
$optionCollection->appendSelections($selectionCollection);
$optionRawData = array();
$selectionRawData = array();
$i = 0;
foreach ($optionCollection as $option) {
$optionRawData[$i] = array(
'option_id' => $option->getOptionId(), //my addition. important otherwise, options going to be duplicated
'required' => $option->getData('required'),
'position' => $option->getData('position'),
'type' => $option->getData('type'),
'title' => $option->getData('title')?$option->getData('title'):$option->getData('default_title'),
'delete' => ''
);
foreach ($option->getSelections() as $selection) {
$selectionRawData[$i][] = array(
'product_id' => $selection->getProductId(),
'position' => $selection->getPosition(),
'is_default' => $selection->getIsDefault(),
'selection_price_type' => $selection->getSelectionPriceType(),
'selection_price_value' => $selection->getSelectionPriceValue(),
'selection_qty' => $selection->getSelectionQty(),
'selection_can_change_qty' => $selection->getSelectionCanChangeQty(),
'delete' => ''
);
}
$i++;
}
$product->setBundleOptionsData($optionRawData); //changed it to $product
$product->setBundleSelectionsData($selectionRawData); //changed it to $product
you can either now change on the raw data in optionsrawdata. or getBundleOptionsData. and same for the other one.