Magento – Get child items of parent bundle product from cart

addtocartbundled-productshopping-cart

Suppose I have a bundle product added into the cart. Now when I try to get all cart items that time I need to find particular bundle child is added with x bundle product.

Is it possible to find ?

Best Answer

You can try below code rendering bundle product items from quote.

$cart = Mage::getModel('checkout/cart')->getQuote();
foreach ($cart->getAllItems() as $_item) :
    $_product = Mage::getModel('catalog/product')->load($_item->getProduct()->getId());
    if($_product->getTypeId()==='bundle') :
        $options = $_item->getProduct()->getTypeInstance(true)->getOrderOptions($_item->getProduct());
        ?>
        <dl class="item-options">
            <?php foreach ($options['bundle_options'] as $option):?>
                <dt><?php echo $option['label'] ?></dt>
                <?php foreach ($option['value'] as $sub) :?>
                    <dd><?php echo $sub['qty'] . " x " . $sub['title'] . " " . Mage::helper('core')->currency($sub['price'])  ?></dd>
            <?php endforeach;
            endforeach;
            ?>
        </dl>
    <?php endif;

endforeach;
Related Topic