I need to get all the child products details like id, name, sizes attribute from a configurable product id in a product listing page(list.phtml) page.
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Framework\Registry')->registry('current_product');//get current product
$productTypeInstance = $product->getTypeInstance();
$usedProducts = $productTypeInstance->getUsedProducts($product);
//echo $product->getId(); //Main configurable product ID
//echo $product->getName(); //Main Configurable Name
foreach ($usedProducts as $child) {
echo $child->getSku()."</br>"; //Child Product Sku
}
Above code is not working showing error Uncaught Error: Call to a member function getTypeInstance() on null
Please help me how to show virtual product information of configurable product in product listing page ?