[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.05 KiB
MD5: d3c4cccddbd7f45ec587dba9377f8a26

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-2009 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 $Id: shipping_estimator.php 14728 2009-11-01 15:40:59Z ajeh $
  15.  */
  16. if (!defined('IS_ADMIN_FLAG')) {
  17.   die('Illegal Access');
  18. }
  19.  
  20. // load JS updater
  21. if ($current_page_base != 'popup_shipping_estimator') {
  22.   require(DIR_WS_MODULES . '/pages/popup_shipping_estimator/jscript_addr_pulldowns.php');
  23. }
  24. ?>
  25. <!-- shipping_estimator //-->
  26.  
  27. <script language="javascript" type="text/javascript">
  28. function shipincart_submit(){
  29.   document.estimator.submit();
  30.   return false;
  31. }
  32. </script>
  33.  
  34. <?php
  35. // Only do when something is in the cart
  36. if ($_SESSION['cart']->count_contents() > 0) {
  37.    $zip_code = (isset($_SESSION['cart_zip_code'])) ? $_SESSION['cart_zip_code'] : '';
  38.    $zip_code = (isset($_POST['zip_code'])) ? strip_tags(addslashes($_POST['zip_code'])) : $zip_code;
  39.    $state_zone_id = (isset($_SESSION['cart_zone'])) ? (int)$_SESSION['cart_zone'] : '';
  40.    $state_zone_id = (isset($_POST['zone_id'])) ? (int)$_POST['zone_id'] : $state_zone_id;
  41.    $selectedState = zen_db_input($_POST['state']);
  42.   // Could be placed in english.php
  43.   // shopping cart quotes
  44.   // shipping cost
  45.   require_once('includes/classes/http_client.php'); // shipping in basket
  46.  
  47. /*
  48. // moved below and altered to include Tare
  49.   // totals info
  50.   $totalsDisplay = '';
  51.   switch (true) {
  52.     case (SHOW_TOTALS_IN_CART == '1'):
  53.     $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());
  54.     break;
  55.     case (SHOW_TOTALS_IN_CART == '2'):
  56.     $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());
  57.     break;
  58.     case (SHOW_TOTALS_IN_CART == '3'):
  59.     $totalsDisplay = TEXT_TOTAL_ITEMS . $_SESSION['cart']->count_contents() . TEXT_TOTAL_AMOUNT . $currencies->format($_SESSION['cart']->show_total());
  60.     break;
  61.   }
  62. */
  63.  
  64.   //if($cart->get_content_type() !== 'virtual') {
  65.   if ($_SESSION['customer_id']) {
  66.     // user is logged in
  67.     if (isset($_POST['address_id'])){
  68.       // user changed address
  69.       $sendto = $_POST['address_id'];
  70.     }elseif ($_SESSION['cart_address_id']){
  71.       // user once changed address
  72.       $sendto = $_SESSION['cart_address_id'];
  73.       //        $sendto = $_SESSION['customer_default_address_id'];
  74.     }else{
  75.       // first timer
  76.       $sendto = $_SESSION['customer_default_address_id'];
  77.     }
  78.     $_SESSION['sendto'] = $sendto;
  79.     // set session now
  80.     $_SESSION['cart_address_id'] = $sendto;
  81.     // set shipping to null ! multipickjup changes address to store address...
  82.     $shipping='';
  83.     // include the order class (uses the sendto !)
  84.     require(DIR_WS_CLASSES . 'order.php');
  85.     $order = new order;
  86.   }else{
  87.     // user not logged in !
  88.     if (isset($_POST['zone_country_id'])){
  89.       // country is selected
  90.       $_SESSION['country_info'] = zen_get_countries($_POST['zone_country_id'],true);
  91.       $country_info = $_SESSION['country_info'];
  92.       $order->delivery = array('postcode' => $zip_code,
  93.                                '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']),
  94.                                'country_id' => $_POST['zone_country_id'],
  95.                                //add state zone_id
  96.                                'zone_id' => $state_zone_id,
  97.                                'format_id' => zen_get_address_format_id($_POST['zone_country_id']));
  98.       $_SESSION['cart_country_id'] = $_POST['zone_country_id'];
  99.       //add state zone_id
  100.       $_SESSION['cart_zone'] = $state_zone_id;
  101.       $_SESSION['cart_zip_code'] = $zip_code;
  102.     } elseif ($_SESSION['cart_country_id']){
  103.       // session is available
  104.       $_SESSION['country_info'] = zen_get_countries($_SESSION['cart_country_id'],true);
  105.       $country_info = $_SESSION['country_info'];
  106.       // fix here - check for error on $cart_country_id
  107.       $order->delivery = array('postcode' => $_SESSION['cart_zip_code'],
  108.                                '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']),
  109.                                'country_id' => $_SESSION['cart_country_id'],
  110.                                'zone_id' => $state_zone_id,
  111.                                'format_id' => zen_get_address_format_id($_SESSION['cart_country_id']));
  112.     } else {
  113.       // first timer
  114.       $_SESSION['cart_country_id'] = STORE_COUNTRY;
  115.       $_SESSION['country_info'] = zen_get_countries(STORE_COUNTRY,true);
  116.       $country_info = $_SESSION['country_info'];
  117.       $order->delivery = array(//'postcode' => '',
  118.                                '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']),
  119.                                'country_id' => STORE_COUNTRY,
  120.                                'zone_id' => $state_zone_id,
  121.                                'format_id' => zen_get_address_format_id($_POST['zone_country_id']));
  122.     }
  123.     // set the cost to be able to calculate free shipping
  124.     $order->info = array('total' => $_SESSION['cart']->show_total(), // TAX ????
  125.                          'currency' => $currency,
  126.                          'currency_value'=> $currencies->currencies[$currency]['value']);
  127.   }
  128.   // weight and count needed for shipping !
  129.   $total_weight = $_SESSION['cart']->show_weight();
  130.   $shipping_estimator_display_weight = $total_weight;
  131.   $total_count = $_SESSION['cart']->count_contents();
  132.   require(DIR_WS_CLASSES . 'shipping.php');
  133.   $shipping_modules = new shipping;
  134.   $quotes = $shipping_modules->quote();
  135.   //print_r($quotes);
  136.   //die('here');
  137.   $order->info['subtotal'] = $_SESSION['cart']->show_total();
  138.  
  139.   // set selections for displaying
  140.   $selected_country = $order->delivery['country']['id'];
  141.   $selected_address = $sendto;
  142.   //}
  143.   // eo shipping cost
  144.   // check free shipping based on order $total
  145.   if ( defined('MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING') && (MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING == 'true')) {
  146.     switch (MODULE_ORDER_TOTAL_SHIPPING_DESTINATION) {
  147.       case 'national':
  148.       if ($order->delivery['country_id'] == STORE_COUNTRY) $pass = true; break;
  149.       case 'international':
  150.       if ($order->delivery['country_id'] != STORE_COUNTRY) $pass = true; break;
  151.       case 'both':
  152.  
  153.       $pass = true; break;
  154.       default:
  155.       $pass = false; break;
  156.     }
  157.     $free_shipping = false;
  158.     if ( ($pass == true) && ($_SESSION['cart']->show_total() >= MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER)) {
  159.       $free_shipping = true;
  160.       include(DIR_WS_LANGUAGES . $_SESSION['language'] . '/modules/order_total/ot_shipping.php');
  161.     }
  162.   } else {
  163.     $free_shipping = false;
  164.   }
  165.   // begin shipping cost
  166.   if(!$free_shipping && $_SESSION['cart']->get_content_type() !== 'virtual'){
  167.     if (zen_not_null($_POST['scid'])){
  168.       list($module, $method) = explode('_', $_POST['scid']);
  169.       $_SESSION['cart_sid'] = $_POST['scid'];
  170.     }elseif ($_SESSION['cart_sid']){
  171.       list($module, $method) = explode('_', $_SESSION['cart_sid']);
  172.     }else{
  173.       $module="";
  174.       $method="";
  175.     }
  176.     if (zen_not_null($module)){
  177.       $selected_quote = $shipping_modules->quote($method, $module);
  178.       if($selected_quote[0]['error'] || !zen_not_null($selected_quote[0]['methods'][0]['cost'])){
  179. //        $selected_shipping = $shipping_modules->cheapest();
  180.         $order->info['shipping_method'] = $selected_shipping['title'];
  181.         $order->info['shipping_cost'] = $selected_shipping['cost'];
  182.         $order->info['total']+= $selected_shipping['cost'];
  183.       }else{
  184.         $order->info['shipping_method'] = $selected_quote[0]['module'].' ('.$selected_quote[0]['methods'][0]['title'].')';
  185.         $order->info['shipping_cost'] = $selected_quote[0]['methods'][0]['cost'];
  186.         $order->info['total']+= $selected_quote[0]['methods'][0]['cost'];
  187.         $selected_shipping['title'] = $order->info['shipping_method'];
  188.         $selected_shipping['cost'] = $order->info['shipping_cost'];
  189.         $selected_shipping['id'] = $selected_quote[0]['id'].'_'.$selected_quote[0]['methods'][0]['id'];
  190.       }
  191.     }else{
  192. //      $selected_shipping = $shipping_modules->cheapest();
  193.       $order->info['shipping_method'] = $selected_shipping['title'];
  194.       $order->info['shipping_cost'] = $selected_shipping['cost'];
  195.       $order->info['total']+= $selected_shipping['cost'];
  196.     }
  197.   }
  198.   // virtual products need a free shipping
  199.   if($_SESSION['cart']->get_content_type() == 'virtual') {
  200.     $order->info['shipping_method'] = CART_SHIPPING_METHOD_FREE_TEXT . ' ' . CART_SHIPPING_METHOD_ALL_DOWNLOADS;
  201.     $order->info['shipping_cost'] = 0;
  202.   }
  203.   if($free_shipping) {
  204.     $order->info['shipping_method'] = MODULE_ORDER_TOTAL_SHIPPING_TITLE;
  205.     $order->info['shipping_cost'] = 0;
  206.   }
  207.  
  208. // set cheapest last
  209.   $selected_shipping = $shipping_modules->cheapest();
  210.   $shipping=$selected_shipping;
  211.   if (SHOW_SHIPPING_ESTIMATOR_BUTTON == '1') {
  212.     $show_in = FILENAME_POPUP_SHIPPING_ESTIMATOR;
  213.   } else {
  214.     $show_in = FILENAME_SHOPPING_CART;
  215.   }
  216. //  if(sizeof($quotes)) {
  217.     if ($_SESSION['customer_id']) {
  218.       $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'] . "'");
  219.       // only display addresses if more than 1
  220.       if ($addresses->RecordCount() > 1){
  221.         while (!$addresses->EOF) {
  222.           $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, ' ', ' '));
  223.           $addresses->MoveNext();
  224.         }
  225.       }
  226.     } else {
  227.       if($_SESSION['cart']->get_content_type() != 'virtual'){
  228.         $state_array[] = array('id' => '', 'text' => PULL_DOWN_SHIPPING_ESTIMATOR_SELECT);
  229.         $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");
  230.         while (!$state_values->EOF) {
  231.           $state_array[] = array('id' => $state_values->fields['zone_id'],
  232.                                  'text' => $state_values->fields['zone_name']);
  233.           $state_values->MoveNext();
  234.         }
  235.       }
  236.     }
  237. //  }
  238.  
  239. // This is done after quote-calcs in order to include Tare info accurately.  NOTE: tare values are *not* included in weights shown on-screen.
  240.   $totalsDisplay = '';
  241.   if (SHOW_SHIPPING_ESTIMATOR_BUTTON != 2) {
  242.     switch (true) {
  243.       case (SHOW_TOTALS_IN_CART == '1'):
  244.       $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());
  245.       break;
  246.       case (SHOW_TOTALS_IN_CART == '2'):
  247.       $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());
  248.       break;
  249.       case (SHOW_TOTALS_IN_CART == '3'):
  250.       $totalsDisplay = TEXT_TOTAL_ITEMS . $_SESSION['cart']->count_contents() . TEXT_TOTAL_AMOUNT . $currencies->format($_SESSION['cart']->show_total());
  251.       break;
  252.     }
  253.   }
  254.  
  255.   if (!isset($tplVars['flagShippingPopUp']) || $tplVars['flagShippingPopUp'] !== true) {
  256. /**
  257.  * use the template tpl_modules_shipping_estimator.php to display the result
  258.  *
  259. **/
  260.     require($template->get_template_dir('tpl_modules_shipping_estimator.php', DIR_WS_TEMPLATE, $current_page_base,'templates'). '/' . 'tpl_modules_shipping_estimator.php');
  261.   }
  262. } else { // Only do when something is in the cart
  263. ?>
  264. <h2><?php echo CART_SHIPPING_OPTIONS; ?></h2>
  265. <div class="cartTotalsDisplay important"><?php echo EMPTY_CART_TEXT_NO_QUOTE; ?></div>
  266. <?php
  267. }
  268. ?>
  269. <script type="text/javascript" language="javascript">update_zone(document.estimator); </script>
  270. <!-- shipping_estimator_eof //-->


cron