And when the request is finished, it returns a 302 redirect to the Wishlist overview page. During this request, the mentioned observer events are triggered. In this particular case, when you press an 'Add to Wishlist' button, a post request is sent. I don't think that you will be able to achieve what you want by using php observers.
How do I add this type of javascript code inside the PHP observable file? 'shippingEastMalaysia': '4.00' //shipping fee 'shippingWestMalaysia': '0.00', //shipping fee 'productCategory': 'grocery', //product category 'productName': '18 grains dried fruits granola (7 X 40g) X 4 packs', 'eventDetails.label': '18 grains dried fruits granola (7 X 40g) X 4 packs', 'eventDetails.action': 'add to wish list', 'eventDetails.category': 'product search result engagement', So instead of var_dump('wishlist_product_add_after') The code above is able to work perfectly fine, and I am able to get the below output when adding an item to the wishlist string(26) "wishlist_product_add_after"īut now I want to add a javascript code when an observer is executed Var_dump('wishlist_product_add_after') die I am adding a new module to add an Observer that will trigger some js code during an event that happensīelow are the file and its content I have addedĪpp/code/Vendor/MyModule/registration.phpįile Name and Path : app/code/Vendor/MyModule/etc/events.xmlįile Name and Path for Observer to trigger during wishlist add an item :Īpp/code/Vendor/MyModule/Observer/WishlistAddItem.phpįile Name and Path for Observer to trigger during wishlist product add afterĪpp/code/Vendor/MyModule/Observer/WishlistProductAddAfter.php