custom/plugins/NextagMail/src/Helper/MailGenerator.php line 56

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Nextag\Mail\Helper;
  4. use Symfony\Component\Mime\Email;
  5. use Twig\Error\LoaderError;
  6. use Twig\Error\RuntimeError;
  7. use Twig\Error\SyntaxError;
  8. use Twig\Extra\CssInliner\CssInlinerExtension;
  9. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  10. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  11. use Shopware\Core\Framework\Adapter\Translation\Translator;
  12. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  13. use Shopware\Core\Content\Mail\Service\AbstractMailSender;
  14. use League\Flysystem\FilesystemInterface;
  15. use Mpdf\Mpdf;
  16. use Mpdf\Config\ConfigVariables;
  17. use Mpdf\Config\FontVariables;
  18. /**
  19.  * Class MailGenerator
  20.  * @package Nextag\Flow\Helper
  21.  */
  22. class MailGenerator
  23. {
  24.     protected $configService;
  25.     protected $log;
  26.     private $twig;
  27.     private $translator;
  28.     private $mailSender;
  29.     protected FilesystemInterface $filesystem;
  30.     protected $nextagCheckoutRepository;
  31.     protected $customerGroupRepository;
  32.     protected $customerRepository;
  33.     protected $baseUrl;
  34.     public function __construct(
  35.         \Shopware\Core\System\SystemConfig\SystemConfigService $configService,
  36.         Translator $translator,
  37.         \Twig\Environment $twig,
  38.         AbstractMailSender $mailSender,
  39.         FilesystemInterface $filesystem,
  40.         \Nextag\Mail\Helper\Log $log,
  41.         EntityRepositoryInterface $customerGroupRepository,
  42.         EntityRepositoryInterface $customerRepository
  43.     ) {
  44.         $this->configService $configService;
  45.         $this->twig $twig;
  46.         try {
  47.             $this->twig->getExtension("Twig\Extra\CssInliner\CssInlinerExtension");
  48.         } catch (\Exception $e) {
  49.             $this->twig->addExtension(new CssInlinerExtension());
  50.         }
  51.         $this->mailSender $mailSender;
  52.         $this->filesystem $filesystem;
  53.         $this->translator $translator;
  54.         $this->log $log;
  55.         $this->customerGroupRepository $customerGroupRepository;
  56.         $this->customerRepository $customerRepository;
  57.         $this->baseUrl =  $this->configService->get("NextagConnector.config.shopwareBaseUrl");
  58.     }
  59.     /**
  60.      * @param mixed $identifier 
  61.      * @param mixed $subject 
  62.      * @param array $parameters 
  63.      * @return Email 
  64.      * @throws LoaderError 
  65.      * @throws RuntimeError 
  66.      * @throws SyntaxError 
  67.      */
  68.     public function getMessage($identifier$from$sendTo$bcc$subject$data = [], $attachments null$binAttachments null)
  69.     {
  70.         try {
  71.             $templateName 'storefront/mail/' $identifier '.html.twig';
  72.             $template $this->twig->loadTemplate($this->twig->getTemplateClass($templateName), $templateName);
  73.             $bodyHtml $template->renderBlock('body_html'$data);
  74.             $email = (new Email())->subject($subject);
  75.             $email->html($bodyHtml);
  76.             if ($attachments !== null) {
  77.                 foreach ($attachments as $url) {
  78.                     $email->embed($this->filesystem->read($url) ?: ''basename($url), $this->filesystem->getMimetype($url) ?: null);
  79.                 }
  80.             }
  81.             if (isset($binAttachments)) {
  82.                 foreach ($binAttachments as $binAttachment) {
  83.                     $email->embed(
  84.                         $binAttachment['content'],
  85.                         $binAttachment['fileName'],
  86.                         $binAttachment['mimeType']
  87.                     );
  88.                 }
  89.             }
  90.             $email->from($from);
  91.             $email->addTo(...$sendTo);
  92.             if ($bcc && is_array($bcc) && !empty($bcc)) {
  93.                 foreach ($bcc as $k => $v) {
  94.                     if (trim($bcc[$k]) == "") {
  95.                         unset($bcc[$k]);
  96.                     }
  97.                 }
  98.             }
  99.             if ($bcc && !empty($bcc)) {
  100.                 $email->addBcc(...$bcc);
  101.             }
  102.             return $email;
  103.         } catch (\Exception $exception) {
  104.             $this->log->error($exception);
  105.         }
  106.     }
  107.     public function sendEmail($order$config$orderExtension null)
  108.     {
  109.         try {
  110.             $this->log->info("sendEmail start");
  111.             $type null;
  112.             $to null;
  113.             $bcc null;
  114.             if (isset($config['mailType'])) {
  115.                 $type $config['mailType'];
  116.             } else {
  117.                 $this->log->error(new \Exception('No mail type defined for order ' $order->getOrderNumber()));
  118.                 return false;
  119.             }
  120.             if (isset($config['email'])) {
  121.                 $to $config['email'];
  122.             } else {
  123.                 $this->log->error(new \Exception('No send to defined for mail: ' $type ' for order ' $order->getOrderNumber()));
  124.                 return false;
  125.             }
  126.             if (isset($config['bccEmail'])) {
  127.                 $bcc $config['bccEmail'];
  128.             }
  129.             setlocale(LC_ALL"de_CH.UTF-8");
  130.             $subject '';
  131.             switch ($type) {
  132.                 case 'orderConfirmation':
  133.                     $subject 'Danke für Ihre Bestellung (' $order->getOrderNumber() . ')';
  134.                     break;
  135.                 case 'orderConfirmationInternal':
  136.                     $subject 'Neue Online-Bestellung Nr. ' $order->getOrderNumber();
  137.                     break;
  138.             }
  139.             $requestScheme "https";
  140.             if (isset($_SERVER["REQUEST_SCHEME"])) {
  141.                 $requestScheme $_SERVER["REQUEST_SCHEME"];
  142.             }
  143.             $data = array(
  144.                 'baseUrl' =>  $requestScheme "://" $_SERVER["SERVER_NAME"],
  145.                 'order' => $order,
  146.                 'orderUrl' =>  $requestScheme "://" $_SERVER["SERVER_NAME"] . "/account/order",
  147.                 'checkoutExtension' => $orderExtension
  148.             );
  149.             if (isset($config["exportorder"]) && isset($config["exportorder"]["result"])) {
  150.                 if ($config["exportorder"]["result"] === false) {
  151.                     $data["exportResult"] = "2";
  152.                     $subject .= " - Import fehlgeschlagen!";
  153.                 } else {
  154.                     $data["exportResult"] = "1";
  155.                 }
  156.             }
  157.             $from $this->configService->get("core.basicInformation.email");
  158.             if ($this->configService->get("core.basicInformation.shopName")) {
  159.                 $from "Weinhandlung Martel" ' <' $from '>'// $this->configService->get("core.basicInformation.shopName")
  160.             }
  161.             $context \Shopware\Core\Framework\Context::createDefaultContext();
  162.             $groupId $order->getOrderCustomer()->getCustomer()->getGroupId();
  163.             $criteria = new Criteria();
  164.             $criteria->addFilter(new EqualsFilter(
  165.                 'id',
  166.                 $groupId
  167.             ));
  168.             $customerGroup $this->customerGroupRepository->search($criteria$context)->first();
  169.             $data['customerGroup'] = $customerGroup;
  170.             $data['orderDateTime'] = date('d.m.Y / H:i:s'$order->getOrderDateTime()->getTimestamp());
  171.             // generate pdf
  172.             $attachments = [];
  173.             $context \Shopware\Core\Framework\Context::createDefaultContext();
  174.             $pdf $this->createOrderPdf($order$data);
  175.             if ($pdf) {
  176.                 $attachment = [
  177.                     'content' => file_get_contents($pdf),
  178.                     'fileName' => pathinfo($pdfPATHINFO_BASENAME),
  179.                     'mimeType' => mime_content_type($pdf)
  180.                 ];
  181.                 $attachments[] = $attachment;
  182.             }
  183.             // $events = $this->createEventPdfs($order,$data);
  184.             // if (!empty($events)) {
  185.             //     foreach($events as $event) {
  186.             //         $attachment = [
  187.             //             'content' => file_get_contents($event),
  188.             //             'fileName' => pathinfo($event, PATHINFO_BASENAME),
  189.             //             'mimeType' => mime_content_type($event)
  190.             //         ];
  191.             //         $attachments[] = $attachment;
  192.             //     }
  193.             // }
  194.             $email $this->getMessage(
  195.                 strtolower($type "_withpdf"),
  196.                 $from,
  197.                 $this->getEmailAddresses($to$order),
  198.                 $this->getEmailAddresses($bcc$order),
  199.                 $subject,
  200.                 $data,
  201.                 null,
  202.                 $attachments
  203.             );
  204.             /* if ($requestScheme . "://" . $_SERVER["SERVER_NAME"] == "https://martel.dev5") {
  205.                 // generate pdf
  206.                 $attachments = [];
  207.                 $orderNumber = $order->getOrdernumber();
  208.                 $context = \Shopware\Core\Framework\Context::createDefaultContext();
  209.                
  210.                 $pdf = $this->createOrderPdf($order, $data);
  211.               
  212.                 if ($pdf) {
  213.                     $attachment = [
  214.                         'content' => file_get_contents($pdf),
  215.                         'fileName' => pathinfo($pdf, PATHINFO_BASENAME),
  216.                         'mimeType' => mime_content_type($pdf)
  217.                     ];
  218.                     $attachments[] = $attachment;
  219.                 }
  220.                 $email = $this->getMessage(
  221.                     strtolower($type."_withpdf"),
  222.                     $from,
  223.                     $this->getEmailAddresses($to, $order),
  224.                     $this->getEmailAddresses($bcc, $order),
  225.                     $subject,
  226.                     $data,
  227.                     null,
  228.                     $attachments
  229.                 );
  230.             } else {
  231.                 $email = $this->getMessage(
  232.                     strtolower($type),
  233.                     $from,
  234.                     $this->getEmailAddresses($to, $order),
  235.                     $this->getEmailAddresses($bcc, $order),
  236.                     $subject,
  237.                     $data
  238.                 );
  239.             } */
  240.             $this->mailSender->send($email);
  241.             if (is_array($to)) {
  242.                 $logTo implode(","$to);
  243.             } else {
  244.                 $logTo = [$to];
  245.             }
  246.             foreach ($logTo as $k => $v) {
  247.                 if ($v == "[KUNDE]") {
  248.                     $logTo[$k] = $order->getOrderCustomer()->getEmail();
  249.                 }
  250.             }
  251.             $this->log->info('Mail (' $type ') wurde gesendet an: ' implode(","$logTo) . ' (Bestellnummer: ' $order->getOrderNumber() . ')');
  252.             $this->log->info("sendEmail END");
  253.         } catch (\Exception $e) {
  254.             $this->log->error($e);
  255.         }
  256.     }
  257.     public function createOrderPdf($order$data)
  258.     {
  259.         try {
  260.             if ($order) {
  261.                 $showDetails true;
  262.                 $language "de";
  263.                 $context \Shopware\Core\Framework\Context::createDefaultContext();
  264.                 $orderCustomer $order->getOrderCustomer();
  265.                 if ($orderCustomer->getCustomer()) {
  266.                     $customer $orderCustomer->getCustomer();
  267.                 } else {
  268.                     $criteria = new Criteria();
  269.                     $criteria->addFilter(new EqualsFilter("email"$orderCustomer->getEmail()));
  270.                     $criteria->addFilter(new EqualsFilter("guest"false));
  271.                     $customer $this->customerRepository->search($criteria$context)->first();
  272.                     if (!$customer) {
  273.                         $criteria = new Criteria();
  274.                         $criteria->addFilter(new EqualsFilter("email"$orderCustomer->getEmail()));
  275.                         $criteria->addFilter(new EqualsFilter("guest"true));
  276.                     }
  277.                 }
  278.                 $items json_decode(json_encode($order->getLineItems()), true);
  279.                 $templateName 'storefront/pdf/order.html.twig';
  280.                 $template $this->twig->loadTemplate($this->twig->getTemplateClass($templateName), $templateName);
  281.                 $data["customer"] = $customer;
  282.                 $data["imageBasePath"] = $this->baseUrl '/images';
  283.                 $data["context"] = $context;
  284.                 if ($showDetails == "true") {
  285.                     $data["showDetails"] = true;
  286.                     $data["maxpage"] = ceil(sizeof($items) / 4);
  287.                 } else {
  288.                     $data["showDetails"] = false;
  289.                     $data["maxpage"] = ceil(sizeof($items) / 20);
  290.                 }
  291.                 $html $template->renderBlock('body_html'$data);
  292.                 $defaultConfig = (new ConfigVariables())->getDefaults();
  293.                 $fontDirs $defaultConfig['fontDir'];
  294.                 $defaultFontConfig = (new FontVariables())->getDefaults();
  295.                 $fontData $defaultFontConfig['fontdata'];
  296.                 if ($showDetails == "true") {
  297.                     $mpdf = new Mpdf([
  298.                         'mode' => 'utf-8',
  299.                         'format' => 'A4',
  300.                         'margin_left' => 10,
  301.                         'margin_right' => 10,
  302.                         'margin_top' => 15,
  303.                         'margin_bottom' => 25,
  304.                         'orientation' => 'P',
  305.                         'fontDir' => array_merge($fontDirs, [
  306.                             __DIR__ '/fonts',
  307.                         ]),
  308.                         'fontdata' => $fontData + [
  309.                             'thesans' => [
  310.                                 'R' => 'TheSans_B2_500_.ttf',
  311.                                 'B' => 'TheSans_B2_700_.ttf'
  312.                             ],
  313.                             'slimbach' => [
  314.                                 'R' => 'SlimbachEF-Book.ttf'
  315.                             ],
  316.                         ],
  317.                         'default_font' => 'thesans',
  318.                         'default_font_size' => 11
  319.                     ]);
  320.                 } else {
  321.                     $mpdf = new Mpdf([
  322.                         'mode' => 'utf-8',
  323.                         'format' => 'A4-L',
  324.                         'margin_left' => 10,
  325.                         'margin_right' => 10,
  326.                         'margin_top' => 15,
  327.                         'margin_bottom' => 25,
  328.                         'orientation' => 'P',
  329.                         'fontDir' => array_merge($fontDirs, [
  330.                             __DIR__ '/fonts',
  331.                         ]),
  332.                         'fontdata' => $fontData + [
  333.                             'thesans' => [
  334.                                 'R' => 'TheSans_B2_500_.ttf',
  335.                                 'B' => 'TheSans_B2_700_.ttf'
  336.                             ],
  337.                             'slimbach' => [
  338.                                 'R' => 'SlimbachEF-Book.ttf'
  339.                             ],
  340.                         ],
  341.                         'default_font' => 'thesans',
  342.                         'default_font_size' => 11
  343.                     ]);
  344.                 }
  345.                 $mpdf->showImageErrors true;
  346.                 $mpdf->defaultheaderline 0;
  347.                 $mpdf->defaultfooterline 0;
  348.                 $mpdf->defaultfooterfontstyle 'R';
  349.                 if ($language == "en") {
  350.                     $title "Martel_Order_" trim(str_replace("`"""str_replace("'"""$order->getOrderNumber())));
  351.                 } elseif ($language == "fr") {
  352.                     $title "Martel_Commande_" trim(str_replace("`"""str_replace("'"""$order->getOrderNumber())));
  353.                 } else {
  354.                     $title "Martel_Bestellung_" trim(str_replace("`"""str_replace("'"""$order->getOrderNumber())));
  355.                 }
  356.                 $filename $title ".pdf";
  357.                 $mpdf->setTitle($title);
  358.                 if ($showDetails == "false") {
  359.                     // $mpdf->SetHTMLFooter('
  360.                     //     <table width="100%">
  361.                     //         <tr>
  362.                     //             <td width="33%" align="right" style="padding-right: 30px;">Seite {PAGENO} von {nbpg}</td> 
  363.                     //         </tr>
  364.                     //     </table>');
  365.                 }
  366.                 $mpdf->writeHTML($html);
  367.                 $basePath $this->configService->get("NextagMail.config.pdfFilepath");
  368.                 $filepath $basePath "/" $title ".pdf";
  369.                 $mpdf->Output($filepath'F');
  370.                 return $filepath;
  371.             }
  372.         } catch (\Exception $e) {
  373.             $this->log->error($efalse);
  374.             return $e->getmessage();
  375.         }
  376.     }
  377.     public function createEventPdfs($order$data)
  378.     {
  379.         try {
  380.             $files = [];
  381.             if ($order) {
  382.                 $context \Shopware\Core\Framework\Context::createDefaultContext();
  383.                 $orderCustomer $order->getOrderCustomer();
  384.                 if ($orderCustomer->getCustomer()) {
  385.                     $customer $orderCustomer->getCustomer();
  386.                 } else {
  387.                     $criteria = new Criteria();
  388.                     $criteria->addFilter(new EqualsFilter("email"$orderCustomer->getEmail()));
  389.                     $criteria->addFilter(new EqualsFilter("guest"false));
  390.                     $customer $this->customerRepository->search($criteria$context)->first();
  391.                     if (!$customer) {
  392.                         $criteria = new Criteria();
  393.                         $criteria->addFilter(new EqualsFilter("email"$orderCustomer->getEmail()));
  394.                         $criteria->addFilter(new EqualsFilter("guest"true));
  395.                     }
  396.                 }
  397.                 $fileCounter 1;
  398.                 foreach ($order->getLineItems() as $lineItem) {
  399.                     $payload $lineItem->getPayload();
  400.                     if ($payload && isset($payload["customData"]) && !is_array($payload["customData"])) {
  401.                         if (isset($payload["isEvent"]) &&  $payload["isEvent"] == true) {
  402.                             $language "de";
  403.                             //$templateName = 'storefront/pdf/event.html.twig';
  404.                             //$template = $this->twig->loadTemplate($this->twig->getTemplateClass($templateName), $templateName);
  405.                             $data["customer"] = $customer;
  406.                             $data["order"] = $order;
  407.                             $data["lineItem"] = $lineItem;
  408.                             $data["payload"] = $payload;
  409.                             $data["imageBasePath"] = $this->baseUrl '/images';
  410.                             $data["context"] = $context;
  411.                             //$html = $template->renderBlock('body_html', $data);
  412.                             $html '<img src="https://www.martel.ch/images/event/martel-event-pdf-bg-05.png" style="width: 100%">';
  413.                             
  414.                             if (!empty($payload["eventTitle"]) || !empty($payload["eventName"])) {
  415.                                 $eventText = !empty($payload["eventTitle"]) ? $payload["eventTitle"] : $payload["eventName"];
  416.                                 $html .= '<div style="position:absolute; top: 425px; left: 70px; width: 600px; height: 70px; font-family: slimbach; font-size: 38px;">' $eventText '</div>';
  417.                             }
  418.                             
  419.                             if($payload["eventDate"] && $payload["eventTime"] && $payload["eventLocation"]) {
  420.                                 $html .= '<div style="position:absolute; top: 503px; left: 70px; width: 350px; height: 120px;">';
  421.                                 if($payload["eventDateTextReplace"]) {
  422.                                     $html .= $payload["eventDateTextReplace"] . '<br>';
  423.                                 } else {
  424.                                     $html .= $payload["eventDate"] . '<br>';
  425.                                 }
  426.                                 $html .= $payload["eventTime"] . '<br>' $payload["eventLocation"];
  427.                                 if($payload["eventWineConsultationBookingOptionsChoice"]) {
  428.                                     $html .= '<br>Degustationsberatung: ' $payload["eventWineConsultationBookingOptionsChoice"];
  429.                                 }
  430.                                 $html .= '</div>';
  431.                             }
  432.                             
  433.                             if($payload["recipients"]) {
  434.                                 $html .= '<div style="position:absolute; top: 503px; left: 430px; width: 330px; height: 170px;">';
  435.                                     foreach ($payload["recipients"] as $user) {
  436.                                         $html .= $user["firstname"] . ' ' $user["lastname"] . '<br>';
  437.                                     }
  438.                                 $html .= '</div>';
  439.                             }
  440.                             $html .= '<div style="font-size: 11px; position:absolute; top: 635px; left: 70px; width: 200px; height: 20px;">Ausstelldatum: ' date("d.m.y") . '</div>';  
  441.                             $defaultConfig = (new ConfigVariables())->getDefaults();
  442.                             $fontDirs $defaultConfig['fontDir'];
  443.                             $defaultFontConfig = (new FontVariables())->getDefaults();
  444.                             $fontData $defaultFontConfig['fontdata'];
  445.                             $mpdf = new Mpdf([
  446.                                 'mode' => 'utf-8',
  447.                                 'format' => 'A4',
  448.                                 'margin_left' => 0,
  449.                                 'margin_right' => 0,
  450.                                 'margin_top' => 0,
  451.                                 'margin_bottom' => 0,
  452.                                 'orientation' => 'P',
  453.                                 'fontDir' => array_merge($fontDirs, [
  454.                                     __DIR__ '/fonts',
  455.                                 ]),
  456.                                 'fontdata' => $fontData + [
  457.                                     'thesans' => [
  458.                                         'R' => 'TheSans_B2_500_.ttf',
  459.                                         'B' => 'TheSans_B2_700_.ttf'
  460.                                     ],
  461.                                     'slimbach' => [
  462.                                         'R' => 'SlimbachEF-Book.ttf'
  463.                                     ],
  464.                                 ],
  465.                                 'default_font' => 'thesans',
  466.                                 'default_font_size' => 11
  467.                             ]);
  468.                             $mpdf->showImageErrors true;
  469.                             $mpdf->defaultheaderline 0;
  470.                             $mpdf->defaultfooterline 0;
  471.                             $mpdf->defaultfooterfontstyle 'R';
  472.                             if ($language == "en") {
  473.                                 $title "Martel_Event-Ticket_" trim(str_replace("`"""str_replace("'"""$order->getOrderNumber() . "_" $fileCounter)));
  474.                             } elseif ($language == "fr") {
  475.                                 $title "Martel_Event-Ticket_" trim(str_replace("`"""str_replace("'"""$order->getOrderNumber() . "_" $fileCounter)));
  476.                             } else {
  477.                                 $title "Martel_Event-Ticket_" trim(str_replace("`"""str_replace("'"""$order->getOrderNumber() . "_" $fileCounter)));
  478.                             }
  479.                             $filename $title ".pdf";
  480.                             $mpdf->setTitle($title);
  481.                             if (isset($showDetails) && $showDetails == "false") {
  482.                                 // $mpdf->SetHTMLFooter('
  483.                                 //     <table width="100%">
  484.                                 //         <tr>
  485.                                 //             <td width="33%" align="right" style="padding-right: 30px;">Seite {PAGENO} von {nbpg}</td> 
  486.                                 //         </tr>
  487.                                 //     </table>');
  488.                             }
  489.                             $mpdf->writeHTML($html);
  490.                             $basePath $this->configService->get("NextagMail.config.pdfFilepath");
  491.                             $filepath $basePath "/" $title ".pdf";
  492.                             $mpdf->Output($filepath'F');
  493.                             $files[] = $filepath;
  494.                         }
  495.                     }
  496.                     $fileCounter++;
  497.                 }
  498.             }
  499.             return $files;
  500.         } catch (\Exception $e) {
  501.             $this->log->error($efalse);
  502.             return $e->getmessage();
  503.         }
  504.     }
  505.     public function processOrderEmails($order$config$orderExtension null)
  506.     {
  507.         try {
  508.             if ($config["orderconfirmation"]["status"]) {
  509.                 $config["mailType"] = "orderConfirmation";
  510.                 $config['email'] = $config["orderconfirmation"]["email"];
  511.                 $config['bccEmail'] = $config["orderconfirmation"]["bccEmail"];
  512.                 $this->sendEmail($order$config$orderExtension);
  513.             }
  514.             if ($config["orderconfirmationinternal"]["status"]) {
  515.                 $config["mailType"] = "orderConfirmationInternal";
  516.                 $config['email'] = $config["orderconfirmationinternal"]["email"];
  517.                 $config['bccEmail'] = $config["orderconfirmationinternal"]["bccEmail"];
  518.                 $this->sendEmail($order$config$orderExtension);
  519.             }
  520.         } catch (\Exception $e) {
  521.             $this->log->error($e);
  522.         }
  523.     }
  524.     private function getEmailAddresses($emails$order)
  525.     {
  526.         $emailArr = [];
  527.         $emailsSplit explode(','$emails);
  528.         foreach ($emailsSplit as $mail) {
  529.             $mailStr trim($mail);
  530.             if ($mailStr === '[KUNDE]') {
  531.                 $emailArr[] = trim($order->getOrderCustomer()->getFirstname() . " " $order->getOrderCustomer()->getLastname()) . ' <' $order->getOrderCustomer()->getEmail() . '>';
  532.             } else {
  533.                 $emailArr[] = $mailStr;
  534.             }
  535.         }
  536.         return $emailArr;
  537.     }
  538.     public function sendAccountDeleteRequest($customer$data)
  539.     {
  540.         try {
  541.             setlocale(LC_ALL"de_CH.UTF-8");
  542.             $subject "Martel Online-Shop: Anfrage zum Löschen eines Kundenkontos";
  543.             $type "accountdeleterequest";
  544.             $from $this->configService->get("core.basicInformation.email");
  545.             if ($this->configService->get("core.basicInformation.shopName")) {
  546.                 $from $this->configService->get("core.basicInformation.shopName") . ' <' $from '>';
  547.             } else {
  548.                 $from "Martel Online Shop" ' <' $from '>';
  549.             }
  550.             $mimeType "application/json";
  551.             $sendTo = [$this->configService->get("core.basicInformation.email")];
  552.             if ($sendTo) {
  553.                 $email $this->getMessage(
  554.                     $type,
  555.                     $from,
  556.                     $sendTo,
  557.                     ['technik@nextag.ch'],
  558.                     $subject,
  559.                     $data,
  560.                     [],
  561.                     []
  562.                 );
  563.             }
  564.             $this->mailSender->send($email);
  565.         } catch (\Exception $e) {
  566.             $this->log->error($e);
  567.         }
  568.     }
  569.     public function sendExportOrderError($filepath)
  570.     {
  571.         try {
  572.             setlocale(LC_ALL"de_CH.UTF-8");
  573.             $subject "Fehler in Martel Online-Shop: Bestellung konnte nicht nach Abacus übertragen werden";
  574.             $type "exportordererror";
  575.             $data = [];
  576.             $from $this->configService->get("core.basicInformation.email");
  577.             if ($this->configService->get("core.basicInformation.shopName")) {
  578.                 $from $this->configService->get("core.basicInformation.shopName") . ' <' $from '>';
  579.             } else {
  580.                 $from "Martel Online Shop" ' <' $from '>';
  581.             }
  582.             $mimeType "application/json";
  583.             $filename explode("/"$filepath);
  584.             $attachment = [
  585.                 'content' => file_get_contents($filepath),
  586.                 'fileName' => $filename[sizeof($filename) - 1],
  587.                 'mimeType' => $mimeType
  588.             ];
  589.             $attachments[] = $attachment;
  590.             $sendTo explode(","$this->configService->get("NextagStoremanager.config.exportSendTo"));
  591.             if ($sendTo) {
  592.                 $email $this->getMessage(
  593.                     $type,
  594.                     $from,
  595.                     $sendTo,
  596.                     ['technik@nextag.ch'],
  597.                     $subject,
  598.                     $data,
  599.                     [],
  600.                     $attachments
  601.                 );
  602.             }
  603.             $this->mailSender->send($email);
  604.         } catch (\Exception $e) {
  605.             $this->log->error($e);
  606.         }
  607.     }
  608.     public function sendExportOrderMissingError($errors$type)
  609.     {
  610.         try {
  611.             setlocale(LC_ALL"de_CH.UTF-8");
  612.             $subject "Fehler in Martel Online-Shop: Bestellung konnte nicht nach " $type " übertragen werden";
  613.             $type "exportordermissingerror";
  614.             $data["errors"] = implode("<br>"$errors);
  615.             $from $this->configService->get("core.basicInformation.email");
  616.             if ($this->configService->get("core.basicInformation.shopName")) {
  617.                 $from $this->configService->get("core.basicInformation.shopName") . ' <' $from '>';
  618.             } else {
  619.                 $from "Martel Online Shop" ' <' $from '>';
  620.             }
  621.             $sendTo explode(","$this->configService->get("NextagStoremanager.config.errorSendTo"));
  622.             if ($sendTo) {
  623.                 $email $this->getMessage(
  624.                     $type,
  625.                     $from,
  626.                     $sendTo,
  627.                     [],
  628.                     $subject,
  629.                     $data,
  630.                     [],
  631.                     []
  632.                 );
  633.             }
  634.             $this->mailSender->send($email);
  635.         } catch (\Exception $e) {
  636.             $this->log->error($e);
  637.         }
  638.     }
  639.     public function sendAddressChange($oldAddress$newAddressJsonArray$filepath)
  640.     {
  641.         try {
  642.             setlocale(LC_ALL"de_CH.UTF-8");
  643.             $this->log->info("sendAddressChange start");
  644.             $subject "Adressänderung in Martel Online-Shop";
  645.             $type "addresschange";
  646.             $data = [
  647.                 "oldAddress" => $oldAddress,
  648.                 "newAddress" => $newAddressJsonArray
  649.             ];
  650.             $from $this->configService->get("core.basicInformation.email");
  651.             if ($this->configService->get("core.basicInformation.shopName")) {
  652.                 $from $this->configService->get("core.basicInformation.shopName") . ' <' $from '>';
  653.             } else {
  654.                 $from "Marrtel Online Shop" ' <' $from '>';
  655.             }
  656.             $mimeType "application/json";
  657.             $this->log->info("filepath" $filepath);
  658.             $filename explode("/"$filepath);
  659.             $this->log->info("before attachment");
  660.             $attachment = [
  661.                 'content' => file_get_contents($filepath),
  662.                 'fileName' => $filename[sizeof($filename) - 1],
  663.                 'mimeType' => $mimeType
  664.             ];
  665.             $attachments[] = $attachment;
  666.             $sendTo explode(","$this->configService->get("NextagStoremanager.config.exportSendToAddressChange"));
  667.             $this->log->info("before send");
  668.             if ($sendTo) {
  669.                 $email $this->getMessage(
  670.                     $type,
  671.                     $from,
  672.                     $sendTo,
  673.                     ['technik@nextag.ch'],
  674.                     $subject,
  675.                     $data,
  676.                     null,
  677.                     $attachments
  678.                 );
  679.             }
  680.             $this->mailSender->send($email);
  681.             $this->log->info("sendAddressChange end");
  682.         } catch (\Exception $e) {
  683.             $this->log->error($e);
  684.         }
  685.     }
  686.     public function sendErrorMail($errormessage)
  687.     {
  688.         try {
  689.             setlocale(LC_ALL"de_CH.UTF-8");
  690.             $subject "Martel Online-Shop Fehlermeldung: " $errormessage;
  691.             $type "error";
  692.             $data = [
  693.                 "message" => $errormessage
  694.             ];
  695.             $from $this->configService->get("core.basicInformation.email");
  696.             if ($this->configService->get("core.basicInformation.shopName")) {
  697.                 $from $this->configService->get("core.basicInformation.shopName") . ' <' $from '>';
  698.             } else {
  699.                 $from "Martel Online Shop" ' <' $from '>';
  700.             }
  701.             $attachments = [];
  702.             $sendTo explode(","$this->configService->get("NextagStoremanager.config.errorSendTo"));
  703.             $email $this->getMessage(
  704.                 $type,
  705.                 $from,
  706.                 $sendTo,
  707.                 null,
  708.                 $subject,
  709.                 $data,
  710.                 null,
  711.                 $attachments
  712.             );
  713.             $this->mailSender->send($email);
  714.         } catch (\Exception $e) {
  715.             $this->log->error($e);
  716.         }
  717.     }
  718.     public function sendImportErrorLog($filepath)
  719.     {
  720.         try {
  721.             setlocale(LC_ALL"de_CH.UTF-8");
  722.             $subject "Martel Online-Shop: fehlende Preise";
  723.             $type "importproductlog";
  724.             $data = [];
  725.             $from $this->configService->get("core.basicInformation.email");
  726.             if ($this->configService->get("core.basicInformation.shopName")) {
  727.                 $from $this->configService->get("core.basicInformation.shopName") . ' <' $from '>';
  728.             } else {
  729.                 $from "Martel Online Shop" ' <' $from '>';
  730.             }
  731.             $mimeType "application/json";
  732.             $filename explode("/"$filepath);
  733.             $attachment = [
  734.                 'content' => file_get_contents($filepath),
  735.                 'fileName' => $filename[sizeof($filename) - 1],
  736.                 'mimeType' => $mimeType
  737.             ];
  738.             $attachments[] = $attachment;
  739.             $sendTo explode(","$this->configService->get("NextagStoremanager.config.exportSendTo"));
  740.             $email $this->getMessage(
  741.                 $type,
  742.                 $from,
  743.                 $sendTo,
  744.                 ['technik@nextag.ch'],
  745.                 $subject,
  746.                 $data,
  747.                 null,
  748.                 $attachments
  749.             );
  750.             $this->mailSender->send($email);
  751.         } catch (\Exception $e) {
  752.             $this->log->error($e);
  753.         }
  754.     }
  755. }