Esempio n. 1
0
 /**
  * Loads values from MailModel into Mail
  *
  * @param \Enlight_Components_Mail $mail
  * @param \Shopware\Models\Mail\Mail $mailModel
  * @param array $overrideConfig
  * @return \Enlight_Components_Mail
  * @throws \Enlight_Exception
  */
 public function loadValues(\Enlight_Components_Mail $mail, \Shopware\Models\Mail\Mail $mailModel, $overrideConfig = array())
 {
     $stringCompiler = $this->getStringCompiler();
     $subject = $stringCompiler->compileString($mailModel->getSubject());
     if (!empty($subject)) {
         $mail->setSubject($subject);
     }
     if (!empty($overrideConfig["fromMail"])) {
         $fromMail = $overrideConfig["fromMail"];
     } else {
         $fromMail = $stringCompiler->compileString($mailModel->getFromMail());
     }
     if (!empty($overrideConfig["fromName"])) {
         $fromName = $overrideConfig["fromName"];
     } else {
         $fromName = $stringCompiler->compileString($mailModel->getFromName());
     }
     if (!empty($fromMail) && !empty($fromName)) {
         $mail->setFrom($fromMail, $fromName);
     } elseif (!empty($fromMail)) {
         $mail->setFrom($fromMail);
     }
     $bodyText = $stringCompiler->compileString($mailModel->getContent());
     $mail->setBodyText($bodyText);
     if ($mailModel->isHtml()) {
         $mail->setBodyHtml($stringCompiler->compileString($mailModel->getContentHtml()));
     }
     /** @var $attachment \Shopware\Models\Mail\Attachment */
     foreach ($mailModel->getAttachments() as $attachment) {
         if ($attachment->getShopId() !== null && ($this->getShop() === null || $attachment->getShopId() != $this->getShop()->getId())) {
             continue;
         }
         $mediaService = Shopware()->Container()->get('shopware_media.media_service');
         if (!$mediaService->has($attachment->getPath())) {
             Shopware()->Container()->get('corelogger')->error('Could not load file: ' . $attachment->getPath());
         } else {
             $fileAttachment = $mail->createAttachment($mediaService->read($attachment->getPath()));
             $fileAttachment->filename = $attachment->getFileName();
         }
     }
     return $mail;
 }
Esempio n. 2
0
 /**
  * Loads values from MailModel into Mail
  *
  * @param \Enlight_Components_Mail $mail
  * @param \Shopware\Models\Mail\Mail $mailModel
  * @param array $overrideConfig
  * @return \Enlight_Components_Mail
  * @throws \Enlight_Exception
  */
 public function loadValues(\Enlight_Components_Mail $mail, \Shopware\Models\Mail\Mail $mailModel, $overrideConfig = array())
 {
     $stringCompiler = $this->getStringCompiler();
     $subject = $stringCompiler->compileString($mailModel->getSubject());
     if (!empty($subject)) {
         $mail->setSubject($subject);
     }
     if (!empty($overrideConfig["fromMail"])) {
         $fromMail = $overrideConfig["fromMail"];
     } else {
         $fromMail = $stringCompiler->compileString($mailModel->getFromMail());
     }
     if (!empty($overrideConfig["fromName"])) {
         $fromName = $overrideConfig["fromName"];
     } else {
         $fromName = $stringCompiler->compileString($mailModel->getFromName());
     }
     if (!empty($fromMail) && !empty($fromName)) {
         $mail->setFrom($fromMail, $fromName);
     } elseif (!empty($fromMail)) {
         $mail->setFrom($fromMail);
     }
     $bodyText = $stringCompiler->compileString($mailModel->getContent());
     $mail->setBodyText($bodyText);
     if ($mailModel->isHtml()) {
         $mail->setBodyHtml($stringCompiler->compileString($mailModel->getContentHtml()));
     }
     /** @var $attachment \Shopware\Models\Mail\Attachment */
     foreach ($mailModel->getAttachments() as $attachment) {
         if ($attachment->getShopId() !== null && ($this->getShop() === null || $attachment->getShopId() != $this->getShop()->getId())) {
             continue;
         }
         if (false === ($fileHandle = fopen($attachment->getPath(), 'r'))) {
             throw new \Enlight_Exception('Could not load file: ' . $attachment->getPath());
         }
         $fileAttachment = $mail->createAttachment($fileHandle);
         $fileAttachment->filename = $attachment->getFileName();
     }
     return $mail;
 }