2

I am trying to render custom option in my custom page. I found an example for magento 1 here but it dint work out as in magento 2 addOptionRenderer is removed I guess.

I tried this to call in from ajax which will return html

$layout = $this->layoutFactory->create();

$block_header = $layout->createBlock('Magento\Catalog\Block\Product\View\Options')
->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');
$block_header->setChild('default',$block_links1);

$block_links2  = $layout->createBlock('Magento\Catalog\Block\Product\View\Options\Type\Text','text')->setTemplate('Magento_Catalog::product/view/options/type/text.phtml');
$block_header->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');
$block_header->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');
$block_header->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');
$block_header->setChild('date',$block_links5);


echo $block_header->toHtml();

The error I am getting is

Fatal error: Uncaught Error: Call to a member function renderAmount() on boolean in /my/magento/path/vendor/magento/module-catalog/Block/Product/View/Options/AbstractOptions.php on line 143

  • Did you found any solution for magento 2 ? – Rohan Hapani Sep 19 '18 at 12:32
  • Can you please help me to solve this? It's very urgent for me. – Rohan Hapani Oct 12 '18 at 7:14
1

Add this code in your file:

$block_links6  = $layout->createBlock('Magento\Framework\Pricing\Render','product.price.render.default');
$blockOption->setChild('product.price.render.default',$block_links6);
  • It returns error if I used in controller. main.CRITICAL: Wrong Price Rendering layout configuration. Factory block is missed [] []. How to solve it? – Rohan Hapani Sep 20 '18 at 4:37
  • Can you please help me to solve this? It's very urgent for me. – Rohan Hapani Oct 12 '18 at 7:14

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.