3

By using the following code Get Bundle product ids

$productIDs = $product->getTypeInstance(true)->getChildrenIds($product->getId(), false)

Mage::log($productIDs); 

using above retrive multi-dimensional array..

Array
(
[0] => Array
    (
        [21] => 21
        [25] => 25
    )

[1] => Array
    (
        [28] => 28
    )
)

in my case i have a bundle with three product... i just need product ids(21, 25 and 28) i try a lot but unable figure out. any help would be greatly appreciated

2

1 Answer 1

9

Try the below code ,

         $id = 10;//bundled product id
         $product = Mage::getModel('catalog/product')->setStoreId(Mage::app()->getStore()->getId())->load($id);
         $collection = $product->getTypeInstance(true)
            ->getSelectionsCollection($product->getTypeInstance(true)->getOptionsIds($product), $product);

         $itemIds = array();

         foreach ($collection as $item) {
            $itemIds[] = $item->getId();
           // echo "<pre>";
           // print_r($item->getData());
           // echo "</pre>";
         }
         var_dump($itemIds);
3
  • Thanks @saravanavelu Array ( [0] => 21 [1] => 28 [2] => 25 ) now get array value like this... still i need only array value's 21- 28 and 25...by using these value i need to calculate some value.. please have a look
    – lordman
    Jul 19, 2015 at 18:03
  • Done getting value... here is a code foreach ($itemIds as $key=>$item){ $bundleIds = $itemIds[$keys[$i]]; $i++;
    – lordman
    Jul 19, 2015 at 21:46
  • Very nice code, Can we get only a list of default options of bundle items to a bundle product? Jul 27, 2017 at 11:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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