I need to get the name and assigned attributes value of the first associated product of configurable in Magento 2.

I use something like this:


but this return the value of the configurable product not the value of associated product.

Thank you


Try this:

//$product = $this->productRepository->getById(725);
$childProducts = $product->getTypeInstance()->getUsedProducts($product);
/** @var \Magento\Catalog\Model\Product $child */
foreach($childProducts as $child) {
    echo $child->getId();
|improve this answer|||||
  • Hi, thank you so much, the code is work but how I can display only the first product ID? this code display the ID for all associated products, I need to get only the first product ID. – Robert May 31 '19 at 7:46
  • 1
    You need to add break; inside loop; – Sohel Rana May 31 '19 at 7:59
  • indeed, thank you very much, is work like a charm ... I really appreciate your quick help – Robert May 31 '19 at 8:07

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.