How to Get all Bundle item options details by SKU Magento 2.

You can get the list of Bundle item options details of bundle products by SKU using Magento 2.

Bundle products have multiple options to generate a single bundle item. The bundle will be generated using dropdown, radio and checkbox options. You can see all the options from the admin panel, edit bundle product, Bundle item section of the product.

Magento 2 Sample data bundle products SKU 24-WG080 has four options available. We can get all the four options details by Passing bundle product SKU  using below snippet code,

<?php
namespace Jesadiya\BundleOptions\Model;

use Exception;
use Psr\Log\LoggerInterface;
use Magento\Bundle\Api\Data\OptionInterface;
use Magento\Bundle\Api\ProductOptionRepositoryInterface;

class BundleOptionsListBySku
{
    /**
     * @var ProductOptionRepositoryInterface
     */
    private $productOptionRepo;

    public function __construct(
        LoggerInterface $logger,
        ProductOptionRepositoryInterface $productOptionRepo
    ) {
        $this->logger = $logger;
        $this->productOptionRepo = $productOptionRepo;
    }

    /**
     * all option type details of bundle products
     *
     * @return OptionInterface[]
     */
    public function getBundleOptionDetailBySkuOptionId()
    {
        $sku = '24-WG080';
        try {
            $items = $this->productOptionType->getList($sku);
        } catch (Exception $exception) {
            $this->logger->error($exception->getMessage());
            throw new Exception($exception->getMessage());
        }

        return $items;
    }
}

You can use getList() method from the interface Magento\Bundle\Api\ProductOptionRepositoryInterface to fetch detail of options.

Call Method to get details of each option,

$items = $this->getBundleOptionDetailBySkuOptionId();

foreach ($items as $item) {
    echo "<pre>";print_r($item->getData());
}

bundle-options

Bundle product options detailsOutput:
An array of OptionInterface.

Error On SKU invalid: The product that was requested doesn’t exist. Verify the product and try again.

You can get the details of the specific option of bundle product by link, Bundle Option details.