6

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.

sv3n
11.7k7 gold badges44 silver badges75 bronze badges
asked Nov 22, 2016 at 14:57

2 Answers 2

6

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);
 }
}
answered Nov 22, 2016 at 15:23
3
  • 1
    Thanks for confirmation Raphael! But issue is I don't have control over Magento instances. I develop extension which is used across different users. And to be honest I'm not sure it's the best way to override this entire class by new class distributed with the extension ... Commented Nov 22, 2016 at 15:52
  • 1
    @JanPetr well this is a Magento bug unfortunately. Your only solution would be to change the backend_model and use a custom class that extends the original class and implements the change I gave in my answer Commented Nov 22, 2016 at 15:54
  • Yes, I'm thinking about doing it. Thanks again for the answer Commented Nov 22, 2016 at 15:56
1

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'));

answered Dec 6, 2016 at 0:44
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.