I have added input box in admin's system.xml along with other fields as below:

<field id="mapping" translate="label comment tooltip" sortOrder="80" showInDefault="1" showInWebsite="1" showInStore="0">
  <label>Exclude Days</label>
           <![CDATA[Add bank holidays that are not included in delivery / cut off times.]]>
            <tooltip>Delivery and cuttoff not include these days.</tooltip>

This display in admin as:

enter image description here

I can add many input boxes by clicking ADD button. Below is code to receive input dates of above form:

$offDays = $this->scopeConfig->getValue('deliverycountdown/general/mapping', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);

But output is as below:



a:2:{s:6:"field1";s:4:"BBBB";s:6:"field2";s:10:"2017-11-03";}s:18:"_1509434861359_359"; a:2:{s:6:"field1";s:4:"CCCC";s:6:"field2";s:10:"2017-11-06";} }

It would great help to get dates from this file (i think JSON).

Or guide me another way if thats possible to add fields in admin and get at front-end block file.

2 Answers 2


For grids controls in system configuration using backend model


which serialize array data on save and unserialize before passing to view model.

You need to use \Magento\Framework\Serialize\SerializerInterface::unserialize (for test you can use unserialize) to get original field value with serialized backend model.

Note, that in Magento 2.2 json serializer using as default serializer, so if you will work with low level unserialize then you module will throw exception in 2.2.

$offDays = $this->scopeConfig->getValue('deliverycountdown/general/mapping', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
  • Where to add this : \Magento\Framework\Serialize\SerializerInterface::unserialize
    – Sharma
    Nov 3, 2017 at 9:13
  • add Magento\Framework\Serialize\SerializerInterface as argument in constructor and use $this->serializer->unserialize($offDayas);
    – Max
    Nov 3, 2017 at 9:42
  • My construct in magento 2.1.9 as below==== public function __construct( \Magento\Framework\View\Element\Template\Context $context, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\Stdlib\DateTime\DateTime $date // For date and time functions ) { $this->date = $date; $this->scopeConfig = $scopeConfig; parent::__construct( $context ); } =========== Please guide
    – Sharma
    Nov 3, 2017 at 12:33
  • add ` \Magento\Framework\Serialize\SerializerInterface $serializer` after $date argument and $this->serializer = $serializer; in constructor body
    – Max
    Nov 3, 2017 at 12:54
  • I had tried the same in my module but PHPSTORM highlight error as : Serialize namespace not defined. Site dont load in browser
    – Sharma
    Nov 3, 2017 at 13:00

I done it with following string functions and its working fine.

a:2:{s:6:"field1";s:13:"IIIIIIIIIIIII";s:6:"field2";s:10:"2017-11-20";}}' ; 

        $needle = 's:10:"';
        $count = substr_count($offDaysString, $needle);

        $position = 0;
        for ($i = 0; $i < $count; $i++) {

            $pos = strpos($offDaysString, $needle, $position);
            $position = $pos + 6;// length of this - s:10:
            $startPoint[] = $position;
            $Offdates[] = substr($offDaysString, $startPoint[$i], 10); // 10 = 2017-11-20



For me, above code working fine and i put it in function in block file and called in template file displayed dates.

If anyone get a better to receive values on front-end block then post answer. Thanks

  • you must not use parsing of serialized values, see my answer
    – Max
    Nov 3, 2017 at 8:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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