Skip to main content
40 votes

How to get product image and URL in Magento 2?

If you need to return a product URL it should look like this: //todo get product object $product $objectManager =\Magento\Framework\App\ObjectManager::getInstance(); $helperImport = $objectManager-&...
Shaoqing Ma's user avatar
35 votes
Accepted

How to get product image and URL in Magento 2?

This way may not the best way to get a product image. Inject \Magento\Catalog\Api\ProductRepositoryInterfaceFactory in the constructor. protected $_productRepositoryFactory; public function ...
Khoa TruongDinh's user avatar
30 votes
Accepted

How to disable an event observer defined by default in Magento2

If we take a look at: vendor/magento/framework/Event/Invoker/InvokerDefault.php public function dispatch(array $configuration, Observer $observer) { /** Check whether event observer is ...
Khoa TruongDinh's user avatar
27 votes

How to get product image and URL in Magento 2?

If you want the published/cache frontend URL of an image for a specific store view (like I did) this is working for me: /** * @var \Magento\Store\Model\App\Emulation */ protected $appEmulation; /**...
thaddeusmt's user avatar
  • 1,395
25 votes
Accepted

Difference between `sales_order_place_after` and `sales_order_save_after`?

sales_order_place_after This event is dispatched after the order payment is placed. This event function from Mage_Sales_Model_Order::place() in Magento 1 & \Magento\Sales\Model\Order::place() in ...
Abdul's user avatar
  • 9,711
21 votes
Accepted

Magento 2: Get Customer data after login with observer

Use customer_login event observer for customer login action 1) Create events.xml app/code/Vendor/Module/etc/events.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/...
Prince Patel's user avatar
  • 22.9k
19 votes
Accepted

How to override observers in Magento 2?

I got it working with the help of preference itself. Here is the code which might be helpful to someone di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-...
amitshree's user avatar
  • 7,076
18 votes
Accepted

Magento2: Cart events

Below Are the list of Events for cart : checkout_cart_add_product_complete checkout_cart_update_item_complete checkout_cart_product_add_after checkout_cart_update_items_before ...
Mak David's user avatar
  • 449
17 votes
Accepted

What's the best event/way to listen for all order state changes in Magento 2?

As far as I know, we can use events: sales_order_save_after and sales_order_state_change_before. I refer sales_order_save_after event. In our observer, we can get the state of order: Observer/...
Khoa TruongDinh's user avatar
17 votes
Accepted

How to get RefererUrl in magento 2 observer?

Make your observer class look like this: namespace Vendor\Module\Observer; class ClassNameHere implements \Magento\Framework\Event\ObserverInterface { protected $redirect; public function ...
Marius's user avatar
  • 198k
17 votes
Accepted

How to check if a module is enabled/disabled in Magento 2?

From Storev-Config-Developer-Advanced you only disable the output of a module and not the module itself. So the plugins the preferences and the event observers are still taken into consideration. If ...
Marius's user avatar
  • 198k
16 votes
Accepted

Magento2: How to get shipping method in order using observer `sales_order_save_after`?

You can get the shipping method by $order->getShippingMethod(); or $order->getShippingAddress()->getShippingMethod();
MeenakshiSundaram R's user avatar
15 votes
Accepted

Updating customer group from observer on customer_register_success event?

First create your configuration file in Vendor\Module\etc\frontend\events.xml : <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:...
Raphael at Digital Pianism's user avatar
15 votes
Accepted

What is the event that will fire after cancelling the order in Magento 2

The event you're looking for is order_cancel_after and it's dispatched in the cancel method of \Magento\Sales\Model\Order : public function cancel() { if ($this->canCancel()) { $this-&...
Raphael at Digital Pianism's user avatar
15 votes

How to check if a module is enabled/disabled in Magento 2?

You can check module status by below command: php bin/magento module:status You can see the list of enables modules.
shivashankar m's user avatar
14 votes

Magento 2: Add a mass action block item for a UI Component grid

Please note that since Magento 2.1.x, the XML has slightly changed. You now have to use <listingToolbar/> instead of <container/>: <listingToolbar name="listing_top"> <...
Giel Berkers's user avatar
  • 12.3k
14 votes

Which observer to use after success order on Magento 2?

You can try the event checkout_submit_all_after It runs after order is submited successfully (and in back-end when you created an order too) For example, in events.xml <config xmlns:xsi="...
NgocDB's user avatar
  • 706
14 votes
Accepted

Get post data, in Checkout success observer

protected $_request; public function __construct( \Magento\Framework\App\RequestInterface $request, \Psr\Log\LoggerInterface $logger, \Magento\Sales\Model\Order\Status\HistoryFactory $...
Rakesh Jesadiya's user avatar
13 votes
Accepted

Magento 2: How to get order data in observer on success page

checkout_onepage_controller_success_action give you order id's by using $observer->getEvent()->getOrderIds(). This does not given order object directly so, you are getting the error Then ...
Amit Bera's user avatar
  • 77.6k
13 votes
Accepted

how to save image custom attribute in magento 2

In your observer there is a lot of unnecessary code. You can change it like: <?php namespace Dcw\Vm\Observer; use Magento\Framework\Event\ObserverInterface; class ProductSaveAfter implements ...
Siarhey Uchukhlebau's user avatar
13 votes
Accepted

How to get order id using "sales_order_place_after" event

sales_order_place_after: This event is dispatched after the order payment is placed. $order = $observer->getEvent()->getOrder(); $incrementId = $order->getIncrementId(); ...
Pratik Oza's user avatar
  • 3,992
13 votes

sales_order_place_after not triggering in magento 2

sales_order_place_after is not proper,bcoz of it is not fire every time. sales_order_place_after naturally fires whenever call place() of Magento\Sales\Model\Order and it's call depend on payment ...
Amit Bera's user avatar
  • 77.6k
12 votes

Magento2: redirection from Observer

injecting the \Magento\Framework\App\ActionFlag $actionFlag and $this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);is the way of forcing Magento to stop ...
Zeeshan Khuwaja's user avatar
12 votes

How to disable an event observer defined by default in Magento2

Did some digging and seems its actually pretty easy to disable a certain event observer in Magento2. All we have to do, is create a custom module and add a events.xml file to the same area where the ...
Atish Goswami's user avatar
12 votes

Magento 2 : Event Observer For Payment Method Selection

Unfortunately, observers are useful only within php functions. This means that for an event to be triggered, it has to be initially dispatched dispatch() either by a native or custom event dispatcher. ...
ElGatito's user avatar
  • 890
11 votes
Accepted

Magento 2: Check condition on Click of "Proceed to Checkout"

You have to just use controller_action_predispatch_checkout_index_index action to check before checkout index page is load. <event name="controller_action_predispatch_checkout_index_index"> ...
Rakesh Jesadiya's user avatar
11 votes

Magento 2 - sales_order_place_after not returning Order ID

This is an old question but given I have just faced the same problem myself I thought I would give my take on the answer. sales_order_place_after is triggered before the order is saved to db so at the ...
Andrew Kett's user avatar
  • 3,518
11 votes
Accepted

How to check if cart is empty in observer Magento 2

You can also use the cart helper protected $cartHelper; public function __construct( \Magento\Checkout\Helper\Cart $cartHelper ) { $this->cartHelper = $cartHelper; }...
Nikolas's user avatar
  • 2,291
11 votes

Magento 2: How to implement First Order Discount?

Admin panel -> Marketing -> Cart Sales Rules. When you expand the “Conditions” tab, you’ll be able to set when a given discount applies. For example, you can select the cart value option and ...
Pramod Kharade's user avatar
10 votes
Accepted

Magento 2 : How to Update cart after cart update event (checkout_cart_update_items_after)

I ended up using plugin di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:...
Vishwas Bhatnagar's user avatar

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