Magento 1.9 – Get Product ID in Bundle Selection Dropdown

bundled-productmagento-1.9

I'm using bundle products, and want to get the ID of simple products.

I was trying to get the ID from the product selection, but I think it's impossible.

My code:

<?php foreach ($_options as $_option): ?>
<?php
$_selections = $_option->getSelections();
foreach ($_selections as $_selection) {
    $id = $_selection->getProductId();          
    $product = Mage::getModel('catalog/product')->load($id);

    $descripcion = $product->getDescription();
    $descriptions[ $id ] = $descripcion;
}
?>

But the $_selection->getProductId() its the product ID SELECTION, not the product ID from catalog.

Any idea?

Best Answer

you can get the ids of the bundle items like this:

$mainProductId = your bundle product id here
$children = Mage::getResourceModel('bundle/selection')
                 ->getChildrenIds($mainProductId, false);

$children will be an array like this:

Array
(
    [0] => Array
        (
            [1] => 1
            [5] => 5
        )

    [1] => Array
        (
            [2] => 2
        )

)

The first index in the array (0, 1) is a numerical index for each option and the second dimension holds the product ids (1,5 for the first one, 2 for the second option)

Related Topic