Closed careys7 closed 6 years ago
Definitely a bug, and a PR fixng it was merged into develop
less than a month ago: #7742
But if you'd like to see it on 2.1.x branch, you might consider creating an extra pull request, targeting 2.1-develop
and referencing the previous one.
In my case I had no default value configured. Is it possible that the following use case is not resolved by #7742?
I found the results of $this->scopeConfig->getValue('x/y/z')
were not in a type that would suggest _afterLoad() had been called when used on the frontend. I was expecting an array, but consistently returned a serialized string.
It was as if core_config_data
's value field had been persisted to cache without having been processed by the backend model's _afterLoad() at any stage.
@careys7, thank you for your report. We've created internal ticket(s) MAGETWO-80296 to track progress on the issue.
I'm working on it #SQUASHTOBERFEST, can I be assigned to this issue?
Hi @careys7, looks like described behavior caused by configuration mismatch. Try to declare backend_model for field "country_mapping" in config.xml file:
<country_mapping backend_model="Magento\Config\Model\Config\Backend\Serialized\ArraySerialized"/>
after this fix expression $this->scopeConfig->getValue('shipping/extension/country_mapping')
will return unserialized array.
Could you please take a look at provided solution and leave feedback? Thanks!
Hey @sidolov
Thanks for the feedback! It doesn't look like this is applied consistently in the core, can you think of why?
(eg NewRelicReporting, ProductAlert, Tax, etc)
@careys7 looks like it was overlooked during the implementation. Maybe it makes sense to show raw value for some cases. Is this issue still actual for you or we can close it?
This looks resolved now, thanks for investigating @sidolov
If I understand correctly configuration options that require a backend model must also have a default configuration option node entered under config.xml. I will take a look at the devdocs and open a PR to document this if it's missing. Thanks again
Thanks @careys7, it will be great if you update devdocs!
Preconditions
Steps to reproduce
system.xml
configuration that includes abackend_model
node, eg:Expected result
ArraySerialized::_afterLoad()
is calledActual result
Magento\Framework\App\Config\Value::_afterLoad()
is only called when rendering admin configuration formsRelated: https://github.com/magento/magento2/issues/7741
Is this a feature or a bug? In the case of ArraySerialized, it means that any use of the configuration value in other parts of the application need to handle unserialization in two places:
backend_model
's_afterLoad()
method