Ошибка дублирующегося идентификатора шаблона при программной отправке электронной почты в Magento 2 («dotmailer_current_template_id» уже существует) - PullRequest
0 голосов
/ 26 февраля 2020

Ключ реестра "dotmailer_current_template_id" уже существует в

/var/www/html/vendor/magento/framework/Registry.php:60

Я получаю эту ошибку, когда пытаюсь программно отправить электронное письмо с magento 2.

Мой код выглядит следующим образом. У объекта AmastyConfig есть методы, которые проверяют правильность моих настроек перед отправкой электронного письма.

 public function sendStartSubscriptionEmail( AmastySubscriptionInterface $subscription,$storeId){
        $customerEmail= $this->customerRepositoryInterface->getById($subscription->getCustomerId())->getEmail();
        if ($this->AmastyConfig->isNotifySubscriptionPurchased($storeId)) {
            $template = $this->AmastyConfig->getEmailTemplateSubscriptionPurchased($storeId);
            //$this->Notifier->sendEmail( $subscription, $template, $storeId, $customerEmail);
        }}




This is the definition of the send email class. 

   public function sendEmail(
        AmastySubscriptionInterface $subscription,
        string $template,
        int $storeId,
        string $email,
        array $templateVariables = []
    ) {
        $templateVariables = array_merge($this->prepareTemplateVariables($subscription), $templateVariables);

        $data = new DataObject(
            [
                'template'           => $template,
                'store_id'           => $storeId,
                'email_recipient'    => $email,
                'email_sender'       => $this->config->getEmailSender($storeId),
                'template_variables' => $templateVariables
            ]
        );

        $this->eventManager->dispatch('amasty_recurring_send_email', ['email_data' => $data]);
    }
}



This is the Observer:


class Notification implements ObserverInterface
{
    /**
     * @var TransportBuilder
     */
    private $transportBuilder;

    public function __construct(TransportBuilder $transportBuilder)
    {
        $this->transportBuilder = $transportBuilder;
    }

    /**
     * @param Observer $observer
     *
     * @throws \Exception
     */
    public function execute(Observer $observer)
    {
        $data = $observer->getData('email_data');

        if (!$data) {
            throw new \Exception('Email data not specified');
        }

        /** @var TransportBuilder $transportBuilder */
        $transportBuilder = clone $this->transportBuilder;

        $transportBuilder->setTemplateIdentifier($data['template'] ?? null)
            ->setTemplateVars($data['template_variables'] ?? [])
            ->setTemplateOptions(
                [
                    Area::PARAM_AREA=> Area::AREA_FRONTEND,
                    Store::ENTITY => $data['store_id'] ?? null
                ]
            )
            ->setFrom($data['email_sender'] ?? null)
            ->addTo($data['email_recipient'] ?? null);

        /** @var \Magento\Framework\Mail\TransportInterface $transport */
        $transport = $transportBuilder->getTransport();

        $transport->sendMessage();
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...