So after the some action the customer gets the email with the code.
I assume in the code it's a controller action.
What you need is to add a view for this action (block and template) and in the template show generated coupon code. And the coupon generation function you already have in the module.
Magento doesn’t have default functionality to stop sending newsletter emails.
Below I show an example of how to disable newsletter subscription emails.
Create a custom module and add di.xml
Override Subscriber.php
app/code/Vendor/Module/etc/di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Newsletter\Model\Subscriber">
<plugin name="myplugin" type="Vendor\Module\Newsletter\Model\Subscriber" sortOrder="1" disabled="false"/>
</type>
</config>
Now create Subscriber.php
app/code/Vendor/Module/Newsletter\Model\Subscriber.php
<?php
namespace Vendor\Module\Newsletter\Model;
use Magento\Newsletter\Model\Subscriber as SubscriberModel;
class Subscriber
{
/**
* @param SubscriberModel $oSubject
* @param callable $proceed
*/
public function aroundSendConfirmationRequestEmail(SubscriberModel $oSubject, callable $proceed) {}
/**
* @param SubscriberModel $oSubject
* @param callable $proceed
*/
public function aroundSendConfirmationSuccessEmail(SubscriberModel $oSubject, callable $proceed) {}
/**
* @param SubscriberModel $oSubject
* @param callable $proceed
*/
public function aroundSendUnsubscriptionEmail(SubscriberModel $oSubject, callable $proceed) {}
}
Now run following commands
php bin/magento setup:di:compile
php bin/magento cache:clean
Best Answer
I don't know which Magento version you are talking about so I try to make a generic answer.
Success messages are in the controller file using session messages to display them.
In your case this is in
Mage_Newsletter_SubscriberController
with this code :Here you have three solutions:
1_ Override controller
You can override the controller and change the message in your rewrite
Help : http://inchoo.net/magento/overriding-magento-blocks-models-helpers-and-controllers/
Possible issue : for code evolution rewrites are not the best solution.
2_ Use observer
You can use observer as
controller_action_post_dispatch_*
to add your own message to session and manage them3_ Change traduction
You change change the traduction in files
app/locale/{locale_code}/{module}.csv
Possible issue : misleading when searching this traduction in future or for other people working on your website
In your case I suggest you the rewrite because newsletter is not a "sensible" part of Magento. (Note : Take care if you install a module that is using this feature.)