0

Hi today i'm working on system.xml file. it's not saving correctly.

system.xml

<custom_field translate="label">
     <label>Add Class and it's Params</label>
     <frontend_model>hello/adminhtml_form_field_addclass</frontend_model>
     <backend_model>hello/system_config_backend_addclass</backend_model>
     <sort_order>6</sort_order>
     <show_in_default>1</show_in_default>
     <show_in_website>0</show_in_website>
     <show_in_store>0</show_in_store>
</custom_field>

Test\Block\Adminhtml\Form\Field\AddClass.php

<?php

class Test_Hello_Block_Adminhtml_Form_Field_AddClass extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract
{

    protected function _prepareToRender()
    {
        $this->addColumn('add_param', array(
            'label' => Mage::helper('hello')->__('Add Parameter'),
        ));
        $this->addColumn('add_param_class', array(
            'label' => Mage::helper('hello')->__('Add Parameter Class'),
            'style' => 'width:100px',
        ));
        $this->addColumn('add_param_class_field', array(
            'label' => Mage::helper('hello')->__('Add Parameter Class Fields'),
            'style' => 'width:100px',
        ));
        $this->_addAfter = false;
        $this->_addButtonLabel = Mage::helper('hello')->__('Add Class');
    }

}

Test\Model\System\Config\Backend\AddClass.php

<?php


/**
 * Backend for serialized array data
 *
 */
class Test_Hello_Model_System_Config_Backend_AddClass extends Mage_Core_Model_Config_Data
{
    /**
     * Process data after load
     */
    protected function _afterLoad()
    {
        $value = $this->getValue();
        Mage::log($value,null,'AddClass');
        //$this->setValue($value);
    }

    /**
     * Prepare data before save
     */
    protected function _beforeSave()
    {
        $value = $this->getValue();
        //$this->setValue($value);
        Mage::log($value,null,'AddClass');

    }
}

it's saving core_config_data table like below formate.

path = customtab/custom_attributes/custom_field

value = Array,Array,Array,

Logs are created like below formate

2015-08-10T10:42:55+00:00 DEBUG (7): Array,
2015-08-10T10:58:26+00:00 DEBUG (7): Array
(
    [_1439204268814_814] => Array
        (
            [add_param] => acceptNewClass
            [add_param_class] => AcceptNewClassFields
            [add_param_class_field] => ID,PrimariContact
        )

    [_1439204284271_271] => Array
        (
            [add_param] => TokenID
            [add_param_class] => 
            [add_param_class_field] => 
        )

    [_1439204298185_185] => Array
        (
            [add_param] => memberID
            [add_param_class] => 
            [add_param_class_field] => 
        )

    [__empty] => 
)

how to save & retrieve this?

Any help on this

Thanks.

  • What are you trying to save? Is it just a text field? – rob3000 Aug 10 '15 at 11:42
  • @rob3000, No it's not a text field, i'm not specifying it's type. I'm trying to save just like AddException Field from System->Configuration->Design – M_N Aug 10 '15 at 11:46
2

Make your backend model look like this:

class Test_Hello_Model_System_Config_Backend_AddClass extends Mage_Core_Model_Config_Data
{
    /**
     * Process data after load
     */
    protected function _afterLoad()
    {
        $value = $this->getValue();
        $this->setValue(unserialize($value));
        Mage::log($value,null,'AddClass');
        //$this->setValue($value);
    }

    /**
     * Prepare data before save
     */
    protected function _beforeSave()
    {
        $value = $this->getValue();
        $this->setValue(serialize($value));
        Mage::log($value,null,'AddClass');

    }
}
  • Yes it's saving a:4:{s:17:"_1439207304052_52";a:3:{s:9:"add_param";s:25:"acceptNewClass";s:15:"add_param_class";s:17:"AcceptNewClassFields";s:21:"add_param_class_field";s:6:"MID,PC";}s:17:"_1439207315045_45";a:3:{s:9:"add_param";s:19:"TokenID";s:15:"add_param_class";s:0:"";s:21:"add_param_class_field";s:0:"";}s:18:"_1439207317859_859";a:3:{s:9:"add_param";s:9:"memberIDP";s:15:"add_param_class";s:0:"";s:21:"add_param_class_field";s:0:"";}s:7:"__empty";s:0:"";} it's not user friendly to retrieve values. How Can I retrieve Array Values? – M_N Aug 10 '15 at 11:57
  • just unserialize the values before using them. – Marius Aug 10 '15 at 12:00
  • @M_N You have to unserialize the value. unserialize($yourValue) – MeenakshiSundaram R Aug 10 '15 at 12:00
1

Change your backend_model as

<backend_model>adminhtml/system_config_backend_serialized_array</backend_model>

So now the field value will be saved as serialized format.

And while get the value you need to unserialize the value

$myvals = unserialize(Mage::getStoreConfig('myvals'));

Refer this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.