How to get parent product id in magento?

后端 未结 5 1797
旧巷少年郎
旧巷少年郎 2021-02-07 01:55

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

list( $parentId ) = Mage::getModel(\'catalog/product_type_configurable\')
                                   


        
5条回答
  •  走了就别回头了
    2021-02-07 02:48

    You can just call both and offer a fall-back as it should be one or the other:

    if($product->getTypeId() == "simple"){
        $parentIds = Mage::getModel('catalog/product_type_grouped')->getParentIdsByChild($product->getId());
        if(!$parentIds)
            $parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getId());
        if(isset($parentIds[0])){
            $parent = Mage::getModel('catalog/product')->load($parentIds[0]);
            // do stuff here
        }
    }
    

提交回复
热议问题