Skip to main content
deleted 8 characters in body
Source Link
Bilal Usean
  • 10.1k
  • 14
  • 75
  • 123

I need to display the block in product detail page for bundle product only so I just add preference to overwrite Magento/Catalog/Controller/Product/View

Then alter the product detail page controller execute method like below.

// Render page
$page = $this->resultPageFactory->create();
            
if($this->_type->getById($productId)->getTypeId()=='bundle')
{
    $block=$page->getLayout()->createBlock('Training3\BundleBlock\Block\Index\Index''Vendor\Module\Block\Index\Index');
    $page->getLayout()->getBlock('content')->append($block);
}      

$this->viewHelper->prepareAndRender($page, $productId, $this, $params);
return $page;

but it always throws error like

PHP Fatal error: Call to a member function append() on boolean

I need to add my block to <referenceContainer name="content">

I need to display the block in product detail page for bundle product only so I just add preference to overwrite Magento/Catalog/Controller/Product/View

Then alter the product detail page controller execute method like below.

// Render page
$page = $this->resultPageFactory->create();
            
if($this->_type->getById($productId)->getTypeId()=='bundle')
{
    $block=$page->getLayout()->createBlock('Training3\BundleBlock\Block\Index\Index');
    $page->getLayout()->getBlock('content')->append($block);
}      

$this->viewHelper->prepareAndRender($page, $productId, $this, $params);
return $page;

but it always throws error like

PHP Fatal error: Call to a member function append() on boolean

I need to add my block to <referenceContainer name="content">

I need to display the block in product detail page for bundle product only so I just add preference to overwrite Magento/Catalog/Controller/Product/View

Then alter the product detail page controller execute method like below.

// Render page
$page = $this->resultPageFactory->create();
            
if($this->_type->getById($productId)->getTypeId()=='bundle')
{
    $block=$page->getLayout()->createBlock('Vendor\Module\Block\Index\Index');
    $page->getLayout()->getBlock('content')->append($block);
}      

$this->viewHelper->prepareAndRender($page, $productId, $this, $params);
return $page;

but it always throws error like

PHP Fatal error: Call to a member function append() on boolean

I need to add my block to <referenceContainer name="content">

Source Link
Bilal Usean
  • 10.1k
  • 14
  • 75
  • 123

append block to specific container programatically

I need to display the block in product detail page for bundle product only so I just add preference to overwrite Magento/Catalog/Controller/Product/View

Then alter the product detail page controller execute method like below.

// Render page
$page = $this->resultPageFactory->create();
            
if($this->_type->getById($productId)->getTypeId()=='bundle')
{
    $block=$page->getLayout()->createBlock('Training3\BundleBlock\Block\Index\Index');
    $page->getLayout()->getBlock('content')->append($block);
}      

$this->viewHelper->prepareAndRender($page, $productId, $this, $params);
return $page;

but it always throws error like

PHP Fatal error: Call to a member function append() on boolean

I need to add my block to <referenceContainer name="content">