1

Im using sales_order_place_before event and want to execute some javascript when my observer executes.

 public function execute(\Magento\Framework\Event\Observer $observer)
    {
    $order = $observer->getEvent()->getOrder();
    //add something here
}

note:do not use object manager!

3
  • javascript is a client side language while observer is being run at server side. You cannot run a client side script in your server side observer. Jul 18 '20 at 18:07
  • thanks for the answer but it can be possible like this: $layout = Mage::app()->getLayout(); $layout->getUpdate()->addUpdate(' reference name="head"> <block type="core/text" name="myjs"> <action method="setText"><text><![CDATA[<script type="text/javascript"> //code goes here </script>]]></text></action> </block> </reference>'); $layout->getUpdate()->load(); $layout->generateXml(); Jul 19 '20 at 11:44
  • Hello @nihal, do we have solution for this? Pls update as answer, Thanks Oct 9 '20 at 8:03

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.