/** * @dataProvider getScopeConfigValue * @return void */ public function testCanSendNewShipmentEmail($scopeConfigValue) { $this->setupScopeConfigIsSetFlag(\Magento\Sales\Model\Order\Email\Container\ShipmentIdentity::XML_PATH_EMAIL_ENABLED, $scopeConfigValue); $this->assertEquals($scopeConfigValue, $this->helper->canSendNewShipmentEmail($this->storeMock)); }
/** * Check possibility to send shipment email * * @return bool */ public function canSendShipmentEmail() { return $this->_salesData->canSendNewShipmentEmail($this->getOrder()->getStore()->getId()); }
/** * Send email with shipment data * * @param boolean $notifyCustomer * @param string $comment * @return $this */ public function sendEmail($notifyCustomer = true, $comment = '') { $order = $this->getOrder(); $storeId = $order->getStore()->getId(); if (!$this->_salesData->canSendNewShipmentEmail($storeId)) { return $this; } // Get the destination email addresses to send copies to $copyTo = $this->_getEmails(self::XML_PATH_EMAIL_COPY_TO); $copyMethod = $this->_scopeConfig->getValue(self::XML_PATH_EMAIL_COPY_METHOD, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId); // Check if at least one recipient is found if (!$notifyCustomer && !$copyTo) { return $this; } $paymentBlockHtml = $this->_paymentData->getInfoBlockHtml($order->getPayment(), $storeId); // Retrieve corresponding email template id and customer name if ($order->getCustomerIsGuest()) { $templateId = $this->_scopeConfig->getValue(self::XML_PATH_EMAIL_GUEST_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId); $customerName = $order->getBillingAddress()->getName(); } else { $templateId = $this->_scopeConfig->getValue(self::XML_PATH_EMAIL_TEMPLATE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId); $customerName = $order->getCustomerName(); } if ($notifyCustomer) { $this->_transportBuilder->setTemplateIdentifier($templateId)->setTemplateOptions(array('area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $storeId))->setTemplateVars(array('order' => $order, 'shipment' => $this, 'comment' => $comment, 'billing' => $order->getBillingAddress(), 'payment_html' => $paymentBlockHtml, 'store' => $this->getStore()))->setFrom($this->_scopeConfig->getValue(self::XML_PATH_EMAIL_IDENTITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId))->addTo($order->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' => $order, 'shipment' => $this, 'comment' => $comment, 'billing' => $order->getBillingAddress(), 'payment_html' => $paymentBlockHtml, 'store' => $this->getStore()))->setFrom($this->_scopeConfig->getValue(self::XML_PATH_EMAIL_IDENTITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId))->addTo($email)->getTransport()->sendMessage(); } } $this->setEmailSent(true); $this->_getResource()->saveAttribute($this, 'email_sent'); return $this; }