How to get Bundle product id using bundle item?
-
16-10-2019 - |
Question
I can get bundle item id, using that id I wants bundle product Id. I have used below code, but it is not working:
$grouped_product_model = Mage::getModel('catalog/product_type_bundle');
$groupedParentIds = $grouped_product_model->getParentIdsByChild(#productid); //#productid will be bundle item id.
Thanks
Solution 2
Below code is working for me, There might be indexing issue, i didn't get value of group ids
if($_product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_SIMPLE){
$bundleed_product_model = Mage::getModel('bundle/product_type');
$bundleedParentIds = $bundleed_product_model->getParentIdsByChild($_product->getId());
if(sizeof($bundleedParentIds) >0){
foreach($bundleedParentIds as $bundleedParentId)
{
if(!in_array($bundleedParentId, $bundleProIds)) {
$iCnt++;
$bundleProIds[]= $bundleedParentId;
$bundleProducts[] = Mage::getModel('catalog/product')->load($bundleedParentId);
}
if($iCnt == 4){break;}
}
}
}
Above code will get bundle products array which have current product as a child.
OTHER TIPS
Try it like this:
$bundleIds = Mage::getResourceSingleton('bundle/selection')->getParentIdsByChild($productId);
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange