Hello,
I would like a user does not have to validate his account (only specific user from custom register form).
I use this:
$customer->setConfirmation(null);
$customer->save();
that works fine, but the confirmation email still sent...
How to not sent the email if I use setConfirmation(null)?
any idea?
thank ![]()
Solved! Go to Solution.
Hi @JoouulDev
Sorry for the dealy ![]()
which event you are using?
I have checked with this event
<event name="customer_save_before">
<observer name="my_customer_save_before" instance="\Mymodule\Module\Observer\BehaviorCustomerBeforeSave"/>
</event>and only put this code in observer, not need to save customer in observer
$customer = $observer->getEvent()->getCustomer();
$customer->setConfirmation(null); if ($this->registry->registry('skip_confirmation_if_email')) { $this->registry->unregister('skip_confirmation_if_email'); } $this->registry->register('skip_confirmation_if_email', $customer->getEmail());
and it is working
Please check with this.
Hi @JoouulDev
Please use this code before customer save
if ($this->registry->registry('skip_confirmation_if_email')) { $this->registry->unregister('skip_confirmation_if_email'); } $this->registry->register('skip_confirmation_if_email', $customerEmailAddress);
$customerEmailAddress=> specific user email which for you want to skip confirmation
Hi Geeta,
thank for your reply.
I do this before $customer->save(); and I called this -> use Magento\Framework\Registry; because it's a script wich implements ObserverInterface
$customer->setConfirmation(null);
if ($this->registry->registry('skip_confirmation_if_email')) {
$this->registry->unregister('skip_confirmation_if_email');
}
$this->registry->register('skip_confirmation_if_email', $customerEmailAddress);but email still sended.
Hi @JoouulDev
Can you please send complete class code. I will check and then reply to you with a solution
Hi,
this is my code
<?php
namespace MyModule\ModuleName\Actions;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Registry;
class CustomClass implements ObserverInterface
{
protected $_responseFactory;
protected $_request;
protected $_url;
private $registry;
public function __construct(
\Magento\Framework\App\ResponseFactory $responseFactory,
\Magento\Framework\App\Request\Http $request,
\Magento\Framework\UrlInterface $url,
Registry $registry
) {
$this->_responseFactory = $responseFactory;
$this->_request = $request;
$this->_url = $url;
$this->registry = $registry;
}
public function execute(\Magento\Framework\Event\Observer $observer)
{
$customer = $observer->getEvent()->getCustomer();
$post = $this->_request->getPost();
// $_POST from 2 form. First form
// type-registration == 1 (user have to confirm account by email, ok in back-office)
// type-registration == 2 (user do not confirmed account and email not send)
if ($post['type-registration'] == 2) {
$customer->setConfirmation(null);
if ($this->registry->registry('skip_confirmation_if_email')) {
$this->registry->unregister('skip_confirmation_if_email');
}
$this->registry->register('skip_confirmation_if_email', $customer->getEmail());
$returnUrl = 'custom_url_success';
} else {
$returnUrl = 'custom_url_error';
}
try {
$customer = $customerRepository->save($customer);
} catch (Exception $e) {
return $e->getMessage();
}
$this->_responseFactory->create()->setRedirect($this->_url->getUrl($returnUrl))->sendResponse();
exit();
}
}Thank for help ![]()
Hi @JoouulDev
Sorry for the dealy ![]()
which event you are using?
I have checked with this event
<event name="customer_save_before">
<observer name="my_customer_save_before" instance="\Mymodule\Module\Observer\BehaviorCustomerBeforeSave"/>
</event>and only put this code in observer, not need to save customer in observer
$customer = $observer->getEvent()->getCustomer();
$customer->setConfirmation(null); if ($this->registry->registry('skip_confirmation_if_email')) { $this->registry->unregister('skip_confirmation_if_email'); } $this->registry->register('skip_confirmation_if_email', $customer->getEmail());
and it is working
Please check with this.
@Geeta Modi GREAT ![]()
I'used this event "customer_register_success" and with "customer_save_before"
Thank you very much ![]()