In magento 2 I had created 3 product via my code. Product type is configurable, simple, simple. so now don't know set two simple product into configuration product. thank for help!


You can associate the simple products by loading the Configurable product.

Inject the below Class to Construct Method \Magento\Catalog\Model\ProductRepository $productRepository,

So, $this->_productRepository = $productRepository;

Assuming the id of the configurable product as '3' and the simple as ,'1' and '2' respectively.

$associatedProductIds = [2,3];//Simple Product ids array

$configurableProduct = $this->_productRepository->getById(3);



Hope this helps

| improve this answer | |
  • Thank @richard-valsanlan. I tried you code. it not working. – xanka Oct 18 '17 at 8:58
  • Can you share your code ? – Richard Valsalan Oct 18 '17 at 9:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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