6

Exception #0 (Exception): Notice: Array to string conversion in /public_html/vendor/magento/framework/View/Element/Html/Select.php on line 244

line 235-244 of the Select.php

public function calcOptionHash($optionValue)
{
    return sprintf('%u', crc32($this->getName() . $this->getId() . $optionValue));
}

this is when i try to go to mailchimp configuration tab on the admin page.

full exception message here:

Exception #0 (Exception): Notice: Array to string conversion in /public_html/vendor/magento/framework/View/Element/Html/Select.php on line 243
#0 /public_html/vendor/magento/framework/View/Element/Html/Select.php(243): Magento\Framework\App\ErrorHandler->handler(8, 'Array to string...', '/p...', 243, Array)
#1 /public_html/vendor/mailchimp/mc-magento2/Block/Adminhtml/System/Config/Form/Field/CustomerMap.php(68): Magento\Framework\View\Element\Html\Select->calcOptionHash(Array)
#2 /public_html/vendor/magento/module-config/Block/System/Config/Form/Field/FieldArray/AbstractFieldArray.php(159): Ebizmarts\MailChimp\Block\Adminhtml\System\Config\Form\Field\CustomerMap->_prepareArrayRow(Object(Magento\Framework\DataObject))
#3 /public_html/vendor/magento/module-config/view/adminhtml/templates/system/config/form/field/array.phtml(117): Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray->getArrayRows()
#4 /public_html/vendor/magento/framework/View/TemplateEngine/Php.php(59): include('/p...')
#5 /public_html/vendor/magento/framework/View/Element/Template.php(270): Magento\Framework\View\TemplateEngine\Php->render(Object(Ebizmarts\MailChimp\Block\Adminhtml\System\Config\Form\Field\CustomerMap\Interceptor), '/p...', Array)
#6 /public_html/vendor/magento/framework/View/Element/Template.php(300): Magento\Framework\View\Element\Template->fetchView('/p...')
#7 /public_html/vendor/magento/module-backend/Block/Template.php(126): Magento\Framework\View\Element\Template->_toHtml()
#8 /public_html/vendor/magento/module-config/Block/System/Config/Form/Field/FieldArray/AbstractFieldArray.php(262): Magento\Backend\Block\Template->_toHtml()
#9 /public_html/vendor/magento/module-config/Block/System/Config/Form/Field/FieldArray/AbstractFieldArray.php(116): Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray->_toHtml()
#10 /public_html/vendor/magento/module-config/Block/System/Config/Form/Field.php(73): Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray->_getElementHtml(Object(Magento\Framework\Data\Form\Element\Text))
#11 /public_html/vendor/magento/module-config/Block/System/Config/Form/Field.php(52): Magento\Config\Block\System\Config\Form\Field->_renderValue(Object(Magento\Framework\Data\Form\Element\Text))
#12 /public_html/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Config\Block\System\Config\Form\Field->render(Object(Magento\Framework\Data\Form\Element\Text))
#13 /public_html/vendor/magento/framework/Interception/Interceptor.php(138): Ebizmarts\MailChimp\Block\Adminhtml\System\Config\Form\Field\CustomerMap\Interceptor->___callParent('render', Array)
#14 /public_html/vendor/magento/framework/Interception/Interceptor.php(153): Ebizmarts\MailChimp\Block\Adminhtml\System\Config\Form\Field\CustomerMap\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\Data\Form\Element\Text))
#15 /public_html/generated/code/Ebizmarts/MailChimp/Block/Adminhtml/System/Config/Form/Field/CustomerMap/Interceptor.php(26): Ebizmarts\MailChimp\Block\Adminhtml\System\Config\Form\Field\CustomerMap\Interceptor->___callPlugins('render', Array, Array)
#16 /public_html/vendor/magento/framework/Data/Form/Element/AbstractElement.php(459): Ebizmarts\MailChimp\Block\Adminhtml\System\Config\Form\Field\CustomerMap\Interceptor->render(Object(Magento\Framework\Data\Form\Element\Text))
#17 /public_html/vendor/magento/framework/Data/Form/Element/Text.php(43): Magento\Framework\Data\Form\Element\AbstractElement->getHtml()
#18 /public_html/vendor/magento/framework/Data/Form/Element/AbstractElement.php(473): Magento\Framework\Data\Form\Element\Text->getHtml()
#19 /public_html/vendor/magento/module-config/Block/System/Config/Form/Fieldset.php(86): Magento\Framework\Data\Form\Element\AbstractElement->toHtml()
#20 /public_html/vendor/magento/module-config/Block/System/Config/Form/Fieldset.php(66): Magento\Config\Block\System\Config\Form\Fieldset->_getChildrenElementsHtml(Object(Magento\Framework\Data\Form\Element\Fieldset))
#21 /public_html/vendor/magento/framework/Data/Form/Element/AbstractElement.php(459): Magento\Config\Block\System\Config\Form\Fieldset->render(Object(Magento\Framework\Data\Form\Element\Fieldset))
#22 /public_html/vendor/magento/framework/Data/Form/Element/AbstractElement.php(473): Magento\Framework\Data\Form\Element\AbstractElement->getHtml()
#23 /public_html/vendor/magento/framework/Data/Form.php(325): Magento\Framework\Data\Form\Element\AbstractElement->toHtml()
#24 /public_html/vendor/magento/framework/Data/Form.php(340): Magento\Framework\Data\Form->toHtml()
#25 /public_html/vendor/magento/module-backend/Block/Widget/Form.php(101): Magento\Framework\Data\Form->getHtml()
#26 /public_html/vendor/magento/module-backend/view/adminhtml/templates/widget/form.phtml(15): Magento\Backend\Block\Widget\Form->getFormHtml()
#27 /public_html/vendor/magento/framework/View/TemplateEngine/Php.php(59): include('/p...')
#28 /public_html/vendor/magento/framework/View/Element/Template.php(270): Magento\Framework\View\TemplateEngine\Php->render(Object(Magento\Config\Block\System\Config\Form), '/p...', Array)
#29 /public_html/vendor/magento/framework/View/Element/Template.php(300): Magento\Framework\View\Element\Template->fetchView('/p...')
#30 /public_html/vendor/magento/module-backend/Block/Template.php(126): Magento\Framework\View\Element\Template->_toHtml()
#31 /public_html/vendor/magento/framework/View/Element/AbstractBlock.php(667): Magento\Backend\Block\Template->_toHtml()
#32 /public_html/vendor/magento/framework/View/Layout.php(557): Magento\Framework\View\Element\AbstractBlock->toHtml()
#33 /public_html/vendor/magento/framework/View/Layout.php(533): Magento\Framework\View\Layout->_renderBlock('system\\config\\f...')
#34 /public_html/vendor/magento/framework/View/Layout.php(488): Magento\Framework\View\Layout->renderNonCachedElement('system\\config\\f...')
#35 /public_html/vendor/magento/framework/View/Element/AbstractBlock.php(507): Magento\Framework\View\Layout->renderElement('system\\config\\f...', true)
#36 /public_html/vendor/magento/module-config/view/adminhtml/templates/system/config/edit.phtml(22): Magento\Framework\View\Element\AbstractBlock->getChildHtml('form')
#37 /public_html/vendor/magento/framework/View/TemplateEngine/Php.php(59): include('/p...')
#38 /public_html/vendor/magento/framework/View/Element/Template.php(270): Magento\Framework\View\TemplateEngine\Php->render(Object(Magento\Config\Block\System\Config\Edit), '/p...', Array)
#39 /public_html/vendor/magento/framework/View/Element/Template.php(300): Magento\Framework\View\Element\Template->fetchView('/p...')
#40 /public_html/vendor/magento/module-backend/Block/Template.php(126): Magento\Framework\View\Element\Template->_toHtml()
#41 /public_html/vendor/magento/framework/View/Element/AbstractBlock.php(667): Magento\Backend\Block\Template->_toHtml()
#42 /public_html/vendor/magento/framework/View/Layout.php(557): Magento\Framework\View\Element\AbstractBlock->toHtml()
#43 /public_html/vendor/magento/framework/View/Layout.php(533): Magento\Framework\View\Layout->_renderBlock('system.config.e...')
#44 /public_html/vendor/magento/framework/View/Layout.php(488): Magento\Framework\View\Layout->renderNonCachedElement('system.config.e...')
#45 /public_html/vendor/magento/framework/View/Layout.php(585): Magento\Framework\View\Layout->renderElement('system.config.e...', false)
#46 /public_html/vendor/magento/framework/View/Layout.php(535): Magento\Framework\View\Layout->_renderContainer('content', false)
#47 /public_html/vendor/magento/framework/View/Layout.php(488): Magento\Framework\View\Layout->renderNonCachedElement('content')
#48 /public_html/vendor/magento/framework/View/Layout.php(585): Magento\Framework\View\Layout->renderElement('content', false)
#49 /public_html/vendor/magento/framework/View/Layout.php(535): Magento\Framework\View\Layout->_renderContainer('admin.scope.col...', false)
#50 /public_html/vendor/magento/framework/View/Layout.php(488): Magento\Framework\View\Layout->renderNonCachedElement('admin.scope.col...')
#51 /public_html/vendor/magento/framework/View/Layout.php(585): Magento\Framework\View\Layout->renderElement('admin.scope.col...', false)
#52 /public_html/vendor/magento/framework/View/Layout.php(535): Magento\Framework\View\Layout->_renderContainer('main.col', false)
#53 /public_html/vendor/magento/framework/View/Layout.php(488): Magento\Framework\View\Layout->renderNonCachedElement('main.col')
#54 /public_html/vendor/magento/framework/View/Layout.php(585): Magento\Framework\View\Layout->renderElement('main.col', false)
#55 /public_html/vendor/magento/framework/View/Layout.php(535): Magento\Framework\View\Layout->_renderContainer('page.main.conta...', false)
#56 /public_html/vendor/magento/framework/View/Layout.php(488): Magento\Framework\View\Layout->renderNonCachedElement('page.main.conta...')
#57 /public_html/vendor/magento/framework/View/Layout.php(585): Magento\Framework\View\Layout->renderElement('page.main.conta...', false)
#58 /public_html/vendor/magento/framework/View/Layout.php(535): Magento\Framework\View\Layout->_renderContainer('page.content', false)
#59 /public_html/vendor/magento/framework/View/Layout.php(488): Magento\Framework\View\Layout->renderNonCachedElement('page.content')
#60 /public_html/vendor/magento/framework/View/Layout.php(585): Magento\Framework\View\Layout->renderElement('page.content', false)
#61 /public_html/vendor/magento/framework/View/Layout.php(535): Magento\Framework\View\Layout->_renderContainer('page.wrapper', false)
#62 /public_html/vendor/magento/framework/View/Layout.php(488): Magento\Framework\View\Layout->renderNonCachedElement('page.wrapper')
#63 /public_html/vendor/magento/framework/View/Layout.php(585): Magento\Framework\View\Layout->renderElement('page.wrapper', false)
#64 /public_html/vendor/magento/framework/View/Layout.php(535): Magento\Framework\View\Layout->_renderContainer('backend.page', false)
#65 /public_html/vendor/magento/framework/View/Layout.php(488): Magento\Framework\View\Layout->renderNonCachedElement('backend.page')
#66 /public_html/vendor/magento/framework/View/Layout.php(585): Magento\Framework\View\Layout->renderElement('backend.page', false)
#67 /public_html/vendor/magento/framework/View/Layout.php(535): Magento\Framework\View\Layout->_renderContainer('root', false)
#68 /public_html/vendor/magento/framework/View/Layout.php(488): Magento\Framework\View\Layout->renderNonCachedElement('root')
#69 /public_html/vendor/magento/framework/View/Layout.php(954): Magento\Framework\View\Layout->renderElement('root')
#70 /public_html/generated/code/Magento/Framework/View/Layout/Interceptor.php(37): Magento\Framework\View\Layout->getOutput()
#71 /public_html/vendor/magento/framework/View/Result/Page.php(257): Magento\Framework\View\Layout\Interceptor->getOutput()
#72 /public_html/vendor/magento/framework/View/Result/Layout.php(170): Magento\Framework\View\Result\Page->render(Object(Magento\Framework\App\Response\Http\Interceptor))
#73 /public_html/generated/code/Magento/Backend/Model/View/Result/Page/Interceptor.php(24): Magento\Framework\View\Result\Layout->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor))
#74 /public_html/vendor/magento/framework/App/Http.php(139): Magento\Backend\Model\View\Result\Page\Interceptor->renderResult(Object(Magento\Framework\App\Response\Http\Interceptor))
#75 /public_html/vendor/magento/framework/App/Bootstrap.php(257): Magento\Framework\App\Http->launch()
#76 /public_html/index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http\Interceptor))
#77 {main}

CustomerMap.php code as below

<?php
/**
 * mc-magento2 Magento Component
 *
 * @category Ebizmarts
 * @package mc-magento2
 * @author Ebizmarts Team <[email protected]>
 * @copyright Ebizmarts (http://ebizmarts.com)
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 * @date: 10/27/17 12:01 PM
 * @file: CustomerMap.php
 */

namespace Ebizmarts\MailChimp\Block\Adminhtml\System\Config\Form\Field;

class CustomerMap extends \Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray
{
    /**
     * @var VarsMap
     */
    protected $_varsRenderer=null;
    protected $_mailchimpRenderer=null;

    protected function _getVarsRenderer()
    {
        if (!$this->_varsRenderer) {
            $this->_varsRenderer = $this->getLayout()->createBlock(
                'Ebizmarts\MailChimp\Block\Adminhtml\System\Config\Form\Field\VarsMap',
                '',
                ['data' => ['is_render_to_js_template' => true]]
            );
            $this->_varsRenderer->setClass('customer_field_select');
        }
        return $this->_varsRenderer;
    }
    protected function _getMailchimpRenderer()
    {
        if (!$this->_mailchimpRenderer) {
            $this->_mailchimpRenderer = $this->getLayout()->createBlock(
                'Ebizmarts\MailChimp\Block\Adminhtml\System\Config\Form\Field\MailchimpMap',
                '',
                ['data' => ['is_render_to_js_template' => true]]
            );
            $this->_mailchimpRenderer->setClass('mailchimp_field_select');
        }
        return $this->_mailchimpRenderer;
    }

    protected function _prepareToRender()
    {
//        $this->addColumn('mailchimp', ['label' => __('Mailchimp')]);
        $this->addColumn(
            'mailchimp_field_id',
            ['label' => __('Mailchimp'), 'renderer' => $this->_getMailchimpRenderer()]
        );
        $this->addColumn(
            'customer_field_id',
            ['label' => __('Magento'), 'renderer' => $this->_getVarsRenderer()]
        );
        $this->_addAfter = false;
        $this->_addButtonLabel = __('Add');
    }
    protected function _prepareArrayRow(\Magento\Framework\DataObject $row)
    {
        $optionExtraAttr = [];
        $optionExtraAttr['option_' . $this->_getVarsRenderer()->calcOptionHash($row->getData('customer_field_id'))] =
            'selected="selected"';
        //$optionExtraAttr['option_' . $this->_getMailchimpRenderer()->calcOptionHash($row->getData('mailchimp_field_id'))] =
        //    'selected="selected"';
        $row->setData(
            'option_extra_attrs',
            $optionExtraAttr
        );
    }
}

var/xxx.php.error.log

[21-Mar-2019 06:54:52 UTC] PHP Fatal error:  Uncaught Error: Call to undefined method Ebizmarts\MailChimp\Helper\Data::serialize() in /public_html/vendor/mailchimp/mc-magento2/Helper/VarsMap.php:99 Stack trace:
#0 /public_html/vendor/mailchimp/mc-magento2/Helper/VarsMap.php(49): Ebizmarts\MailChimp\Helper\VarsMap->serializeValue(Array)
#1 /public_html/vendor/mailchimp/mc-magento2/Model/Config/Backend/VarsMap.php(71): Ebizmarts\MailChimp\Helper\VarsMap->makeStorableArrayFieldValue(Array)
#2 /public_html/vendor/magento/framework/Model/ResourceModel/Db/AbstractDb.php(406): Ebizmarts\MailChimp\Model\Config\Backend\VarsMap->beforeSave()
#3 /public_html/vendor/magento/framework/Model/AbstractModel.php(647): Magento\Framework\Model\ResourceModel\Db\AbstractDb->save(Object(Ebizmarts\MailChimp\Model\Config\Backend\VarsMap\Interceptor))
#4 /public_html/vendor/magento/framework/DB/Transaction.php(129): Magento\Framework\Model\AbstractModel->save()
#5 /public_html/vendor/mage in /public_html/vendor/mailchimp/mc-magento2/Helper/VarsMap.php on line 99

VarsMap.php as below

<?php
/**
 * mc-magento2 Magento Component
 *
 * @category Ebizmarts
 * @package mc-magento2
 * @author Ebizmarts Team <[email protected]>
 * @copyright Ebizmarts (http://ebizmarts.com)
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 * @date: 10/27/17 3:41 PM
 * @file: VarsMap.php
 */

namespace Ebizmarts\MailChimp\Block\Adminhtml\System\Config\Form\Field;

class VarsMap extends \Magento\Framework\View\Element\Html\Select
{
    /**
     * @var \Magento\Customer\Model\ResourceModel\Attribute\CollectionFactory
     */
    private $_attCollection;
    /**
     * VarsMap constructor.
     * @param \Magento\Framework\View\Element\Context $context
     * @param \Magento\Customer\Model\ResourceModel\Attribute\CollectionFactory $attCollection
     * @param array $data
     */
    public function __construct(
        \Magento\Framework\View\Element\Context $context,
        \Magento\Customer\Model\ResourceModel\Attribute\CollectionFactory $attCollection,
        array $data = []
    ) {

        parent::__construct($context, $data);
        $this->_attCollection = $attCollection;
    }

    protected function _getCustomerAtt()
    {
        $ret = [];
        $collection = $this->_attCollection->create();
        /**
         * @var $item \Magento\Customer\Model\Attribute
         */
        foreach ($collection as $item) {
            $ret[$item->getId()] = $item->getFrontendLabel();
        }

        natsort($ret);
        return $ret;
    }

    public function setInputName($value)
    {
        return $this->setName($value);
    }

    /**
     * Render block HTML
     *
     * @return string
     */
    public function _toHtml()
    {
        if (!$this->getOptions()) {
            foreach ($this->_getCustomerAtt() as $attId => $attLabel) {
                $this->addOption($attId, addslashes($attLabel));
            }
        }
        return parent::_toHtml();
    }
}

2 Answers 2

6

It is an error of Mailchimp module just go to the below location

Magento_root/vendor/mailchimp/mc-magento2/Block/Adminhtml/System/Config/Form/Field/CustomerMap.php

On the line number 68 comment the below code

$optionExtraAttr['option_' . $this->_getMailchimpRenderer()->calcOptionHash($row->getData('mailchimp_field_id'))] =
            'selected="selected"';

Since initially your Magento store is not connected with the Mailchimp so it is not able to fetch the Mailchimp field values & that's why it is giving error.

Please refer this

5
  • Hi, I tried comment out the line 68 & 69. but when i tried to save at the configuration page. i still get the error page HTTP Error 500. any solution to that? thanks Commented Mar 21, 2019 at 6:01
  • 500 error means there is some problem with the syntax or the code can you please update your code here? Commented Mar 21, 2019 at 6:13
  • i add the CustomerMap.php code in the question, thank you. Commented Mar 21, 2019 at 6:30
  • 1
    after i uninstall the mailchimp extension, remove mailchimp and mailchimp-lib from composer, then i install this version (for magento 2.2.x) "composer require mailchimp/mc-magento2:101.2.34" after that, i apply your solution above (comment out the line 68,69). Everything works now. I'll pick your answer as a solution, thank you Commented Mar 21, 2019 at 7:54
  • You are always welcome @KrisWen !! happy to help you :)!! Commented Mar 21, 2019 at 8:17
2

The error says that the return data type in select is Array but it has been printed as a string. To resolve this, you have to change the way return type is printed using print_r function.

10
  • Hi, i tried that,but still getting the same error message. can you help? thanks. Commented Mar 21, 2019 at 6:04
  • you did like this return print_r('%u', crc32($this->getName() . $this->getId() . $optionValue)); ?
    – fmsthird
    Commented Mar 21, 2019 at 6:05
  • yes, that's what i did. Commented Mar 21, 2019 at 6:28
  • I see no error on your CustomerMap.php code
    – fmsthird
    Commented Mar 21, 2019 at 7:07
  • 2
    thanks, i replace with this version "mailchimp/mc-magento2:101.2.34" , then i had to apply the fix from @ABHISHEK TRIPATHI to get it work. thank you both. Commented Mar 21, 2019 at 7:57

Your Answer

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

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