4
votes

When I upgraded Magento, the AheadWorks module was disabled.

When saving on admin, System -> Configuration -> Advanced -> then click Save Config

An error occurred while saving this configuration: Notice: Trying to get property of non-object in MAGENTO_ROOT/app/code/core/Mage/Adminhtml/Model/Config/Data.php on line 135

I've been searching in many times to find the solution but i got nothing.

http://www.magentocommerce.com/bug-tracking/issue/?issue=13819

How to fix that?

3

3 Answers

13
votes

Find the following lines of code around line 135 of app/code/core/Mage/Adminhtml/Model/Config/Data.php:

$backendClass = $fieldConfig->backend_model;
if (!$backendClass) {
    $backendClass = 'core/config_data';
}

and replace it by:

if (isset($fieldConfig->backend_model)) {
    $backendClass = $fieldConfig->backend_model;
}
if (!isset($backendClass)) {
    $backendClass = 'core/config_data';
}

Hope this helps.

5
votes

MagePsyco is correct, the issue is with the code at line 135 of app/code/core/Mage/Adminhtml/Model/Config/Data.php:

$backendClass = $fieldConfig->backend_model;
if (!$backendClass) {
    $backendClass = 'core/config_data';
}

The issue with the fix MagePsyco suggests in his answer is that the code is executed in a loop. Once it encounters an attribute with a backend model the $backlendModel variable isn't reset back to core/config_data again. So for example on the System page of the System Configuration screen the "Installed Currencies" attribute has a backend model defined, but subsequent attributes don't. This causes the _afterSave method from Mage_Adminhtml_Model_System_Config_Backend_Locale to be run on all of the subsequent attributes (which will fail).

A better solution is the version of this code that can be found in 1.8 alpha releases:

$backendClass = (isset($fieldConfig->backend_model))? $fieldConfig->backend_model : false;
if (!$backendClass) {
    $backendClass = 'core/config_data';
}

This takes care of all null/false/empty issues and ensures the $backendModel variable always contains a valid value. This also suggests that the issue should be resolved and no patching is required once 1.8 is released.

2
votes

You can also turn off Magento's developer mode. I'm not a big fan of modifying the core (or having to extend it), so for the lazy, just disabling/enabling MAGE_IS_DEVELOPER_MODE as needed is the easiest solution until it's fixed.