Skip to content

Customer Custom Attributes deleted upon update #9795

@jayalakshmit

Description

@jayalakshmit

Preconditions

  1. Magento Enterprise 2.1.4

Steps to reproduce

  1. Added Custom customer attribute in UpgradeData

        $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]); 
         $attribute_values = array(
            ['code' => 'custom_attr_1', 'label' => 'XXXXX', 'input' => 'text'],
            ['code' => 'custom_attr_2', 'label'  => 'XXXX', 'input' => 'text']              
        );
        
        foreach ($attribute_values as $value)
        {
            if (!$customerSetup->getAttributeId(Customer::ENTITY, $value['code'])) 
            {
                $customerSetup->addAttribute(Customer::ENTITY, $value['code'], [
                    'type' => 'text',
                    'label' => $value['label'],
                    'input' => $value['input'],
                    'required' => false,
                    'visible' => false,
                    'position' => 120,
                    'system' => false                        
                ]);                
                $attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, $value['code'])
                ->addData([                    
                    'used_in_forms' => ['adminhtml_customer'],
                     'is_user_defined' => 1              
                ]);
                
                $attribute->save();
            } 
        }  
    

These custom attribute has been saved in Database upon customer login.

  1. And on saving the data for these attributes used the below code.

         $data = array(
    		'custom_attr_1' => 'XXXX',
    		'custom_attr_2' => 'XXXXX'
                    );
         $customer_info    = $this->_customerFactory->create()->load(10);
         if ($customer_info->getId()) {             
        try {
            $customer_info->addData($data);               
            $customer_info->save();               
        }
        catch (Exception $e) {
            return false; 
        }
    }
    
  2. These customer custom attribute are saved in customer_entity_text table. On running magento setup:upgrade command(during code deployment on other environment), and customer login, the above code is called and the data from the customer_entity_text table is deleted.

  3. It doesn't happen when setup:upgrade is not run.

Expected result

  1. Data is updated in customer_entity_text table

Actual result

  1. Data (custom customer attribute) gets removed from customer_entity_text table on saving customer object.

Any suggestions please??

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions