Skip to content

Customer Address Custom Attribute gets deleted upon update #6411

@marcoreni

Description

@marcoreni

Preconditions

  1. Magento 2.1.0 CE, php 7.0.8

Steps to reproduce

  1. Define new Customer Address Custom Attribute in UpgradeData:
$customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
$addressEntity = $customerSetup->getEavConfig()->getEntityType('customer_address');
$attributeSetId = $addressEntity->getDefaultAttributeSetId();

/** @var AttributeSet $attributeSet  */
$attributeSet = $this->attributeSetFactory->create();
$attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);

$customerSetup->addAttribute('customer_address','attribute_test',[
                'type'          => 'varchar',
                'label'         => 'Attribute Test',
                'input'         => 'text',
                'required'      => false,

                'visible'       => true,
                'user_defined'  => false,
                'position'      => 200,
                'sort_order'    => 200,
                'system'        => false,
            ]);

$attr1 = $customerSetup->getEavConfig()->getAttribute('customer_address', 'attribute_test');
$attr1->addData($customerAddressData = [
                'attribute_set_id' => $attributeSetId,
                'attribute_group_id' => $attributeGroupId,
                'used_in_forms' => ['adminhtml_customer_address']);
$this->attributeRepository->save($attr1);
  1. Populate the attribute through adminhtml interface. The attribute is correctly persisted on EAV tables
  2. Intercept the LoginPost action with a beforeExecute(), then retrieve and save customer without modifications:
$customer = $this->customerRepositoryInterface->get($login['username']);
$this->customerRepositoryInterface->save($customer);
return;

Expected result

  1. The Custom Attribute should stay there.

Actual result

  1. The Custom Attribute gets deleted

It seems that the problem may reside in Magento\Customer\Model\ResourceModel\Customer\Relation.php:49 which uses $address->save() instead of the repository (thus not having an attribute_set_id set), but if I remove the ->save($customer) in the plugin everything works as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: CustomerEvent: WroCDContribution day in WroIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.1.xThe issue has been reproduced on latest 2.1 releaseReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 releasebug report

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions