phpmagentomagento-1.4

How to get parent product id in magento?


I know that in Magento 1.4.2.0 one gets parent id's like so

list( $parentId ) = Mage::getModel('catalog/product_type_configurable')
                            ->getParentIdsByChild( $product->getId() );

My question is: if I don't know what the parent is, how do I know to use the 'catalog/product_type_configurable' vs 'catalog/product_type_grouped' model to get the id?


Solution

  • You may use:

    $product->getTypeInstance();
    

    Which will return the type object of your product

    Then you can perform your:

    ->getParentIdsByChild()
    

    Giving finally:

    $product->getTypeInstance()->getParentIdsByChild($child->getId());