How do I check if product has used Products. I use the following snippet to get child products

$variants = $this->getCurrentProduct()->getTypeInstance()->getUsedProducts($product);

however if product does not have any child products this would generate a fatal error. So first I would like to check if product has any childs. How would I do that?

1 Answer 1


Your question is a bit unclear.

Are you simply asking how to determine if the product is a complex product (so can have/can have children, or if it is s simple product (so cannot have children)

If so, you'd simply check the product type:

if ($product->getTypeId() == \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE) {
            // YOUR CODE HERE

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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