I came across a persistent issue where the admin user is unable to save any configuration in the administration window and would only be greeted with the error below:

Invalid timezone error
Invalid timezone error showing in the System > Configuration window in Magento admin.

Upon investigation, I noticed that the method _beforeSave() is being called multiple times regardless if the field is for timezone or not as shown in the screenshot below:

Multiple fields being validated against the DateTimeZone::listIdentifiers($allWithBc) method.
Multiple fields being validated against the DateTimeZone::listIdentifiers($allWithBc) method.

The error occurs when the value of a non-timezone field is validated against the array result of the method DateTimeZone::listIdentifiers($allWithBc).

To fix this, duplicate the core file:

app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Locale/Timezone.php

into this path (create the directory if it doesn’t exists)

app/code/local/Mage/Adminhtml/Model/System/Config/Backend/Locale/Timezone.php

Locate the method _beforeSave() and add the code below at the beginning:

if($this->getField() !== 'timezone')
    return $this;

The content of the method _beforeSave() should be similar to the one below (note this is for Magento CE 1.7.0.2 so adjust accordingly with the code changes)

protected function _beforeSave()
{
    if($this->getField() !== 'timezone')
        return $this;

    $allWithBc = self::ALL_WITH_BC;
    if (defined('DateTimeZone::ALL_WITH_BC')) {
        $allWithBc = DateTimeZone::ALL_WITH_BC;
    }

    if (!in_array($this->getValue(), DateTimeZone::listIdentifiers($allWithBc))) {
        Mage::throwException(Mage::helper('adminhtml')->__('Invalid timezone'));
    }

    return $this;
}

After that, you should now be able to save your configuration changes in the admin.

About the author

Richard Feraro is a Magento Enterprise Certified developer from Manila, Philippines with 14 years of solid open-source development experience using Linux, Apache, MySQL & PHP.

By Richard Feraro

Richard Feraro is a Magento Enterprise Certified developer from Manila, Philippines with 14 years of solid open-source development experience using Linux, Apache, MySQL & PHP.

Leave a Reply