1

We are trying to add a functionality to send an additional email to the admin when a user has registered an account.

The core code we want to modify is located at Magento\Customer\Model\AccountManagement.php class: sendEmailConfirmation.

The code we currently believe should work:

di.xml

<?xml version="1.0"?>    
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Customer\Model\AccountManagement">
    <plugin name="EmailAanpassing" type="Sprite\EmailAanpassing\Customer\Model\After" sortOrder="10" disabled="false" />
</type>    
</config>

module.xml

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Sprite_EmailAanpassing" setup_version="1.0.0">
  <sequence>
   <module name="Magento_Customer"/>
  </sequence>
 </module>
</config>

Sprite/EmailAanpassing/Customer/Model/After.php

<?php
namespace Sprite\EmailAanpassing\Customer\Model;

use \Magento\Customer\Model\AccountManagement;


class After extends \Magento\Customer\Model\AccountManagement
{

protected function afterSendEmailConfirmation()//Magento\Customer\Api\Data\CustomerInterface $customer, $redirectUrl)//)//SomeType $iets)
{
       // sendmail test
       mail("email@domain.com","New Registration",'Hello World!');
}
}
?>

When adding to code directly to the core it works fine. The module's basic files are created via Mage2gen.

Magento ver. 2.1.5

4

Plugins work only for public methods. Since sendEmailConfirmation() is a protected method, you can't able write plugin for that. Other way, you can write plugin for createAccountWithPasswordHash() which is the parent function of sendEmailConfirmation().

  • Ah, of course, it is working now, thanks. This, in combination of overloading $subject, $result and returning $result to make it work with the "createAccountWithPasswordHash()" method. – Sprite Apr 18 '17 at 12:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.