customerRepository = $customerRepository; } /** * Customer mass assign group action * * @param AbstractCollection $collection * @return \Magento\Backend\Model\View\Result\Redirect */ protected function massAction(AbstractCollection $collection) { $customersUpdated = 0; foreach ($collection->getAllIds() as $customerId) { // Verify customer exists $customer = $this->customerRepository->getById($customerId); $customer->setGroupId($this->getRequest()->getParam('group')); // No need to validate customer and customer address during assigning customer to the group $this->setIgnoreValidationFlag($customer); $this->customerRepository->save($customer); $customersUpdated++; } if ($customersUpdated) { $this->messageManager->addSuccess(__('A total of %1 record(s) were updated.', $customersUpdated)); } /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); $resultRedirect->setPath($this->getComponentRefererUrl()); return $resultRedirect; } /** * Set ignore_validation_flag to skip unnecessary address and customer validation * * @param Customer $customer * @return void */ private function setIgnoreValidationFlag($customer) { $customer->setData('ignore_validation_flag', true); } }