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)

Leave a Reply

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