We’re rewarding the question askers & reputations are being recalculated! Read more.

Questions tagged [event-observer]

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

Filter by
Sorted by
Tagged with
0
votes
1answer
16 views

Magento2.3 : Unit Case writing for Observers

I was wondering what is best practice for Unit test case writing for observers ? I looked for examples in core , and found below file magento/module-sales/Test/Unit/Observer/...
0
votes
0answers
13 views

how can I convert an attribute value of type date to php datetime object in Magento 1.9

I have created in the backend a product attribute called estimated_date and I would like to manipulate it in an observer for catalog_product_save_after. So from my catalog/product model I would like ...
0
votes
1answer
32 views

Custom Captcha not working in Magento2

I want to show captcha in Product Review Form, Followed the below link. Magento 2: How Captcha Module works? Created the module with relevant files and I am able to see the captcha in review form. ...
2
votes
1answer
41 views

How can I update customer custom attribute on order save?

I have an observer for the event when an order is placed by a customer. I tried "sales_model_service_quote_submit_before" I would like to take a value from the Order and save it to the customer. For ...
0
votes
2answers
100 views

Magento 2 - Adding custom layout handle for layouts (1 column, 2column etc) set via product admin page

I want separate layout handles defined for products dependent on their layout set via the layout options for product within admin (1 column, 2 column left, 2 column right). I need to set additional ...
0
votes
2answers
5k views

add product to cart and change price and weight

I need a module that when you add product to cart check two conditions and if they are correct will change the price for the product in the basket. I need do something like this: - when product is ...
6
votes
5answers
3k views

Magento 2: How to implement First Order Discount?

I am planning to give the discount to the customers for their first order purchase. After shipment selection, I want to show the discount in the order summary(discount is only for the first order). ...
8
votes
6answers
11k 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 ...
1
vote
2answers
637 views

Update custom attribute when product data updated through import

We import product data using a feed we get from a wholesaler - one full import a week that merges product data and a daily import that only updates price and stock data. I have created a custom ...
0
votes
3answers
53 views

Unable to redirect to cart page from observer?

Here is the code, please review and let advise. Demo/Test/etc/frontend/events.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:...
0
votes
1answer
11 views

Magento 2.2.2 custom observer attribute name not valid atomic type

I have a custom observer for admin admin_system_config_changed_section_{{$section_name}} the following are: events.xml: <?xml version="1.0" encoding="UTF-8"?> <config xmlns:xsi="http://www....
0
votes
2answers
40 views

Magento 2 observer is not triggering

We are going to use controller_action_layout_generate_blocks_before frontend event in M2. please note same event which is working on M1 but it is not working please review my below code and share ...
10
votes
3answers
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,...
1
vote
1answer
736 views

How to set cookie on salesQuoteSaveAfterObserver in magento2

In my custom module events.xml <event name="sales_quote_save_after"> <observer name="cedapi_set_checkout_quote_id" instance="Vender\Module\Observer\SalesQuoteSaveAfter" /> <...
2
votes
0answers
23 views

Magento2 - update to custom status after shipment creation

I created an Observer that makes some execution based on the company needs using event sales_order_shipment_save_after. It does everything I need except changing the order status to a specific. I ...
1
vote
1answer
703 views

Get order id after Paypal Express Checkout

I want an order Id (not Increment Id) and quote after redirecting back from PayPal to my store. For this purpose I am using sales_order_place_after event. But this event does not return order Id ...
2
votes
1answer
685 views

Message in postdispatch

Can't make messages to appear on frontend. I have an observer on event: <event name="controller_action_postdispatch_cms"> <observer name="some_module_controller_action_postdispatch" ...
0
votes
1answer
38 views

How to print field in order email?

I want print a custom file in order transactional emails. Here is my Setup file: namespace xxx\xxxx\Setup; $quote = $setup->getTable('quote'); $salesOrder = $setup->getTable('...
0
votes
1answer
987 views

Magento 2 - Prevent form submit on page reload when Product add from sample script to Magento Shopping Cart

Below sample PHP script will list simple/configurable product with add to cart button. When user clicks on submit button, it will redirect to Magento shopping cart page and selected product will be ...
2
votes
5answers
2k views

How to get customer custom attribute value in observer in magento 2.2.X?

I have created a customer custom attribute like(gst_no). In my Observer where I get my customer data I want to get the value of this attribute too. $order = $observer->getEvent()->getOrder(); ...
0
votes
1answer
792 views

how to get customer group id from last order id in magento 2

I want to change customer group after placing an order so I need Customer Group id which can be update in observer . How to achieve it?
0
votes
2answers
28 views

Magento2 : checkout_cart_product_add_after Event not working with API

I have created an observer on event "checkout_cart_product_add_after" and its working fine for web but not working with REST API.
0
votes
2answers
808 views

Mage registry key Already Exist Magento 1.9.2.1

I have used the Observer event in my Custom module, but when i load the added event, it is showing below error message, Mage Registry key "Observer" already exists. I have checked the Compiler Mode, ...
0
votes
0answers
14 views

How to get Giftcard Code programmatically in Magento 2 EE?

How to create Gift Card Account programmatically, as I need to get coupon code using API. I am looking if it is possible to trigger built in observer programmatically in Model class e.g <event ...
2
votes
1answer
786 views

Magento2, Customized quote subtotal in cart page

Through observing the event checkout_cart_product_add_after, I was able to customize the price of the item in the cart, now I need to have an observer for customizing its subtotal calculation. What ...
1
vote
1answer
963 views

Magento 2.1-rc1 How to customize Topmenu Html Markup

Like in Magento1, the Topmenu html structure is still pretty hardcoded. To change the html markup of the submenus in 2.0, I added a plugin which altered the getHtml Method of Magento\Theme\Block\Html\...
0
votes
2answers
27 views

Magento 2 Observer class print event data

I want to preview all the details inside the object such as Order, Customers after saving the event. I tired below way but it not printing the object inside attributes.... Customer Object Magento\...
0
votes
2answers
800 views

checkout_cart_update_items_after is not working

I'm stuck in this. The checkout_cart_update_items_after is not firing. I already put a log statement in the function but is not getting executed. Whereas checkout_cart_product_add_after is working ...
0
votes
0answers
19 views

Magento2 - Listen for order new comments

I am trying to create some kind of observer that will listen for new order comments and execute the function every time a comment is added. I tried three ways that did not work for me: Observer ...
0
votes
2answers
851 views

Accessing data in catalog_product_save_before observer

I created an catalog_product_save_before observer to update some attributes based on other attributes. Specifically, I use m2epro to update my ebay listings. Sometimes I want ebay to show less in ...
1
vote
1answer
917 views

Get current store name in observer method

I have created Two stores under two websites in my Magento installation I have tried following code in my observer method, $store = Mage::app()->getStore(); $name = $store->getName();...
2
votes
1answer
30 views

Magento 2.3 - limit certain categories products

We have a few categories which function like "bestsellers" categories; these categories can hold any number of products, but I'd like to show only the top four. So I figured to create an observer ...
0
votes
0answers
21 views

How can I get the customer increment ID in an observer in Magento2 if using the human friendly ID

I am trying to get a magento customer increment ID. I'm thinking I have to use the resource-model class just not sure what the best way to access it is or how to get it. public function __construct( ...
1
vote
1answer
1k views

Magento 2 direct sql query for insert not working

I was trying to insert values into mlx_cot_custom_option_type_value because module files are encrypted.I want to add something after product save i am using catalog_product_save_after event Here is ...
0
votes
2answers
393 views

how to trigger observer by rest api

I need to trigger observer whenever I call specific rest api I've created module/Observer/ObserverClass, module/etc/events.xml and module/etc/webapi-rest/events.xml but I don't know How to trigger it ...
0
votes
2answers
33 views

Cannot redirect to a specific page using Observer events such as sales_order_place_before, and checkout_submit_before in Magento 2.3

I am currently implementing a behavior where I will check the quote items in cart, then check if it contains my custom attributes. If true, then it will redirect me to a specific page(CMS) page. This ...
1
vote
1answer
795 views

using event after catalog collection load doesn't get the count right

I'm trying to modify items in a collection on page load (catalog) and using the event: catalog_product_collection_load_after and the code for the event is : $observer->getCollection() ...
0
votes
2answers
36 views

Magento 1.9 - What is wrong in my Event Observer?

I just want to display my event name : app\etc\modules\Gta_RestrictProductByCountry.xml <?xml version="1.0"?> <config> <modules> <Gta_RestrictProductByCountry&...
1
vote
1answer
836 views

How to update the layout file in observer

public function CodeOrdeStatus(Varien_Event_Observer $observer) { $order = $observer->getEvent()->getPayment()->getOrder(); $order=Mage::getModel('sales/...
1
vote
1answer
604 views

How to send mail when get events in observer?

I create adminhtml/events.xml and frontend/events.html with code content: <?xml version="1.0" encoding="UTF-8"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:...
1
vote
1answer
24 views

Magento 2: Get names of all people who ordered the product

Our client would like to have names of all people who ordered a product included into the Out of Stock notification email. I seem to have issue with getting such info ... Code I have to get the ...
1
vote
0answers
46 views

Help - Magento 1.9 - How to do Observer should be trigger before place an order?

After calculated grand total in checkout page observer not trigger, Observer : app\etc\modules\Gta_RestrictProductByCountry.xml <?xml version="1.0"?> <config> <modules> ...
0
votes
1answer
620 views

How to call an observer from custom module: Magento 2

I built a custom module which has a custom observer OrderSaveAfter.php. How can I call any function inside the custom observer from another custom code ?
1
vote
1answer
786 views

sales_order_place_after not firing for admin-created orders

I have a simple custom module that sends a separate email to an admin user once an order has been placed (email uses a different template). This email is supposed to work for orders placed from the ...
0
votes
1answer
787 views

Admin order update price programmatically in quote loop

I have a bit of custom pricing that needs to be carried out for each product in an order which alters the end price of the item. I am using an observer with the sales_quote_item_qty_set_after event ...
1
vote
2answers
45 views

How to put log in observer Magento 2 [duplicate]

I am trying to put log in observer sales_order_save_after Whenever I put logger in the execute I can’t do any checkout it complains about guest checkout payment Is there any other way I could see ...
0
votes
0answers
17 views

Observer on item removed

I need to trigger this event but just before the item is removed : sales_quote_remove_item But for now, the event is trigger after I want to do this : when the user is tryinng to remove the ...
3
votes
1answer
885 views

Programatically set product attribute defaults - Magento 2

My specific use case is that I want to set the news_from_date and news_to_date for the a thirty day period from when the product is created. I would like this to work so when a user goes into the ...
2
votes
1answer
22 views

Event not fired when Full Page Cache is enabled in Magento 2

I am trying to run a piece of code on every page load. I have the following <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/...
0
votes
1answer
16 views

Magento2 after comment added observer

I need an observer to be executed when I add a new comment to an order. On Magento 1.9 I used sales_order_save_after event but it does not exist on M2 anymore. Anyone can help me with an event to do ...