5

Above answer is not working for me I have updated my observer code public function execute(\Magento\Framework\Event\Observer $observer) { $params = []; // If you want to redirect with data // $url = $this->_urlInterface->getUrl('checkout/cart/index',$params); $url = $this->_urlInterface->getUrl('checkout/...


4

i have get the reference URL for your solution... please look at this https://magecomp.com/blog/send-email-to-admin-after-customer-registration-magento-2/ in Your Observer you need to replace setTemplateVars(['post' => $postObject]) with setTemplateVars(['customer' => $postObject]) for send the customer name and email Id to mail. Let me know ...


4

Logically I don't see any benefit of creating multiple classes for same functionality. Moreover having same class it will help in code redundancy, upgrading and also debugging. In case of Plugin you should have different class defined even if the functionality is same . But in case of observer it would be better if you use the same class in my opinion.


4

vendor/magento/module-config/Model/Config.php Check save method. Following event dispatch: $this->_eventManager->dispatch( "admin_system_config_changed_section_{$this->getSection()}", ['website' => $this->getWebsite(), 'store' => $this->getStore()] ); Ex. For catalog section event should be: ...


4

Observer doesn't provide sort order. So, it may be create issue when create same events in multiple events. So, I would like to suggest you to create plugin for that and avoid same events use in multiple module. Plugin provide you to set sort order if same function's plugin create in multiple action. You can use plugin in method type will be public. ...


4

You can declare your observer at the following location to call it via the REST API only. app/code/Vendor/Module/etc/webapi_rest/events.xml


4

You have to place a events.xml in the webapi_rest area: app/[Vendor]/[Module]/etc/webapi_rest/events.xml By placing the events.xml in the webapi_restdirectory the observer only listens to events dispatched in that area. You can read about the areas and events in the devdocs.


3

Check event observer in $productobject->getId() is already exist or not if not exist then consider it's new one.. and use catalog_product_save_before


3

For me, sales_order_save_commit_after was the only event that worked well: If you need the event to be triggered in the admin area and also in the frontend, you can add the following code in etc/events.xml. If you need it for the order created from admin only, you need to add the following code in etc/adminhtml/events.xml Code: <?xml version="1.0"?> ...


3

There is no such event to get abandoned carts,you have to create it custom. I have idea to overcome this,you have to create cron that run every specific time and collect all quote which is not ordered and between time you set(difference between created and updated quote time). you have to just manage updatedAtFrom and updatedAtTo By doing this you will ...


3

Use sales_quote_item_qty_set_after which will fire when Qty is update. $this->_eventManager->dispatch('sales_quote_item_qty_set_after', ['item' => $this]); I guess that you want to update cart item price. sales_quote_item_qty_set_after event provide quote item as it parameter.So you don't need to inject cart object $this->cart here. Also, ...


3

You can use controller_action_postdispatch_downloadable_download_link. Note that this can include invalid requests for download etc. Additional validation will be required based on your requirements. To get product downloaded load (by link_hash) \Magento\Downloadable\Model\Link\Purchased\Item received in id GET parameter. Note that I also answered your ...


3

Yes you could use them in any number of Observers. Events are dispatched in broadcasting manner, so any number of Observers can be listening to the same event. Either in same module or different module.


3

Yes, We could use multiple modules : <event name="catalog_product_save_after"> <observer name="adams_mage_add_custom_option" instance="CompanyName\ModuleName\Observer\AddCustomOption" /> </event> for another module same event : <event name="catalog_product_save_after"> <observer name="inventory" instance="...


3

Try below code in your observer, it'll work for you. public function checkproductinorder($Observer) { $order = $Observer->getEvent()->getOrder(); $items = $order->getAllItems(); $skus = array('600','800'); //product SKUs $skuList = array(); foreach ($items as $item) { if(in_array($item->getSku(), $skus)) { ...


3

The event before placing order is “sales_order_place_before“


3

How to do an action if an order is placed by a customer You have 2 events you might use (there might be others). sales_order_place_before is dispatched before the order is placed. sales_order_place_after is dispatched after the order is placed. You can create an observer for one of those events. You will find here a tutorial on how to create observers. You ...


3

In magento1 try to do with this event sales_order_place_before which is work with before place order. and put in config.xml <sales_order_place_before> <observers> <Gta_KolupadiRestrict_Model_Observer> <type>singleton</type> <class>gta_kolupadiRestrict/...


3

You can use sales_order_place_before event before placing the order. Also, for getting shipping description for the order, you can use below code in your observer. $order = $observer->getEvent()->getOrder(); echo $order->getShippingDescription(); If you want shipping method data, then you can use below code $shipping = $order->...


3

Create a helper class and define in function in helper. Then you can use where ever in those Magento project. Helpers are usually used as elements that are global and always available. Magento 2 Helper contains functions and methods that are commonly used throughout the application. Methods that are declared as Helpers can be called from any template file, ...


3

The Magento 2 helper is the class which is used for adding functionalities to several features and can be used anywhere in the entire website. They are created as Singleton (single instances of objects) which can be called in controllers, views, models, templates etc. Create Magento 2 Custom Module Add module.xml file in app/code/Magenticians/Mymodule/etc ...


3

namespace Your\Module\Plugin; use Magento\Framework\Controller\ResultFactory; use Magento\Framework\Registry; use Magento\Framework\UrlInterface; class Redirect { protected $coreRegistry; protected $url; protected $resultFactory; public function __construct(Registry $registry, UrlInterface $url, ResultFactory $resultFactory) { ...


3

You can try below code. <?php class Gta_MerchantNotification_Model_Observer { public function merchantremainder($Observer) { $order = $Observer->getEvent()->getOrder(); $order_details = $order->getAllVisibleItems(); foreach ($order_details as $list) { $incrementid = $order->getIncrementId(); ...


3

I don't think it's related to customer being logged in or not, but I think order items are not persisted yet, as you're retrieving new order object. Also you should never use objectManager directly. Try updating your code to this: public function execute(\Magento\Framework\Event\Observer $observer){ $order = $observer->getEvent()->getOrder(); $...


2

Below is my code to stop product from being added to cart and display error message using observer. <?php use Magento\Framework\Event\ObserverInterface; class ProductAddCartBefore implements ObserverInterface { protected $_request; protected $_checkoutSession; protected $_messageManager; public function __construct( \Magento\...


2

According to Magento technical guide (https://devdocs.magento.com/guides/v2.1/coding-standards/technical-guidelines.html#14-events): All values (including objects) passed to an event MUST NOT be modified in the event observer. Instead, plugins SHOULD BE used for modifying the input or output of a function. For me the main difference between plugins and ...


2

@mohith your code is fine if your using magento 2.2.x. Registry has been deprecated in Magento 2.3.x. Use Magento/Catalog/Model/Session in Magento Latest version to get the current product.


2

Istead of the observer you can use the following method to get the detail of current product use Magento\Framework\Registry; class yourclassname { /** * @var Registry */ protected $_registry; public function __construct(Registry $registry) { $this->_registry = $registry; } public yourfunction() { ...


2

The main idea is use a request for your purposes. There is a two cases: path without an url rewrite and with url rewrite. Here is a sample code which parse path from request and obtain a product id: <?php namespace Vendor\Module\Observer; use Magento\Framework\Event\Observer; use Magento\Framework\Event\ObserverInterface; /** * Class ResponseBefore *...


2

Try this, You should use this event controller_action_predispatch_catalog_product_view instead of adding_to_cart_before but the problem is, it will trigger only on first time when you visit the product page, since it is cacheable page. You may try disable cacheable="false" to any of the block from product page and check then it will trigger all the time ...


Only top voted, non community-wiki answers of a minimum length are eligible