Pregunta

I've edited this function below and i'm overriding this method in app/code/FF/Customer/Model/EmailNotification.php natively this file exists in vendor/magento/module-customer/Model/EmailNotification.php

/**
 * Send corresponding email template
 *
 * @param CustomerInterface $customer
 * @param string $template configuration path of email template
 * @param string $sender configuration path of email identity
 * @param array $templateParams
 * @param int|null $storeId
 * @param string $email
 * @return void
 * @throws \Magento\Framework\Exception\MailException
 */
private function sendEmailTemplate(
    $customer,
    $template,
    $sender,
    $templateParams = [],
    $storeId = null,
    $email = null
) {
    $templateId = $this->scopeConfig->getValue($template, 'store', $storeId);
    if ($email === null) {
        $email = $customer->getEmail();
    }

    /** @var array $from */
    $from = $this->senderResolver->resolve(
        $this->scopeConfig->getValue($sender, 'store', $storeId),
        $storeId
    );

    $ccEmail   = $this->scopeConfig->getValue('sales_email/order/copy_to', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
    $bccEmail  = "myemail@gmail.com";

    $transport = $this->transportBuilder->setTemplateIdentifier($templateId)
        ->setTemplateOptions(['area' => 'frontend', 'store' => $storeId])
        ->setTemplateVars($templateParams)
        ->setFrom($from)
        ->addTo($email, $this->customerViewHelper->getCustomerName($customer))
        ->addCc($ccEmail)
        ->addBcc($bccEmail)
        ->getTransport();

    $transport->sendMessage();
}

I've also created my di.xml file and added this line of code.It resides here: app/code/FF/Customer/etc/di.xml

<preference for="Magento\Customer\Model\EmailNotification" type="FF\Customer\Model\EmailNotification"/>

I'm not sure if there is something i'm still missing but I can't get it to CC or BCC. It sends the welcome email fine like usual but my code is not working.

I can't use a plugin because it's a private method, right? I'm stuck and need some help.

¿Fue útil?

Solución

You should pass cc email as array

$ccEmail   = $this->scopeConfig->getValue('sales_email/order/copy_to', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);

$transport = $this->transportBuilder->setTemplateIdentifier($templateId)
        ->setTemplateOptions(['area' => 'frontend', 'store' => $storeId])
        ->setTemplateVars($templateParams)
        ->setFrom($from)
        ->addTo($email, $this->customerViewHelper->getCustomerName($customer))
        ->addCc([$ccEmail])
        ->addBcc([$bccEmail])
        ->getTransport();
Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange
scroll top