Questions tagged [event-observer]

Event/observer is used to work dynamically with Magento without altering the core code.

Filter by
Sorted by
Tagged with
94
votes
15answers
23k 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?
45
votes
2answers
5k 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 ...
33
votes
2answers
68k views

How to check whether user has logged in or not in magento?

I am doing mobile apps and I would like to know how to check whether user is already logged in or not. Is there any observer event to track? If it is detected that the account is logged in, the user ...
31
votes
4answers
16k 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 ...
28
votes
4answers
35k views

Confusion with order id, order increment id and I am not getting order id as 20001201

I am bit confused with order id and order increment id, So can any one help me to understand the difference between these two? I have an observer for sales_order_place_after where I store sales ...
27
votes
4answers
3k views

Returning $this after observer

I see some conflicting information on the internet and in 3rd party modules alike - is it a requirement or best practice to return $this at the end of an observer method? E.g.: ...
26
votes
2answers
6k 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 ...
24
votes
1answer
48k 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) { $...
19
votes
3answers
23k views

Redirect from Observer [duplicate]

I am creating a module that needs to do a check right before payment is made. If the check fails, it needs to forward the user to the cart with an error. I have an observer and have verified ...
18
votes
2answers
12k 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 ...
18
votes
3answers
11k 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 ...
16
votes
5answers
12k 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)
16
votes
1answer
9k views

Why are my SOAP v2 WS-I calls so slow (7-10 sec. per product update)?

We're using the Magento SOAP v2 API with WS-I. The problem is, that the SOAP calls are extremly slow (7-10 seconds per product!). We're calling catalogProductUpdate without images. The shop itself ...
15
votes
5answers
36k 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->...
15
votes
2answers
8k views

Magento failing when trying to save product inside event observer on frontend?

I have a function that is tied to an event observer One of the requirements is that when it loops through the order item data, if a certain product attribute is empty it issues a request to get ...
15
votes
2answers
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(...
15
votes
3answers
5k views

How to get events/observers in magento 2

In Magento 1 I can get list of events/observers by debugging dispatchEvent() method from Mage.php like below. /** * Dispatch event * * Calls all observer callbacks registered for this ...
14
votes
4answers
2k views

When to dispatch events in a custom module?

This is a question regarding both Magento 1 and Magento 2. I understand that, as a good practice, 3rd party modules developers are encouraged to dispatch events in their custom module to make it ...
14
votes
2answers
15k views

Changing the layout of the layered navigation

I have a layered navigation, and the customer wants to have <select/> fields instead of a long list of links. I thought about just changing the template with a observer if the name/id of the ...
13
votes
3answers
7k 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 ...
12
votes
2answers
2k views

Difference between `sales_order_place_after` and `sales_order_save_after`?

Magento 1 and Magento 2 both have the two event: sales_order_place_after sales_order_save_after. I have some confusion about them, what is the detailed differences between them? Which situation ...
12
votes
2answers
14k 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
2answers
2k 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 ...
11
votes
4answers
23k 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 ...
11
votes
2answers
827 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
3answers
11k 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 ...
11
votes
1answer
311 views

Is there an event or plugin spot for when cart rule is no longer valid?

Is there an event or place I can plugin for when a shopping cart price rule is no longer valid (such as when it expires or if you change the quantity of other products where it no longer applies)? I ...
10
votes
2answers
12k 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,...
10
votes
3answers
2k views

How can I alter a string passed by an event?

In my observer function, I get a variable passed by the event like that: public function observerFunc(Varien_Event_Observer $observer) { $sth = $observer->getEvent()->getSth(); } If sth is ...
10
votes
3answers
5k 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
1answer
829 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 ...
10
votes
2answers
1k views

Magento event to calculate price when custom option text field changes

I am trying to create a product with two custom text fields: Length and Width. When the user types in both a length and width, the price needs to calculate via custom formula. I'm trying to find the ...
9
votes
3answers
945 views

Does interception in magento2 replace observers in magento1?

Is interception intended to be the preferred method when dealing with changing the behavior of an original method in Magento2 as observers was in magento1? https://wiki.magento.com/display/MAGE2DOC/...
9
votes
4answers
2k 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; ...
9
votes
3answers
954 views

Magento 2: Which extension mechanism to choose?

We can extend controller in two ways: using preference and using plugin. But I do not understand that, which one is good and advantages/disadvantages of preference vs plugin. <preference for="...
9
votes
3answers
6k views

Determine if customer is new in customer_save_after

I have events that I wish to execute when a customer registers or saves their details. For this, I am using two events: customer_register_success and customer_save_after. The problem I am having is ...
9
votes
0answers
360 views

Magento 2: Observer add product to cart?

I've read some other post about adding products to cart, but nothing seems to fit. I've an observer for checkout_cart_update_items_before that adds another product in same qty if specific product is ...
8
votes
4answers
11k views

sales_order_save_commit_after event triggered twice?

I registered an observer for the sales_order_save_commit_after event to be notified when a new order comes in. This works fine but the event is triggered two times in a row with the same order. My ...
8
votes
4answers
8k 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. ...
8
votes
3answers
2k views

Magento 1: why some observer method call getEvent() and some don't?

Something I noticed recently and I'm curious about it. Example 1: the use of getEvent() In Mage_Core_Model_Locale in the setLocale() method, an event is dispatched: Mage::dispatchEvent('...
8
votes
3answers
12k views

Observing order state change

It seems there is no order state event by default, so how do you usually go about observing order state change? There are two possibilities I see: a) Overwrite the sales/order model to create your ...
8
votes
2answers
4k 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:...
8
votes
1answer
7k 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
2answers
16k views

Saving data to session using Magento observer function

Is it possible to store data in the Magento session or registry using the the observer function, with: Mage::getSingleton('core/session')->setFoo('bar'); //Or 'customer/session', 'admin/session' ...
8
votes
2answers
8k views

Difference between catalog_product_save_after and catalog_product_save_commit_after?

Can anyone explain the difference between these events. Just the quick and dirty please. Thank you. I have an Observer method like so: public function detectProductChanges($observer) { $...
8
votes
2answers
6k views

Modifying custom options of an item when adding it to the cart?

I am listening to the sales_quote_save_before event to notice when an item is added to the cart. Once its fired, I iterate through the items options like this: $quote = $observer->getEvent()->...
8
votes
1answer
2k views

How can I get Response getBody() in Observer event?

In Magento 1 I can do the following: $response = $observer->getEvent()->getControllerAction()->getResponse(); if(!$response) { return $this; } $html = $response->getBody(); How can ...
8
votes
2answers
3k views

review_save_after event observer is not running correctly

I am using Magento 1.8 version. I have written an observer that has to run when admin save a product review with status "Approved". And i have created a ratings attribute for every product with ...
8
votes
1answer
142 views

Observer for Abandonment of Cart

I need help!!! I am creating a module that integrates with another platform via API. I already got the Observer or Event for customer registration (customer_register_success), purchase completed (...
8
votes
2answers
4k views

Magento 2 : Catalog Product save after Observer Event

I have a custom multiselect field in Products edit section. The values in the multiselect values from my custom table. If I click on the save button in Manage Products section by selecting any one ...