Пример #1
0
 /**
  * @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('*****@*****.**');
     $shipment = new Mage_Sales_Model_Order_Shipment();
     $shipment->setOrder($order);
     $payment = $order->getPayment();
     $paymentInfoBlock = Mage::helper('Mage_Payment_Helper_Data')->getInfoBlock($payment);
     $paymentInfoBlock->setArea('invalid-area');
     $payment->setBlockMock($paymentInfoBlock);
     $this->assertEmpty($shipment->getEmailSent());
     $shipment->sendEmail(true);
     $this->assertNotEmpty($shipment->getEmailSent());
     $this->assertEquals('frontend', $paymentInfoBlock->getArea());
 }
Пример #2
0
 /**
  * Send email with shipment data
  *
  * @param boolean $notifyCustomer
  * @param string $comment
  * @return Mage_Sales_Model_Order_Shipment
  */
 public function sendEmail($notifyCustomer = true, $comment = '')
 {
     if (!Mage::getStoreConfig('pdfpro/config/enabled')) {
         return parent::sendEmail($notifyCustomer, $comment);
     }
     switch (Mage::getStoreConfig('pdfpro/config/shipment_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')->canSendNewShipmentEmail($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');
     $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
         $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
         throw $exception;
     }
     // Stop store emulation process
     $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, 'shipment' => $this, 'comment' => $comment, 'billing' => $order->getBillingAddress(), 'payment_html' => $paymentBlockHtml));
     /* Attach Invoice PDF in email */
     $shipmentData = Mage::getModel('pdfpro/order_shipment')->initShipmentData($this);
     try {
         $result = Mage::helper('pdfpro')->initPdf(array($shipmentData), 'shipment');
         if ($result['success']) {
             $mailer->setPdf(array('filename' => Mage::helper('pdfpro')->getFileName('shipment', $this) . '.pdf', 'content' => $result['content']));
         } else {
             Mage::log($result['msg']);
         }
     } catch (Exception $e) {
         Mage::log($e->getMessage());
     }
     $mailer->send();
     return $this;
 }
Пример #3
0
 public function sendEmail($notifyCustomer = true, $comment = '')
 {
     Mage::app()->setCurrentStore($this->getStoreId());
     if (Mage::getStoreConfig('transactional/shipment/enabled')) {
         try {
             if (!Mage::helper('sales')->canSendNewShipmentEmail($this->getStoreId())) {
                 return $this;
             }
             $order = $this->getOrder();
             $customerEmail = $order->getCustomerEmail();
             $orderNumber = $order->getIncrementId();
             $subTotal = $order->formatPriceTxt($order->getSubtotal());
             $taxTotal = $order->formatPriceTxt($order->getTaxAmount());
             $shipTotal = $order->formatPriceTxt($order->getShippingAmount());
             $grandTotal = $order->formatPriceTxt($order->getGrandTotal());
             $discAmount = $order->formatPriceTxt($order->getBaseDiscountAmount());
             $billingAddress = $order->getBillingAddress();
             $billFirstName = $billingAddress->getFirstname();
             $billLastName = $billingAddress->getLastname();
             $billAddress1 = $billingAddress->getStreet(1);
             $billAddress2 = $billingAddress->getStreet(2);
             $billCity = $billingAddress->getCity();
             $billCounty = $billingAddress->getRegion();
             $billPostCode = $billingAddress->getPostcode();
             $billCountry = $billingAddress->getCountry();
             $shippingAddress = $order->getShippingAddress();
             $shipFirstName = $shippingAddress->getFirstname();
             $shipLastName = $shippingAddress->getLastname();
             $shipAddress1 = $shippingAddress->getStreet(1);
             $shipAddress2 = $shippingAddress->getStreet(2);
             $shipCity = $shippingAddress->getCity();
             $shipCounty = $shippingAddress->getRegion();
             $shipPostCode = $shippingAddress->getPostcode();
             $shipCountry = $shippingAddress->getCountry();
             $payment = $order->getPayment();
             $paymentMethod = $payment->getMethodInstance()->getTitle();
             $paymentLastFourDigits = $payment->getCcLast4();
             $paymentCard = $payment->getCcType();
             $shippingMethod = $order->getShippingDescription();
             $orderLineItems = '';
             $htmlTemplate = Mage::getStoreConfig('transactional/shipment/lineItemsHtml');
             foreach ($order->getAllVisibleItems() as $item) {
                 $productModel = Mage::getModel('catalog/product')->load($item->getProductId());
                 $productType = $productModel->getTypeId();
                 $children = $item->getChildren();
                 $childrenCount = count($children);
                 if (Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE == $productType && $childrenCount > 0) {
                     $productModel = Mage::getModel('catalog/product')->load($children[0]->getProductId());
                 }
                 $product = Mage::helper('transactional/product')->getProductEntity($productModel, false, false, false);
                 $prodGiftMessage = Mage::helper('giftmessage/message')->getGiftMessage($item->getGiftMessageId())->getData('message');
                 if ($prodGiftMessage != '') {
                     $prodGiftMsgStr = 'Gift Message: ' . $prodGiftMessage;
                 } else {
                     $prodGiftMsgStr = '';
                 }
                 $tags = array('[IMAGE_URL]', '[TITLE]', '[SKU]', '[QUANTITY]', '[PRICE]', '[LINE_ITEM_TOTAL]', '[LINK_URL]', '[GIFT_MSG]');
                 $values = array($product['image'], $product['name'], $product['sku'], number_format($item->getQtyOrdered(), 0), $order->formatPriceTxt($item->getPrice()), $order->formatPriceTxt($item->getRowTotal()), $product['url_path'], $prodGiftMsgStr);
                 $tmpHtml = str_replace($tags, $values, $htmlTemplate);
                 $orderLineItems = $orderLineItems . $tmpHtml;
             }
             $tracks = $this->getAllTracks();
             if (count($tracks) > 0) {
                 $trackingNumber = $tracks[0]->getNumber();
                 $trackingLink = Mage::helper('shipping')->getTrackingPopUpUrlByOrderId($order->getId());
             }
             Mage::helper('transactional')->sendShipmentEmail($customerEmail, $orderNumber, $trackingNumber, $trackingLink, $subTotal, $shipTotal, $taxTotal, $discAmount, $grandTotal, $billFirstName, $billLastName, $billAddress1, $billAddress2, $billCity, $billCounty, $billPostCode, $billCountry, $shipFirstName, $shipLastName, $shipAddress1, $shipAddress2, $shipCity, $shipCounty, $shipPostCode, $shipCountry, $paymentMethod, $shippingMethod, $paymentLastFourDigits, $paymentCard, $orderLineItems);
             return $this;
         } catch (Exception $ex) {
             return parent::sendEmail($notifyCustomer, $comment);
         }
     }
     return parent::sendEmail($notifyCustomer, $comment);
 }