0

How to get list of all selected items of bundle product on detail page magento2

  • you want all items for that bundle product in any page, right? – sarvesh Dineshkumar Patel Feb 19 at 7:04
  • yes all selected items for that bundle product – Junaid Ashfaq Feb 19 at 7:12
  • please check answer I uodated. and you add more details what you need in array ok. – sarvesh Dineshkumar Patel Feb 19 at 7:13
  • it give me Mage error in magento 2 – Junaid Ashfaq Feb 19 at 7:14
1
<ul>
<?php

$productId = 17; //any bundle product id
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Catalog\Model\Product')->load($productId);
        //get all the selection products used in bundle product.
        $selectionCollection = $product->getTypeInstance(true)
        ->getSelectionsCollection(
            $product->getTypeInstance(true)->getOptionsIds($product),
            $product
        );

    foreach ($selectionCollection as $proselection) {
                $selectionArray = [];
              echo  '<li>'; 
               echo $selectionArray['selection_product_name'] = $proselection->getName();
               echo '<br>';

               echo $selectionArray['selection_product_price'] = $proselection->getSelectionQty();
                 echo '</li>';
            }    




?>
</ul>

this work for me

| improve this answer | |
0

Pleas try below code.

$product_id = 'your bundle product id';

$_objectManager = \Magento\Framework\App\ObjectManager::getInstance();

        $store_id = 1;
        $options = $_objectManager->create('Magento\Bundle\Model\Option')
            ->getResourceCollection()
            ->setProductIdFilter($product_id)
            ->setPositionOrder();
        $options->joinValues($store_id);
        $typeInstance = $_objectManager->get('Magento\Bundle\Model\Product\Type');
        $selections = $typeInstance->getSelectionsCollection($typeInstance->getOptionsIds($product), $product);
        foreach($selections as $selection){
            if($product->getSku() == $selection->getSku()){
                return $selection->getSelectionQty();
            }
        }
        print_r($selections); 
| improve this answer | |

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.