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.