I want to find a solution for sending an email to the customer when the administrator in backend changes its customer group. I have 3 customer groups, each one has different discounts in the store, so if I switch the user to another customer group, I want to send an email telling about the new discount.
I was thinking in an observer because I have made some observers to send an email with different events.
But what would it be the event for this situation? something like adminhtml_customer_update.
I also guess I would need to get the group where the customer is assigned. Thank you! Plugin code:
public function afterSetGroupId(\Magento\Customer\Api\Data\CustomerInterface $customer, $result)
{
//$groupId = $customer->getGroupId();
//$this->sendYourCustomEmail($customer);
$customer_group = $customer->getGroupId();
/* Receiver Detail the person who is going to receive the info that user logged in*/
$receiverInfo = [
'name' => 'Admin',
'email' => '[email protected]'
];
$store = $this->storeManager->getStore();
$templateParams = ['store' => $store, 'administrator_name' => $receiverInfo['name'], 'customer_group' => $customer_group];
$transport = $this->transportBuilder->setTemplateIdentifier(
'phpcuong_transactional_email_customer_group'
)->setTemplateOptions(
['area' => 'frontend', 'store' => $store->getId()]
)->addTo(
$receiverInfo['email'], $receiverInfo['name']
)->setTemplateVars(
$templateParams
)->setFrom(
'general'
)->getTransport();
try {
// Send an email
$transport->sendMessage();
} catch (\Exception $e) {
// Write a log message whenever get errors
$this->logger->critical($e->getMessage());
}
}