Domanda

I have an extension which adds panel to System > Configuration, but suddenly in 1.9.3 it ignores default values for settings with <backend_model>adminhtml/system_config_backend_serialized_array</backend_model>. So after installing the module settings are empty instead of having default data configured.

I have setting defined in system.xml file like:

<setting_name>
    <label>My label</label>
    <frontend_model>my/frontend_model</frontend_model>
    <backend_model>adminhtml/system_config_backend_serialized_array</backend_model>
    <sort_order>10</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>1</show_in_website>
    <show_in_store>1</show_in_store>
    <comment><![CDATA[...]]></comment>
</setting_name>

And in config.xml file I have defined default values:

<correct_group_name>
    <setting_name>a:1:{s:18:"_1450089283397_397";a:3:{s:4:"name";s:5:"pages";s:5:"label";s:5:"Pages";s:11:"hitsPerPage";s:1:"2";}}</setting_name>
</correct_group_name>

It works in all versions >= 1.6.2 and <=1.9.2.1. Did something changed in 1.9.3? I'm not able to find anything in relase notes.

Version 1.9.2.1: enter image description here

Version 1.9.3.1: enter image description here

Thanks for any help or suggestions.

P.S. All other settings' default values (like text inputs, select boxes, ...) work correctly.

È stato utile?

Soluzione

After some tests I can confirm this is a bug introduced by Magento 1.9.3.0 (see here: https://github.com/OpenMage/magento-mirror/commit/d48bebc211cc216aaf78bdf25d7f0b0143d6333b#diff-139e884940505308d9c796f5e3a78865 )

Side note: this also affects SUPEE-8788

As a temporary fix, here is what I suggest: copy app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Serialized.php to app/code/local/Mage/Adminhtml/Model/System/Config/Backend/Serialized.php and modify the _afterLoad() method like this:

protected function _afterLoad()
{
    if (!is_array($this->getValue())) {
        $serializedValue = $this->getValue();
        $unserializedValue = false;
        if (!empty($serializedValue)) {
            try {
                $unserializedValue = Mage::helper('core/unserializeArray')
                    ->unserialize((string)$serializedValue);
            } catch (Exception $e) {
                Mage::logException($e);
            }
        }
        $this->setValue($unserializedValue);
    }
}

Altri suggerimenti

Another option lays within your defined <frontend_model> by providing the data there, in case it's not set - At least it prevents providing another separate model.

class StackExchange_Workaround_Block_Adminhtml_Receptiontimes extends Mage_Adminhtml_Block_System_Config_Form_Field
{
    protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
    {   
        $this->setElement($element);

        // Workaround for Magento bug within 1.9.3.x
        // [Default configuration value for serialized_array settings is ignored](http://magento.stackexchange.com/questions/146978)
        if (!$this->getElement()->getData('value')) {
            $this->getElement()->setData('value', Mage::helper('workaround')->getArrayData());
        }

Where getArrayData() is just a helper you likely also use elsewhere to fetch that data and returns unserialize(Mage::getStoreConfig('workaround/arraydata'));

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange
scroll top