1

I have to add a panel into the frontend's product view page. Originally, I will find the full action name of the product page, which is catalog_product_view in this case, and add a handler which reference to the panel's block later. However, something really strange is happening, as Magento only look for configurable products to add the panel: enter image description here

Not with the simple products:

enter image description here

Here's the code for that:

$fullActionName = $observer->getEvent()->getFullActionName();
$layout = $observer->getEvent()->getLayout();
$option_wrapper = $layout->getBlock('product.info.options.wrapper');
$handler = '';
if ( $fullActionName == 'catalog_product_view') {
    $handler = 'catalog_product_view_handler';
}
if ($handler)  $layout->getUpdate()->addHandle($handler);

I'm pretty sure my solution is right. How could this happen?

1 Answer 1

1

It should be possible to add custom block to all product pages by creating custom layout handle in your module VendorName/ModuleName/view/frontend/layout/catalog_product_view.xml. Is there any reason why it is not suitable in your case and observer should be used instead?

6
  • Well I did implement these code in an observer, which is triggered on the event layout_load_before.
    – Joel
    Dec 9, 2015 at 9:20
  • Have you tried to add new catalog_product_view handle in your module? It is not clear why you need to manipulate with layout manually in observer when the same result can be achieved using standard framework capabilities. Dec 9, 2015 at 9:22
  • I usually look for specific events to add blocks into the page, this is what I learned before. I'm quite new to the framework :)
    – Joel
    Dec 9, 2015 at 9:29
  • By the way, my handler references to the block product.info.options.wrapper and add a new block within it. Is this part of the problem?
    – Joel
    Dec 9, 2015 at 9:37
  • It may be a problem if this block is not rendered in on simple product page (not sure about this). Try to use product.info instead. Dec 9, 2015 at 9:41

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.