0

I want to load bundle child products from bundle product parent id in Magento 2.

anyone know how can we achieve this?

Thanks :)

2

You can get the type instance in your bundle product, then get the children IDs, as below.

$typeInstance = $product->getTypeInstance();
$requiredChildrenIds = $typeInstance->getChildrenIds($product->getId(), true);
| improve this answer | |
0

Try this code

    protected $productdata;
    
    
    public function __construct(
        ............................................
        ............................................
        \Magento\Catalog\Model\Product $productdata,
        ............................................
        ............................................
    ) {
        ............................................
        ............................................
        $this->productdata = $productdata;
        ............................................
        ............................................
    }
.......................................................................
.......................................................................
.......................................................................

    public function getBundleProudct(){
    
        //$prd is current product collection
    
        if ($prd->getTypeId() == 'bundle') {
    
            $typeInstance = $prd->getTypeInstance();
            $requiredChildrenIds = $typeInstance->getChildrenIds($prd->getId(), false);
            //print_r($requiredChildrenIds);

            foreach ($requiredChildrenIds as $Childrenkey => $Childrenvalue) {
                foreach ($Childrenvalue as $key => $value) {
                    //print_r($value);
                    $child = $this->productdata->load($value);
                    print_r($child->getName());
                    echo "<br/>";
                }

            }
    }

I Hope This Helps You

| 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.