Magento 2 How to get the configurable products related all child products in list page using object manager?

magento.stackexchange https://magento.stackexchange.com/questions/264596

  •  21-02-2021
  •  | 
  •  

Вопрос

Magento 2 in how to get the configurable products related all child (simple products QTY) in list page using object manager?

Please give me a solution this questions?

Это было полезно?

Решение 2

Its Working .

<?php
             $productId = 161;
              $objectManager =  \Magento\Framework\App\ObjectManager::getInstance();
              $currentproduct = $objectManager->create('Magento\Catalog\Model\Product')->load($productId);                $configProduct = $objectManager->create('Magento\Catalog\Model\Product')->load($productId);       
              $_children1 = $configProduct->getTypeInstance()->getUsedProducts($configProduct);
              foreach ($_children1 as $child1) {
               echo $child->getsku();
}
?>

Другие советы

you can get all simple products associate to configurable product:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$configProduct = $objectManager->create('Magento\Catalog\Model\Product')->load($product_id);

$_children = $configProduct->getTypeInstance()->getUsedProducts($configProduct);
foreach ($_children as $child){
echo "Here are your child Product Ids ".$child->getID()."\n";
}
echo "count: ".count($_children);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с magento.stackexchange
scroll top