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