Skip to content

Magento 2.4.2 : Multi select options for customer custom Attribute is not update

Update in admin panel is not update the values

<?php
namespace GemPaymentMethodRestrictionSetupPatchData;

use MagentoEavSetupEavSetupFactory;
use MagentoFrameworkSetupModuleDataSetupInterface;
use MagentoFrameworkSetupPatchDataPatchInterface;
use MagentoFrameworkSetupPatchPatchRevertableInterface;
use MagentoCustomerSetupCustomerSetupFactory;
use MagentoCustomerModelCustomer;

class InstallData implements DataPatchInterface, PatchRevertableInterface
{
    private $eavSetupFactory;
    private $customerSetupFactory;
    private $moduleDataSetup;

    public function __construct(
        EavSetupFactory $eavSetupFactory,
        CustomerSetupFactory $customerSetupFactory,
        ModuleDataSetupInterface $moduleDataSetup
    ) {
        $this->eavSetupFactory = $eavSetupFactory;
        $this->customerSetupFactory = $customerSetupFactory;
        $this->moduleDataSetup = $moduleDataSetup;
    }

    public function apply()
    {
        $this->moduleDataSetup->getConnection()->startSetup();

        /** @var MagentoCustomerSetupCustomerSetup $customerSetup */
        $customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]);

        // Add the customer attribute with the payment options
        $customerSetup->addAttribute(
            Customer::ENTITY,
            'allowed_payment_methods',
            [
                'type' => 'text',
                'label' => 'Allowed Payment Methods',
                'input' => 'multiselect',
                'required' => false,
                'visible' => true,
                'user_defined' => true,
                'sort_order' => 1000,
                'position' => 1000,
                'system' => false,
                'is_used_in_grid' => true,
                'is_visible_in_grid' => true,
                'is_filterable_in_grid' => true,
                'is_searchable_in_grid' => true,
                'backend' => 'MagentoEavModelEntityAttributeBackendArrayBackend',
                'source' => GemPaymentMethodRestrictionModelAttributeSourceAllowedPaymentMethods::class,
            ]
        );

        // Make the attribute available in the customer forms
        $attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'allowed_payment_methods')
            ->addData([
                'used_in_forms' => [
                    'adminhtml_customer', 'customer_account_create', 'customer_account_edit'
                ],
            ]);
        $attribute->save();

        $this->moduleDataSetup->getConnection()->endSetup();
    }

    public static function getDependencies()
    {
        return [];
    }
    
    public function getVersion()
    {
        return '1.0.0';
    }

    public function revert()
    {
        $this->moduleDataSetup->getConnection()->startSetup();
        
        $customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]);
        $customerSetup->removeAttribute(Customer::ENTITY, 'allowed_payment_methods');
        
        $this->moduleDataSetup->getConnection()->endSetup();
    }

    public function getAliases()
    {
        return [];
    }
}