module – Magento2: how to obtain simple Assosiate products for configurable products

You can use this code below using the factory method:

protected $ productFactory;

public function __constructed (
....
 Magento  Catalog  Model  ProductFactory $ productFactory,
....
)
{
....
$ this-> productFactory = $ productFactory;
....
}

public function its function ()
{
$ configProduct = $ this-> productFactory-> create () -> load ($ product_id);

$ _children = $ configProduct-> getTypeInstance () -> getUsedProducts ($ configProduct);
foreach ($ _children as $ child) {
echo "Simple product ID". $ child-> getID (). "
"; } }