observer and event.xml sales_model_service_quote_submit_before
/**
* @var \Magento\Checkout\Model\Session
*/
protected $_checkoutSession;
public function __construct(
\Magento\Checkout\Model\Session $checkoutSession
)
{
$this->_checkoutSession = $checkoutSession;
}
/**
* @param Observer $observer
*
* @return void
*/
public function execute(Observer $observer)
{
$order = $observer->getEvent()->getOrder();
$quote = $observer->getEvent()->getQuote();
$this->_checkoutSession->setEmailCc($quote->getData(CustomFieldsInterface::CHECKOUT_EMAIL_CC));
}
override plugin Magento\Sales\Model\Order\Email\Container\OrderIdentity
public function getEmailCopyTo()
{
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$currentEmailCc = $objectManager->get('Magento\Checkout\Model\Session');
$emailCC = $currentEmailCc->getEmailCc();
$data = $this->getConfigValue(self::XML_PATH_EMAIL_COPY_TO, $this->getStore()->getStoreId());
$data2 = $data.','.$emailCC;
if (!empty($data) && !empty($emailCC)) {
return array_map('trim', explode(',', $data2));
}
if (empty($data) && !empty($emailCC)){
return array_map('trim', explode(',', $emailCC));
}
if (!empty($data) && empty($emailCC) ){
return array_map('trim', explode(',', $data));
}
if (empty($data) && empty($emailCC)) {
return false;
}
}