Magento2 - How to see if configurable products has simple products attached
Try below script from magento2 root:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
use Magento\Framework\App\Bootstrap;
try{
require __DIR__ . '/app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$obj = $bootstrap->getObjectManager();
$resource = $obj->get('Magento\Framework\App\ResourceConnection');
$connection = $resource->getConnection();
$sql = "SELECT * FROM catalog_product_entity WHERE type_id = 'configurable' and entity_id NOT IN (SELECT parent_id FROM catalog_product_relation)";
$result = $connection->fetchAll($sql);
if (!count($result)) {
$sql = "SELECT * FROM catalog_product_entity WHERE type_id = 'configurable' and entity_id NOT IN (SELECT parent_id FROM catalog_product_super_link)";
$result = $connection->fetchAll($sql);
}
echo "Number of products: " . count($result) . "<br/>";
echo '<pre>';print_r($result);
} catch (Exception $e) {
echo $e->getMessage();
}
If you are comfortable with using MySQL to answer your question, you could write a query such as
select * from catalog_product_entity left join catalog_product_relation on (parent_id = entity_id) where type_id = "configurable" group by parent_id having (count(*) = 0)
This will join the table for products with the table that houses the parent/child relationship. Then filtering that down via a having clause to find all the ones without that relationship.