3

How to update the customer information in Magento 2 (Code to set data for customer).
Example: Update email_backup column of customer_entity table.

2
  • Within Magento or outside Magento? Which information?
    – Jackson
    Dec 20, 2016 at 7:49
  • I just updated my question.
    – MrTo-Kane
    Dec 20, 2016 at 7:53

1 Answer 1

6

The email_backup is the custom customer attribute. We can use Magento\Customer\Api\CustomerRepositoryInterface to save the customer info.

/**
 * @var CustomerRepositoryInterface
 */
protected $customerRepository;

public function __construct(

    CustomerRepositoryInterface $customerRepository
)
{

    $this->customerRepository = $customerRepository;
}

We can save:

$customer = $this->customerRepository->getById($customerId);

$customer->setCustomAttribute('email_backup', $emailBackupData);
$this->customerRepository->save($customer);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.