2

I have a configurable product with two virtual products as children. I have the child product ID. How can I the parent product ID from the child product ID?

I have tried this but it is not working

// the $parent is always empty
$parent = $childProduct->getTypeInstance()->getParentIdsByChild($childProductId);
  • Added the code I have tried. – Paul Aug 31 '16 at 15:32
6

Try following way:

$parentIds = $this->objectManager->get('Magento\ConfigurableProduct\Model\Product\Type\Configurable')
            ->getParentIdsByChild($productId);
$parentId = array_shift($parentIds);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.