0

In magento 2.3 i want bundle item options as per in product detail page.How can i get all html of bundle item. Please suggest any solution

1

Try this, it will work 100%.

 public function getBundleOptionsHtml($product)
 {
    $_product = $this->_objectManager->create('\Magento\Catalog\Model\Product')->load($product->getId());

    $this->coreRegistry->register('current_product',$_product);/*this used for default file of observer*/
    $layout = $this->layoutFactory->create();
    $blockOption = $layout->createBlock('Magento\Bundle\Block\Catalog\Product\View\Type\Bundle', 'type_bundle_options')->setProduct($_product)->setTemplate('Magento_Bundle::catalog/product/view/type/bundle/options.phtml');
    $price_renderer_block = $layout
            ->createBlock(
                    "Magento\Framework\Pricing\Render", "product.price.render.default", [
                'data' => [
                    'price_render_handle' => 'catalog_product_prices',
                    'use_link_for_as_low_as' => 'true'
                ]
                    ]
            )
            ->setData('area', 'frontend');

    $blockOption->setChild('product.price.render.default', $price_renderer_block);


    $block_links2 = $layout->createBlock('Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Option\Multi', 'multi')->setProduct($_product);
    $blockOption->setChild('multi', $block_links2);

    $block_links3 = $layout->createBlock('Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Option\Radio', 'radio')->setProduct($_product);
    $blockOption->setChild('radio', $block_links3);


    $block_links4 = $layout->createBlock('Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Option\Select', 'select')->setProduct($_product);
    $blockOption->setChild('select', $block_links4);


    $block_links5 = $layout->createBlock('Magento\Bundle\Block\Catalog\Product\View\Type\Bundle\Option\Checkbox', 'checkbox')->setProduct($_product);
    $blockOption->setChild('checkbox', $block_links5);


    return $blockOption->toHtml();

}

Call this function where you want to get html of bundle product by pass product in argument.

  • Its perfectly working code. Thanks – Manish Maheshwari Aug 7 '19 at 9:06
  • where we can add this code and where put file in folder – Junaid Ashfaq Feb 19 at 6:13
1

Please check with below code :

   $store_id = $_storeManager->getStore()->getId();
                $options = $_objectManager->get('Magento\Bundle\Model\Option')
             ->getResourceCollection()
                              ->setProductIdFilter($product->getId())
                              ->setPositionOrder();
             $options->joinValues($store_id);
    $typeInstance = $_objectManager->get('Magento\Bundle\Model\Product\Type');
    $selections = $typeInstance->getSelectionsCollection($typeInstance->getOptionsIds($product), $product);

I hope its work for you.

  • It is return product collection options but not giving html – Manish Maheshwari Aug 5 '19 at 8:50
  • its return only collection.. – Anas Mansuri Aug 5 '19 at 8:53
  • 1
    absolutely ! but i want its html. – Manish Maheshwari Aug 5 '19 at 8:54

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.