1

I tried with this code

public function getCustomOptionsHtml($product)
{

    $_product = $this->_objectManager->create('\Magento\Catalog\Model\Product')->load($product);
    $layout = $this->layoutFactory->create();

    $blockOptionData = $layout->createBlock("Magento\Catalog\Block\Product\View\Options")->setProduct($_product)->setTemplate('Magento_Catalog::product/view/options.phtml');

    $block_links1 = $layout->createBlock('Magento\Catalog\Block\Product\View\Options\Type\DefaultType', 'default')->setTemplate('Magento_Catalog::product/view/options/type/default.phtml');
    $blockOptionData->setChild('default', $block_links1);


    $option_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' => 'false'
                ]
                    ]
            )
            ->setData('area', 'frontend');

    $option_price_renderer_block->setProduct($_product);
    $blockOptionData->setChild('product.price.render.default', $option_price_renderer_block);


    $block_links2 = $layout->createBlock('Magento\Catalog\Block\Product\View\Options\Type\Text', 'text')->setTemplate('Magento_Catalog::product/view/options/type/text.phtml');
    $blockOptionData->setChild('text', $block_links2);


    $block_links3 = $layout->createBlock('Magento\Catalog\Block\Product\View\Options\Type\File', 'file')->setTemplate('Magento_Catalog::product/view/options/type/file.phtml');
    $blockOptionData->setChild('file', $block_links3);

    $block_links4 = $layout->createBlock('Magento\Catalog\Block\Product\View\Options\Type\Select', 'select')->setTemplate('Magento_Catalog::product/view/options/type/select.phtml');
    $blockOptionData->setChild('select', $block_links4);

    $block_links5 = $layout->createBlock('Magento\Catalog\Block\Product\View\Options\Type\Date', 'date')->setTemplate('Magento_Catalog::product/view/options/type/date.phtml');
    $blockOptionData->setChild('date', $block_links5);

    return $blockOptionData->toHtml();


}

show error like this

Fatal error: Uncaught Error: Call to a member function renderAmount() on boolean in /home/userdrive/www/magentoproject/vendor/magento/module-catalog/Block/Product/View/Options/AbstractOptions.php:161 Stack trace: /home/userdrive/www/magentoproject/vendor/magento/module-catalog/Block/Product/View/Options/Type/Select/Multiple.php(95): Magento\Catalog\Block\Product\View\Options\AbstractOptions->_formatPrice(Array, false) /home/userdrive/www/magentoproject/vendor/magento/module-catalog/Block/Product/View/Options/Type/Select/Multiple.php(43): Magento\Catalog\Block\Product\View\Options\Type\Select\Multiple->processSelectOption(Object(Magento\Framework\View\Element\Html\Select), Object(Magento\Catalog\Model\Product\Option)) /home/manishm/www/magentoproject/vendor/magento/module-catalog/Block/Product/View/Options/Type/Select.php(79): Magento\Catalog\Block\Product\View\Options\Type\Select\Multiple->_toHtml() /home/userdrive/www/magentoproject/vendor/magento/module-catalog/view/frontend/templates/product/view/options/type/select.phtml(21): Magento in /home/userdrive/www/magentoproject/vendor/magento/module-catalog/Block/Product/View/Options/AbstractOptions.php on line 161

3
  • 1
    In Magento 2.3 working fine. Aug 6, 2019 at 8:38
  • In Magento 2.3.0 working fine. but not working in 2.3.1 & 2.3.2 Aug 6, 2019 at 9:20
  • @DivyeshRana did you find any solution? How did you fix this? Nov 1, 2019 at 9:53

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.