Magento – Magento 2 : How to Get Selected Bundle Option Product Details in Cart Page

bundled-productcartmagento2product

I need to get details of selected product of a bundled product. I tried following code in cart page. But it's not working.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$cart = $objectManager->get('\Magento\Checkout\Model\Cart'); 

// get cart items
$items = $cart->getItems();

// get custom options value of cart items
foreach ($items as $item) {
    $options = $item->getProduct()->getTypeInstance(true)->getOptions($item->getProduct());
    $customOptions = $options['options'];
}

Best Answer

For Future Seekers:

Try: $customOptions = $options['bundle_options']

It will give you array list of options like this: (this is json representation of data)

"bundle_options": {
                    "55": {
                        "option_id": "55",
                        "label": "Suction tips",
                        "value": [
                            {
                                "title": "Suction Tips (Premium Quality-100Pcs)",
                                "qty": 2,
                                "price": 0
                            }
                        ]
                    }
                },
Related Topic