magento2 - Magento 2 observer event not triggering -
i have added observer module , put event definition in events.xml
# app/code/vendor/modulename/etc/frontend/events.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:nonamespaceschemalocation="urn:magento:framework:event/etc/events.xsd"> <event name="checkout_submit_before"> <observer name="vendor_modulename_order_save_before" instance="vendor\modulename\observer\orderobserver" /> </event> </config>
i have added logic in observer
# app/code/vendor/name/observer/orderobserver.php namespace vendor\modulename\observer; use magento\framework\event\observer; use magento\framework\event\observerinterface; class orderobserver implements observerinterface { public function __construct() { } /** * @param observer $observer * @return void */ public function execute(\magento\framework\event\observer $observer) { $quote = $observer->getquote(); ... ... ... } }
try placing events.xml etc/events.xml
# app/code/vendor/modulename/etc/events.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:nonamespaceschemalocation="urn:magento:framework:event/etc/events.xsd"> <event name="checkout_submit_before"> <observer name="vendor_modulename_order_save_before" instance="vendor\modulename\observer\orderobserver" /> </event> </config>
and no need use magento\framework\event\observer
# app/code/vendor/modulename/observer/orderobserver.php namespace vendor\modulename\observer; use magento\framework\event\observerinterface; class orderobserver implements observerinterface { /** * @param observer $observer * @return void */ public function execute(\magento\framework\event\observer $observer) { $quote = $observer->getquote(); ... ... ... } }
make sure clean cache
bin/magento cache:clean
let me know if still having issues
Comments
Post a Comment