分类
后端

magento2 通过简单产品ID获取可配置产品ID

$productId = '简单产品ID';
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$attributeModel = $objectManager->create('Magento\ConfigurableProduct\Model\Product\Type\Configurable');
$parentConfigObject  = $attributeModel->getParentIdsByChild($productId);
//获取可配置产品ID
$parent_id = isset($parentConfigObject[0])&&$parentConfigObject[0]?$parentConfigObject[0]:$productId;