1

I have developed a module store view pricing in which I have edited price attribute's scope. Whenever I install that extension of time below warning populates during setup: upgrade in the command window

Warning: array_merge(): Argument #1 is not an array /var/www/html/magento219/vendor/magento/framework/App/Config/Initial/Converter.php on line 78

Could anyone tell the reason about that? It is because of extension bug or a core bug? This is code to edit price attribute:

use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\InstallDataInterface;

    /**
     * InstallData for install Database for StoreViewPricing
     */

        class InstallData implements InstallDataInterface
        {
            /**
             * eav Setup Factory
             *
             * @var \Magento\Eav\Setup\EavSetupFactory
             */
            private $eavSetupFactory;

            /**
             * @param \Magento\Eav\Setup\EavSetupFactory $eavSetupFactory
             */
            public function __construct(EavSetupFactory $eavSetupFactory)
            {
               $this->eavSetupFactory = $eavSetupFactory;
            }


            /**
             * @param \Magento\Framework\Setup\ModuleDataSetupInterface $setup
             * @param \Magento\Framework\Setup\ModuleContextInterface $context;
             */
            public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
            { 
                /** @var EavSetup $eavSetup */

                $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
                $entityType = $eavSetup->getEntityTypeId('catalog_product');
                $eavSetup->updateAttribute($entityType, 'price', 'is_global',0);

            }
        }

I have add condition

&& is_array($nodeData) at vendor/magento/framework/App/Config/Initial/Converter.php on line 78

for temporary solution

if (is_array($childrenData) && is_array($nodeData)) {
                $nodeData = array_merge($nodeData, $childrenData);
            } else {
                $nodeData = $childrenData;
            }

My Module.xml is

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
    <module name="Mageants_StoreViewPricing" schema_version="2.0.0" setup_version="2.0.0" active="true">
         <sequence>
            <module name="Magento_Catalog"/>
            <module name="Magento_Directory"/>
        </sequence>
    </module>
</config>

I know it's wrong to edit core files so i need permanent solution if any one can help on this.

Thank you

0

2 Answers 2

1

You setup script seems to be correct.

Can you please try to debug the $nodeData value in order to know where the value come from. You should be able to know the root cause.

Can you please share your module configuration files too.

Can you please share your Magento 2 version.

In the latest version, the function is :

/**
 * Convert node oto array
 *
 * @param \DOMNode $node
 * @param string $path
 * @return array|string|null
 *
 * @SuppressWarnings(PHPMD.CyclomaticComplexity)
 */
protected function _convertNode(\DOMNode $node, $path = '')
{
    $output = [];
    if ($node->nodeType == XML_ELEMENT_NODE) {
        if ($node->hasAttributes()) {
            $backendModel = $node->attributes->getNamedItem('backend_model');
            if ($backendModel) {
                $this->_metadata[$path] = ['backendModel' => $backendModel->nodeValue];
            }
        }
        $nodeData = [];
        /** @var $childNode \DOMNode */
        foreach ($node->childNodes as $childNode) {
            $childrenData = $this->_convertNode($childNode, ($path ? $path . '/' : '') . $childNode->nodeName);
            if ($childrenData == null) {
                continue;
            }
            if (is_array($childrenData)) {
                $nodeData = array_merge($nodeData, $childrenData);
            } else {
                $nodeData = $childrenData;
            }
        }
        if (is_array($nodeData) && empty($nodeData)) {
            $nodeData = null;
        }
        $output[$node->nodeName] = $nodeData;
    } elseif ($node->nodeType == XML_CDATA_SECTION_NODE || $node->nodeType == XML_TEXT_NODE && trim(
        $node->nodeValue
    ) != ''
    ) {
        return $node->nodeValue;
    }

    return $output;
}

But indeed, for me there is a bug in the code. Magento should check that $nodeData is an array, and manage the exception if it should not be.

2
  • Thank you @Franck Garnier I have edited question with module.xml yes my magento version is 2.1.9 and i am going to debug as you have suggested :) Sep 28, 2017 at 13:25
  • i got the actual root in extension which was causing problem, i am updating in answer Sep 29, 2017 at 7:16
1

I found the actual problem. To enable selection of base price's scope to store view. i have use following code in config.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
    <default>  
        <currency>
            <options>
                <base>
                    <showInStore>1</showInStore>
                </base>
            </options>      
        </currency>
    </default>
</config>

Which was causing error:Warning: array_merge(): Argument #1 is not an array vendor/magento/framework/App/Config/Initial/Converter.php on line 78

I removed config.xml and i have override system.xml of core's module module-directory in my module with following code.

<?xml version="1.0"?>
<!--
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
    <system>
        <section id="currency" translate="label" sortOrder="60" showInDefault="1" showInWebsite="1" showInStore="1">
            <label>Currency Setup</label>
            <tab>general</tab>
            <resource>Magento_Backend::currency</resource>
            <group id="options" translate="label" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Currency Options</label>
                <field id="base" translate="label comment" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
                    <label>Base Currency</label>
                    <frontend_model>Magento\Directory\Block\Adminhtml\Frontend\Currency\Base</frontend_model>
                    <source_model>Magento\Config\Model\Config\Source\Locale\Currency</source_model>
                    <backend_model>Magento\Config\Model\Config\Backend\Currency\Base</backend_model>
                    <comment>
                        <![CDATA[Base currency is used for all online payment transactions. The base currency scope is defined by the catalog price scope ("Catalog" > "Price" > "Catalog Price Scope").]]>
                    </comment>
                </field>

            </group>

        </section>
    </system>
</config>

It works. Error solved

0

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.