Viewing Magento model data changes on before/after save event?

Viewing Magento model data changes on before/after save event?

July 26, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Viewing Magento model data changes on before/after save event?

Viewing Magento Model Data Changes on Before/After Save Event

When working with the Magento e-commerce platform, it’s often necessary to observe or process changes made to model data before or after the save event. You might want to log changes, send notifications, or integrate third-party services based on these modifications.

The Simplest Approach: Hook and Compare Data

The straightforward way is as follows:

  1. Attach a MODEL_save_after event (or MODEL_save_before, depending on your needs). This can be done using Magento’s event observer system.

  2. Utilize the getData() method to obtain the current state of the model, and compare it with the getOrigData() method which contains the original data before any changes were made.

public function onSaveAfter(Varien_Event_Observer $observer)
{
    $model = $observer->getModel();
    $data = $model->getData();
    $origData = $model->getOrigData();

    // Compare $data and $origData to see what changed
}

The Problem with the customer_address Model

Let’s consider the customer_address model as an example. When editing an address through the backend in Magento v1.3.2.4, both save events (customer_address_save_before and customer_address_save_after) are triggered twice.

First Trigger: Before Entering User Data

In the first trigger of each event:

  • getOrigData() and getData() are nearly identical.
  • The exception is that getOriginData() lacks a new updated_at value and does not have a store_id set. This seems like a potential bug in Magento’s core.

Since these events occur before the user data enters or is validated, they provide limited use for comparing changes made by the user.

Second Trigger: After Validation and Saving

Both events are triggered again. In this second set:

  • getOrigData() is empty.
  • getData() now contains all the submitted data from the user.

This happens after validation and saving have already occurred, which means you can’t compare the before and after states to see what exactly changed during the editing process.

Why Does the Save Process Occur Twice?

The exact reason for this double-saving behavior in Magento v1.3.2.4 is not clear without further investigation into the core codebase. However, it appears to be a quirk of how Magento handles saving operations in its internal processes.

Conclusion and Recommendations

In summary, while the theoretical approach of hooking save events and comparing data works for many models, the customer_address model in version 1.3.2.4 presents an unusual scenario where this method fails to provide the expected results due to the double-saving behavior and inconsistent data formats.

For most other models, the standard event observer technique should serve you well:

  • Attach a save event (before or after, as needed).
  • Compare getData() with getOrigData().
  • Process changes as required in your business logic.

Remember that Magento is a complex system with many internal processes running concurrently. Always be prepared for edge cases and quirks like this one.

For more insights into Magento development best practices and advanced techniques, check out our in-depth guides at Laravel Company.

Extensions Admin Customers Errors

Our network