I am working in Magento 2.2 and I am using an extension that allows the site admin to confirm new accounts before they are active. The extension can be found here: https://github.com/enrico69/magento2-customer-activation
When a new user registers the admin is sent an email that shows the email address of the new user.
This code sends the email:
public function send($customer)
{
$siteOwnerEmail = $this->scopeConfigInterface->getValue(
'trans_email/ident_sales/email',
ScopeInterface::SCOPE_STORE,
$customer->getStoreId()
);
$this->transportBuilder->setTemplateIdentifier('enrico69_activation_email_notification')
->setTemplateOptions(
[
'area' => Area::AREA_FRONTEND,
'store' => $customer->getStoreId(),
]
)
->setTemplateVars(['email' => $customer->getEmail()]);
$this->transportBuilder->addTo($siteOwnerEmail);
$this->transportBuilder->setFrom(
[
'name'=> $this->storeManagerInterface->getStore($customer->getStoreId())->getName(),
'email' => $siteOwnerEmail
]
);
$this->transportBuilder->getTransport()->sendMessage();
}
That file that emails the code to the admin is at: https://github.com/enrico69/magento2-customer-activation/blob/master/Model/AdminNotification.php
And I believe line 70 below controls pulling the customers email:
->setTemplateVars(['email' => $customer->getEmail()]);
I also found the line below in https://github.com/enrico69/magento2-customer-activation/blob/master/Observer/UserActivation.php that prepares the code.
$newCustomer = $this->customerRepository->get($customer->getEmail());
I am trying to pull custom Customer attributes values added to my eav_attribute table. The attribute is "company_name" and is already created. I found the following code which I modified here: http://www.w3solver.com/magento2-addcreate-and-get-custom-customer-attribute-value/
So I created the line below in https://github.com/enrico69/magento2-customer-activation/blob/master/Observer/UserActivation.php
$newCustomer = $this->customerRepository->get($customer->getCustomAttribute('company_name')->getValue());
And added the line below in https://github.com/enrico69/magento2-customer-activation/blob/master/Model/AdminNotification.php
->setTemplateVars(['companyname' => $customer->getCustomAttribute('company_name')->getValue()]);
But this still isn't working. Can anyone offer some clues to get me on the correct path? Thanks!