1

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?

2 Answers 2

3
+50

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)

1
  • Thanks a lot Marius! You always so successful! Next time i will call you instantly! =) Pd: edit $children variable, you write childred.
    – ntzz
    Commented Aug 24, 2015 at 8:56
0

Here we go..

    <?php

    require_once('app/Mage.php');

    Mage::app();

    // Get bundle product
    $product=Mage::getModel('catalog/product')->load('2');
    $selections = $product->getTypeInstance(true)
                ->getSelectionsCollection($product->getTypeInstance(true)
                ->getOptionsIds($product), $product);

    // get Selections
    foreach ($selections as $selection) {
    // Fetch information from selection
    print_r($selection->getId());
    }
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.