Here i will show you how to fetch
We will start by making a simple class that gets all our parent(Configurable products)
<?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\ResourceModel\Product\CollectionFactory $_product_res_fac
)
{
$this->_product_res_fac = $_product_res_fac;
}
public function getParentProducts()
{
return $this->_product_res_fac->create()->addAttributeToSelect('*')->addAttributeToFilter('type_id', ['eq' => 'configurable']);
}
}
As you see above our getParentProducts function will now return all configuarble products we currently have in our system.
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.