0

我想从产品详细信息和类别页面中的可配置产品中获取所选样本的产品 ID。

4

2 回答 2

0
You can print your child products ids ( of configurable products) via making a small change to your code as follow

foreach($collection as $_product) {
        $logger->info("Here are Parent Product Name".$_product->getName());
        $_children = $_product->getTypeInstance()->getUsedProducts($_product);
        foreach ($_children as $child){
            $logger->info("Here are your child Product Ids ".$child->getID());
        }
    }

After this look at to your log files and you will have your child IDS.
于 2021-11-27T07:45:08.990 回答
0

以下示例代码演示了如何通过对象管理器加载可配置产品并将所有子产品(关联的简单产品)作​​为数组获取。

$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);
于 2021-11-10T14:41:38.990 回答