Magento – Magento2 How to Check any simple product is a child of grouped product

grouped-productslist-viewmagento2

In a list page of Magento 2, I want to check that @ every product "Is it a child of any grouped product or not?" if yes then I want to change their URL link when I click on add-to-cart it should be redirected to its parent grouped product detail page.

Thank you.

Best Answer

Product relations in Magento is stored in catalog_product_relation table.

So you can check if the particular simple product has any data present in the table to check if it has any parent product.

SELECT * FROM catalog_product_relation WHERE child_id = <product_id>

If it has any parent product you can get the Product ID of parent to check the parent product is grouped and you can get the respective product page URL.

Related Topic