0

When I created one Customer Custom Attribute and changed its value website-wise from Admin-> Edit Customer Information so did not change it.

  <?php
    namespace Vendor\Extension\Setup\Patch\Data;
    
    use Magento\Eav\Setup\EavSetup;
    use Magento\Eav\Setup\EavSetupFactory;
    use Magento\Framework\Setup\ModuleDataSetupInterface;
    use Magento\Framework\Setup\Patch\DataPatchInterface;
    use Magento\Customer\Model\Customer;
    use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
    use Magento\Customer\Setup\CustomerSetupFactory;
    
    class AddCustomerStatusAttribute implements DataPatchInterface
    {
        private $moduleDataSetup;
    
        private $customerSetupFactory;
    
        public function __construct(
            ModuleDataSetupInterface $moduleDataSetup,
            CustomerSetupFactory $customerSetupFactory
        ) {
            $this->moduleDataSetup = $moduleDataSetup;
            $this->customerSetupFactory = $customerSetupFactory;
        }
        
        public function apply()
        {
            /** @var EavSetup $eavSetup */
            $customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]);
            $customerSetup->addAttribute(
                Customer::ENTITY,
                'customer_status',
                [
                    'label' => 'Customer Approve',
                    'input' => 'select',
                    'required' => false,
                    'sort_order' => 40,
                    'visible' => true,
                    'system' => false,
                    'is_used_in_grid' => true,
                    'is_visible_in_grid' => true,
                    'is_filterable_in_grid' => true,
                    'is_searchable_in_grid' => false,
                    'type' => 'int',
                    'default'  => 1,
                    'source' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean',
                    "note"    => "Set Approve to login"
                ]
            );
    
            $attribute = $customerSetup->getEavConfig()->getAttribute('customer', 'customer_status');
            
            $used_in_forms[]="adminhtml_customer";
            
            $attribute->setData('used_in_forms', $used_in_forms)
                    ->setData("is_visible", 1)
                    ->setData("sort_order", 100);
            $attribute->save();
        }
    
       /**
        * {@inheritdoc}
        */
        public static function getDependencies()
        {
            return [];
        }
    
       /**
        * {@inheritdoc}
        */
        public function getAliases()
        {
            return [];
        }
    }
1

2 Answers 2

2

Magento Known Issue : https://github.com/magento/magento2/issues/38730

Here you can find the patch : https://github.com/magento/magento2/commit/6db1257dd697af0a206f46bd9de95bd712a178ab

0

This will be resolved in 2.4.8 as mentioned here https://experienceleague.adobe.com/en/docs/commerce-operations/release/notes/magento-open-source/2-4-8

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.