Exemplo n.º 1
0
 /**
  * @magentoConfigFixture sales_email/invoice/enabled 1
  * @magentoConfigFixture current_store design/theme/full_name default/default/default
  * @magentoDataFixture Mage/Sales/_files/order.php
  */
 public function testSendEmail()
 {
     $order = new Mage_Sales_Model_Order();
     $order->loadByIncrementId('100000001');
     $order->setCustomerEmail('*****@*****.**');
     $invoice = new Mage_Sales_Model_Order_Invoice();
     $invoice->setOrder($order);
     $paymentInfoBlock = Mage::helper('Mage_Payment_Helper_Data')->getInfoBlock($order->getPayment());
     $paymentInfoBlock->setArea('invalid-area');
     $invoice->setPaymentInfoBlock($paymentInfoBlock);
     $this->assertNull($invoice->getEmailSent());
     $invoice->sendEmail(true);
     $this->assertTrue($invoice->getEmailSent());
     $this->assertEquals('frontend', $paymentInfoBlock->getArea());
 }
Exemplo n.º 2
0
 /**
  * Set capture transaction ID and enable Void to invoice for informational purposes
  * @param Mage_Sales_Model_Order_Invoice $invoice
  * @param Mage_Sales_Model_Order_Payment $payment
  * @return Mage_Payment_Model_Method_Abstract
  */
 public function processInvoice($invoice, $payment)
 {
     if ($payment->getLastTransId()) {
         $invoice->setTransactionId($payment->getLastTransId());
         $invoice->setCanVoidFlag(true);
         if (Mage::helper('sales')->canSendNewInvoiceEmail($payment->getOrder()->getStoreId())) {
             $invoice->setEmailSent(true);
             $invoice->sendEmail();
         }
         return $this;
     }
     return false;
 }
Exemplo n.º 3
0
 /**
  * Send appropriate emails to customer based on configuration.
  * see MageBase_DpsPaymentExpress_Model_System_Invoiceconfig for the config options
  *
  * @param Mage_Sales_Model_Order         $order
  * @param Mage_Sales_Model_Order_Invoice $invoice
  */
 protected function _sendEmails($order, $invoice)
 {
     switch (Mage::getStoreConfig('payment/' . $this->_code . '/emailstosend', $this->getStore())) {
         case MageBase_DpsPaymentExpress_Model_Method_Common::EMAIL_SEND_INVOICE:
             // send invoice email only
             $invoice->sendEmail();
             break;
         case MageBase_DpsPaymentExpress_Model_Method_Common::EMAIL_SEND_BOTH:
             // send both
             $order->sendNewOrderEmail();
             $invoice->sendEmail();
             break;
         case MageBase_DpsPaymentExpress_Model_Method_Common::EMAIL_SEND_ORDER:
             // default - send order email only
         // default - send order email only
         default:
             $order->sendNewOrderEmail();
             break;
     }
 }
Exemplo n.º 4
0
 /**
  * send invoice to customer if that was configured by the merchant
  *
  * @param Mage_Sales_Model_Order_Invoice $invoice Invoice to be sent
  *
  * @return void
  */
 public function sendInvoiceToCustomer(Mage_Sales_Model_Order_Invoice $invoice)
 {
     if (false == $invoice->getEmailSent() && $this->getConfig()->getSendInvoice()) {
         $invoice->sendEmail($notifyCustomer = true);
     }
 }
Exemplo n.º 5
0
 /**
  * @param Mage_Sales_Model_Order_Invoice $invoice
  */
 protected function sendInvoiceEmail(Mage_Sales_Model_Order_Invoice $invoice)
 {
     $invoice->setEmailSent(true);
     $invoice->sendEmail();
     $invoice->save();
 }
Exemplo n.º 6
0
 /**
  * Send email with invoice data
  *
  * @param boolean $notifyCustomer
  * @param string $comment
  * @return Mage_Sales_Model_Order_Invoice
  */
 public function sendEmail($notifyCustomer = true, $comment = '')
 {
     if (!Mage::getStoreConfig('pdfpro/config/enabled')) {
         return parent::sendEmail($notifyCustomer, $comment);
     }
     switch (Mage::getStoreConfig('pdfpro/config/invoice_email_attach')) {
         case VES_PdfPro_Model_Source_Attach::ATTACH_TYPE_NO:
             return parent::sendEmail();
         case VES_PdfPro_Model_Source_Attach::ATTACH_TYPE_ADMIN:
             $this->sendEmailForAdmin($notifyCustomer, $comment, true);
             $this->sendEmailForCustomer($notifyCustomer, $comment, false);
             return $this;
         case VES_PdfPro_Model_Source_Attach::ATTACH_TYPE_CUSTOMER:
             $this->sendEmailForAdmin($notifyCustomer, $comment, false);
             $this->sendEmailForCustomer($notifyCustomer, $comment, true);
             return $this;
     }
     $order = $this->getOrder();
     $storeId = $order->getStore()->getId();
     if (!Mage::helper('sales')->canSendNewInvoiceEmail($storeId)) {
         return $this;
     }
     // Get the destination email addresses to send copies to
     $copyTo = $this->_getEmails(self::XML_PATH_EMAIL_COPY_TO);
     $copyMethod = Mage::getStoreConfig(self::XML_PATH_EMAIL_COPY_METHOD, $storeId);
     // Check if at least one recepient is found
     if (!$notifyCustomer && !$copyTo) {
         return $this;
     }
     // Start store emulation process
     $appEmulation = Mage::getSingleton('pdfpro/app_emulation');
     if ($appEmulation) {
         $initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);
     }
     try {
         // Retrieve specified view block from appropriate design package (depends on emulated store)
         $paymentBlock = Mage::helper('payment')->getInfoBlock($order->getPayment())->setIsSecureMode(true);
         $paymentBlock->getMethod()->setStore($storeId);
         $paymentBlockHtml = $paymentBlock->toHtml();
     } catch (Exception $exception) {
         // Stop store emulation process
         if ($appEmulation) {
             $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
         }
         throw $exception;
     }
     // Stop store emulation process
     if ($appEmulation) {
         $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
     }
     // Retrieve corresponding email template id and customer name
     if ($order->getCustomerIsGuest()) {
         $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_GUEST_TEMPLATE, $storeId);
         $customerName = $order->getBillingAddress()->getName();
     } else {
         $templateId = Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE, $storeId);
         $customerName = $order->getCustomerName();
     }
     $mailer = Mage::getModel('pdfpro/email_template_mailer');
     if ($notifyCustomer) {
         $emailInfo = Mage::getModel('pdfpro/email_info');
         $emailInfo->addTo($order->getCustomerEmail(), $customerName);
         if ($copyTo && $copyMethod == 'bcc') {
             // Add bcc to customer email
             foreach ($copyTo as $email) {
                 $emailInfo->addBcc($email);
             }
         }
         $mailer->addEmailInfo($emailInfo);
     }
     // Email copies are sent as separated emails if their copy method is 'copy' or a customer should not be notified
     if ($copyTo && ($copyMethod == 'copy' || !$notifyCustomer)) {
         foreach ($copyTo as $email) {
             $emailInfo = Mage::getModel('pdfpro/email_info');
             $emailInfo->addTo($email);
             $mailer->addEmailInfo($emailInfo);
         }
     }
     // Set all required params and send emails
     $mailer->setSender(Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $storeId));
     $mailer->setStoreId($storeId);
     $mailer->setTemplateId($templateId);
     $mailer->setTemplateParams(array('order' => $order, 'invoice' => $this, 'comment' => $comment, 'billing' => $order->getBillingAddress(), 'payment_html' => $paymentBlockHtml));
     /* Attach Invoice PDF in email */
     $invoiceData = Mage::getModel('pdfpro/order_invoice')->initInvoiceData($this);
     try {
         $result = Mage::helper('pdfpro')->initPdf(array($invoiceData));
         if ($result['success']) {
             $mailer->setPdf(array('filename' => Mage::helper('pdfpro')->getFileName('invoice', $this) . '.pdf', 'content' => $result['content']));
         } else {
             Mage::log($result['msg']);
         }
     } catch (Exception $e) {
         Mage::log($e->getMessage());
     }
     $mailer->send();
     $this->setEmailSent(true);
     $this->_getResource()->saveAttribute($this, 'email_sent');
     return $this;
 }