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-&...
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 ...
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 ...
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;
/**...
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 ...
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/...
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-...
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
...
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/...
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 ...
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 ...
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();
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:...
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-&...
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.
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">
<...
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="...
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 $...
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 ...
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 ...
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();
...
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 ...
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 ...
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 ...
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. ...
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">
...
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 ...
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;
}...
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 ...
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:...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
event-observer × 2159magento2 × 828
magento-1.9 × 472
module × 121
magento-1 × 120
orders × 109
checkout × 100
product × 96
cart × 94
sales-order × 91
customer × 86
magento-1.7 × 82
magento-1.8 × 72
php × 64
magento-2.1 × 63
plugin × 61
magento2.3 × 59
quote × 57
addtocart × 55
layout × 47
redirect × 46
adminhtml × 43
admin × 41
price × 40
product-attribute × 36