0

Recently I worked on advance system config form field in Magento 2. I checked Braintree payment method for reference.

When I saved a value, it showing following error:

Something went wrong while saving this configuration: Notice: Array to string conversion in
E:\wamp\www\magento2\app\code\Magento\Config\Model\Resource\Config\Data.php on line 38

After print $object->getValue() array is printed with error:

screenshot 1

and

screenshot 2

(click screenshots to enlarge)

1

Add backend model for this config path. Something like

<backend_model>NameSpace\Module\Model\Backend\Config</backend_model>

And backend model class looks like

namespace NameSpace\Module\Model\Backend
class Config  extends \Magento\Framework\App\Config\Value
{
    public function beforeSave()
    {
        $data = $this->getValue();
        if (is_array($data)) {
            $this->setValue(implode(',', $data));
        }
    }
}
0

In Magento 2 serialize values are not directly saved in database it's using some encryption method to store serialize values. After some r & d I found these two methods in Magento 2 to convert serialize and store in db:

   protected function encodeArrayFieldValue(array $value)

and:

   protected function decodeArrayFieldValue(array $value)
0

You have to set a backend_model for your field in the xml. If you don't have any special needs you can use the ArraySerialized model:

<backend_model>Magento\Config\Model\Config\Backend\Serialized\ArraySerialized</backend_model>

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.