/**
  * Send email to customer
  *
  * @param Order $order
  * @param bool $notify
  * @param string $comment
  * @return bool
  */
 public function send(Order $order, $notify = true, $comment = '')
 {
     $transport = ['order' => $order, 'comment' => $comment, 'billing' => $order->getBillingAddress(), 'store' => $order->getStore(), 'formattedShippingAddress' => $this->getFormattedShippingAddress($order), 'formattedBillingAddress' => $this->getFormattedBillingAddress($order)];
     $this->eventManager->dispatch('email_order_comment_set_template_vars_before', ['sender' => $this, 'transport' => $transport]);
     $this->templateContainer->setTemplateVars($transport);
     return $this->checkAndSend($order, $notify);
 }
Пример #2
0
 /**
  * @param \Magento\Sales\Model\Order $order
  * @return bool
  */
 public function canReorder(\Magento\Sales\Model\Order $order)
 {
     if (!$this->isAllowed($order->getStore())) {
         return false;
     }
     if ($this->_customerSession->isLoggedIn()) {
         return $order->canReorder();
     } else {
         return true;
     }
 }
Пример #3
0
 /**
  * Send email to customer
  *
  * @param Order $order
  * @param bool $notify
  * @param string $comment
  * @return bool
  */
 public function send(Order $order, $notify = true, $comment = '')
 {
     if ($order->getShippingAddress()) {
         $formattedShippingAddress = $this->addressRenderer->format($order->getShippingAddress(), 'html');
     } else {
         $formattedShippingAddress = '';
     }
     $formattedBillingAddress = $this->addressRenderer->format($order->getBillingAddress(), 'html');
     $transport = new \Magento\Framework\Object(['template_vars' => ['order' => $order, 'comment' => $comment, 'billing' => $order->getBillingAddress(), 'store' => $order->getStore(), 'formattedShippingAddress' => $formattedShippingAddress, 'formattedBillingAddress' => $formattedBillingAddress]]);
     $this->eventManager->dispatch('email_order_comment_set_template_vars_before', ['sender' => $this, 'transport' => $transport]);
     $this->templateContainer->setTemplateVars($transport->getTemplateVars());
     return $this->checkAndSend($order, $notify);
 }
Пример #4
0
 /**
  * @param Order $order
  * @return bool
  */
 protected function checkAndSend(Order $order)
 {
     $this->identityContainer->setStore($order->getStore());
     if (!$this->identityContainer->isEnabled()) {
         return false;
     }
     $this->prepareTemplate($order);
     /** @var SenderBuilder $sender */
     $sender = $this->getSender();
     $sender->send();
     $sender->sendCopyTo();
     return true;
 }
Пример #5
0
 /**
  * Send email to customer
  *
  * @param Order $order
  * @param bool $notify
  * @return bool
  */
 protected function checkAndSend(Order $order, $notify = true)
 {
     $this->identityContainer->setStore($order->getStore());
     if (!$this->identityContainer->isEnabled()) {
         return false;
     }
     $this->prepareTemplate($order);
     /** @var SenderBuilder $sender */
     $sender = $this->getSender();
     if ($notify) {
         $sender->send();
     } else {
         // Email copies are sent as separated emails if their copy method is 'copy' or a customer should not be notified
         $sender->sendCopyTo();
     }
     return true;
 }
Пример #6
0
 /**
  * @param Order $order
  * @return bool
  */
 protected function checkAndSend(Order $order)
 {
     $this->identityContainer->setStore($order->getStore());
     if (!$this->identityContainer->isEnabled()) {
         return false;
     }
     $this->prepareTemplate($order);
     /** @var SenderBuilder $sender */
     $sender = $this->getSender();
     try {
         $sender->send();
         $sender->sendCopyTo();
     } catch (\Exception $e) {
         $this->logger->error($e->getMessage());
     }
     return true;
 }
Пример #7
0
 /**
  * Get calculated taxes for each tax class
  *
  * This method returns array with format:
  * array(
  *  $index => array(
  *      'tax_amount'        => $taxAmount,
  *      'base_tax_amount'   => $baseTaxAmount,
  *      'hidden_tax_amount' => $hiddenTaxAmount,
  *      'title'             => $title,
  *      'percent'           => $percent
  *  )
  * )
  *
  * @param \Magento\Sales\Model\Order $source
  * @return array
  */
 public function getCalculatedTaxes($source)
 {
     if ($this->_coreRegistry->registry('current_invoice')) {
         $current = $this->_coreRegistry->registry('current_invoice');
     } elseif ($this->_coreRegistry->registry('current_creditmemo')) {
         $current = $this->_coreRegistry->registry('current_creditmemo');
     } else {
         $current = $source;
     }
     $taxClassAmount = array();
     if ($current && $source) {
         if ($current == $source) {
             $orderTaxDetails = $this->orderTaxService->getOrderTaxDetails($current->getId());
             $appliedTaxes = $orderTaxDetails->getAppliedTaxes();
             foreach ($appliedTaxes as $appliedTax) {
                 $taxCode = $appliedTax->getCode();
                 $taxClassAmount[$taxCode]['tax_amount'] = $appliedTax->getAmount();
                 $taxClassAmount[$taxCode]['base_tax_amount'] = $appliedTax->getBaseAmount();
                 $taxClassAmount[$taxCode]['title'] = $appliedTax->getTitle();
                 $taxClassAmount[$taxCode]['percent'] = $appliedTax->getPercent();
             }
         } else {
             $orderTaxDetails = $this->orderTaxService->getOrderTaxDetails($source->getId());
             // Calculate taxes for shipping
             $shippingTaxAmount = $current->getShippingTaxAmount();
             if ($shippingTaxAmount) {
                 $shippingTax = $this->getShippingTax($current);
                 $taxClassAmount = array_merge($taxClassAmount, $shippingTax);
             }
             /** @var $item \Magento\Sales\Model\Order\Invoice\Item|\Magento\Sales\Model\Order\Creditmemo\Item */
             foreach ($current->getItemsCollection() as $item) {
                 $orderItem = $item->getOrderItem();
                 $orderItemId = $orderItem->getId();
                 $orderItemTax = $orderItem->getTaxAmount();
                 $itemTax = $item->getTaxAmount();
                 if (!$itemTax || !$orderItemTax) {
                     continue;
                 }
                 //In the case that invoiced item or creditmemo item qty is different from order item qty
                 $ratio = $itemTax / $orderItemTax;
                 $itemTaxDetails = $orderTaxDetails->getItems();
                 foreach ($itemTaxDetails as $itemTaxDetail) {
                     //Aggregate taxable items associated with an item
                     if ($itemTaxDetail->getItemId() == $orderItemId || $itemTaxDetail->getAssociatedItemId() == $orderItemId) {
                         $itemAppliedTaxes = $itemTaxDetail->getAppliedTaxes();
                         foreach ($itemAppliedTaxes as $itemAppliedTax) {
                             $taxCode = $itemAppliedTax->getCode();
                             if (!isset($taxClassAmount[$taxCode])) {
                                 $taxClassAmount[$taxCode]['title'] = $itemAppliedTax->getTitle();
                                 $taxClassAmount[$taxCode]['percent'] = $itemAppliedTax->getPercent();
                                 $taxClassAmount[$taxCode]['tax_amount'] = $itemAppliedTax->getAmount() * $ratio;
                                 $taxClassAmount[$taxCode]['base_tax_amount'] = $itemAppliedTax->getBaseAmount() * $ratio;
                             } else {
                                 $taxClassAmount[$taxCode]['tax_amount'] += $itemAppliedTax->getAmount() * $ratio;
                                 $taxClassAmount[$taxCode]['base_tax_amount'] += $itemAppliedTax->getBaseAmount() * $ratio;
                             }
                         }
                     }
                 }
             }
         }
         foreach ($taxClassAmount as $key => $tax) {
             if ($tax['tax_amount'] == 0 && $tax['base_tax_amount'] == 0) {
                 unset($taxClassAmount[$key]);
             } else {
                 $taxClassAmount[$key]['tax_amount'] = $source->getStore()->roundPrice($tax['tax_amount']);
                 $taxClassAmount[$key]['base_tax_amount'] = $source->getStore()->roundPrice($tax['base_tax_amount']);
             }
         }
         $taxClassAmount = array_values($taxClassAmount);
     }
     return $taxClassAmount;
 }
Пример #8
0
 /**
  * 2016-09-07
  * @param O|Q $oq [optional]
  * @return Currency
  */
 private function currencyFromOQ($oq)
 {
     return $this->currency($oq->getStore(), dfp_currency($oq));
 }
 /**
  * Send email to customer
  *
  * @param Order $order
  * @param bool $notify
  * @param string $comment
  * @return bool
  */
 public function send(Order $order, $notify = true, $comment = '')
 {
     $this->templateContainer->setTemplateVars(['order' => $order, 'comment' => $comment, 'billing' => $order->getBillingAddress(), 'store' => $order->getStore()]);
     return $this->checkAndSend($order, $notify);
 }
Пример #10
0
 public function informCustomer(\Magento\Sales\Model\Order $order, $amount, $currency)
 {
     try {
         if (!($order_increment_id = $order->getRealOrderId()) or !($method_config = $this->_s2pModel->getFullConfigArray())) {
             return false;
         }
         $siteUrl = $order->getStore()->getBaseUrl();
         $siteName = $this->_helper->getStoreName();
         $supportEmail = $this->_helper->getStoreConfig('trans_email/ident_support/email');
         $supportName = $this->_helper->getStoreConfig('trans_email/ident_support/name');
         $payment_details_arr['site_url'] = $siteUrl;
         $payment_details_arr['order_increment_id'] = $order_increment_id;
         $payment_details_arr['site_name'] = $siteName;
         $payment_details_arr['customer_name'] = $order->getCustomerName();
         $payment_details_arr['order_date'] = $order->getCreatedAtFormatted(\IntlDateFormatter::LONG);
         $payment_details_arr['support_email'] = $supportEmail;
         $payment_details_arr['total_paid'] = number_format($amount / 100, 2);
         $payment_details_arr['currency'] = $currency;
         $transport = $this->_transportBuilder->setTemplateIdentifier($method_config['smart2pay_email_payment_confirmation'])->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_ADMINHTML, 'store' => $order->getStore()->getId()])->setTemplateVars($payment_details_arr)->setFrom(['name' => $supportName, 'email' => $supportEmail])->addTo($order->getCustomerEmail())->getTransport();
         $transport->sendMessage();
     } catch (\Magento\Framework\Exception\MailException $e) {
         $this->_s2pLogger->write('Error sending customer informational email to [' . $order->getCustomerEmail() . ']', 'email_template');
         $this->_s2pLogger->write($e->getMessage(), 'email_exception');
     } catch (\Exception $e) {
         $this->_s2pLogger->write($e->getMessage(), 'exception');
     }
     return true;
 }
Пример #11
0
 /**
  * Get order store object
  *
  * @return \Magento\Store\Model\Store
  */
 public function getStore()
 {
     return $this->_order->getStore();
 }