Hello everyone I want to set group_id = 2 for wholesale customer registration.
I have to override the registration form in view/registration.phtml
and also written
<input type="hidden" name="group_id" id="group_id" value="2" />
I have also created the observer
Magneto\WholesaleCustomer\Observer\Customer\RegisterSuccess.php
<?php
namespace Magneto\WholesaleCustomer\Observer\Customer;
use Magento\Customer\Api\CustomerRepositoryInterface;
class RegisterSuccess implements
\Magento\Framework\Event\ObserverInterface {
/**
* @var CustomerRepositoryInterface
*/
//added by me
private $customerRepository;
public function __construct(
\Magento\Framework\App\RequestInterface $request,
CustomerRepositoryInterface $customerRepository
)
{
$this->_request = $request;
$this->customerRepository = $customerRepository;
}
//ends here
public function execute(
\Magento\Framework\Event\Observer $observer
){
$id = $observer->getEvent()->getCustomer()->getId();
$customer = $this->customerRepository->getById($id);
$group_id = $this->_request->getParam('group_id');
$customer->setGroupId($group_id);
$this->customerRepository->save($customer);
}
}
But the group id is coming 1 in the database I want to set it as 2 in database.