---
title: "Magento 2: How to Get Parent Product ID from Child Product ID for Bundled and Grouped Products"
url: "https://magecomp.com/blog/magento-2-get-parent-product-id-from-child-product-id-for-bundled-and-grouped-products/"
date: "2022-04-11T16:22:35+00:00"
modified: "2025-02-19T05:31:41+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 366
reading_time: "2 min read"
summary: "Hello Magento Friends,"
description: "Description - getBundleParentProduct() and getGroupParentProduct() helps to fetch parent product ID from child product ID, learn more"
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "How to Install Magento 2"
    url: "https://magecomp.com/blog/how-to-install-magento-2/"
  - title: "How to Create Custom Page Layout in Magento 2"
    url: "https://magecomp.com/blog/create-custom-page-layout-in-magento-2/"
  - title: "How to Add Pagination in Custom Collection of Magento 2?"
    url: "https://magecomp.com/blog/add-pagination-in-custom-collection-magento-2/"
---

# Magento 2: How to Get Parent Product ID from Child Product ID for Bundled and Grouped Products

_Published: April 11, 2022_  
_Author: Dhiren Vasoya_  

![How to Get Parent Product ID from Child Product ID for Bundled and Grouped Products M2](https://magecomp.com/blog/wp-content/uploads/2022/04/How-to-Get-Parent-Product-ID-from-Child-Product-ID-for-Bundled-and-Grouped-Products-M2-1024x512.webp)

**Hello Magento Friends,**

Today’s blog is about fetching parent product ID from child product ID for bundled and grouped products in Magento 2.
[**Magento supports 6 Product Types**](https://magecomp.com/blog/magento-2-product-types/) to manage your catalog. In which [**Grouped Products**](https://magecomp.com/blog/create-grouped-product-programmatically-magento-2/) and [**Bundled Products**](https://magecomp.com/blog/create-bundled-product-programmatically-magento-2/) contain child products. When you have the requirement to get the parent product ID from the child product ID, here is the solution.
[![hyva theme development](https://magecomp.com/blog/wp-content/uploads/2025/02/hyva-theme-development-CTA-5.webp)](https://magecomp.com/services/hyva-theme-development/)

Let’s see How to Get Parent Product ID from Child Product ID for Bundled and Grouped Products in Magento 2.
## Steps to Get Parent Product ID from Child Product ID for Bundled and Grouped Products in Magento 2:
**Step 1:** Create a file at the below path
**app\code\Vendor\Extension\Helper\Data.php**

And add the below code
```
<?php
namespace VendorExtensionHelper;

class Data extends MagentoFrameworkAppHelperAbstractHelper
{
    protected $bundletype;
    protected $grouptype;
    protected $_productFactory;

    public function __construct(
        MagentoFrameworkAppHelperContext $context,
        MagentoBundleModelProductType $bundletype,
        MagentoGroupedProductModelProductTypeGrouped $grouptype,
        MagentoCatalogModelProductFactory $_productFactory)
    {
        $this->bundletype=$bundletype;
        $this->grouptype=$grouptype;
        $this->_productFactory = $_productFactory;
        parent::__construct($context);
    }

    public function getBundleParentProduct($id)
    {
        $bundleproduct = $this->bundletype->getParentIdsByChild($id);

        if(isset($bundleproduct[0]))
        {
            $product= $this->_productFactory->create()->load($bundleproduct[0]);
            return $product;
         }
         else
         {
             return false;
         }
    }

    public function getGroupParentProduct($id)
    {
        $groupproduct = $this->grouptype->getParentIdsByChild($id);

        if(isset($groupproduct[0]))
        {
            $product= $this->_productFactory->create()->load($groupproduct[0]);
            return $product;
        }
        else
        {
            return false;
        }
    }
}
```

[![Magento version upgrade](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Version-Upgrade-CTA-1.webp)](https://magecomp.com/services/magento-upgrade-services/)

**Step 2:** Call function from the template file
```
<?php

$helper = $this->helper('VendorExtensionHelperData');
$ childproductid=33;
$parent_bundle = $helper->getBundleParentProduct($childproductid);
echo “Product Id : ”.$parent_bundle ->getId(); //get id of bundle parent product
echo “Product Name : ”.$parent_bundle ->getName(); //get name of bundle parent product

$parent_group = $helper->getGroupParentProduct($childproductid);
echo “Product Id : ”.$parent_ group ->getId(); //get id of group parent product
echo “Product Name : ”.$parent_ group ->getName(); //get name of group parent product
?>
```

## Conclusion:
This way you can obtain Parent Product ID using Child Product ID for Bundled and Grouped Products with the help of the above solution. In case you are unable to get the output, connect with me through comments.
[![Magento 2 Speed & Performance Optimization Services](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Speed-Performance-Optimization-Services-CTA-1.webp)](https://magecomp.com/magento-performance-optimization.html)

**Happy Coding!**


---

_View the original post at: [https://magecomp.com/blog/magento-2-get-parent-product-id-from-child-product-id-for-bundled-and-grouped-products/](https://magecomp.com/blog/magento-2-get-parent-product-id-from-child-product-id-for-bundled-and-grouped-products/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-09-28 14:25:06 UTC_  
