As you know when we works with any customization work related to configurable product and simple product, we need some code snippet that helps us to find out the relation between parent and child product.

Lets take one example, when we have one simple product (child product) and we need all the simple (child) product associated with its parent product. In this case we require solution that gives us Parent product id and using this parent product we are able to find all its simple (child) products.

In order to get the parent product id in Magento 2, you can use below code at any file.

If you want to use this code at block file in Magento 2, then use below code snippet.

That’s it. Enjoy with Magento 2!

Mahendra Paladiya
Mahendra is a Web Developer whose passions includes web development, technical blog writing, and database management. His passion for web development pushed him into learning how to handle different platforms like Core PHP, Magento, Prestashop, WordPress, CodeIgniter, CakePHP and Oracle.