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.

  • Within Magento or outside Magento? Which information? – Ankit Shah Dec 20 '16 at 7:49
  • I just updated my question. – MrTo-Kane Dec 20 '16 at 7:53
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, privacy policy and cookie policy

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