Advertisement
Guest User

Untitled

a guest
Oct 24th, 2014
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.36 KB | None | 0 0
  1.     public function sendNewOrderEmail()
  2.     {
  3.         $storeId = $this->getStore()->getId();
  4.  
  5.         if (!Mage::helper('sales')->canSendNewOrderEmail($storeId)) {
  6.             return $this;
  7.         }
  8.  
  9.         $emailSentAttributeValue = $this->load($this->getId())->getData('email_sent');
  10.         $this->setEmailSent((bool)$emailSentAttributeValue);
  11.         if ($this->getEmailSent()) {
  12.             return $this;
  13.         }
  14.  
  15.         // Get the destination email addresses to send copies to
  16.         $copyTo = $this->_getEmails(self::XML_PATH_EMAIL_COPY_TO);
  17.         $copyMethod = Mage::getStoreConfig(self::XML_PATH_EMAIL_COPY_METHOD, $storeId);
  18.  
  19.         // Start store emulation process
  20.         $appEmulation = Mage::getSingleton('core/app_emulation');
  21.         $initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);
  22.  
  23.         try {
  24.             // Retrieve specified view block from appropriate design package (depends on emulated store)
  25.             $paymentBlock = Mage::helper('payment')->getInfoBlock($this->getPayment())
  26.                 ->setIsSecureMode(true);
  27.             $paymentBlock->getMethod()->setStore($storeId);
  28.             $paymentBlockHtml = $paymentBlock->toHtml();
  29.         } catch (Exception $exception) {
  30.             // Stop store emulation process
  31.             $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
  32.             throw $exception;
  33.         }
  34.  
  35.         // Stop store emulation process
  36.         $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
  37.  
  38.         // Retrieve corresponding email template id and customer name
  39.         if ($this->getCustomerIsGuest()) {
  40.             $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_GUEST_TEMPLATE, $storeId);
  41.             $customerName = $this->getBillingAddress()->getName();
  42.         } else {
  43.             $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE, $storeId);
  44.             $customerName = $this->getCustomerName();
  45.         }
  46.  
  47.         $mailer = Mage::getModel('core/email_template_mailer');
  48.         $emailInfo = Mage::getModel('core/email_info');
  49.         $emailInfo->addTo($this->getCustomerEmail(), $customerName);
  50.         if ($copyTo && $copyMethod == 'bcc') {
  51.             // Add bcc to customer email
  52.             foreach ($copyTo as $email) {
  53.                 $emailInfo->addBcc($email);
  54.             }
  55.         }
  56.         $mailer->addEmailInfo($emailInfo);
  57.  
  58.         // Email copies are sent as separated emails if their copy method is 'copy'
  59.         if ($copyTo && $copyMethod == 'copy') {
  60.             foreach ($copyTo as $email) {
  61.                 $emailInfo = Mage::getModel('core/email_info');
  62.                 $emailInfo->addTo($email);
  63.                 $mailer->addEmailInfo($emailInfo);
  64.             }
  65.         }
  66.  
  67.         // Set all required params and send emails
  68.         $mailer->setSender(Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $storeId));
  69.         $mailer->setStoreId($storeId);
  70.         $mailer->setTemplateId($templateId);
  71.         $mailer->setTemplateParams(array(
  72.                 'order'        => $this,
  73.                 'billing'      => $this->getBillingAddress(),
  74.                 'payment_html' => $paymentBlockHtml
  75.             )
  76.         );
  77.         $mailer->send();
  78.  
  79.         $this->setEmailSent(true);
  80.         $this->_getResource()->saveAttribute($this, 'email_sent');
  81.  
  82.         return $this;
  83.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement