0

I have created multi select customer attribute programatically. But getting while select this attribute at customer segments level conditions facing an issue below. Could you please advise.

( ! ) TypeError: Argument 1 passed to Magento\Eav\Model\Entity\Attribute\Source\Config::__construct() must be of the type array, null given, called in /var/www/html/magentoiqc/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 121 in /var/www/html/magentoiqc/vendor/magento/module-eav/Model/Entity/Attribute/Source/Config.php on line 26

<?php

namespace Demo\Customer\Setup;

use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\UpgradeDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Customer\Setup\CustomerSetupFactory;
use Magento\Customer\Model\Customer;
use Magento\Eav\Model\Entity\Attribute\Set as AttributeSet;
use Magento\Eav\Model\Entity\Attribute\SetFactory as AttributeSetFactory;
use Magento\Framework\Setup\InstallDataInterface;

/**
 * @codeCoverageIgnore
 */
class UpgradeData implements UpgradeDataInterface
{
   /**
     * @var CustomerSetupFactory
     */
    protected $customerSetupFactory;

    /**
     * @var AttributeSetFactory
     */
    private $attributeSetFactory;

    /**
     * UpgradeData constructor.
     * @param CustomerSetupFactory $customerSetupFactory
     * @param AttributeSetFactory $attributeSetFactory
     */
    public function __construct(
       CustomerSetupFactory $customerSetupFactory,
       AttributeSetFactory $attributeSetFactory
    ) {
        $this->customerSetupFactory = $customerSetupFactory;
        $this->attributeSetFactory = $attributeSetFactory;
    }

    /**
     * @param ModuleDataSetupInterface $setup
     * @param ModuleContextInterface $context
     */
    public function upgrade(
        ModuleDataSetupInterface $setup,
        ModuleContextInterface $context
    ) {
        $installer = $setup;
        $installer->startSetup();
        if (version_compare($context->getVersion(), '1.0.1', '<')) {
        /** @var CustomerSetup $customerSetup */
        $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
        $customerEntity = $customerSetup->getEavConfig()->getEntityType('customer');
        $attributeSetId = $customerEntity->getDefaultAttributeSetId();
        /** @var $attributeSet AttributeSet */
        $attributeSet = $this->attributeSetFactory->create();
        $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);
        $customerSetup->addAttribute(Customer::ENTITY, 'purchased_igs', [
            'label' => 'Purchased IGs',
            'system' => 0,
            'position' => 10,
            'sort_order' => 10,
            'visible' => true,
            'required' => false,
            'user_defined' => true=,
            'note' => '',
            'type' => 'varchar',
            'input' => 'multiselect',
            'backend' => 'Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend',
            'option' =>
          array (
            'values' => 
            array (
                    '1LG',
                    '2LG',
                    '3LG',
                    '3TLAU',
                    '3TLU',
                    '4TLA',
                    '4TLAP',
                    '7TBU',
                    '7TLU',
                    '9TBW',
                    'ACG',
                    'BSG',
                    'CCG',
                    'DCG',
                    'DSG',
                    'ECG',
                    'FLG',
                    'FSG',
                    'GCG',
                    'GSG',
                    'PCG',
                    'T2TB',
                    '8TBW',
                    'BLTW',
                    '4TL',
                    '5TBW',
                    'ASG',
                    'BCCG',
                    'BCG',
                    'CSG',
                    '6TLU',
                    '8TL',
                    '590',
                    '7TBW',
                    'ATBW',
                    'ESG',
                    'KLG',
                    'T6TL',
                    '330-PG',
                    'TCG',
                    '7TS',
                    'RL64I',
                    '520-PG',
                    '430-PG',
                    '670-01',
                    '130-PG',
                    'JCG',
                    '230-PG',
                    '530-PG',
                    'HLG',
                    '690-01',
                    '420',
                    '560',
                    'ETB',
                    'JLG',
                    '610-01',
                    '660-01',
                    'HSG',
                    '320',
                    '220',
                    '120'
            ),
          ),
        ]);

        $attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'purchased_igs')
            ->addData([
                'is_used_for_customer_segment' => true,
                'attribute_set_id' => $attributeSetId,
                'attribute_group_id' => $attributeGroupId,
                'used_in_forms' => ['adminhtml_customer']
                ]);
        $attribute->save();
      }
        $installer->endSetup();
    }
}

I enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.