magento2 - 如何从magento 2中的可配置产品中获取简单产品
问题描述
我想从产品详细信息和类别页面中的可配置产品中获取所选样本的产品 ID。
解决方案
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.
推荐阅读
- java - java long 除法两个值意外结果
- android - 如何将来自不同路径的图像附加到电子邮件?
- node.js - 在没有浏览器的情况下使用 Node.js 应用程序观看以太坊智能合约事件
- php - Yii2:如何在使用 Codeception 进行测试时将日志写入文件?
- visual-studio - 如何使用 msbuild 引导生成的文件任务输出
- vba - 使用 vba Excel 过滤
- mysql - DISTINCT 语句如何合并一张表中的两行
- python - sin(x) TypeError: 只有大小为 1 的数组可以转换为 Python 标量
- three.js - Three.js:在skinnedMesh周围绘制边界框
- tensorflow - 类实例之间的 TensorFlow 变量共享