/** * Collect address subtotal * * @param Address $address * @return $this */ public function collect(Address $address) { parent::collect($address); $address->setTotalQty(0); $baseVirtualAmount = $virtualAmount = 0; /** * Process address items */ $items = $this->_getAddressItems($address); foreach ($items as $item) { if ($this->_initItem($address, $item) && $item->getQty() > 0) { /** * Separately calculate subtotal only for virtual products */ if ($item->getProduct()->isVirtual()) { $virtualAmount += $item->getRowTotal(); $baseVirtualAmount += $item->getBaseRowTotal(); } } else { $this->_removeItem($address, $item); } } $address->setBaseVirtualAmount($baseVirtualAmount); $address->setVirtualAmount($virtualAmount); /** * Initialize grand totals */ $this->_salesData->checkQuoteAmount($address->getQuote(), $address->getSubtotal()); $this->_salesData->checkQuoteAmount($address->getQuote(), $address->getBaseSubtotal()); return $this; }
/** * @return bool */ public function canSendCommentEmail() { switch ($this->getParentType()) { case 'invoice': return $this->_salesData->canSendInvoiceCommentEmail($this->getEntity()->getOrder()->getStore()->getId()); case 'shipment': return $this->_salesData->canSendShipmentCommentEmail($this->getEntity()->getOrder()->getStore()->getId()); case 'creditmemo': return $this->_salesData->canSendCreditmemoCommentEmail($this->getEntity()->getOrder()->getStore()->getId()); } return true; }
/** * Check allow to send order comment email * * @return bool */ public function canSendCommentEmail() { return $this->_salesData->canSendOrderCommentEmail($this->getOrder()->getStore()->getId()); }
/** * Check if new invoice emails can be sent * * @return bool */ public function canSendInvoiceEmail() { return $this->_salesData->canSendNewInvoiceEmail($this->getOrder()->getStore()->getId()); }
/** * Check allow to send new credit memo email * * @return bool */ public function canSendCreditmemoEmail() { return $this->_salesData->canSendNewCreditmemoEmail($this->getOrder()->getStore()->getId()); }
/** * Collect totals * * @return $this */ public function collectTotals() { /** * Protect double totals collection */ if ($this->getTotalsCollectedFlag()) { return $this; } $this->_eventManager->dispatch($this->_eventPrefix . '_collect_totals_before', array($this->_eventObject => $this)); $this->_collectItemsQtys(); $this->setSubtotal(0); $this->setBaseSubtotal(0); $this->setSubtotalWithDiscount(0); $this->setBaseSubtotalWithDiscount(0); $this->setGrandTotal(0); $this->setBaseGrandTotal(0); foreach ($this->getAllAddresses() as $address) { $address->setSubtotal(0); $address->setBaseSubtotal(0); $address->setGrandTotal(0); $address->setBaseGrandTotal(0); $address->collectTotals(); $this->setSubtotal((double) $this->getSubtotal() + $address->getSubtotal()); $this->setBaseSubtotal((double) $this->getBaseSubtotal() + $address->getBaseSubtotal()); $this->setSubtotalWithDiscount((double) $this->getSubtotalWithDiscount() + $address->getSubtotalWithDiscount()); $this->setBaseSubtotalWithDiscount((double) $this->getBaseSubtotalWithDiscount() + $address->getBaseSubtotalWithDiscount()); $this->setGrandTotal((double) $this->getGrandTotal() + $address->getGrandTotal()); $this->setBaseGrandTotal((double) $this->getBaseGrandTotal() + $address->getBaseGrandTotal()); } $this->_salesData->checkQuoteAmount($this, $this->getGrandTotal()); $this->_salesData->checkQuoteAmount($this, $this->getBaseGrandTotal()); $this->setData('trigger_recollect', 0); $this->_validateCouponCode(); $this->_eventManager->dispatch($this->_eventPrefix . '_collect_totals_after', array($this->_eventObject => $this)); $this->setTotalsCollectedFlag(true); return $this; }
/** * Check allow to send new order confirmation email * * @return bool */ public function canSendNewOrderConfirmationEmail() { return $this->_salesData->canSendNewOrderConfirmationEmail($this->getQuote()->getStoreId()); }
/** * 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; }
/** * @dataProvider getScopeConfigValue * @return void */ public function testCanSendCreditmemoCommentEmail($scopeConfigValue) { $this->setupScopeConfigIsSetFlag(\Magento\Sales\Model\Order\Email\Container\CreditmemoCommentIdentity::XML_PATH_EMAIL_ENABLED, $scopeConfigValue); $this->assertEquals($scopeConfigValue, $this->helper->canSendCreditmemoCommentEmail($this->storeMock)); }