/**
  * @param Mirasvit_Helpdesk_Model_Ticket $ticket
  *
  * @return string
  */
 public function getParsedTemplate($ticket)
 {
     $storeId = $ticket->getStoreId();
     $storeOb = Mage::getModel('core/store')->load($storeId);
     if (!($name = Mage::getStoreConfig('general/store_information/name', $storeId))) {
         $name = $storeOb->getName();
     }
     $store = new Varien_Object(array('name' => $name, 'phone' => Mage::getStoreConfig('general/store_information/phone', $storeId), 'address' => Mage::getStoreConfig('general/store_information/address', $storeId)));
     /** @var Mage_Admin_Model_User $user */
     $user = Mage::getSingleton('admin/session')->getUser();
     $result = Mage::helper('mstcore/parsevariables')->parse($this->getTemplate(), array('ticket' => $ticket, 'store' => $store, 'user' => $user), array(), $store->getId());
     return $result;
 }
예제 #2
0
 /**
  * @param Mirasvit_Helpdesk_Model_Ticket       $ticket
  * @param Mage_Customer_Model_Customer|false   $customer
  * @param Mage_Admin_Model_User|false          $user
  * @param $recipientEmail
  * @param $recipientName
  * @param $templateName
  * @param Mirasvit_Helpdesk_Model_Attachment[] $attachments
  * @param array                                $variables
  * @param bool                                 $emailFlag
  *
  * @return bool
  *
  * @throws Exception
  * @throws Zend_Mail_Exception
  */
 public function mail($ticket, $customer, $user, $recipientEmail, $recipientName, $templateName, $attachments = array(), $variables = array(), $emailFlag = false)
 {
     if ($templateName == 'none') {
         return false;
     }
     $storeId = $ticket->getStoreId();
     $config = Mage::getSingleton('helpdesk/config');
     if ($config->getDeveloperIsActive($storeId)) {
         if ($sandboxEmail = $config->getDeveloperSandboxEmail($storeId)) {
             $recipientEmail = $sandboxEmail;
         }
     }
     $department = $ticket->getDepartment();
     $store = $ticket->getStore();
     if (!$customer) {
         $customer = $ticket->getCustomer();
     }
     if (!$user) {
         $user = $ticket->getUser();
     }
     // save current design settings
     $currentDesignConfig = clone $this->_getDesignConfig();
     $this->_setDesignConfig(array('area' => 'frontend', 'store' => $store->getId()));
     $this->_applyDesignConfig();
     $variables = array_merge($variables, array('ticket' => $ticket, 'customer' => $customer, 'user' => $user, 'department' => $department, 'store' => $store, 'hidden_separator' => Mage::helper('helpdesk/email')->getHiddenSeparator(), 'logo_url' => $this->_getLogoUrl($store), 'logo_alt' => $this->_getLogoAlt($store)));
     if (isset($variables['email_subject'])) {
         $variables['email_subject'] = $this->processVariable($variables['email_subject'], $variables);
     }
     if (isset($variables['email_body'])) {
         $variables['email_body'] = $this->processVariable($variables['email_body'], $variables);
     }
     $senderName = Mage::getStoreConfig("trans_email/ident_{$department->getSenderEmail()}/name", $storeId);
     $senderEmail = Mage::getStoreConfig("trans_email/ident_{$department->getSenderEmail()}/email", $storeId);
     if (!$senderEmail) {
         return;
     }
     if (!$recipientEmail) {
         return;
     }
     $template = Mage::getModel('core/email_template');
     foreach ($attachments as $attachment) {
         /* @noinspection PhpUndefinedClassInspection */
         $template->getMail()->createAttachment($attachment->getBody(), $attachment->getType(), Zend_Mime::DISPOSITION_ATTACHMENT, Zend_Mime::ENCODING_BASE64, $attachment->getName());
     }
     $translate = Mage::getSingleton('core/translate');
     $translate->setTranslateInline(false);
     if ($emailFlag) {
         $template->getMail()->addHeader('Auto-Submitted', $emailFlag);
     }
     // Mandrill NOT ABLE to send CC - so we need an overwork
     if (method_exists($template->getMail(), 'addCc')) {
         if (count($ticket->getCc())) {
             $template->getMail()->addCc($ticket->getCc());
         }
     } else {
         $recipientEmail = array_unique(array_merge((array) $recipientEmail, $ticket->getCc()));
     }
     $bcc = array_unique(array_merge($this->getConfig()->getGeneralBccEmail($storeId), $ticket->getBcc()));
     if (count($bcc)) {
         $template->getMail()->addBcc($bcc);
     }
     $template->setDesignConfig(array('area' => 'frontend', 'store' => $storeId));
     $template->sendTransactional($templateName, array('name' => $senderName, 'email' => $senderEmail), $recipientEmail, $recipientName, $variables, $storeId);
     $text = $template->getProcessedTemplate($variables, true);
     $this->emails[] = $text;
     $translate->setTranslateInline(true);
     // restore previous design settings
     $this->_setDesignConfig($currentDesignConfig->getData());
     $this->_applyDesignConfig();
 }