AD0-E724 · Question #41
A developer needs to run a piece of custom logic, such as sending a notification to an external system, every time a customer successfully places an order. The custom logic does not need to modify the
The correct answer is B. An observer for the 'checkout_onepage_controller_success_action' or 'sales_order_place_after'. Option B is correct because Adobe Commerce's event/observer system is purpose-built for reacting to system events without modifying core behavior - sales_order_place_after fires immediately after an order is saved, and checkout_onepage_controller_success_action fires after the su
Question
A developer needs to run a piece of custom logic, such as sending a notification to an external system, every time a customer successfully places an order. The custom logic does not need to modify the order object itself. What is the most appropriate and conventional Adobe Commerce component to use for this task?
Options
- AA preference for the '\Magento\Sales\Model\Order' class.
- BAn observer for the 'checkout_onepage_controller_success_action' or 'sales_order_place_after'
- CAn "around" plugin on the '\Magento\Quote\Model\QuoteManagement::placeOrder' method.
- DA cron job that checks for new orders every minute.
How the community answered
(66 responses)- A5% (3)
- B82% (54)
- C3% (2)
- D11% (7)
Explanation
Option B is correct because Adobe Commerce's event/observer system is purpose-built for reacting to system events without modifying core behavior - sales_order_place_after fires immediately after an order is saved, and checkout_onepage_controller_success_action fires after the success page loads, making either a clean, decoupled hook for triggering external notifications.
Why the distractors fail:
- A (Preference) replaces a class entirely, which is overkill and breaks extensibility - preferences are for changing how a class behaves, not for side effects.
- C (Around plugin) intercepts a method call and requires you to call
$proceed()to let the original logic run; it's intended to modify input/output, not to trigger fire-and-forget side effects, and introduces unnecessary coupling to the method signature. - D (Cron job) introduces latency (up to 60 seconds), added database polling overhead, and complexity - it's the wrong tool when a real-time event hook is available.
Memory tip: Think of it as "observe, don't obstruct" - when your logic is a reaction (not a modification), an observer is always the right choice. Plugins modify; preferences replace; observers react.
Topics
Community Discussion
No community discussion yet for this question.