1

This question already has an answer here:

I want to get simple products Associate to configurable products in custom module using factory method. (not using object manager)

marked as duplicate by Manashvi Birla, Jai, saravanavelu, Teja Bhagavan Kollepara, Mohit Kumar Arora Mar 16 at 4:45

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

You can use this below code using factory method :

protected $productFactory;

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

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

   $_children = $configProduct->getTypeInstance()->getUsedProducts($configProduct);
   foreach ($_children as $child){
    echo "Simple Product Ids ".$child->getID()."<br/>";
   }
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.