예제 #1
0
 /**
  * Prepare and send email message
  *
  * @return void
  */
 public function send()
 {
     $this->configureEmailTemplate();
     $this->transportBuilder->addTo($this->identityContainer->getCustomerEmail(), $this->identityContainer->getCustomerName());
     $copyTo = $this->identityContainer->getEmailCopyTo();
     if (!empty($copyTo) && $this->identityContainer->getCopyMethod() == 'bcc') {
         foreach ($copyTo as $email) {
             $this->transportBuilder->addBcc($email);
         }
     }
     $transport = $this->transportBuilder->getTransport();
     $transport->sendMessage();
 }
 /**
  * @covers \Magento\Framework\Mail\Template\TransportBuilder::addBcc
  */
 public function testAddBcc()
 {
     $this->messageMock->expects($this->once())->method('addBcc')->with('*****@*****.**')->will($this->returnSelf());
     $this->builder->addBcc('*****@*****.**');
 }
예제 #3
0
 /**
  * Send email with order update information
  *
  * @param boolean $notifyCustomer
  * @param string $comment
  * @return $this
  */
 public function sendOrderUpdateEmail($notifyCustomer = true, $comment = '')
 {
     $storeId = $this->getStore()->getId();
     if (!$this->_salesData->canSendOrderCommentEmail($storeId)) {
         return $this;
     }
     // Get the destination email addresses to send copies to
     $copyTo = $this->_getEmails(self::XML_PATH_UPDATE_EMAIL_COPY_TO);
     $copyMethod = $this->_scopeConfig->getValue(self::XML_PATH_UPDATE_EMAIL_COPY_METHOD, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId);
     // Check if at least one recipient is found
     if (!$notifyCustomer && !$copyTo) {
         return $this;
     }
     // Retrieve corresponding email template id and customer name
     if ($this->getCustomerIsGuest()) {
         $templateId = $this->_scopeConfig->getValue(self::XML_PATH_UPDATE_EMAIL_GUEST_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId);
         $customerName = $this->getBillingAddress()->getName();
     } else {
         $templateId = $this->_scopeConfig->getValue(self::XML_PATH_UPDATE_EMAIL_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId);
         $customerName = $this->getCustomerName();
     }
     if ($notifyCustomer) {
         $this->_transportBuilder->setTemplateIdentifier($templateId)->setTemplateOptions(array('area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $storeId))->setTemplateVars(array('order' => $this, 'comment' => $comment, 'billing' => $this->getBillingAddress(), 'store' => $this->getStore()))->setFrom($this->_scopeConfig->getValue(self::XML_PATH_UPDATE_EMAIL_IDENTITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId))->addTo($this->getCustomerEmail(), $customerName);
         if ($copyTo && $copyMethod == 'bcc') {
             // Add bcc to customer email
             foreach ($copyTo as $email) {
                 $this->_transportBuilder->addBcc($email);
             }
         }
         /** @var \Magento\Framework\Mail\TransportInterface $transport */
         $transport = $this->_transportBuilder->getTransport();
         $transport->sendMessage();
     }
     // 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) {
             $this->_transportBuilder->setTemplateIdentifier($templateId)->setTemplateOptions(array('area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $storeId))->setTemplateVars(array('order' => $this, 'comment' => $comment, 'billing' => $this->getBillingAddress(), 'store' => $this->getStore()))->setFrom($this->_scopeConfig->getValue(self::XML_PATH_UPDATE_EMAIL_IDENTITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId))->addTo($email)->getTransport()->sendMessage();
         }
     }
     return $this;
 }