How to get all variants under particular object?

Hi All,

Help me to extract all variants of particular object since i’m new to pimcore. I tried extracting by this line

$objectArray=$object->getChildren([\Pimcore\Model\DataObject\AbstractObject::OBJECT_TYPE_VARIANT],true);

It returned count as expected but all values are null though Variants have values.

Thanks,
Karthikeyan B

 public function getVariants()
{
    
    $list = new Product\Listing();
    $list->setCondition('o_parentId = ?', $this->getId());
    $list->setObjectTypes([AbstractObject::OBJECT_TYPE_VARIANT]);
    $list->setOrder('ASC');

    return $list->load();
    
}

@pdchaudhary (https://talk.pimcore.org/u/pdchaudhary)Thanks it works and we also need to set the flag to read the inherited field also.

\Pimcore\Model\DataObject\AbstractObject::setGetInheritedValues(true);