Here we first fetch our parent product and the we will get all children products that this parent have.
<?php
namespace Test\Test\Controller\Test;
use Magento\Framework\App\Action\Context;
class Products extends \Magento\Framework\App\Action\Action
{
public function __construct(
\Magento\Catalog\Model\Product $productModel
)
{
$this->product= $productModel;
}
public function getParentProduct()
{
return $this->product->load("a product entity id goes here")
}
public function getChildProducts()
{
$_children = $this->getParentProduct()->getTypeInstance()->getUsedProducts($this->getParentProduct());
}
}
The function getChildProducts now returns a children collection so you would be able to run it through a foreach loop and get all product attributes that might be on it.