/**
  * Returns the shipping costs or null
  *
  * @return integer|null
  */
 protected function getShippingCosts()
 {
     $isOrderNet = (bool) $this->Order->getNet() || (bool) $this->Order->getTaxFree();
     if ($this->Order->getInvoiceShipping() >= 0) {
         if (!$isOrderNet) {
             return $this->Order->getInvoiceShipping();
         } else {
             $taxRate = 0;
             // Use the highest tax rate
             if ($this->Order->getDispatch()->getTaxCalculation() == 0) {
                 /** @var $detail Shopware\Models\Order\Detail */
                 foreach ($this->Order->getDetails() as $detail) {
                     $taxRate = max($taxRate, $detail->getTaxRate());
                 }
             } else {
                 $tax = Shopware()->Models()->find('Shopware\\Models\\Tax\\Tax', $this->Order->getDispatch()->getTaxCalculation());
                 if ($tax instanceof Shopware\Models\Tax\Tax) {
                     $taxRate = $tax->getTax();
                 }
             }
             if (!$taxRate) {
                 return $this->Order->getDispatch()->getTaxCalculation();
             } else {
                 return $this->Order->getInvoiceShipping() * ((100 + $taxRate) / 100);
             }
         }
     }
     return null;
 }
コード例 #2
0
 /**
  * @param \Shopware\Models\Order\Order $orderModel
  * @return array
  */
 private function prepareOrderConfirmationMailData($orderModel)
 {
     $billingAddress = Shopware()->Db()->fetchRow('SELECT *, userID AS customerBillingId FROM s_order_billingaddress WHERE orderID = ?', [$orderModel->getId()]);
     $billingAddressAttributes = Shopware()->Db()->fetchRow('SELECT * FROM s_order_billingaddress_attributes WHERE billingID = ?', [$billingAddress['id']]);
     if (!empty($billingAddressAttributes)) {
         $billingAddress = array_merge($billingAddress, $billingAddressAttributes);
     }
     /** @var \Shopware_Components_CreateBackendOrder $createBackendOrder */
     $createBackendOrder = Shopware()->CreateBackendOrder();
     if ($createBackendOrder->getEqualBillingAddress()) {
         $shippingAddress = $billingAddress;
     } else {
         $shippingAddress = Shopware()->Db()->fetchRow('SELECT *, userID AS customerBillingId FROM s_order_shippingaddress WHERE orderID = ?', [$orderModel->getId()]);
         $shippingAddressAttributes = Shopware()->Db()->fetchRow('SELECT * FROM s_order_shippingaddress_attributes WHERE shippingID = ?', [$shippingAddress['id']]);
         if (!empty($shippingAddressAttributes)) {
             $shippingAddress = array_merge($shippingAddress, $shippingAddressAttributes);
         }
     }
     $context['billingaddress'] = $billingAddress;
     $context['shippingaddress'] = $shippingAddress;
     $context['sOrderNumber'] = $orderModel->getNumber();
     $currency = $orderModel->getCurrency();
     $context['sCurrency'] = $currency;
     $context['sAmount'] = $orderModel->getInvoiceAmount() . ' ' . $currency;
     $context['sAmountNet'] = $orderModel->getInvoiceAmountNet() . ' ' . $currency;
     $context['sShippingCosts'] = $orderModel->getInvoiceShipping() . ' ' . $currency;
     $orderTime = $orderModel->getOrderTime();
     $context['sOrderDay'] = $orderTime->format('d.m.Y');
     $context['sOrderTime'] = $orderTime->format('H:i');
     $context['sComment'] = '';
     $context['sLanguage'] = $orderModel->getLanguageSubShop()->getId();
     $context['sSubShop'] = $orderModel->getShop()->getId();
     $orderAttributes = Shopware()->Db()->fetchRow('SELECT * FROM s_order_attributes WHERE orderID = ?', [$orderModel->getId()]);
     $context['attributes'] = $orderAttributes;
     $dispatch = Shopware()->Db()->fetchRow('SELECT * FROM s_premium_dispatch WHERE id = ?', [$orderModel->getDispatch()->getId()]);
     $dispatch = $this->translateDispatch($dispatch, $orderModel->getLanguageSubShop()->getId());
     $context['sDispatch'] = $dispatch;
     $user = Shopware()->Db()->fetchRow('SELECT * FROM s_user WHERE id = ?', [$orderModel->getCustomer()->getId()]);
     $context['additional']['user'] = $user;
     $country = Shopware()->Db()->fetchRow('SELECT * FROM s_core_countries WHERE id = ?', [$orderModel->getBilling()->getCountry()->getId()]);
     $context['additional']['country'] = $country;
     $context['additional']['state'] = [];
     if ($orderModel->getBilling()->getState()) {
         $state = Shopware()->Db()->fetchRow('SELECT * FROM s_core_countries_states WHERE id = ?', [$orderModel->getBilling()->getState()->getId()]);
         $context['additional']['state'] = $state;
     }
     $country = Shopware()->Db()->fetchRow('SELECT * FROM s_core_countries WHERE id = ?', [$orderModel->getShipping()->getCountry()->getId()]);
     $context['additional']['countryShipping'] = $country;
     $context['additional']['stateShipping'] = [];
     if ($orderModel->getShipping()->getState()) {
         $state = Shopware()->Db()->fetchRow('SELECT * FROM s_core_countries_states WHERE id = ?', [$orderModel->getShipping()->getState()->getId()]);
         $context['additional']['stateShipping'] = $state;
     }
     $payment = Shopware()->Db()->fetchRow('SELECT * FROM s_core_paymentmeans WHERE id = ?', [$orderModel->getPayment()->getId()]);
     $payment = $this->translatePayment($payment, $orderModel->getLanguageSubShop()->getId());
     $context['additional']['payment'] = $payment;
     $context['sPaymentTable'] = [];
     if ($context['additional']['payment']['name'] === 'debit') {
         $paymentTable = Shopware()->Db()->fetchRow('SELECT * FROM s_core_payment_data WHERE user_id = ?', [$orderModel->getCustomer()->getId()]);
         $context['sPaymentTable'] = $paymentTable;
     }
     $context['additional']['show_net'] = $orderModel->getNet();
     $context['additional']['charge_var'] = 1;
     return $context;
 }