示例#1
0
function oaGetShippingCostTakingIntoTax($cartContent, $shippingMethodID, $addresses, $orderDetails, $CALC_TAX = TRUE, $shServiceID = 0, $shServiceFull = FALSE)
{
    $Rates = array();
    $SimpleFormat = false;
    $shipping_method = shGetShippingMethodById($shippingMethodID);
    if ($shipping_method) {
        $shippingModule = modGetModuleObj($shipping_method["module_id"], SHIPPING_RATE_MODULE);
        if ($shippingModule) {
            //shipping address
            if (!is_array($addresses[0])) {
                $shippingAddress = regGetAddress($addresses[0]);
            } else {
                $shippingAddress = $addresses[0];
            }
            //order content
            $order = array("first_name" => $orderDetails["first_name"], "last_name" => $orderDetails["last_name"], "email" => $orderDetails["email"], "orderContent" => $cartContent, "order_amount" => $orderDetails["order_amount"]);
            $Rates = $shippingModule->calculate_shipping_rate($order, $shippingAddress, $shServiceID);
            if (!is_array($Rates)) {
                $Rates = array(array('name' => '', 'rate' => $Rates));
            }
        }
    }
    if (!count($Rates)) {
        $Rates[] = array('rate' => '0', 'name' => '');
    }
    foreach ($Rates as $_ind => $_Rate) {
        $Rates[$_ind]['rate'] += $cartContent["freight_cost"];
    }
    if ($CALC_TAX) {
        if (is_array($addresses[0])) {
            $rate = taxCalculateTaxByClass2(CONF_CALCULATE_TAX_ON_SHIPPING, $addresses[0], $addresses[1]);
        } else {
            $rate = taxCalculateTaxByClass(CONF_CALCULATE_TAX_ON_SHIPPING, $addresses[0], $addresses[1]);
        }
        foreach ($Rates as $_ind => $_Rate) {
            $Rates[$_ind]['rate'] += $Rates[$_ind]['rate'] / 100 * $rate;
        }
    }
    return $Rates;
}
示例#2
0
function getOrderSummarize($shippingMethodID, $paymentMethodID, $shippingAddressID, $billingAddressID, $shippingModuleFiles, $paymentModulesFiles, $shServiceID = 0)
{
    // result this function
    $sumOrderContent = array();
    $q = db_query('select email_comments_text from ' . PAYMENT_TYPES_TABLE . ' where PID=' . (int) $paymentMethodID);
    $payment_email_comments_text = db_fetch_row($q);
    $payment_email_comments_text = $payment_email_comments_text[0];
    $q = db_query('select email_comments_text from ' . SHIPPING_METHODS_TABLE . ' where SID=' . (int) $shippingMethodID);
    $shipping_email_comments_text = db_fetch_row($q);
    $shipping_email_comments_text = $shipping_email_comments_text[0];
    $cartContent = cartGetCartContent();
    $pred_total = oaGetClearPrice($cartContent);
    if (isset($_SESSION['log'])) {
        $log = $_SESSION['log'];
    } else {
        $log = null;
    }
    $d = oaGetDiscountPercent($cartContent, $log);
    $discount = $pred_total / 100 * $d;
    // ordering with registration
    if ($shippingAddressID != 0 || isset($log)) {
        $addresses = array($shippingAddressID, $billingAddressID);
        $shipping_address = regGetAddressStr($shippingAddressID);
        $billing_address = regGetAddressStr($billingAddressID);
        $shaddr = regGetAddress($shippingAddressID);
        $sh_firstname = $shaddr['first_name'];
        $sh_lastname = $shaddr['last_name'];
    } else {
        if (!isset($_SESSION['receiver_countryID']) || !isset($_SESSION['receiver_zoneID'])) {
            return NULL;
        }
        $shippingAddress = array('countryID' => $_SESSION['receiver_countryID'], 'zoneID' => $_SESSION['receiver_zoneID']);
        $billingAddress = array('countryID' => $_SESSION['billing_countryID'], 'zoneID' => $_SESSION['billing_zoneID']);
        $addresses = array($shippingAddress, $billingAddress);
        $shipping_address = quickOrderGetReceiverAddressStr();
        $billing_address = quickOrderGetBillingAddressStr();
        $sh_firstname = $_SESSION['receiver_first_name'];
        $sh_lastname = $_SESSION['receiver_last_name'];
    }
    foreach ($cartContent['cart_content'] as $key => $cartItem) {
        // if conventional ordering
        if ($shippingAddressID != 0) {
            $productID = GetProductIdByItemId($cartItem['id']);
            $cartItem['tax'] = taxCalculateTax($productID, $addresses[0], $addresses[1]);
        } else {
            $productID = $cartItem['id'];
            $cartItem['tax'] = taxCalculateTax2($productID, $addresses[0], $addresses[1]);
        }
        if (!empty($cartItem['opt_margin']) && $paymentMethodID == 2) {
            $cost = $cartItem['costUC'];
            $margin = $cost / 100 * CONF_PERCENT_MARGIN;
            $cost += $margin;
            $costShow = show_price($cost * $cartItem['quantity']);
            $pred_total += $margin * $cartItem['quantity'];
            $cartContent['cart_content'][$key]['costUC'] = $cost;
            $cartContent['cart_content'][$key]['cost'] = $costShow;
            $cartItem['costUC'] = $cost;
            $cartItem['cost'] = $costShow;
        }
        $sumOrderContent[] = $cartItem;
    }
    $shipping_method = shGetShippingMethodById($shippingMethodID);
    if (!$shipping_method) {
        $shipping_name = '-';
    } else {
        $shipping_name = $shipping_method['Name'];
    }
    $payment_method = payGetPaymentMethodById($paymentMethodID);
    if (!$payment_method) {
        $payment_name = '-';
    } else {
        $payment_name = $payment_method['Name'];
    }
    //do not calculate tax for this payment type!
    if (isset($payment_method['calculate_tax']) && (int) $payment_method['calculate_tax'] == 0) {
        foreach ($sumOrderContent as $key => $val) {
            $sumOrderContent[$key]['tax'] = 0;
        }
        $orderDetails = array('first_name' => $sh_firstname, 'last_name' => $sh_lastname, 'email' => '', 'order_amount' => oaGetOrderAmountExShippingRate($cartContent, $addresses, $log, FALSE, $shServiceID));
        $tax = 0;
        $total = oaGetOrderAmount($cartContent, $addresses, $shippingMethodID, $log, $orderDetails, FALSE, $shServiceID);
        $shipping_cost = oaGetShippingCostTakingIntoTax($cartContent, $shippingMethodID, $addresses, $orderDetails, FALSE, $shServiceID);
    } else {
        $orderDetails = array('first_name' => $sh_firstname, 'last_name' => $sh_lastname, 'email' => '', 'order_amount' => oaGetOrderAmountExShippingRate($cartContent, $addresses, $log, FALSE));
        $tax = oaGetProductTax($cartContent, $d, $addresses);
        $total = oaGetOrderAmount($cartContent, $addresses, $shippingMethodID, $log, $orderDetails, TRUE, $shServiceID);
        $shipping_cost = oaGetShippingCostTakingIntoTax($cartContent, $shippingMethodID, $addresses, $orderDetails, TRUE, $shServiceID);
    }
    $tServiceInfo = null;
    if (is_array($shipping_cost)) {
        $_T = array_shift($shipping_cost);
        $tServiceInfo = $_T['name'];
        $shipping_cost = $_T['rate'];
    }
    $payment_form_html = '';
    $paymentModule = modGetModuleObj($payment_method['module_id'], PAYMENT_MODULE);
    if ($paymentModule) {
        $order = array();
        $address = array();
        if ($shippingAddressID != 0) {
            $payment_form_html = $paymentModule->payment_form_html(array('BillingAddressID' => $billingAddressID));
        } else {
            $payment_form_html = $paymentModule->payment_form_html(array('countryID' => $_SESSION['billing_countryID'], 'zoneID' => $_SESSION['billing_zoneID'], 'first_name' => $_SESSION['billing_first_name'], 'last_name' => $_SESSION['billing_last_name'], 'city' => $_SESSION['billing_city'], 'address' => $_SESSION['billing_address']));
        }
    }
    return array('sumOrderContent' => $sumOrderContent, 'discount' => $discount, 'discount_percent' => $d, 'discount_show' => show_price($discount), 'pred_total_disc' => show_price($pred_total * ((100 - $d) / 100)), 'pred_total' => show_price($pred_total), 'totalTax' => show_price($tax), 'totalTaxUC' => $tax, 'shipping_address' => $shipping_address, 'billing_address' => $billing_address, 'shipping_name' => $shipping_name, 'payment_name' => $payment_name, 'shipping_cost' => show_price($shipping_cost), 'shipping_costUC' => $shipping_cost, 'payment_form_html' => $payment_form_html, 'total' => show_price($total), 'totalUC' => $total, 'payment_email_comments_text' => $payment_email_comments_text, 'shipping_email_comments_text' => $shipping_email_comments_text, 'orderContentCartProductsCount' => count($sumOrderContent), 'shippingServiceInfo' => $tServiceInfo);
}
示例#3
0
 $order = _getOrder();
 $strAddress = regGetAddressStr($shippingAddressID);
 $moduleFiles = GetFilesInDirectory("core/modules/shipping", "php");
 foreach ($moduleFiles as $fileName) {
     include $fileName;
 }
 $shipping_methods = shGetAllShippingMethods(true);
 $shipping_costs = array();
 $res = cartGetCartContent();
 $sh_address = regGetAddress($shippingAddressID);
 $addresses = array($sh_address, $sh_address);
 $j = 0;
 foreach ($shipping_methods as $key => $shipping_method) {
     $_ShippingModule = modGetModuleObj($shipping_method["module_id"], SHIPPING_RATE_MODULE);
     if ($_ShippingModule) {
         if ($_ShippingModule->allow_shipping_to_address(regGetAddress($shippingAddressID))) {
             $shipping_costs[$j] = oaGetShippingCostTakingIntoTax($res, $shipping_method["SID"], $addresses, $order);
         } else {
             $shipping_costs[$j] = array(array('rate' => -1));
         }
     } else {
         $shipping_costs[$j] = oaGetShippingCostTakingIntoTax($res, $shipping_method["SID"], $addresses, $order);
     }
     $j++;
 }
 $_i = count($shipping_costs) - 1;
 for (; $_i >= 0; $_i--) {
     $_t = count($shipping_costs[$_i]) - 1;
     for (; $_t >= 0; $_t--) {
         if ($shipping_costs[$_i][$_t]['rate'] > 0) {
             $shipping_costs[$_i][$_t]['rate'] = show_price($shipping_costs[$_i][$_t]['rate']);
示例#4
0
function regGetAddressStr($addressID, $NoTransform = false)
{
    $address = regGetAddress($addressID);
    // countryID, zoneID, state
    $country = cnGetCountryById($address["countryID"]);
    $country = $country["country_name"];
    if (trim($address["state"]) == "") {
        $zone = znGetSingleZoneById($address["zoneID"]);
        $zone = $zone["zone_name"];
    } else {
        $zone = trim($address["state"]);
    }
    if ($country != "") {
        $strAddress = $address["first_name"] . "  " . $address["last_name"];
        if (strlen($address["address"]) > 0) {
            $strAddress .= "<br>" . $address["address"];
        }
        if (strlen($address["city"]) > 0) {
            $strAddress .= "<br>" . $address["city"];
        }
        if (strlen($zone) > 0) {
            $strAddress .= "  " . $zone;
        }
        if (strlen($country) > 0) {
            $strAddress .= "<br>" . $country;
        }
    } else {
        $strAddress = $address["first_name"] . "  " . $address["last_name"];
        if (strlen($address["address"]) > 0) {
            $strAddress .= "<br>" . $address["address"];
        }
        if (strlen($address["city"]) > 0) {
            $strAddress .= "<br>" . $address["city"];
        }
        if (strlen($zone) > 0) {
            $strAddress .= " " . $zone;
        }
    }
    return $strAddress;
}
示例#5
0
function taxCalculateTaxByClass($taxClassID, $shippingAddressID, $billingAddressID)
{
    $shippingAddress = regGetAddress($shippingAddressID);
    $billingAddress = regGetAddress($billingAddressID);
    return taxCalculateTaxByClass2($taxClassID, $shippingAddress, $billingAddress);
}