[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
Zen Cart 源代码 shipping_estimator.php

Zen Cart 源代码 shipping_estimator.php




下载文件

文件名: shipping_estimator.php
文件类型: PHP文件
文件大小: 13.79 KiB
MD5: f74c7bdf533064c3d95b1a026e76d062

shipping_estimator.php - 关闭高亮
  1. <?php
  2. /**
  3.  * Shipping Estimator module
  4.  *
  5.  * Customized by: Linda McGrath osCommerce@WebMakers.com to:
  6.  * - Handles Free Shipping for orders over $total as defined in the Admin
  7.  * - Shows Free Shipping on Virtual products
  8.  *
  9.  * @package modules
  10.  * @copyright Copyright 2003-2013 Zen Cart Development Team
  11.  * @copyright Portions Copyright 2003 osCommerce
  12.  * portions Copyright (c) 2003 Edwin Bekaert (edwin@ednique.com)
  13.  * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
  14.  * @version GIT: $Id: Author: DrByte  Sun Jul 28 01:49:38 2013 -0400 Modified in v1.5.2 $
  15.  */
  16. if (!defined('IS_ADMIN_FLAG')) {
  17.   die('Illegal Access');
  18. }
  19. if (isset($_POST['zone_country_id'])) $_POST['zone_country_id'] = (int)$_POST['zone_country_id'];
  20. if (isset($_POST['scid'])) $_POST['scid'] = preg_replace('/[^a-z_0-9\- ]/i', '', $_POST['scid']);
  21.  
  22. // load JS updater
  23. if ($current_page_base != 'popup_shipping_estimator') {
  24.   require(DIR_WS_MODULES . '/pages/popup_shipping_estimator/jscript_addr_pulldowns.php');
  25. }
  26. ?>
  27. <!-- shipping_estimator //-->
  28.  
  29. <script language="javascript" type="text/javascript">
  30. function shipincart_submit(){
  31.   document.estimator.submit();
  32.   return false;
  33. }
  34. </script>
  35.  
  36. <?php
  37. // Only do when something is in the cart
  38. if ($_SESSION['cart']->count_contents() > 0) {
  39.    $zip_code = (isset($_SESSION['cart_zip_code'])) ? $_SESSION['cart_zip_code'] : '';
  40.    $zip_code = (isset($_POST['zip_code'])) ? strip_tags(addslashes($_POST['zip_code'])) : $zip_code;
  41.    $state_zone_id = (isset($_SESSION['cart_zone'])) ? (int)$_SESSION['cart_zone'] : '';
  42.    $state_zone_id = (isset($_POST['zone_id'])) ? (int)$_POST['zone_id'] : $state_zone_id;
  43.    $selectedState = zen_output_string_protected($_POST['state']);
  44.   // Could be placed in english.php
  45.   // shopping cart quotes
  46.   // shipping cost
  47.  
  48.   // deprecated; to be removed
  49.   if (file_exists(DIR_WS_CLASSES . 'http_client.php')) require_once(DIR_WS_CLASSES . 'http_client.php'); // shipping in basket
  50.  
  51. /*
  52. // moved below and altered to include Tare
  53.   // totals info
  54.   $totalsDisplay = '';
  55.   switch (true) {
  56.     case (SHOW_TOTALS_IN_CART == '1'):
  57.     $totalsDisplay = TEXT_TOTAL_ITEMS . $_SESSION['cart']->count_contents() . TEXT_TOTAL_WEIGHT . $_SESSION['cart']->show_weight() . TEXT_PRODUCT_WEIGHT_UNIT . TEXT_TOTAL_AMOUNT . $currencies->format($_SESSION['cart']->show_total());
  58.     break;
  59.     case (SHOW_TOTALS_IN_CART == '2'):
  60.     $totalsDisplay = TEXT_TOTAL_ITEMS . $_SESSION['cart']->count_contents() . ($_SESSION['cart']->show_weight() > 0 ? TEXT_TOTAL_WEIGHT . $_SESSION['cart']->show_weight() . TEXT_PRODUCT_WEIGHT_UNIT : '') . TEXT_TOTAL_AMOUNT . $currencies->format($_SESSION['cart']->show_total());
  61.     break;
  62.     case (SHOW_TOTALS_IN_CART == '3'):
  63.     $totalsDisplay = TEXT_TOTAL_ITEMS . $_SESSION['cart']->count_contents() . TEXT_TOTAL_AMOUNT . $currencies->format($_SESSION['cart']->show_total());
  64.     break;
  65.   }
  66. */
  67.  
  68.   //if($cart->get_content_type() !== 'virtual') {
  69.   if ($_SESSION['customer_id']) {
  70.     // user is logged in
  71.     if (isset($_POST['address_id'])){
  72.       // user changed address
  73.       $sendto = $_POST['address_id'];
  74.     }elseif ($_SESSION['cart_address_id']){
  75.       // user once changed address
  76.       $sendto = $_SESSION['cart_address_id'];
  77.       //        $sendto = $_SESSION['customer_default_address_id'];
  78.     }else{
  79.       // first timer
  80.       $sendto = $_SESSION['customer_default_address_id'];
  81.     }
  82.     $_SESSION['sendto'] = $sendto;
  83.     // set session now
  84.     $_SESSION['cart_address_id'] = $sendto;
  85.     // set shipping to null ! multipickjup changes address to store address...
  86.     $shipping='';
  87.     // include the order class (uses the sendto !)
  88.     require(DIR_WS_CLASSES . 'order.php');
  89.     $order = new order;
  90.   } else {
  91.     // user not logged in !
  92.     require(DIR_WS_CLASSES . 'order.php');
  93.     $order = new order;
  94.     if (isset($_POST['zone_country_id'])){
  95.       // country is selected
  96.       $_SESSION['country_info'] = zen_get_countries($_POST['zone_country_id'],true);
  97.       $country_info = $_SESSION['country_info'];
  98.       $order->delivery = array('postcode' => $zip_code,
  99.                                'country' => array('id' => $_POST['zone_country_id'], 'title' => $country_info['countries_name'], 'iso_code_2' => $country_info['countries_iso_code_2'], 'iso_code_3' =>  $country_info['countries_iso_code_3']),
  100.                                'country_id' => $_POST['zone_country_id'],
  101.                                //add state zone_id
  102.                                'zone_id' => $state_zone_id,
  103.                                'format_id' => zen_get_address_format_id($_POST['zone_country_id']));
  104.       $_SESSION['cart_country_id'] = $_POST['zone_country_id'];
  105.       //add state zone_id
  106.       $_SESSION['cart_zone'] = $state_zone_id;
  107.       $_SESSION['cart_zip_code'] = $zip_code;
  108.     } elseif ($_SESSION['cart_country_id']){
  109.       // session is available
  110.       $_SESSION['country_info'] = zen_get_countries($_SESSION['cart_country_id'],true);
  111.       $country_info = $_SESSION['country_info'];
  112.       // fix here - check for error on $cart_country_id
  113.       $order->delivery = array('postcode' => $_SESSION['cart_zip_code'],
  114.                                'country' => array('id' => $_SESSION['cart_country_id'], 'title' => $country_info['countries_name'], 'iso_code_2' => $country_info['countries_iso_code_2'], 'iso_code_3' =>  $country_info['countries_iso_code_3']),
  115.                                'country_id' => $_SESSION['cart_country_id'],
  116.                                'zone_id' => $state_zone_id,
  117.                                'format_id' => zen_get_address_format_id($_SESSION['cart_country_id']));
  118.     } else {
  119.       // first timer
  120.       $_SESSION['cart_country_id'] = STORE_COUNTRY;
  121.       $_SESSION['country_info'] = zen_get_countries(STORE_COUNTRY,true);
  122.       $country_info = $_SESSION['country_info'];
  123.       $order->delivery = array(//'postcode' => '',
  124.                                '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']),
  125.                                'country_id' => STORE_COUNTRY,
  126.                                'zone_id' => $state_zone_id,
  127.                                'format_id' => zen_get_address_format_id($_POST['zone_country_id']));
  128.     }
  129.     // set the cost to be able to calculate free shipping
  130.     $order->info = array('total' => $_SESSION['cart']->show_total(), // TAX ????
  131.                          'currency' => $currency,
  132.                          'currency_value'=> $currencies->currencies[$currency]['value']);
  133.   }
  134.   // weight and count needed for shipping !
  135.   $total_weight = $_SESSION['cart']->show_weight();
  136.   $shipping_estimator_display_weight = $total_weight;
  137.   $total_count = $_SESSION['cart']->count_contents();
  138.   require(DIR_WS_CLASSES . 'shipping.php');
  139.   $shipping_modules = new shipping;
  140.   $quotes = $shipping_modules->quote();
  141.   //print_r($quotes);
  142.   //die('here');
  143.   $order->info['subtotal'] = $_SESSION['cart']->show_total();
  144.  
  145.   // set selections for displaying
  146.   $selected_country = $order->delivery['country']['id'];
  147.   $selected_address = $sendto;
  148.   //}
  149.   // eo shipping cost
  150.   // check free shipping based on order $total
  151.   if ( defined('MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING') && (MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING == 'true')) {
  152.     switch (MODULE_ORDER_TOTAL_SHIPPING_DESTINATION) {
  153.       case 'national':
  154.       if ($order->delivery['country_id'] == STORE_COUNTRY) $pass = true; break;
  155.       case 'international':
  156.       if ($order->delivery['country_id'] != STORE_COUNTRY) $pass = true; break;
  157.       case 'both':
  158.  
  159.       $pass = true; break;
  160.       default:
  161.       $pass = false; break;
  162.     }
  163.     $free_shipping = false;
  164.     if ( ($pass == true) && ($_SESSION['cart']->show_total() >= MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER)) {
  165.       $free_shipping = true;
  166.       include(DIR_WS_LANGUAGES . $_SESSION['language'] . '/modules/order_total/ot_shipping.php');
  167.     }
  168.   } else {
  169.     $free_shipping = false;
  170.   }
  171.   // begin shipping cost
  172.   if(!$free_shipping && $_SESSION['cart']->get_content_type() !== 'virtual'){
  173.     if (zen_not_null($_POST['scid'])){
  174.       list($module, $method) = explode('_', $_POST['scid']);
  175.       $_SESSION['cart_sid'] = $_POST['scid'];
  176.     }elseif ($_SESSION['cart_sid']){
  177.       list($module, $method) = explode('_', $_SESSION['cart_sid']);
  178.     }else{
  179.       $module="";
  180.       $method="";
  181.     }
  182.  
  183.     if (zen_not_null($module)){
  184.       foreach ($quotes as $key=>$value) {
  185.         if ($value['id'] == $module) {
  186.           $selected_quote[0] = $value;
  187.           if (zen_not_null($method)) {
  188.             foreach ($selected_quote[0]['methods'] as $qkey=>$qval) {
  189.               if ($qval['id'] == $method) {
  190.                 $selected_quote[0]['methods'] = array($qval);
  191.                 continue;
  192.               }
  193.             }
  194.           }
  195.         }
  196.       }
  197.  
  198.       if($selected_quote[0]['error'] || !zen_not_null($selected_quote[0]['methods'][0]['cost'])){
  199. //        $selected_shipping = $shipping_modules->cheapest();
  200.         $order->info['shipping_method'] = $selected_shipping['title'];
  201.         $order->info['shipping_cost'] = $selected_shipping['cost'];
  202.         $order->info['total']+= $selected_shipping['cost'];
  203.       }else{
  204.         $order->info['shipping_method'] = $selected_quote[0]['module'].' ('.$selected_quote[0]['methods'][0]['title'].')';
  205.         $order->info['shipping_cost'] = $selected_quote[0]['methods'][0]['cost'];
  206.         $order->info['total']+= $selected_quote[0]['methods'][0]['cost'];
  207.         $selected_shipping['title'] = $order->info['shipping_method'];
  208.         $selected_shipping['cost'] = $order->info['shipping_cost'];
  209.         $selected_shipping['id'] = $selected_quote[0]['id'].'_'.$selected_quote[0]['methods'][0]['id'];
  210.       }
  211.     }else{
  212. //      $selected_shipping = $shipping_modules->cheapest();
  213.       $order->info['shipping_method'] = $selected_shipping['title'];
  214.       $order->info['shipping_cost'] = $selected_shipping['cost'];
  215.       $order->info['total']+= $selected_shipping['cost'];
  216.     }
  217.   }
  218.   // virtual products need a free shipping
  219.   if($_SESSION['cart']->get_content_type() == 'virtual') {
  220.     $order->info['shipping_method'] = CART_SHIPPING_METHOD_FREE_TEXT . ' ' . CART_SHIPPING_METHOD_ALL_DOWNLOADS;
  221.     $order->info['shipping_cost'] = 0;
  222.   }
  223.   if($free_shipping) {
  224.     $order->info['shipping_method'] = MODULE_ORDER_TOTAL_SHIPPING_TITLE;
  225.     $order->info['shipping_cost'] = 0;
  226.   }
  227.  
  228. // set cheapest last
  229.   $selected_shipping = $shipping_modules->cheapest();
  230.   $shipping=$selected_shipping;
  231.   if (SHOW_SHIPPING_ESTIMATOR_BUTTON == '1') {
  232.     $show_in = FILENAME_POPUP_SHIPPING_ESTIMATOR;
  233.   } else {
  234.     $show_in = FILENAME_SHOPPING_CART;
  235.   }
  236. //  if(sizeof($quotes)) {
  237.     if ($_SESSION['customer_id']) {
  238.       $addresses = $db->execute("select address_book_id, entry_city as city, entry_postcode as postcode, entry_state as state, entry_zone_id as zone_id, entry_country_id as country_id from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . (int)$_SESSION['customer_id'] . "'");
  239.       // only display addresses if more than 1
  240.       if ($addresses->RecordCount() > 1){
  241.         while (!$addresses->EOF) {
  242.           $addresses_array[] = array('id' => $addresses->fields['address_book_id'], 'text' => zen_address_format(zen_get_address_format_id($addresses->fields['country_id']), $addresses->fields, 0, ' ', ' '));
  243.           $addresses->MoveNext();
  244.         }
  245.       }
  246.     } else {
  247.       if($_SESSION['cart']->get_content_type() != 'virtual'){
  248.         $state_array[] = array('id' => '', 'text' => PULL_DOWN_SHIPPING_ESTIMATOR_SELECT);
  249.         $state_values = $db->Execute("select zone_name, zone_id from " . TABLE_ZONES . " where zone_country_id = '" . (int)$selected_country . "' order by zone_country_id DESC, zone_name");
  250.         while (!$state_values->EOF) {
  251.           $state_array[] = array('id' => $state_values->fields['zone_id'],
  252.                                  'text' => $state_values->fields['zone_name']);
  253.           $state_values->MoveNext();
  254.         }
  255.       }
  256.     }
  257. //  }
  258.  
  259. // This is done after quote-calcs in order to include Tare info accurately.  NOTE: tare values are *not* included in weights shown on-screen.
  260.   $totalsDisplay = '';
  261.   if (SHOW_SHIPPING_ESTIMATOR_BUTTON != 2) {
  262.     switch (true) {
  263.       case (SHOW_TOTALS_IN_CART == '1'):
  264.       $totalsDisplay = TEXT_TOTAL_ITEMS . $_SESSION['cart']->count_contents() . TEXT_TOTAL_WEIGHT . $shipping_estimator_display_weight . TEXT_PRODUCT_WEIGHT_UNIT . TEXT_TOTAL_AMOUNT . $currencies->format($_SESSION['cart']->show_total());
  265.       break;
  266.       case (SHOW_TOTALS_IN_CART == '2'):
  267.       $totalsDisplay = TEXT_TOTAL_ITEMS . $_SESSION['cart']->count_contents() . ($shipping_estimator_display_weight > 0 ? TEXT_TOTAL_WEIGHT . $shipping_estimator_display_weight . TEXT_PRODUCT_WEIGHT_UNIT : '') . TEXT_TOTAL_AMOUNT . $currencies->format($_SESSION['cart']->show_total());
  268.       break;
  269.       case (SHOW_TOTALS_IN_CART == '3'):
  270.       $totalsDisplay = TEXT_TOTAL_ITEMS . $_SESSION['cart']->count_contents() . TEXT_TOTAL_AMOUNT . $currencies->format($_SESSION['cart']->show_total());
  271.       break;
  272.     }
  273.   }
  274.  
  275.   if (!isset($tplVars['flagShippingPopUp']) || $tplVars['flagShippingPopUp'] !== true) {
  276. /**
  277.  * use the template tpl_modules_shipping_estimator.php to display the result
  278.  *
  279. **/
  280.     require($template->get_template_dir('tpl_modules_shipping_estimator.php', DIR_WS_TEMPLATE, $current_page_base,'templates'). '/' . 'tpl_modules_shipping_estimator.php');
  281.   }
  282. } else { // Only do when something is in the cart
  283. ?>
  284. <h2><?php echo CART_SHIPPING_OPTIONS; ?></h2>
  285. <div class="cartTotalsDisplay important"><?php echo EMPTY_CART_TEXT_NO_QUOTE; ?></div>
  286. <?php
  287. }
  288. ?>
  289. <script type="text/javascript" language="javascript">update_zone(document.estimator); </script>
  290. <!-- shipping_estimator_eof //-->