Pregunta

I set the configuration for Magento 2 customer to do email confirmation after register and change e-mail, is there a way to confirm customer e-mail programmatically only by customer id or customer e-mail?

$customerId = '35';
$customerEmail = 'test@test.com';
$this->confirmCustomerEmailByCustomerId($customerId);  //how ?
$this->confirmCustomerEmailByCustomerEmail($customerEmail); //how ?
¿Fue útil?

Solución

You can confirm the customer registration as following

<?php 

private $customer;

public function __construct(
    ...
    \Magento\Customer\Model\Customer $customer,
    ...
) {
    ...
    $this->customer = $customer;
    ...
}


...

$customerId = '1';
$customer = $this->customer->load($customerId);
$customer->setConfirmation(null);
$customer->save();

Otros consejos

When I created accounts, they were already confirmed, but they were disabled! This fixed it:

  $customer = $this->customer->load($customerId);
  $customer->setConfirmation(null);
  $customer->setStatus(1);
  $customer->save();
Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange
scroll top