Magento - get bundled products where a simple product belongs to

Magento - get bundled products where a simple product belongs to

September 5, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento - get bundled products where a simple product belongs to

Solving Magento Bundled Product Retrieval Challenges

Hello developers! Today I want to address a common Magento query that many of you might face while working with bundled products. The question is about retrieving all the bundles where a simple product belongs, and it seems like a straightforward task at first glance. However, as we’ll see, there are some complexities involved.

Understanding the Problem

The core issue lies in the way Magento handles relationships between simple and bundle products. Unlike grouped or configurable products, which have built-in functions to fetch related items, Magento doesn’t provide a direct method for retrieving parent bundles from child products in a bundle configuration.

What We’ve Tried So Far

Let’s first look at what has been attempted by the questioner so far:

  1. Using Mage::getModel('bundle/product_selection') to get parent IDs by child ID didn’t work because it requires the bundled item (not the simple product) as input.

  2. Searching the catalog_product_bundle_selection table directly seemed like a good idea, but there wasn’t an existing Magento function for this purpose.

  3. Checking Mage_Bundle for relevant methods also proved fruitless.

The Clean Way: Using Resource Model

After some exploration, I realized that we can leverage the built-in resource model to achieve our goal. Here’s how you can do it:

// Get the required simple product IDs
$simpleProductIds = [3, 5, 7]; // Replace these with your actual IDs

// Initialize the bundle selection collection
$bundleSelectionCollectionModel = Mage::getResourceModel('bundle/selection_collection');

// Filter by child product IDs
$bundlesCollection = $bundleSelectionCollectionModel->getSelect()
    ->where('`selection`.`product_id` in (' . join(',', $simpleProductIds) . ')');

In this code snippet, we first define an array of simple product IDs. We then create a new instance of the bundle/selection_collection resource model and use its getSelect() method to obtain the underlying SQL query.

Next, we modify the query by adding a where clause that filters records based on the provided child product IDs using the IN operator.

Populating Bundles Data

Now that we have the query prepared, let’s populate the actual data:

$bundledProductIds = [];

foreach ($bundlesCollection as $bundleItem) {
    $bundledProductIds[] = $bundleItem->getParentProductId();
}

// Print or process the retrieved bundle IDs
print_r($bundledProductIds);

In this section, we initialize an empty array $bundledProductIds to store the parent product (bundle) IDs. We then iterate through each record in the $bundlesCollection, and for each item, we extract the parent_product_id using the getParentProductId() method.

Finally, we print or process the retrieved bundle IDs as needed.

Conclusion

Retrieving bundled products based on a simple product in Magento requires a bit of creativity and understanding of the database structure. By utilizing the resource model and constructing a custom SQL query, we can efficiently fetch all the bundles where our desired simple product is included.

Remember to replace the $simpleProductIds array with your actual product IDs or implement a dynamic way to retrieve them based on your specific business logic.

This approach ensures that you don’t need to hack into Magento’s core files or use undocumented methods. Instead, we leverage the built-in functionality provided by the resource model, which is a more maintainable and reliable solution in the long run.

Happy coding! If you have any further questions or want to discuss this topic in more depth, feel free to drop a comment below. I’m always here to help!

Don’t forget to check out our website at Laravel Company for more Magento tips and tricks!

Catalog Database Themes Configuration

Our network