How to get Grouped Product id from child product id in Magento 2?

You can get Parent Grouped Product id from child product id. Using Magento 2, You can fetch Parent product Ids as an array from child id of the product.

For Fetch Parent product id, You need Child Item Id associated with Grouped Product. Using Magento\GroupedProduct\Model\Product\Type\Grouped Magento Core class you can fetch parent product Id.

Used function getParentIdsByChild($childProductId)

You need to pass first parameter as $childProductId for getting parent product ID of child item id.

You can call Grouped Class in your Block __construct function, Create Block class,

Call from a template file,

$childId = 33;
echo $block->getGroupedProductId($childId)

One Reply to “How to get Grouped Product id from child product id in Magento 2?”

  1. Sir any tutorial on how to add custom display mode in category admin side,on selected custom display mode,change the category page.
    For example already options like, product only,static block or product and static block both…
    So one custom option in this drop-down,and on select change the category page according to the custom option

Leave a Reply

Your email address will not be published. Required fields are marked *