0

I had below code which was working fine on Magento 2.2 after upgrading to 2.3.5 event observer not working as expected.

Events.xml

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="core_layout_render_element">
      <observer name="mycompany_delivery_date_add_to_order_view" instance="MyCompany\DeliveryDate\Observer\OrderShippingBlockObserver" />
    </event>
</config>

OrderShippingBlockObserver.php

if($observer->getElementName() == 'sales.order.info') {
   $orderShippingViewBlock = $observer->getLayout()->getBlock($observer->getElementName());
   $order = $orderShippingViewBlock->getOrder();
}

This used to be working before in Magento 2.2 now I don't see the observer element name as sales.order.info. the ultimate goal here is to modify the output of the block and render it again.

$deliveryDateBlock->setTemplate('MyCompany_DeliveryDate::order_info_shipping_info.phtml');
$html = $observer->getTransport()->getOutput() . $deliveryDateBlock->toHtml();
$observer->getTransport()->setOutput($html);
  • you what want to output.Please explain shortly – Mohit Patel May 10 at 4:52
  • that's basically a template file. $deliveryDateBlock->setTemplate('MyCompany_DeliveryDate::order_info_shipping_info.phtml'); which contains logic to delivery pickup locations within radius 15 km. – kamlesh.bar May 10 at 7:25
  • I can see that event in 2.3.5. $this->_eventManager->dispatch( 'core_layout_render_element', ['element_name' => $name, 'layout' => $this, 'transport' => $this->_renderingOutput] ); – kunj May 18 at 7:40
  • I can see the event is been triggering and if I output var_dump($observer->getElementName()); it shows elementName but not going inside if condition, looks element name is been changed in latest version from sales.order.info to something else. I tried other options like checkout_page_head_components but other options didn't work either – kamlesh.bar May 18 at 22:24
  • can you give us more details? is your block showing on frontend/backend, in checkout? how can we test whether we replicate your issue? – Herve Tribouilloy May 19 at 19:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.