Magento 1.9 – Get Only Default Items from Bundle Product Options

bundled-productmagento-1.9

I have a bundle product that have different options, and each options have different items. How can I get only a list of default items and it's Default Qty of those options, programmatically.

See the screen shot, I only want to get Sku 020524 and Sku 020592

enter image description here

Best Answer

You can do this:

$product = Mage::getModel('catalog/product')->load(bundle_pruduct_id);
$selectionCollection = $product->getTypeInstance(true)->getSelectionsCollection(
    $product->getTypeInstance(true)->getOptionsIds($product), $product
);
$bundled_items = array();
foreach($selectionCollection as $option) {
    if ($option->is_default) {
       $bundled_items[] = array(
           'id' => $option->product_id,
           'name' => $option->name,
           'qty'=> $option->selection_qty,
       );
    }

}
print_r($bundled_items);
Related Topic