i had make few bundled product which is bacially group of two products.

now i want to get list of all product id that have other product in bundle.

Suppose i made bundled product using (1,2) ,(1,4) ,(3,2), (1,6)

by id 1 i want to get product ids: 2,4,6

how can i do it

1 Answer 1

  1. find all bundle selections for your product

    $selectionsForReferenceProduct = Mage::getResourceModel('bundle/selection_collection')
            ->addAttributeToFilter('entity_id', $productId);
  2. for each of them, get the option id

    $optionId = $selection->getOptionId();
  3. find all other bundle selections associated to these options

    $selectionsForAssociatedProducts = Mage::getResourceModel('bundle/selection_collection')->setOptionIdsFilter($optionIds)
  4. for each of them, get the product id

    $productId = $selection->getId();

Note that Mage_Bundle_Model_Resource_Selection_Collection extends Mage_Catalog_Model_Resource_Product_Collection and joins the selection table, this is why the collection items are instances of Mage_Catalog_Model_Product with additional data from the selection table and you get the product id with 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.