How to detect changed fields only in admin section?
-
13-12-2019 - |
Question
I need to insert some values to custom database table based on the values of changed custom field, if the specific custom field value (in a custom shipping method) had changed.I need to check this in my Observer.php event that I'm firing is admin_system_config_changed_section_carriers
is there any possible way to do this ?
Solution
If this custom field comes from your own module, you can use a backend model to do additional things before save:
Add this to the field definition in system.xml
<backend_model>your_module/system_config_backend_custom</backend_model>
And write the model like this:
class Your_Module_Model_System_Config_Backend_Custom extends Mage_Core_Model_Config_Data
{
protected function _afterSave()
{
if ($this->isValueChanged()) {
// do your thing here
}
}
}
Actually this also works for existing modules without changing their code: you can override the backend model in your own system.xml
and make your module depend on the original one to make sure, yours is loaded afterwards.