0

How to Disable Customer Welcome Email Only Using preference not with plugin

5
  • Would it be possible to explain your problem a little more, what you did and what didn't work and why you don't want to use the plugin when it is recommended by Magento instead preference and possible for this method ?
    – PЯINCƎ
    Commented Jun 28, 2022 at 19:25
  • If you want to use reference, better to create reference for Magento\Customer\Model\EmailNotificationInterface. But I suggest to use plugin for the interface and use around with correct sortOrder for prevent to replace your logic by 3rd party extension like DotMailer, etc. Commented Jun 28, 2022 at 21:07
  • Hey @PЯINCƎ and Victor Tihonchuk thank you for your reply i have completed my task using below answer.
    – Mark
    Commented Jun 29, 2022 at 4:50
  • Preference is never a good solution, you can use plugin or event observer Commented Jun 29, 2022 at 7:08
  • okay thanks @Pyaray Afzel
    – Mark
    Commented Jun 29, 2022 at 7:32

1 Answer 1

1

You can create your preference like so:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="\Magento\Customer\Model\EmailNotification" type="Vendor\Module\Model\NoEmailNotification" />
</config>

and then override the newAccount method as follows:

<?php
namespace Vendor\Module\Model\Onepage;

class NoEmailNotification extends \Magento\Customer\Model\EmailNotification
{
      /**
     * Don't send email with new account related information
     *
     * @param CustomerInterface $customer
     * @param string $type
     * @param string $backUrl
     * @param int|null $storeId
     * @param string $sendemailStoreId
     * @return void
     * @throws LocalizedException
     */
    public function newAccount(
        CustomerInterface $customer,
        $type = self::NEW_ACCOUNT_EMAIL_REGISTERED,
        $backUrl = '',
        $storeId = null,
        $sendemailStoreId = null
    ): void {
        return;
    }
}

Which essentially inverts the original functionality of the method linked here (https://github.com/magento/magento2/blob/cd826aa2215e19d543a3a606aebde18fa3e40d4e/app/code/Magento/Customer/Model/EmailNotification.php#L384)

So the customer no longer receives a welcome email

2
  • Hey @SNAFU thank you so much its working fine
    – Mark
    Commented Jun 29, 2022 at 4:50
  • You're very welcome @Imran :)
    – SNAFU
    Commented Jun 30, 2022 at 8:01

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