Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upgrading Magento 1.6.1 to 1.7.0 save custom module

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?

like image 351
Josua Marcel C Avatar asked Oct 01 '12 08:10

Josua Marcel C


3 Answers

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.

like image 149
MagePsycho Avatar answered Nov 11 '22 17:11

MagePsycho


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.

like image 25
Jim OHalloran Avatar answered Nov 11 '22 18:11

Jim OHalloran


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.

like image 2
Zachary Schuessler Avatar answered Nov 11 '22 19:11

Zachary Schuessler