首页 > 解决方案 > 如何从magento 2中的可配置产品中获取简单产品

问题描述

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

标签: magento2magento2.4

解决方案


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.

推荐阅读