cancel
Showing results for 
Search instead for 
Did you mean: 

Add a customer to a group

SOLVED

Add a customer to a group

How do I add a customer to a group programatically in magento2

 

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Add a customer to a group

Hi @arunsomanhere

 

did you try to use setGroupId() method on the customer model object?

 

/** @var \Magento\Customer\Api\Data\CustomerInterface $customer */
$customer->setGroupId($someCustomerGroupId);
/** @var \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository */
$customerRepository->save($customer);

 

 

Cheers,

BX

View solution in original post

2 REPLIES 2

Re: Add a customer to a group

Hi @arunsomanhere

 

did you try to use setGroupId() method on the customer model object?

 

/** @var \Magento\Customer\Api\Data\CustomerInterface $customer */
$customer->setGroupId($someCustomerGroupId);
/** @var \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository */
$customerRepository->save($customer);

 

 

Cheers,

BX

Re: Add a customer to a group

Yeah I did this , $this->session->getCustomer()->setGroupId("5")->save(); and it worked , thanks