/**
  * Determine the appropriate shipping method if applicable
  * By default, selects the lowest-cost quote
  */
 function setShippingMethod()
 {
     global $total_count, $total_weight;
     // ensure that cart contents is calculated properly for weight and value
     if (!isset($total_weight)) {
         $total_weight = $_SESSION['cart']->show_weight();
     }
     if (!isset($total_count)) {
         $total_count = $_SESSION['cart']->count_contents();
     }
     // set the shipping method if one is not already set
     // defaults to the cheapest shipping method
     if (!$_SESSION['shipping'] || $_SESSION['shipping'] && $_SESSION['shipping'] == false && zen_count_shipping_modules() > 1) {
         require_once DIR_WS_CLASSES . 'http_client.php';
         require_once DIR_WS_CLASSES . 'shipping.php';
         $shipping_Obj = new shipping();
         // generate the quotes
         $shipping_Obj->quote();
         // set the cheapest one
         $_SESSION['shipping'] = $shipping_Obj->cheapest();
     }
 }
    }
} else {
    $free_shipping = false;
}
// process the selected shipping method
if (isset($_POST['action']) && $_POST['action'] == 'process') {
    if (xtc_count_shipping_modules() > 0 || $free_shipping == true) {
        if (isset($_POST['shipping']) && strpos($_POST['shipping'], '_')) {
            $_SESSION['shipping'] = $_POST['shipping'];
            list($module, $method) = explode('_', $_SESSION['shipping']);
            if (is_object(${$module}) || $_SESSION['shipping'] == 'free_free') {
                if ($_SESSION['shipping'] == 'free_free') {
                    $quote[0]['methods'][0]['title'] = FREE_SHIPPING_TITLE;
                    $quote[0]['methods'][0]['cost'] = '0';
                } else {
                    $quote = $shipping_modules->quote($method, $module);
                }
                if (isset($quote['error'])) {
                    unset($_SESSION['shipping']);
                } else {
                    if (isset($quote[0]['methods'][0]['title']) && isset($quote[0]['methods'][0]['cost'])) {
                        $_SESSION['shipping'] = array('id' => $_SESSION['shipping'], 'title' => $free_shipping == true ? $quote[0]['methods'][0]['title'] : $quote[0]['module'] . ' (' . $quote[0]['methods'][0]['title'] . ')', 'cost' => $quote[0]['methods'][0]['cost']);
                        xtc_redirect(xtc_href_link(FILENAME_PAYPAL_CHECKOUT, '', 'SSL'));
                    }
                }
            } else {
                unset($_SESSION['shipping']);
            }
        }
    } else {
        $_SESSION['shipping'] = false;
示例#3
0
// Load the selected shipping module(needed to calculate tax correctly)
require DIR_WS_CLASSES . 'shipping.php';
$shipping_modules = new shipping();
require DIR_WS_CLASSES . 'order_total.php';
$order_total_modules = new order_total();
$order_total_modules->collect_posts();
$order_total_modules->pre_confirmation_check();
//4px
//require(DIR_WS_CLASSES . 'DSFShipping.php');
// $objDSFShipping = new DSFShipping();
//  $country_info = zen_get_countries($order->delivery['country_id'], true);
//var_dump($country_info, $total_weight);
//$dsf_shippings = $objDSFShipping->calculate($country_info['countries_iso_code_2'], $total_weight);
//4px end
// get all available shipping quotes
$quotes = $shipping_modules->quote();
//4px shipping
//$quotes = array_merge($dsf_shippings, $quotes);
//end 4px shipping
//  $_SESSION['comments'] = '';
$comments = $_SESSION['comments'];
if (!empty($quotes)) {
    $_SESSION['shipping_list'] = $quotes;
}
if (empty($_SESSION['sendto']) && !empty($_SESSION['billto'])) {
    $_SESSION['sendto'] = $_SESSION['billto'];
}
// load all enabled payment modules
require DIR_WS_CLASSES . 'payment.php';
$payment_modules = new payment();
$flagOnSubmit = sizeof($payment_modules->selection());
         // first timer
         $_SESSION['cart_country_id'] = STORE_COUNTRY;
         $_SESSION['country_info'] = zen_get_countries(STORE_COUNTRY, true);
         $country_info = $_SESSION['country_info'];
         $order->delivery = array('country' => array('id' => STORE_COUNTRY, 'title' => $country_info['countries_name'], 'iso_code_2' => $country_info['countries_iso_code_2'], 'iso_code_3' => $country_info['countries_iso_code_3']), 'country_id' => STORE_COUNTRY, 'zone_id' => $state_zone_id, 'format_id' => zen_get_address_format_id($_POST['zone_country_id']));
     }
     // set the cost to be able to calculate free shipping
     $order->info = array('total' => $_SESSION['cart']->show_total(), 'currency' => $currency, 'currency_value' => $currencies->currencies[$currency]['value']);
 }
 // weight and count needed for shipping !
 $total_weight = $_SESSION['cart']->show_weight();
 $shipping_estimator_display_weight = $total_weight;
 $total_count = $_SESSION['cart']->count_contents();
 require DIR_WS_CLASSES . 'shipping.php';
 $shipping_modules = new shipping();
 $quotes = $shipping_modules->quote();
 // print_r($quotes);
 // die('here');
 $order->info['subtotal'] = $_SESSION['cart']->show_total();
 // set selections for displaying
 $selected_country = $order->delivery['country']['id'];
 $selected_address = $sendto;
 // }
 // eo shipping cost
 // check free shipping based on order $total
 if (defined('MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING') && MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING == 'true') {
     switch (MODULE_ORDER_TOTAL_SHIPPING_DESTINATION) {
         case 'national':
             if ($order->delivery['country_id'] == STORE_COUNTRY) {
                 $pass = true;
             }
    if (isset($_POST['campaign_id']) && is_numeric($_POST['campaign_id'])) {
        $_SESSION['campaigns_id'] = intval($_POST['campaign_id']);
    }

    if ( (oos_count_shipping_modules() > 0) || ($free_shipping == true) ) {
        if ( (isset($_POST['shipping'])) && (strpos($_POST['shipping'], '_')) ) {
            $_SESSION['shipping'] = $_POST['shipping'];

            list($module, $method) = explode('_', $_SESSION['shipping']);
            if ( is_object($$module) || ($_SESSION['shipping'] == 'free_free') ) {
                if ($_SESSION['shipping'] == 'free_free') {
                    $quote[0]['methods'][0]['title'] = $aLang['free_shipping_title'];
                    $quote[0]['methods'][0]['cost'] = '0';
                } else {
                    $quote = $oShippingModules->quote($method, $module);
                }

                if (isset($quote['error'])) {
                   unset($_SESSION['shipping']);
                } else {
                    if ( (isset($quote[0]['methods'][0]['title'])) && (isset($quote[0]['methods'][0]['cost'])) ) {
                        $_SESSION['shipping'] = array('id' => $_SESSION['shipping'],
                                                      'title' => (($free_shipping == true) ?  $quote[0]['methods'][0]['title'] : $quote[0]['module'] . ' (' . $quote[0]['methods'][0]['title'] . ')'),
                                                      'cost' => $quote[0]['methods'][0]['cost']);

                        MyOOS_CoreApi::redirect(oos_href_link($aPages['checkout_payment'], '', 'SSL'));
                    }
                }
            } else {
                unset($_SESSION['shipping']);
示例#6
0
/**
 * Process a <merchant-calculation-callback>.
 */
function process_merchant_calculation_callback_single($google_response)
{
    global $google_checkout, $order, $cart, $total_weight, $total_count;
    list($root, $gc_data) = $google_response->GetParsedXML();
    $currencies = new currencies();
    // Get a hash array with the description of each shipping method
    $shipping_methods = $google_checkout->getMethods();
    require DIR_WS_CLASSES . 'order.php';
    $order = new order();
    $items = gc_get_arr_result($gc_data[$root]['shopping-cart']['items']['item']);
    // Get Coustoms OT
    $custom_order_totals_total = 0;
    $custom_order_totals = array();
    $order->products = array();
    foreach ($items as $item) {
        if (isset($item['merchant-private-item-data']['item']['VALUE'])) {
            $order->products[] = unserialize(base64_decode($item['merchant-private-item-data']['item']['VALUE']));
        } else {
            if ($item['merchant-private-item-data']['order_total']['VALUE']) {
                $ot = unserialize(base64_decode($item['merchant-private-item-data']['order_total']['VALUE']));
                $custom_order_totals[] = $ot;
                $order_total_value = $ot['value'] * (strrpos($ot['text'], '-') === false ? 1 : -1);
                $custom_order_totals_total += $currencies->get_value($gc_data[$root]['order-total']['currency']) * $order_total_value;
            } else {
                // For invoices.
                $order->products[] = array('qty' => $item['quantity']['VALUE'], 'name' => $item['item-name']['VALUE'], 'model' => $item['item-description']['VALUE'], 'tax' => 0, 'tax_description' => @$item['tax-table-selector']['VALUE'], 'price' => $item['unit-price']['VALUE'], 'final_price' => $item['unit-price']['VALUE'], 'onetime_charges' => 0, 'weight' => 0, 'products_priced_by_attribute' => 0, 'product_is_free' => 0, 'products_discount_type' => 0, 'products_discount_type_from' => 0, 'id' => @$item['merchant-item-id']['VALUE']);
            }
        }
    }
    $ex_cart = $cart;
    $cart = new shoppingCart();
    $prod_attr = gc_get_prattr($order->products);
    foreach ($prod_attr as $product_id => $item_data) {
        //$products_id, $qty = '1', $attributes = '
        $cart->add_cart($product_id, $item_data['qty'], $item_data['attr']);
    }
    // Register a random ID in the session to check throughout the checkout procedure
    // against alterations in the shopping cart contents.
    // TODO(eddavisson): Why is this commented out?
    //if (!tep_session_is_registered('cartID')) {
    //  tep_session_register('cartID');
    //}
    //$cartID = $cart->cartID;
    $total_weight = $cart->show_weight();
    $total_count = $cart->count_contents();
    // Create the results and send it
    $merchant_calc = new GoogleMerchantCalculations(DEFAULT_CURRENCY);
    // Loop through the list of address ids from the callback.
    $addresses = gc_get_arr_result($gc_data[$root]['calculate']['addresses']['anonymous-address']);
    // Get all the enabled shipping methods.
    require_once DIR_WS_CLASSES . 'shipping.php';
    // Required for some shipping methods (ie. USPS).
    require_once 'includes/classes/http_client.php';
    foreach ($addresses as $curr_address) {
        // Set up the order address.
        $curr_id = $curr_address['id'];
        $country = $curr_address['country-code']['VALUE'];
        $city = $curr_address['city']['VALUE'];
        $region = $curr_address['region']['VALUE'];
        $postal_code = $curr_address['postal-code']['VALUE'];
        $row = tep_db_fetch_array(tep_db_query("select * from " . TABLE_COUNTRIES . " where countries_iso_code_2 = '" . gc_make_sql_string($country) . "'"));
        $order->delivery['country'] = array('id' => $row['countries_id'], 'title' => $row['countries_name'], 'iso_code_2' => $country, 'iso_code_3' => $row['countries_iso_code_3']);
        $order->delivery['country_id'] = $row['countries_id'];
        $order->delivery['format_id'] = $row['address_format_id'];
        $row = tep_db_fetch_array(tep_db_query("select * from " . TABLE_ZONES . " where zone_code = '" . gc_make_sql_string($region) . "'"));
        $order->delivery['zone_id'] = $row['zone_id'];
        $order->delivery['state'] = $row['zone_name'];
        $order->delivery['city'] = $city;
        $order->delivery['postcode'] = $postal_code;
        //print_r($order);
        $shipping_modules = new shipping();
        // Loop through each shipping method if merchant-calculated shipping
        // support is to be provided
        //print_r($gc_data[$root]['calculate']['shipping']['method']);
        if (isset($gc_data[$root]['calculate']['shipping'])) {
            $shipping = gc_get_arr_result($gc_data[$root]['calculate']['shipping']['method']);
            // TODO(eddavisson): If we reactivate this, need to move to new configuration system.
            if (MODULE_PAYMENT_GOOGLECHECKOUT_MULTISOCKET == 'True') {
                // Single.
                // Get all the enabled shipping methods.
                $name = $shipping[0]['name'];
                // Compute the price for this shipping method and address id
                list($a, $method_name) = explode(': ', $name);
                if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY && $shipping_methods[$method_name][1] == 'domestic_types' || $order->delivery['country']['id'] != SHIPPING_ORIGIN_COUNTRY && $shipping_methods[$method_name][1] == 'international_types') {
                    // Reset the shipping class to set the new address
                    if (class_exists($shipping_methods[$method_name][2])) {
                        $GLOBALS[$shipping_methods[$method_name][2]] = new $shipping_methods[$method_name][2]();
                    }
                }
                $quotes = $shipping_modules->quote('', $shipping_methods[$method_name][2]);
            } else {
                // Standard
                foreach ($shipping as $curr_ship) {
                    $name = $curr_ship['name'];
                    // Compute the price for this shipping method and address id
                    list($a, $method_name) = explode(': ', $name);
                    if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY && $shipping_methods[$method_name][1] == 'domestic_types' || $order->delivery['country']['id'] != SHIPPING_ORIGIN_COUNTRY && $shipping_methods[$method_name][1] == 'international_types') {
                        // Reset the shipping class to set the new address.
                        if (class_exists($shipping_methods[$method_name][2])) {
                            $GLOBALS[$shipping_methods[$method_name][2]] = new $shipping_methods[$method_name][2]();
                        }
                    }
                }
                $quotes = $shipping_modules->quote();
            }
            reset($shipping);
            foreach ($shipping as $curr_ship) {
                $name = $curr_ship['name'];
                // Compute the price for this shipping method and address id
                list($a, $method_name) = explode(': ', $name);
                unset($quote_provider);
                unset($quote_method);
                if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY && $shipping_methods[$method_name][1] == 'domestic_types' || $order->delivery['country']['id'] != SHIPPING_ORIGIN_COUNTRY && $shipping_methods[$method_name][1] == 'international_types') {
                    foreach ($quotes as $key_provider => $shipping_provider) {
                        // privider name (class)
                        if ($shipping_provider['id'] == $shipping_methods[$method_name][2]) {
                            // method name
                            $quote_provider = $key_provider;
                            if (is_array($shipping_provider['methods'])) {
                                foreach ($shipping_provider['methods'] as $key_method => $shipping_method) {
                                    if ($shipping_method['id'] == $shipping_methods[$method_name][0]) {
                                        $quote_method = $key_method;
                                        break;
                                    }
                                }
                            }
                            break;
                        }
                    }
                }
                //if there is a problem with the method, i mark it as non-shippable
                if (isset($quotes[$quote_provider]['error']) || !isset($quotes[$quote_provider]['methods'][$quote_method]['cost'])) {
                    $price = "9999.09";
                    $shippable = "false";
                } else {
                    $price = $quotes[$quote_provider]['methods'][$quote_method]['cost'];
                    $shippable = "true";
                }
                $merchant_result = new GoogleResult($curr_id);
                $merchant_result->SetShippingDetails($name, $currencies->get_value(DEFAULT_CURRENCY) * $price, $shippable);
                if ($gc_data[$root]['calculate']['tax']['VALUE'] == "true") {
                    // Compute tax for this address id and shipping type
                    $amount = 15;
                    // Modify this to the actual tax value
                    $merchant_result->SetTaxDetails($currencies->get_value(DEFAULT_CURRENCY) * $amount);
                }
                if (isset($gc_data[$root]['calculate']['merchant-code-strings']['merchant-code-string'])) {
                    $codes = gc_get_arr_result($gc_data[$root]['calculate']['merchant-code-strings']['merchant-code-string']);
                    foreach ($codes as $curr_code) {
                        // Update this data as required to set whether the coupon is valid, the code and the amount
                        $coupons = new GoogleCoupons("true", $curr_code['code'], $currencies->get_value(DEFAULT_CURRENCY) * 5, "test2");
                        $merchant_result->AddCoupons($coupons);
                    }
                }
                $merchant_calc->AddResult($merchant_result);
            }
        } else {
            $merchant_result = new GoogleResult($curr_id);
            if ($gc_data[$root]['calculate']['tax']['VALUE'] == "true") {
                // Compute tax for this address id and shipping type
                $amount = 15;
                // Modify this to the actual tax value
                $merchant_result->SetTaxDetails($currencies->get_value(DEFAULT_CURRENCY) * $amount);
            }
            //calculate_coupons($google_response, $merchant_result);
            $merchant_calc->AddResult($merchant_result);
        }
    }
    $cart = $ex_cart;
    $google_response->ProcessMerchantCalculations($merchant_calc);
}
示例#7
0
 function osC_Checkout_Shipping()
 {
     global $osC_Database, $osC_Session, $osC_Customer, $osC_Services, $breadcrumb, $order, $cart, $total_weight, $total_count, $shipping_modules, $pass, $free_shipping, $quotes;
     if ($cart->count_contents() < 1) {
         tep_redirect(tep_href_link(FILENAME_CHECKOUT, '', 'SSL'));
     }
     if ($osC_Services->isStarted('breadcrumb')) {
         $breadcrumb->add(NAVBAR_TITLE_CHECKOUT_SHIPPING, tep_href_link(FILENAME_CHECKOUT, $this->_module, 'SSL'));
     }
     if ($osC_Customer->hasDefaultAddress() === false) {
         $this->page_contents = 'checkout_shipping_address.php';
     }
     // if no shipping destination address was selected, use the customers own address as default
     if ($osC_Session->exists('sendto') == false) {
         $osC_Session->set('sendto', $osC_Customer->default_address_id);
     } else {
         // verify the selected shipping address
         $Qcheck = $osC_Database->query('select count(*) as total from :table_address_book where customers_id = :customers_id and address_book_id = :address_book_id');
         $Qcheck->bindTable(':table_address_book', TABLE_ADDRESS_BOOK);
         $Qcheck->bindInt(':customers_id', $osC_Customer->id);
         $Qcheck->bindInt(':address_book_id', $osC_Session->value('sendto'));
         $Qcheck->execute();
         if ($Qcheck->valueInt('total') != 1) {
             $osC_Session->set('sendto', $osC_Customer->default_address_id);
             $osC_Session->remove('shipping');
         }
     }
     $order = new order();
     // register a random ID in the session to check throughout the checkout procedure
     // against alterations in the shopping cart contents
     $osC_Session->set('cartID', $cart->cartID);
     // if the order contains only virtual products, forward the customer to the billing page as
     // a shipping address is not needed
     if ($order->content_type == 'virtual') {
         $false = false;
         $osC_Session->set('shipping', $false);
         $osC_Session->set('sendto', $false);
         tep_redirect(tep_href_link(FILENAME_CHECKOUT, 'payment', 'SSL'));
     }
     $total_weight = $cart->show_weight();
     $total_count = $cart->count_contents();
     // load all enabled shipping modules
     require DIR_WS_CLASSES . 'shipping.php';
     $shipping_modules = new shipping();
     if (defined('MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING') && MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING == 'true') {
         $pass = false;
         switch (MODULE_ORDER_TOTAL_SHIPPING_DESTINATION) {
             case 'national':
                 if ($order->delivery['country_id'] == STORE_COUNTRY) {
                     $pass = true;
                 }
                 break;
             case 'international':
                 if ($order->delivery['country_id'] != STORE_COUNTRY) {
                     $pass = true;
                 }
                 break;
             case 'both':
                 $pass = true;
                 break;
         }
         $free_shipping = false;
         if ($pass == true && $order->info['total'] - $order->info['shipping_cost'] >= MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER) {
             $free_shipping = true;
             include DIR_WS_LANGUAGES . $osC_Session->value('language') . '/modules/order_total/ot_shipping.php';
         }
     } else {
         $free_shipping = false;
     }
     // get all available shipping quotes
     $quotes = $shipping_modules->quote();
     // if no shipping method has been selected, automatically select the cheapest method.
     // if the modules status was changed when none were available, to save on implementing
     // a javascript force-selection method, also automatically select the cheapest shipping
     // method if more than one module is now enabled
     if ($osC_Session->exists('shipping') == false || $osC_Session->exists('shipping') && $osC_Session->value('shipping') == false && tep_count_shipping_modules() > 1) {
         $osC_Session->set('shipping', $shipping_modules->cheapest());
     }
     if ($_GET[$this->_module] == 'process') {
         $this->_process();
     }
 }
// Required for some shipping methods (ie. USPS).
require_once 'includes/classes/http_client.php';
// Set up the order address.
$country = 'US';
$city = 'Miami';
$region = 'FL';
$postal_code = '33102';
$row = tep_db_fetch_array(tep_db_query("select * from " . TABLE_COUNTRIES . " where countries_iso_code_2 = '" . $country . "'"));
$order->delivery['country'] = array('id' => $row['countries_id'], 'title' => $row['countries_name'], 'iso_code_2' => $country, 'iso_code_3' => $row['countries_iso_code_3']);
$order->delivery['country_id'] = $row['countries_id'];
$order->delivery['format_id'] = $row['address_format_id'];
$row = tep_db_fetch_array(tep_db_query("select * from " . TABLE_ZONES . " where zone_code = '" . $region . "'"));
$order->delivery['zone_id'] = $row['zone_id'];
$order->delivery['state'] = $row['zone_name'];
$order->delivery['city'] = $city;
$order->delivery['postcode'] = $postal_code;
$shipping_modules = new shipping();
foreach ($shippers as $shipper) {
    list($start_m, $start_s) = explode(' ', microtime());
    $start = $start_m + $start_s;
    $quotes = $shipping_modules->quote('', $shipper);
    list($end_m, $end_s) = explode(' ', microtime());
    $end = $end_m + $end_s;
    echo $shipper . " took " . number_format($end - $start, 5) . " Secs\n";
}
list($start_m, $start_s) = explode(' ', microtime());
$start = $start_m + $start_s;
$quotes = $shipping_modules->quote();
list($end_m, $end_s) = explode(' ', microtime());
$end = $end_m + $end_s;
echo "All quotes took " . number_format($end - $start, 5) . " Secs\n";
示例#9
0
function process_merchant_calculation_callback_single($Gresponse)
{
    global $googlepayment, $order, $db, $total_weight, $total_count;
    list($root, $data) = $Gresponse->GetParsedXML();
    $currencies = new currencies();
    $cart = $_SESSION['cart'];
    $methods_hash = $googlepayment->getMethods();
    require DIR_WS_CLASSES . 'order.php';
    $order = new order();
    // Register a random ID in the session to check throughout the checkout procedure
    // against alterations in the shopping cart contents.
    //  if (!tep_session_is_registered('cartID')) {
    //  tep_session_register('cartID');
    // }
    //  $cartID = $cart->cartID;
    $items = get_arr_result($data[$root]['shopping-cart']['items']['item']);
    $products = array();
    foreach ($items as $item) {
        if (isset($item['merchant-private-item-data']['item']['VALUE'])) {
            $products[] = unserialize(base64_decode($item['merchant-private-item-data']['item']['VALUE']));
        }
    }
    $order->products = $products;
    $total_weight = $cart->show_weight();
    $total_count = $cart->count_contents();
    // Create the results and send it
    $merchant_calc = new GoogleMerchantCalculations(DEFAULT_CURRENCY);
    // Loop through the list of address ids from the callback.
    $addresses = get_arr_result($data[$root]['calculate']['addresses']['anonymous-address']);
    // Get all the enabled shipping methods.
    require DIR_WS_CLASSES . 'shipping.php';
    // Required for some shipping methods (ie. USPS).
    require_once 'includes/classes/http_client.php';
    foreach ($addresses as $curr_address) {
        // Set up the order address.
        $curr_id = $curr_address['id'];
        $country = $curr_address['country-code']['VALUE'];
        $city = $curr_address['city']['VALUE'];
        $region = $curr_address['region']['VALUE'];
        $postal_code = $curr_address['postal-code']['VALUE'];
        $countr_query = $db->Execute("select * \n                     from " . TABLE_COUNTRIES . " \n                     where countries_iso_code_2 = '" . makeSqlString($country) . "'");
        $row = $countr_query->fields;
        $order->delivery['country'] = array('id' => $row['countries_id'], 'title' => $row['countries_name'], 'iso_code_2' => $country, 'iso_code_3' => $row['countries_iso_code_3']);
        $order->delivery['country_id'] = $row['countries_id'];
        $order->delivery['format_id'] = $row['address_format_id'];
        $zone_query = $db->Execute("select * \n        \t\t                               from " . TABLE_ZONES . "\n        \t\t                               where zone_code = '" . makeSqlString($region) . "'");
        $row = $zone_query->fields;
        $order->delivery['zone_id'] = $row['zone_id'];
        $order->delivery['state'] = $row['zone_name'];
        $order->delivery['city'] = $city;
        $order->delivery['postcode'] = $postal_code;
        $shipping_modules = new shipping();
        // Loop through each shipping method if merchant-calculated shipping
        // support is to be provided
        //print_r($data[$root]['calculate']['shipping']['method']);
        if (isset($data[$root]['calculate']['shipping']['method'])) {
            $shipping = get_arr_result($data[$root]['calculate']['shipping']['method']);
            //      if (MODULE_PAYMENT_GOOGLECHECKOUT_MULTISOCKET == 'True') {
            //        // Single
            //        // i get all the enabled shipping methods
            //        $name = $shipping[0]['name'];
            //        //            Compute the price for this shipping method and address id
            //        list ($a, $method_name) = explode(': ', $name);
            //        if ((($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY)
            //              && ($methods_hash[$method_name][1] == 'domestic_types'))
            //           || (($order->delivery['country']['id'] != SHIPPING_ORIGIN_COUNTRY)
            //              && ($methods_hash[$method_name][1] == 'international_types'))) {
            //          //								reset the shipping class to set the new address
            //          if (class_exists($methods_hash[$method_name][2])) {
            //            $GLOBALS[$methods_hash[$method_name][2]] = new $methods_hash[$method_name][2];
            //          }
            //        }
            //        $quotes = $shipping_modules->quote('', $methods_hash[$method_name][2]);
            //      } else {
            // Standard
            foreach ($shipping as $curr_ship) {
                $name = $curr_ship['name'];
                //            Compute the price for this shipping method and address id
                list($a, $method_name) = explode(': ', $name, 2);
                if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY && $methods_hash[$method_name][1] == 'domestic_types' || $order->delivery['country']['id'] != SHIPPING_ORIGIN_COUNTRY && $methods_hash[$method_name][1] == 'international_types') {
                    //								reset the shipping class to set the new address
                    if (class_exists($methods_hash[$method_name][2])) {
                        $GLOBALS[$methods_hash[$method_name][2]] = new $methods_hash[$method_name][2]();
                    }
                }
            }
            $quotes = $shipping_modules->quote();
            //      }
            reset($shipping);
            foreach ($shipping as $curr_ship) {
                $name = $curr_ship['name'];
                //            Compute the price for this shipping method and address id
                list($a, $method_name) = explode(': ', $name, 2);
                unset($quote_povider);
                unset($quote_method);
                if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY && $methods_hash[$method_name][1] == 'domestic_types' || $order->delivery['country']['id'] != SHIPPING_ORIGIN_COUNTRY && $methods_hash[$method_name][1] == 'international_types') {
                    foreach ($quotes as $key_provider => $shipping_provider) {
                        // privider name (class)
                        if ($shipping_provider['id'] == $methods_hash[$method_name][2]) {
                            // method name
                            $quote_povider = $key_provider;
                            if (is_array($shipping_provider['methods'])) {
                                foreach ($shipping_provider['methods'] as $key_method => $shipping_method) {
                                    if ($shipping_method['id'] == $methods_hash[$method_name][0]) {
                                        $quote_method = $key_method;
                                        break;
                                    }
                                }
                            }
                            break;
                        }
                    }
                }
                //if there is a problem with the method, i mark it as non-shippable
                if (isset($quotes[$quote_povider]['error']) || !isset($quotes[$quote_povider]['methods'][$quote_method]['cost'])) {
                    $price = "9999.09";
                    $shippable = "false";
                } else {
                    $price = $quotes[$quote_povider]['methods'][$quote_method]['cost'];
                    $shippable = "true";
                }
                // fix for item shipping function bug if called more than once in a session.
                $price = $price >= 0 ? $price : 0;
                $merchant_result = new GoogleResult($curr_id);
                $merchant_result->SetShippingDetails($name, $currencies->get_value(DEFAULT_CURRENCY) * $price, $shippable);
                if ($data[$root]['calculate']['tax']['VALUE'] == "true") {
                    //Compute tax for this address id and shipping type
                    $amount = 15;
                    // Modify this to the actual tax value
                    $merchant_result->SetTaxDetails($currencies->get_value(DEFAULT_CURRENCY) * $amount);
                }
                ////							 start cupons and gift processing (working)
                //								// only one coupon per order is valid!
                //                $_POST['dc_redeem_code'] = 'ROPU';
                //
                ////                require(DIR_WS_CLASSES . 'order.php');
                ////                $order = new order;
                //                require_once(DIR_WS_CLASSES . 'order_total.php');
                //                $order_total_modules = new order_total;
                ////                $order_total_modules->collect_posts();
                ////                $order_total_modules->pre_confirmation_check();
                //
                ////                print_r($order_total_modules);
                //                   $order_totals = $order_total_modules->process();
                ////                print_r($order_totals);
                //
                calculate_coupons($Gresponse, $merchant_result, $price);
                // end cupons
                $merchant_calc->AddResult($merchant_result);
            }
        } else {
            $merchant_result = new GoogleResult($curr_id);
            if ($data[$root]['calculate']['tax']['VALUE'] == "true") {
                //Compute tax for this address id and shipping type
                $amount = 15;
                // Modify this to the actual tax value
                $merchant_result->SetTaxDetails($currencies->get_value(DEFAULT_CURRENCY) * $amount);
            }
            calculate_coupons($Gresponse, $merchant_result);
            $merchant_calc->AddResult($merchant_result);
        }
    }
    $Gresponse->ProcessMerchantCalculations($merchant_calc);
}
}
$_SESSION['delivery_zone'] = $order->delivery['country']['iso_code_2'];
//suppot downloads and gifts
if ($order->content_type == 'virtual' || $order->content_type == 'virtual_weight' || $_SESSION['cart']->count_contents_virtual() == 0) {
    $shipping_content = array();
    $shipping_content[] = array('NAME' => _SHIPPING_FREE);
} else {
    require DIR_WS_CLASSES . 'shipping.php';
    $shipping = new shipping();
    $free_shipping = $free_shipping_freeamount = $has_freeamount = false;
    require DIR_WS_MODULES . 'order_total/ot_shipping.php';
    include DIR_WS_LANGUAGES . $_SESSION['language'] . '/modules/order_total/ot_shipping.php';
    $ot_shipping = new ot_shipping();
    $ot_shipping->process();
    // load all enabled shipping modules
    $quotes = $shipping->quote();
    foreach ($quotes as $quote) {
        if ($quote['id'] == 'freeamount') {
            $has_freeamount = true;
            if (isset($quote['methods'])) {
                $free_shipping_freeamount = true;
                break;
            }
        }
    }
    $shipping_content = array();
    if ($free_shipping == true) {
        $shipping_content[] = array('NAME' => FREE_SHIPPING_TITLE, 'VALUE' => $xtPrice->xtcFormat(0, true, 0, true));
    } else {
        if ($free_shipping_freeamount) {
            $shipping_content[] = array('NAME' => $quote['module'] . ' - ' . $quote['methods'][0]['title'], 'VALUE' => $xtPrice->xtcFormat(0, true, 0, true));
 function confirmation()
 {
     global $order, $smarty, $xtPrice, $main, $messageStack, $total_weight, $total_count, $free_shipping;
     if (isset($_GET['conditions_message'])) {
         $message_condition = str_replace('\\n', '', ERROR_CONDITIONS_NOT_ACCEPTED);
         $message_address = str_replace('\\n', '', ERROR_ADDRESS_NOT_ACCEPTED);
         switch ($_GET['conditions_message']) {
             case "1":
                 $messageStack->add('checkout_confirmation', $message_condition);
                 break;
             case "13":
                 $messageStack->add('checkout_confirmation', $message_condition);
                 $messageStack->add('checkout_confirmation', ERROR_CHECKOUT_SHIPPING_NO_METHOD);
                 break;
             case "2":
                 $messageStack->add('checkout_confirmation', $message_address);
                 break;
             case "23":
                 $messageStack->add('checkout_confirmation', $message_address);
                 $messageStack->add('checkout_confirmation', ERROR_CHECKOUT_SHIPPING_NO_METHOD);
                 break;
             case "12":
                 $messageStack->add('checkout_confirmation', $message_condition);
                 $messageStack->add('checkout_confirmation', $message_address);
                 break;
             case "123":
                 $messageStack->add('checkout_confirmation', $message_condition);
                 $messageStack->add('checkout_confirmation', $message_address);
                 $messageStack->add('checkout_confirmation', ERROR_CHECKOUT_SHIPPING_NO_METHOD);
                 break;
             case "3":
                 $messageStack->add('checkout_confirmation', ERROR_CHECKOUT_SHIPPING_NO_METHOD);
                 break;
         }
     }
     if ($order->delivery['country']['iso_code_2'] != '') {
         $_SESSION['delivery_zone'] = $order->delivery['country']['iso_code_2'];
     }
     $no_shipping = false;
     if ($order->content_type == 'virtual' || $order->content_type == 'virtual_weight' || $_SESSION['cart']->count_contents_virtual() == 0) {
         $no_shipping = true;
     }
     $total_weight = $_SESSION['cart']->show_weight();
     $total_count = $_SESSION['cart']->count_contents();
     // load all enabled shipping modules
     $shipping_modules = new shipping();
     // add unallowed payment / shipping
     if (defined('MODULE_EXCLUDE_PAYMENT_STATUS') && MODULE_EXCLUDE_PAYMENT_STATUS == 'True') {
         for ($i = 1; $i <= MODULE_EXCLUDE_PAYMENT_NUMBER; $i++) {
             $payment_exclude = explode(',', constant('MODULE_EXCLUDE_PAYMENT_PAYMENT_' . $i));
             if (in_array($this->code, $payment_exclude)) {
                 $shipping_exclude = explode(',', constant('MODULE_EXCLUDE_PAYMENT_SHIPPING_' . $i));
                 for ($i = 0, $n = count($shipping_modules->modules); $i < $n; $i++) {
                     if (in_array(substr($shipping_modules->modules[$i], 0, -4), $shipping_exclude)) {
                         unset($shipping_modules->modules[$i]);
                     }
                 }
             }
         }
     }
     $free_shipping = false;
     $ot_shipping = new ot_shipping();
     $ot_shipping->process();
     if ($no_shipping === true) {
         $_SESSION['shipping'] = false;
     }
     // get all available shipping quotes
     $quotes = $shipping_modules->quote();
     // if no shipping method has been selected, automatically select the cheapest method.
     // if the modules status was changed when none were available, to save on implementing
     // a javascript force-selection method, also automatically select the cheapest shipping
     // method if more than one module is now enabled
     if (!isset($_SESSION['shipping']) && CHECK_CHEAPEST_SHIPPING_MODUL == 'true' || isset($_SESSION['shipping']) && $_SESSION['shipping'] == false && xtc_count_shipping_modules() > 1) {
         $_SESSION['shipping'] = $shipping_modules->cheapest();
     }
     if ($no_shipping === true) {
         $_SESSION['shipping'] = false;
     }
     if (defined('SHOW_SELFPICKUP_FREE') && SHOW_SELFPICKUP_FREE == 'true') {
         if ($free_shipping == true) {
             $free_shipping = false;
             $quotes = array_merge($ot_shipping->quote(), $shipping_modules->quote('selfpickup', 'selfpickup'));
         }
     }
     $module_smarty = new Smarty();
     $shipping_block = '';
     if (xtc_count_shipping_modules() > 0) {
         $showtax = $_SESSION['customers_status']['customers_status_show_price_tax'];
         $module_smarty->assign('FREE_SHIPPING', $free_shipping);
         # free shipping or not...
         if ($free_shipping == true) {
             $module_smarty->assign('FREE_SHIPPING_TITLE', FREE_SHIPPING_TITLE);
             $module_smarty->assign('FREE_SHIPPING_DESCRIPTION', sprintf(FREE_SHIPPING_DESCRIPTION, $xtPrice->xtcFormat($free_shipping_value_over, true, 0, true)) . xtc_draw_hidden_field('shipping', 'free_free'));
             $module_smarty->assign('FREE_SHIPPING_ICON', $quotes[$i]['icon']);
         } else {
             $radio_buttons = 0;
             #loop through installed shipping methods...
             for ($i = 0, $n = sizeof($quotes); $i < $n; $i++) {
                 if (!isset($quotes[$i]['error'])) {
                     for ($j = 0, $n2 = sizeof($quotes[$i]['methods']); $j < $n2; $j++) {
                         # set the radio button to be checked if it is the method chosen
                         $quotes[$i]['methods'][$j]['radio_buttons'] = $radio_buttons;
                         $checked = isset($_SESSION['shipping']) && $quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id'] == $_SESSION['shipping']['id'] ? true : false;
                         if ($checked == true || $n == 1 && $n2 == 1) {
                             $quotes[$i]['methods'][$j]['checked'] = 1;
                         }
                         if ($n > 1 || $n2 > 1) {
                             if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 0 || !isset($quotes[$i]['tax'])) {
                                 $quotes[$i]['tax'] = 0;
                             }
                             $quotes[$i]['methods'][$j]['price'] = $xtPrice->xtcFormat(xtc_add_tax($quotes[$i]['methods'][$j]['cost'], $quotes[$i]['tax']), true, 0, true);
                             $quotes[$i]['methods'][$j]['radio_field'] = xtc_draw_radio_field('shipping', $quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id'], $checked, 'id="rd-' . ($i + 1) . '" onChange="this.form.submit()"');
                         } else {
                             if ($_SESSION['customers_status']['customers_status_show_price_tax'] == 0) {
                                 $quotes[$i]['tax'] = 0;
                             }
                             $quotes[$i]['methods'][$j]['price'] = $xtPrice->xtcFormat(xtc_add_tax($quotes[$i]['methods'][$j]['cost'], isset($quotes[$i]['tax']) ? $quotes[$i]['tax'] : 0), true, 0, true) . xtc_draw_hidden_field('shipping', $quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id']);
                         }
                         $radio_buttons++;
                     }
                 }
             }
             $module_smarty->assign('module_content', $quotes);
         }
         $module_smarty->assign('language', $_SESSION['language']);
         $module_smarty->caching = 0;
         $shipping_block = $module_smarty->fetch(CURRENT_TEMPLATE . '/module/checkout_shipping_block.html');
     }
     if ($no_shipping === false) {
         $module_smarty->assign('FORM_SHIPPING_ACTION', xtc_draw_form('checkout_shipping', xtc_href_link(FILENAME_CHECKOUT_CONFIRMATION, xtc_get_all_get_params(), 'SSL')) . xtc_draw_hidden_field('action', 'process'));
         $shipping_found = false;
         for ($i = 0, $n = sizeof($quotes); $i < $n; $i++) {
             for ($j = 0, $n2 = sizeof($quotes[$i]['methods']); $j < $n2; $j++) {
                 if ($quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id'] == $_SESSION['shipping']['id']) {
                     $shipping_found = true;
                     break;
                 }
             }
         }
         if ($shipping_found === false) {
             $module_smarty->assign('shipping_message', ERROR_CHECKOUT_SHIPPING_NO_METHOD);
             /*
             if (xtc_count_shipping_modules() == 1) {
               $module_smarty->assign('BUTTON_CONTINUE', xtc_image_submit('button_confirm.gif', IMAGE_BUTTON_CONFIRM));
             }
             */
         }
         $module_smarty->assign('BUTTON_CONTINUE', xtc_image_submit('button_confirm.gif', IMAGE_BUTTON_CONFIRM));
         $module_smarty->assign('FORM_END', '</form>');
         if ($no_shipping === false) {
             $module_smarty->assign('SHIPPING_BLOCK', $shipping_block);
         }
         $module_smarty->assign('language', $_SESSION['language']);
         $module_smarty->caching = 0;
         $shipping_method = $module_smarty->fetch(DIR_FS_EXTERNAL . '/paypal/templates/shipping_block.html');
         $smarty->assign('SHIPPING_METHOD', $shipping_method);
     }
     $smarty->assign('SHIPPING_ADDRESS_EDIT', xtc_href_link(FILENAME_CHECKOUT_SHIPPING_ADDRESS, xtc_get_all_get_params(), 'SSL'));
     $smarty->assign('BILLING_ADDRESS_EDIT', xtc_href_link(FILENAME_CHECKOUT_PAYMENT_ADDRESS, xtc_get_all_get_params(), 'SSL'));
     $smarty->clear_assign('SHIPPING_EDIT');
     $smarty->clear_assign('PAYMENT_EDIT');
     //$smarty->clear_assign('PRODUCTS_EDIT');
 }
示例#12
0
function mod_calculate_shipping_cost($products_id, $products_price)
{
    // set globals
    global $xtPrice, $total_weight, $shipping_weight, $shipping_quoted, $shipping_num_boxes, $em_shipping_countries;
    // init shipping content array
    $shipping_content = array();
    foreach ($em_shipping_countries as $country) {
        // init order class for dummy order
        $order = new order();
        //Data for shipping cost
        $default_data_query_raw = "SELECT countries_id,\n\t\t\t\t\t\t\t\t\t\tcountries_name,\n\t\t\t\t\t\t\t\t\t\tcountries_iso_code_2,\n\t\t\t\t\t\t\t\t\t\tcountries_iso_code_3,\n\t\t\t\t\t\t\t\t\t\taddress_format_id\n\t\t\t\t\t\t\t\t   FROM " . TABLE_COUNTRIES . "\n\t\t\t\t\t\t\t\t  WHERE countries_iso_code_2 = '" . strtoupper(trim($country)) . "'";
        $default_data_query = xtc_db_query($default_data_query_raw);
        $default_data = xtc_db_fetch_array($default_data_query);
        $default_data['entry_postcode'] = '10000';
        $default_data['zone_name'] = '';
        $default_data['zone_id'] = '';
        // set customer data
        $order->customer = array('postcode' => $default_data['entry_postcode'], 'state' => $default_data['zone_name'], 'zone_id' => $default_data['zone_id'], 'format_id' => $default_data['address_format_id'], 'country' => array('id' => $default_data['countries_id'], 'title' => $default_data['countries_name'], 'iso_code_2' => $default_data['countries_iso_code_2'], 'iso_code_3' => $default_data['countries_iso_code_3']));
        // set delivery data
        $order->delivery = array('postcode' => $default_data['entry_postcode'], 'state' => $default_data['zone_name'], 'zone_id' => $default_data['zone_id'], 'format_id' => $default_data['address_format_id'], 'country' => array('id' => $default_data['countries_id'], 'title' => $default_data['countries_name'], 'iso_code_2' => $default_data['countries_iso_code_2'], 'iso_code_3' => $default_data['countries_iso_code_3']));
        $GLOBALS['order'] = $order;
        // set session for calculation shipping costs
        $_SESSION['delivery_zone'] = $order->delivery['country']['iso_code_2'];
        // init shipping class
        $shipping = new shipping();
        // init shipping modules
        $quotes = $shipping->quote();
        $free_shipping = false;
        if (defined('MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING') && MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING == 'true') {
            switch (MODULE_ORDER_TOTAL_SHIPPING_DESTINATION) {
                case 'national':
                    if ($order->delivery['country']['id'] == STORE_COUNTRY) {
                        $pass = true;
                    }
                    break;
                case 'international':
                    if ($order->delivery['country']['id'] != STORE_COUNTRY) {
                        $pass = true;
                    }
                    break;
                case 'both':
                    $pass = true;
                    break;
                default:
                    $pass = false;
                    break;
            }
            if ($pass == true && $products_price >= $xtPrice->xtcFormat(MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER, false, 0, true)) {
                $free_shipping = true;
            }
        }
        $has_freeamount = false;
        $free_shipping_freeamount = false;
        foreach ($quotes as $quote) {
            if ($quote['id'] == 'freeamount') {
                $has_freeamount = true;
                if (isset($quote['methods'])) {
                    $free_shipping_freeamount = true;
                    break;
                }
            }
        }
        if ($free_shipping == true) {
            $shipping_content[] = array('country' => $order->delivery['country']['iso_code_2'], 'service' => mod_convert_string(FREE_SHIPPING_TITLE), 'price' => floatval(0));
        } elseif ($free_shipping_freeamount) {
            $shipping_content[] = array('country' => $order->delivery['country']['iso_code_2'], 'service' => mod_convert_string($quote['module']), 'price' => floatval(0));
        } else {
            foreach ($quotes as $quote) {
                if ($quote['id'] != 'freeamount') {
                    $quote['methods'][0]['cost'] = $xtPrice->xtcCalculateCurr($quote['methods'][0]['cost']);
                    $value = isset($quote['tax']) && $quote['tax'] > 0 ? $xtPrice->xtcAddTax($quote['methods'][0]['cost'], $quote['tax']) : (!empty($quote['methods'][0]['cost']) ? $quote['methods'][0]['cost'] : '0');
                    $value = $xtPrice->xtcFormat($value, false);
                    $shipping_content[] = array('country' => $order->delivery['country']['iso_code_2'], 'service' => mod_convert_string($quote['module'] . (!empty($quote['methods'][0]['title']) ? ' - ' . $quote['methods'][0]['title'] : '')), 'price' => floatval($value));
                }
            }
        }
        // unset used variables and objects
        unset($quotes);
        unset($shipping);
        unset($order);
        unset($_SESSION['delivery_zone']);
        unset($_SESSION['shipping']);
    }
    // return cheapest Shipping module
    return $shipping_content;
}
         }
         // set the cost to be able to calvculate free shipping
         $order->info = array('total' => $cart->show_total());
         // TAX ????
     }
     // weight and count needed for shipping !
     $total_weight = $cart->show_weight();
     $total_count = $cart->count_contents();
     //require(DIR_WS_CLASSES . 'shipping.php');
     if (defined('MVS_STATUS') && MVS_STATUS == 'true') {
         include DIR_WS_CLASSES . 'vendor_shipping.php';
     } else {
         include DIR_WS_CLASSES . 'shipping.php';
     }
     $shipping_modules = new shipping();
     $quotes = $shipping_modules->quote();
     $cheapest = $shipping_modules->cheapest();
     // set selections for displaying
     //if (!isset($order->delivery['country'])) {
     //  $order->delivery['country'] = false;
     //}
     //if (!isset($order->delivery['postcode'])) {
     //  $order->delivery['postcode'] = false;
     //}
     $selected_country = $order->delivery['country']['id'];
     $selected_zip = $order->delivery['postcode'];
     if (isset($_SESSION['sendto'])) {
         $selected_address = $_SESSION['sendto'];
     }
 }
 // eo shipping cost