I want to add a cc to all sales emails based on a custom customer condition.
My plugin isn’t currently adding a cc to the email at all.
I have a Magento plugin with an /etc/adminhtml/di.xml with the following code
<?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="MagentoFrameworkMailTemplateTransportBuilder">
<plugin name="<name>_<name>_send_order_copy" type="<name><name>PluginsSendOrderCopy"
sortOrder="1" disabled="false" />
</type>
</config>
And the plugin which looks like this
<?php
namespace <name><company>Plugins;
use Exception;
use MagentoFrameworkMailTemplateTransportBuilder;
use PsrLogLoggerInterface;
/**
* Class SendOrderCopy.
*/
class SendOrderCopy extends TransportBuilder
{
/**
* @var LoggerInterface
*/
private LoggerInterface $logger;
/**
* @var TransportBuilder
*/
protected $transportBuilder;
public function __construct(
LoggerInterface $logger,
TransportBuilder $transportBuilder
)
{
$this->logger = $logger;
$this->transportBuilder = $transportBuilder;
}
// public function beforeGetTransport(TransportBuilder $subject)
// {
// try {
// $ccEmailAddress = ["name@company.com"];
// $this->logger->debug('processed the cc for email');
// $subject->addCc($ccEmailAddress);
// } catch (Exception $e) {
// $this->logger->error('Failure in MyCompany Cc module: ' . $e->getMessage());
// }
// }
public function afterGetTransport($subject, $result)
{
$result->getMessage()->addCc('name@company.com','');
return $result;
}
}
As you can see, I tried both before and after plugins but I get nothing in the logs and no changes or errors at all