Questions tagged [event-observer]
Event/observer is used to work dynamically with Magento without altering the core code.
275
questions
26
votes
1
answer
53k
views
How to create an new observer on the event catalog_product_save_before
I want auto generation of meta description for my products by create an new observer on the event catalog_product_save_before with this code :
public function autoMetaDescription($observer) {
$...
96
votes
15
answers
24k
views
Where can I find a complete list of Magento events?
I know that Magento has a hook-like system called events. Does anyone have a complete list or a script which can be used to determine which events can be called?
14
votes
3
answers
21k
views
Magento2 - How to stop a product from getting added to cart programmatically?
What I want to do is if my custom attribute is set in quote then i do not want any product to be added in cart. My custom attribute is being set correctly.
To stop product from getting added to cart,...
18
votes
3
answers
12k
views
Creating Custom Option on Product Save
I'm working on creating a custom option for my products automatically any time a product is created. What I've got so far is an observer that fires on the catalog_product_save_before event and runs ...
9
votes
1
answer
19k
views
What's the best event/way to listen for all order state changes in Magento 2?
I want to observe every order state change and react depending on the old and new status. What is the best way to accomplish this in Magento 2?
It looks like there is the event ...
9
votes
4
answers
4k
views
Magento Observer Events - order of operations
I am attempting to inject functionality into the catalog_model_product_duplicate event. Part of this module will be to ensure that the stock status of the duplicated product is also duplicated; ...
30
votes
3
answers
14k
views
Magento 2: Plugin vs Observer
In Magento 2, what are the pros and cons of using a plugin vs an observer to achieve something?
I understand that observers are subscribed to events whereas plugins can jump in before and/or after a ...
19
votes
2
answers
14k
views
Detect inventory change
I need to detect whenever the inventory level of a product changes. I've had some success using the cataloginventory_stock_item_save_after event which is triggered when inventory is changed in the ...
12
votes
9
answers
28k
views
Magento2: redirection from Observer
We have already know that How to redirect from an Observer for magento 1.x version.
but for magento 2,we does not know How to forcefully do redirection from an observer.
I have done google ,but does ...
6
votes
2
answers
17k
views
How to bind an action after customer login success using Magento?
I'm using Magento 1.4.1.1. After logout success, customer is rooted to "logout.phtml" first and "home page" later.
Is there anyway I could make Magento run couple of "php" codes after "login" ...
0
votes
2
answers
318
views
Observer Mage::throwException error - status 503 error
I just want to restrict some of the category of products to purchase with other category products,
Workout :
If customer click add to cart using observer compare current add-to-cart product ...
15
votes
2
answers
11k
views
Creating Custom option and prize to just added product to cart using observer
I want to add custom option to quoteitem using observer which observer checkoutCartProductAddAfter event and fires after product added to cart.
public function checkoutCartProductAddAfter(...
0
votes
2
answers
132
views
Restrict products to purchase using Observer not trigger
Condition: I have restricted category of products [category id = 680, 894, 895], this category of products should be purchase alone, not mixed with other products.
Workout:
Case 1: If cart had other ...
32
votes
4
answers
20k
views
Modify tax rate on cart quote items and recalculate
I have a category of products which (legally) need to have their tax rate changed when you are ordering more than a certain quantity. I have extended the various tax models to get this working when ...
8
votes
1
answer
5k
views
magento 2 event cataloginventory_stock_item_save_after
I need to detect whenever the inventory level of a product changes.
As there is cataloginventory_stock_item_save_after in magento 1.x
wanto to implemet same in magento 2.1
<event name="...
8
votes
4
answers
10k
views
How prevent a model data save using _save_before event
I have create a model which has its own database table. For a customization I need to trigger save_before event of this model.
If one field value is not matched, then the data should not be saved.
...
7
votes
3
answers
23k
views
Magento 2: Get Customer data after login with observer
I need to detect in frontend section for my custom module if customer has just successfully logged in, and i need to run some function before it redirect to another page, is there any way to do this?
2
votes
1
answer
11k
views
Magento 2 - sales_order_shipment_save_after
I need to call some API on ship item from magento but nothing is working.
Following things I already tried:
1) Use event/observer: sales_order_shipment_save_after (As I thought It will work in ...
1
vote
1
answer
934
views
Product edit form issue in admin panel magento2
Here is my etc/adminhtml/events.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events....
48
votes
2
answers
6k
views
Magento Event Observers: Singleton versus Model
So Magento offers 2 ways of declaring an observer. Singleton and Model (new instance) by specifying the <type> tag in Magento 1.x and by specifying the shared attribute in Magento 2.
Magento 1 ...
25
votes
12
answers
122k
views
How to get product image and URL in Magento 2?
This is my observer:
public function execute(\Magento\Framework\Event\Observer $observer)
{
$orderIds = $observer->getEvent()->getOrderIds();
$order = $this->...
16
votes
5
answers
17k
views
Magento 2 events list
Is there any complete list of events in Magento 2?
I'm looking for something like Magento Events Cheat Sheet (1.9)
15
votes
2
answers
4k
views
how to save image custom attribute in magento 2
I need to display few images of product in frontend based on condition: use for virtual mirror should be checked.
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for ...
14
votes
4
answers
13k
views
Magento 2 : Event Observer For Payment Method Selection
I am working on a custom extension where I need to call an observer when any payment method is select from the available payment method list on the frontend checkout page.
Can anyone tell me which ...
11
votes
4
answers
24k
views
Watching Add to Cart Event - quote item id is empty
I am trying to catch the event that fires once an item is added to the cart. I'm currently watching the following event: checkout_cart_product_add_after
According to magento source this event is ...
10
votes
2
answers
11k
views
what is the event in magento 2 when store configuration save?
what is the event that is triggered after the save config action is performed in magento 2 Stores - Configuration, and how to write a simple observer method after the save is done.
3
votes
1
answer
830
views
observer getting called more than once
i wrote below observer to add extra price to product price based on get paramter id of product
<catalog_product_load_after>
<observers>
<setcustomprice>
...
2
votes
4
answers
8k
views
customer_register_success not triggered after successful registration
I would like to send an sms on every successful registration. Below is my code. But I am not sure whether the method is triggered after successful registration.
app\etc\modules\Php_Sms.xml
<?...
1
vote
0
answers
1k
views
Magento 2: Admin price changes are not refreshing minicart immediately till checkout
I have added 1 product with it's price in Cart. It's value is 100 USD.
Now from backend I'm enabling Special Price & set it to 50 USD.
How can I directly apply that price in Cart? I know we can ...
14
votes
4
answers
28k
views
Which observer to use after success order on Magento 2?
I am working on this Magento 2 extension and part of the features is to push information about the orders to an external application using web services. I need to push this information after an order ...
10
votes
3
answers
7k
views
Event/Observer for customer password change?
I'm looking for a way to hook into the event of customers changing their passwords. So if someone changes the password in the customer frontend, I'd like to send an e-mail somewhere.
I did consult ...
10
votes
3
answers
15k
views
How to override observers in Magento 2?
I was trying to override execute function of Magento\CatalogUrlRewrite\Observer\ProductProcessUrlRewriteSavingObserver using preference in di.xml
<preference for="Magento\CatalogUrlRewrite\...
9
votes
3
answers
8k
views
Magento 2 - sales_order_place_after not returning Order ID
I have created an event for sales_order_place_after event.
This doesn't return Order Id. However, it returns Increment ID
public function execute(Observer $observer)
{
$order = $...
6
votes
2
answers
1k
views
How to exclude products being added to cart based on products attributes?
How can i set a condition, if pre-ordered products are purchased, no other products can be added to cart?
How can I set a condition like, if some of the "non-pre-order" products
is in the cart, ...
6
votes
2
answers
8k
views
What is the event that will fire after cancelling the order in Magento 2
I am trying to do something customization from my custom module after an order has been cancelled (Frontend as well Backend). For this I have gone through cancelled Observer on the sales/etc/events....
4
votes
2
answers
5k
views
Magento 2: Add a mass action block item for a UI Component grid
I am trying to add a mass action item to the product grid mass action block using an observer.
Here is what I am doing but it does not seem to be working, I feel like I am missing something
app/code/...
2
votes
1
answer
6k
views
How do i get active filters in observer method?
i want to check the currently applied layered navigation filters using an observer. When specific filter values are selected an additional layout handle should be added which adds a static block to ...
1
vote
2
answers
16k
views
Add to cart after event in magento2
I have created add to cart before the event it's working fine. But I want to the observer after add to cart please tell me how to do it.
<?xml version="1.0"?>
<config xmlns:xsi="http://www....
1
vote
1
answer
1k
views
Adding extra fields to newsletter_subscriber table not work
I try to add a type(extra field) to newsletter_subscriber table.
Following is my approach to add the field.
1.Add new column to newsletter_subscriber table(types)
2.Add types check box to subscribe....
1
vote
2
answers
10k
views
Return error message from observer Magento
I made a custom module for observer on customer save before event for admin-side
My config file in local/Pavans/Profile/etc
<adminhtml>
<events>
<...
1
vote
2
answers
12k
views
Magento 2 : How to Update cart after cart update event (checkout_cart_update_items_after)
I am trying tho again update cart after update cart action(when cart qty is updated from cart page Or from miniCart) and change the qty if some cases
$mappedProductSkus= $this->_helperData->...
1
vote
1
answer
3k
views
Magento2 - dispatched event for create shipment
I'm looking for similar event like sales_order_shipment_save_after and sales_order_shipment_save_before in Magento1.
Oh I am using Magento 2.1.3.
I tried
<?xml version="1.0"?>
<config ...
0
votes
2
answers
4k
views
Magento event for adding order comment
Can anyone please let me know if there is any magento event available for adding comment to a particular order?
Let me know if question is not clear.
12
votes
2
answers
15k
views
How can i get customer data from observer after successful login?
I have made a custom module in which I have an observer file. I need to display all information about the logged in user.
12
votes
2
answers
1k
views
What's the last event dispatched before content is sent to the browser?
I need to set or update a cookie, but I want to ensure that all (or as much as possible) of the request processing occurs before my cookie generation code runs. i.e. if the user logs in, I want to ...
11
votes
1
answer
2k
views
Remove observer from third party extension
I have installed a blog module onto my Magento 2 platform. This blog module has an observer which automatically adds a new menu item into the primary navigation. I wish to stop this.
The events.xml ...
9
votes
7
answers
12k
views
How to get order id using "sales_order_place_after" event
I have an event Observer for sales_order_place_after
namespace Company\Ordertool\Observer;
use Magento\Framework\Event\ObserverInterface;
class OrderComplete implements ObserverInterface
{
/**
...
8
votes
1
answer
8k
views
Add block to layout dynamically in event observer
I want to know how to use layout.xml with event observer.
I want to show a message in footer when payment made successfully.
I know I have to use the event ...
8
votes
3
answers
3k
views
Unregister event observer programatically
Does anyone know if it's possible to unregister an event observer programatically? I have an observer on newsletter_subscribe_save_after that updates a custom attribute in the customer model but when ...
8
votes
4
answers
10k
views
Magento 2 : Event Observer Exception Not Showing in Screen
In custom extension, I create observer like this.
app\code\Vendor\Extension\etc\frontend\events.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:...