コード例 #1
0
ファイル: orders.php プロジェクト: Doluci/tomatocart
 function loadOrder()
 {
     global $toC_Json;
     $osC_Order = new osC_Order(isset($_REQUEST['orders_id']) ? $_REQUEST['orders_id'] : null);
     require_once '../includes/classes/customer.php';
     $osC_Customer = new osC_Customer();
     $osC_Customer->setCustomerData($osC_Order->getCustomersID());
     $enable_store_credit = false;
     if ($osC_Order->isUseStoreCredit() || $osC_Customer->hasStoreCredit()) {
         $enable_store_credit = true;
     }
     $data = array('customers_name' => $osC_Order->_customer['name'], 'currency' => $osC_Order->getCurrency(), 'email_address' => $osC_Order->_customer['email_address'], 'coupon_code' => $osC_Order->_coupon_code, 'payment_method' => $osC_Order->getPaymentModule(), 'use_store_credit' => $osC_Order->isUseStoreCredit(), 'has_payment_method' => $osC_Order->hasPaymentMethod(), 'enable_store_credit' => $enable_store_credit, 'gift_wrapping' => $osC_Order->_customer['gift_wrapping'] == '1' ? true : false, 'wrapping_message' => $osC_Order->_customer['wrapping_message'], 'billing_address' => str_replace(',', ' ', $osC_Order->getBilling('name')) . ',' . $osC_Order->getBilling('company') . ',' . $osC_Order->getBilling('street_address') . ',' . $osC_Order->getBilling('suburb') . ',' . $osC_Order->getBilling('city') . ',' . $osC_Order->getBilling('postcode') . ',' . $osC_Order->getBilling('state') . ',' . $osC_Order->getBilling('country_title'), 'shipping_address' => str_replace(',', ' ', $osC_Order->getDelivery('name')) . ',' . $osC_Order->getDelivery('company') . ',' . $osC_Order->getDelivery('street_address') . ',' . $osC_Order->getDelivery('suburb') . ',' . $osC_Order->getDelivery('city') . ',' . $osC_Order->getDelivery('postcode') . ',' . $osC_Order->getDelivery('state') . ',' . $osC_Order->getDelivery('country_title'));
     unset($_SESSION['osC_Customer_data']);
     $response = array('success' => true, 'data' => $data);
     echo $toC_Json->encode($response);
 }
コード例 #2
0
 function _calculate($set_shipping = true)
 {
     global $osC_Currencies, $osC_Tax, $osC_Weight, $osC_Shipping, $osC_OrderTotal, $osC_Customer;
     //put the order currency code in the session for order total modules and shipping modules
     $_SESSION['currency'] = $this->getCurrency();
     $this->restoreStoreCredit();
     require_once '../includes/classes/customer.php';
     $osC_Customer = new osC_Customer();
     $osC_Customer->setCustomerData($this->getCustomersID());
     $this->_sub_total = 0;
     $this->_total = 0;
     $this->_weight = 0;
     $this->_tax = 0;
     $this->_tax_groups = array();
     $this->_shipping_boxes_weight = 0;
     $this->_shipping_boxes = 0;
     $this->_shipping_quotes = array();
     $this->_order_totals = array();
     if ($this->hasContents()) {
         foreach ($this->_contents as $products_id => $data) {
             $products_weight = $osC_Weight->convert($data['weight'], $data['weight_class_id'], SHIPPING_WEIGHT_UNIT);
             $this->_weight += $products_weight * $data['quantity'];
             $tax = $osC_Tax->getTaxRate($data['tax_class_id'], $this->getTaxingAddress('country_id'), $this->getTaxingAddress('zone_id'));
             $tax_description = $osC_Tax->getTaxRateDescription($data['tax_class_id'], $this->getTaxingAddress('country_id'), $this->getTaxingAddress('zone_id'));
             //update tax to database
             $this->_contents[$products_id]['tax'] = $tax;
             $this->_updateProductTax($this->_contents[$products_id]['orders_products_id'], $tax);
             $shown_price = $osC_Currencies->addTaxRateToPrice($data['final_price'], $tax, $data['quantity']);
             $this->_sub_total += $shown_price;
             $this->_total += $shown_price;
             if (DISPLAY_PRICE_WITH_TAX == '1') {
                 $tax_amount = $shown_price - $shown_price / ($tax < 10 ? '1.0' . str_replace('.', '', $tax) : '1.' . str_replace('.', '', $tax));
             } else {
                 $tax_amount = $tax / 100 * $shown_price;
                 //oscommerce 3 bug, no matter the tax is displayed or not, tax should not be add to total
                 $this->_total += $tax_amount;
             }
             $this->_tax += $tax_amount;
             if (isset($this->_tax_groups[$tax_description])) {
                 $this->_tax_groups[$tax_description] += $tax_amount;
             } else {
                 $this->_tax_groups[$tax_description] = $tax_amount;
             }
         }
         $this->_shipping_boxes_weight = $this->_weight;
         $this->_shipping_boxes = 1;
         if (SHIPPING_BOX_WEIGHT >= $this->_shipping_boxes_weight * SHIPPING_BOX_PADDING / 100) {
             $this->_shipping_boxes_weight = $this->_shipping_boxes_weight + SHIPPING_BOX_WEIGHT;
         } else {
             $this->_shipping_boxes_weight = $this->_shipping_boxes_weight + $this->_shipping_boxes_weight * SHIPPING_BOX_PADDING / 100;
         }
         if ($this->_shipping_boxes_weight > SHIPPING_MAX_WEIGHT) {
             // Split into many boxes
             $this->_shipping_boxes = ceil($this->_shipping_boxes_weight / SHIPPING_MAX_WEIGHT);
             $this->_shipping_boxes_weight = $this->_shipping_boxes_weight / $this->_shipping_boxes;
         }
         if ($set_shipping === true) {
             unset($_SESSION['osC_ShoppingCart_data']['shipping_quotes']);
             if (!class_exists('osC_Shipping')) {
                 include 'includes/classes/shipping.php';
             }
             //check if this order already have a delivery method
             if (!empty($this->_deliver_module)) {
                 $osC_Shipping = new osC_Shipping($this->_deliver_module);
                 $this->setShippingMethod($osC_Shipping->getQuote(), false);
             } else {
                 if (!$this->hasShippingMethod() || $this->getShippingMethod('is_cheapest') === true) {
                     $osC_Shipping = new osC_Shipping();
                     $this->setShippingMethod($osC_Shipping->getCheapestQuote(), false);
                 } else {
                     $osC_Shipping = new osC_Shipping($this->getShippingMethod('id'));
                     $this->setShippingMethod($osC_Shipping->getQuote(), false);
                 }
             }
         }
     }
     if (!class_exists('osC_OrderTotal')) {
         include 'includes/classes/order_total.php';
     }
     $osC_OrderTotal = new osC_OrderTotal();
     $this->_order_totals = $osC_OrderTotal->getResult();
     if ($this->isUseStoreCredit()) {
         $this->insertStoreCredit();
     }
     unset($_SESSION['currency']);
     unset($_SESSION['osC_Customer_data']);
 }