Back to Top

How to Get Bundle Product Items in Magento 2

Updated 13 February 2026

Here, we will explore how to retrieve and work with bundle product items in Magento 2, including their product IDs and associated selection data.

Now here is the code to get all the selected products of bundle products:

<?php
	
namespace Webkul\Test\Helper;

use Magento\Catalog\Model\ProductFactory;


class Data extends \Magento\Framework\App\Helper\AbstractHelper 
{
	/**
     * @var Magento\Catalog\Model\ProductFactory
     */
    protected $_productFactory;


    public function __construct(
        \Magento\Framework\App\Helper\Context $context,
        ProductFactory $productFactory
    ) {
        parent::__construct($context);
        $this->_productFactory = $productFactory;
    }

    public function getBundleProductOptionsData()
    {

		$productId = 40;//any product id
		$product = $this->_productFactory->create()->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 = [];
	        $selectionArray['selection_product_name'] = $proselection->getName();
	        $selectionArray['selection_product_quantity'] = $proselection->getPrice();
	        $selectionArray['selection_product_price'] = $proselection->getSelectionQty();
	        $selectionArray['selection_product_id'] = $proselection->getProductId();
	        $productsArray[$proselection->getOptionId()][$proselection->getSelectionId()] = $selectionArray;
	    }

	    //get all options of product
	    $optionsCollection = $product->getTypeInstance(true)
	        ->getOptionsCollection($product);

	    foreach ($optionsCollection as $options) {
	        $optionArray[$options->getOptionId()]['option_title'] = $options->getDefaultTitle();
	        $optionArray[$options->getOptionId()]['option_type'] = $options->getType();
	    	
	    }
	}
}

It returns all the product’s items with item data and selection product data.

Here, $productId is a product ID of bundle type product.

$_productFactory is an instance of Magento/Catalog/Model/ProductFactory

Searching for an experienced
Magento 2 Company ?
Find out More

$product is a type of Magento/Catalog/Model/Product that holds the product data of the product with id $productId.

$selectionCollection is a collection of products in bundle type products.

$optionsCollection is a collection of items used in bundle products.

After Printing $optionArray and $productArray you will get data of bundle product’s items.

Thank you for reading this dev doc article, hope you liked it. If you have any queries, you may reach out to our team via a support ticket.

For more functionalities and features, you can check various Magento 2 extensions and also check out Magento 2 Product Bundle to provide custom offers on products.

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home