[ Index ] |
|
Code source de Zen Cart E-Commerce Shopping Cart 1.3.7.1 |
1 <?php 2 /** 3 * @package shippingMethod 4 * @copyright Copyright 2003-2006 Zen Cart Development Team 5 * @copyright Portions Copyright 2003 osCommerce 6 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0 7 * @version $Id: freeoptions.php 4238 2006-08-24 10:01:04Z drbyte $ 8 */ 9 10 class freeoptions extends base { 11 var $code, $title, $description, $icon, $enabled; 12 var $ck_freeoptions_total, $ck_freeoptions_weight, $ck_freeoptions_items; 13 14 // class constructor 15 function freeoptions() { 16 global $order, $db; 17 18 $this->code = 'freeoptions'; 19 $this->title = MODULE_SHIPPING_FREEOPTIONS_TEXT_TITLE; 20 $this->description = MODULE_SHIPPING_FREEOPTIONS_TEXT_DESCRIPTION; 21 $this->sort_order = MODULE_SHIPPING_FREEOPTIONS_SORT_ORDER; 22 $this->icon = ''; 23 $this->tax_class = MODULE_SHIPPING_FREEOPTIONS_TAX_CLASS; 24 $this->tax_basis = MODULE_SHIPPING_FREEOPTIONS_TAX_BASIS; 25 26 // disable only when entire cart is free shipping 27 if (zen_get_shipping_enabled($this->code)) { 28 $this->enabled = ((MODULE_SHIPPING_FREEOPTIONS_STATUS == 'True') ? true : false); 29 } 30 31 if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_FREEOPTIONS_ZONE > 0) ) { 32 $check_flag = false; 33 $check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_FREEOPTIONS_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id"); 34 while (!$check->EOF) { 35 if ($check->fields['zone_id'] < 1) { 36 $check_flag = true; 37 break; 38 } elseif ($check->fields['zone_id'] == $order->delivery['zone_id']) { 39 $check_flag = true; 40 break; 41 } 42 $check->MoveNext(); 43 } 44 45 if ($check_flag == false) { 46 $this->enabled = false; 47 } 48 } 49 } 50 51 // class methods 52 function quote($method = '') { 53 global $order; 54 $order_weight = round($_SESSION['cart']->show_weight(),9); 55 56 // check if anything is configured for total, weight or item 57 if ((MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN !='' or MODULE_SHIPPING_FREEOPTIONS_TOTAL_MAX !='')) { 58 $this->ck_freeoptions_total = true; 59 } else { 60 $this->ck_freeoptions_total = false; 61 } 62 if ((MODULE_SHIPPING_FREEOPTIONS_WEIGHT_MIN !='' or MODULE_SHIPPING_FREEOPTIONS_WEIGHT_MAX !='')) { 63 $this->ck_freeoptions_weight = true; 64 } else { 65 $this->ck_freeoptions_weight = false; 66 } 67 if ((MODULE_SHIPPING_FREEOPTIONS_ITEMS_MIN !='' or MODULE_SHIPPING_FREEOPTIONS_ITEMS_MAX !='')) { 68 $this->ck_freeoptions_items = true; 69 } else { 70 $this->ck_freeoptions_items = false; 71 } 72 if ($this->ck_freeoptions_total or $this->ck_freeoptions_weight or $this->ck_freeoptions_items) { 73 $this->enabled = true; 74 } else { 75 $this->enabled = false; 76 } 77 78 // disabled if nothing validates for total, weight or item 79 if ($this->enabled) { 80 if ($this->ck_freeoptions_total) { 81 switch (true) { 82 case ((MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN !='' and MODULE_SHIPPING_FREEOPTIONS_TOTAL_MAX !='')): 83 // free shipping total should not need adjusting 84 // if (($_SESSION['cart']->show_total() - $_SESSION['cart']->free_shipping_prices()) >= MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN and ($_SESSION['cart']->show_total() - $_SESSION['cart']->free_shipping_prices()) <= MODULE_SHIPPING_FREEOPTIONS_TOTAL_MAX) { 85 if (($_SESSION['cart']->show_total()) >= MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN and ($_SESSION['cart']->show_total()) <= MODULE_SHIPPING_FREEOPTIONS_TOTAL_MAX) { 86 $this->ck_freeoptions_total = true; 87 } else { 88 $this->ck_freeoptions_total = false; 89 } 90 break; 91 case ((MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN !='')): 92 // if (($_SESSION['cart']->show_total() - $_SESSION['cart']->free_shipping_prices()) >= MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN) { 93 if (($_SESSION['cart']->show_total()) >= MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN) { 94 $this->ck_freeoptions_total = true; 95 } else { 96 $this->ck_freeoptions_total = false; 97 } 98 break; 99 case ((MODULE_SHIPPING_FREEOPTIONS_TOTAL_MAX !='')): 100 // if (($_SESSION['cart']->show_total() - $_SESSION['cart']->free_shipping_prices()) <= MODULE_SHIPPING_FREEOPTIONS_TOTAL_MAX) { 101 if (($_SESSION['cart']->show_total()) <= MODULE_SHIPPING_FREEOPTIONS_TOTAL_MAX) { 102 $this->ck_freeoptions_total = true; 103 } else { 104 $this->ck_freeoptions_total = false; 105 } 106 break; 107 } 108 } 109 110 if ($this->ck_freeoptions_weight) { 111 switch (true) { 112 case ((MODULE_SHIPPING_FREEOPTIONS_WEIGHT_MIN !='' and MODULE_SHIPPING_FREEOPTIONS_WEIGHT_MAX !='')): 113 if ($order_weight >= MODULE_SHIPPING_FREEOPTIONS_WEIGHT_MIN and $order_weight <= MODULE_SHIPPING_FREEOPTIONS_WEIGHT_MAX) { 114 $this->ck_freeoptions_weight = true; 115 } else { 116 $this->ck_freeoptions_weight = false; 117 } 118 break; 119 case ((MODULE_SHIPPING_FREEOPTIONS_WEIGHT_MIN !='')): 120 if ($order_weight >= MODULE_SHIPPING_FREEOPTIONS_WEIGHT_MIN) { 121 $this->ck_freeoptions_weight = true; 122 } else { 123 $this->ck_freeoptions_weight = false; 124 } 125 break; 126 case ((MODULE_SHIPPING_FREEOPTIONS_WEIGHT_MAX !='')): 127 if ($order_weight <= MODULE_SHIPPING_FREEOPTIONS_WEIGHT_MAX) { 128 $this->ck_freeoptions_weight = true; 129 } else { 130 $this->ck_freeoptions_weight = false; 131 } 132 break; 133 } 134 } 135 136 if ($this->ck_freeoptions_items) { 137 switch (true) { 138 case ((MODULE_SHIPPING_FREEOPTIONS_ITEMS_MIN !='' and MODULE_SHIPPING_FREEOPTIONS_ITEMS_MAX !='')): 139 // free shipping items should not need adjusting 140 // if (($_SESSION['cart']->count_contents() - $_SESSION['cart']->free_shipping_items()) >= MODULE_SHIPPING_FREEOPTIONS_ITEMS_MIN and ($_SESSION['cart']->count_contents() - $_SESSION['cart']->free_shipping_items()) <= MODULE_SHIPPING_FREEOPTIONS_ITEMS_MAX) { 141 if (($_SESSION['cart']->count_contents()) >= MODULE_SHIPPING_FREEOPTIONS_ITEMS_MIN and ($_SESSION['cart']->count_contents()) <= MODULE_SHIPPING_FREEOPTIONS_ITEMS_MAX) { 142 $this->ck_freeoptions_items = true; 143 } else { 144 $this->ck_freeoptions_items = false; 145 } 146 break; 147 case ((MODULE_SHIPPING_FREEOPTIONS_ITEMS_MIN !='')): 148 // if (($_SESSION['cart']->count_contents() - $_SESSION['cart']->free_shipping_items()) >= MODULE_SHIPPING_FREEOPTIONS_ITEMS_MIN) { 149 if (($_SESSION['cart']->count_contents()) >= MODULE_SHIPPING_FREEOPTIONS_ITEMS_MIN) { 150 $this->ck_freeoptions_items = true; 151 } else { 152 $this->ck_freeoptions_items = false; 153 } 154 break; 155 case ((MODULE_SHIPPING_FREEOPTIONS_ITEMS_MAX !='')): 156 // if (($_SESSION['cart']->count_contents() - $_SESSION['cart']->free_shipping_items())<= MODULE_SHIPPING_FREEOPTIONS_ITEMS_MAX) { 157 if (($_SESSION['cart']->count_contents())<= MODULE_SHIPPING_FREEOPTIONS_ITEMS_MAX) { 158 $this->ck_freeoptions_items = true; 159 } else { 160 $this->ck_freeoptions_items = false; 161 } 162 break; 163 } 164 } 165 } 166 167 /* 168 echo 'I see count: ' . $_SESSION['cart']->count_contents() . ' free count: ' . $_SESSION['cart']->free_shipping_items() . '<br>' . 169 'I see weight: ' . $_SESSION['cart']->show_weight() . '<br>' . 170 'I see total: ' . $_SESSION['cart']->show_total() . ' free price: ' . $_SESSION['cart']->free_shipping_prices() . '<br>' . 171 'Final check ' . ($this->ck_freeoptions_total ? 'T: YES ' : 'T: NO ') . ($this->ck_freeoptions_weight ? 'W: YES ' : 'W: NO ') . ($this->ck_freeoptions_items ? 'I: YES ' : 'I: NO ') . '<br>'; 172 */ 173 174 // final check for display of Free Options 175 if ($this->ck_freeoptions_total or $this->ck_freeoptions_weight or $this->ck_freeoptions_items) { 176 $this->enabled = true; 177 } else { 178 $this->enabled = false; 179 } 180 181 if ($this->enabled) { 182 $this->quotes = array('id' => $this->code, 183 'module' => MODULE_SHIPPING_FREEOPTIONS_TEXT_TITLE, 184 'methods' => array(array('id' => $this->code, 185 'title' => MODULE_SHIPPING_FREEOPTIONS_TEXT_WAY, 186 'cost' => MODULE_SHIPPING_FREEOPTIONS_COST + MODULE_SHIPPING_FREEOPTIONS_HANDLING))); 187 } 188 189 if ($this->tax_class > 0) { 190 $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); 191 } 192 193 if (zen_not_null($this->icon)) $this->quotes['icon'] = zen_image($this->icon, $this->title); 194 195 return $this->quotes; 196 } 197 198 function check() { 199 global $db; 200 if (!isset($this->_check)) { 201 $check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_FREEOPTIONS_STATUS'"); 202 $this->_check = $check_query->RecordCount(); 203 } 204 return $this->_check; 205 } 206 207 function install() { 208 global $db; 209 $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Free Options Shipping', 'MODULE_SHIPPING_FREEOPTIONS_STATUS', 'True', 'Free Options is used to display a Free Shipping option when other Shipping Modules are displayed. 210 It can be based on: Always show, Order Total, Order Weight or Order Item Count. 211 The Free Options module does not show when Free Shipper is displayed.<br /><br /> 212 Setting Total to >= 0.00 and <= nothing (leave blank) will activate this module to show with all shipping modules, except for Free Shipping - freeshipper.<br /><br /> 213 NOTE: Leaving all settings for Total, Weight and Item count blank will deactivate this module.<br /><br /> 214 NOTE: Free Shipping Options does not display if Free Shipping is used based on 0 weight is Free Shipping. 215 See: freeshipper<br /><br />Do you want to offer per freeoptions rate shipping?', '6', '0', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())"); 216 $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Shipping Cost', 'MODULE_SHIPPING_FREEOPTIONS_COST', '0.00', 'The shipping cost will be $0.00', '6', '0', now())"); 217 $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Handling Fee', 'MODULE_SHIPPING_FREEOPTIONS_HANDLING', '0', 'Handling fee for this shipping method.', '6', '0', now())"); 218 219 $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Total >=', 'MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN', '0.00', 'Free Shipping when Total >=', '6', '0', now())"); 220 $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Total <=', 'MODULE_SHIPPING_FREEOPTIONS_TOTAL_MAX', '', 'Free Shipping when Total <=', '6', '0', now())"); 221 222 $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Weight >=', 'MODULE_SHIPPING_FREEOPTIONS_WEIGHT_MIN', '', 'Free Shipping when Weight >=', '6', '0', now())"); 223 $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Weight <=', 'MODULE_SHIPPING_FREEOPTIONS_WEIGHT_MAX', '', 'Free Shipping when Weight <=', '6', '0', now())"); 224 225 $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Item Count >=', 'MODULE_SHIPPING_FREEOPTIONS_ITEMS_MIN', '', 'Free Shipping when Item Count >=', '6', '0', now())"); 226 $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Item Count <=', 'MODULE_SHIPPING_FREEOPTIONS_ITEMS_MAX', '', 'Free Shipping when Item Count <=', '6', '0', now())"); 227 228 $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Tax Class', 'MODULE_SHIPPING_FREEOPTIONS_TAX_CLASS', '0', 'Use the following tax class on the shipping fee.', '6', '0', 'zen_get_tax_class_title', 'zen_cfg_pull_down_tax_classes(', now())"); 229 $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Tax Basis', 'MODULE_SHIPPING_FREEOPTIONS_TAX_BASIS', 'Shipping', 'On what basis is Shipping Tax calculated. Options are<br />Shipping - Based on customers Shipping Address<br />Billing Based on customers Billing address<br />Store - Based on Store address if Billing/Shipping Zone equals Store zone', '6', '0', 'zen_cfg_select_option(array(\'Shipping\', \'Billing\', \'Store\'), ', now())"); 230 $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Shipping Zone', 'MODULE_SHIPPING_FREEOPTIONS_ZONE', '0', 'If a zone is selected, only enable this shipping method for that zone.', '6', '0', 'zen_get_zone_class_title', 'zen_cfg_pull_down_zone_classes(', now())"); 231 $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_SHIPPING_FREEOPTIONS_SORT_ORDER', '0', 'Sort order of display.', '6', '0', now())"); 232 } 233 234 function remove() { 235 global $db; 236 $db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key LIKE 'MODULE_SHIPPING_FREEOPTIONS_%'"); 237 } 238 239 function keys() { 240 return array('MODULE_SHIPPING_FREEOPTIONS_STATUS', 'MODULE_SHIPPING_FREEOPTIONS_COST', 'MODULE_SHIPPING_FREEOPTIONS_HANDLING', 'MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN', 'MODULE_SHIPPING_FREEOPTIONS_TOTAL_MAX', 'MODULE_SHIPPING_FREEOPTIONS_WEIGHT_MIN', 'MODULE_SHIPPING_FREEOPTIONS_WEIGHT_MAX', 'MODULE_SHIPPING_FREEOPTIONS_ITEMS_MIN', 'MODULE_SHIPPING_FREEOPTIONS_ITEMS_MAX', 'MODULE_SHIPPING_FREEOPTIONS_TAX_CLASS', 'MODULE_SHIPPING_FREEOPTIONS_TAX_BASIS', 'MODULE_SHIPPING_FREEOPTIONS_ZONE', 'MODULE_SHIPPING_FREEOPTIONS_SORT_ORDER'); 241 } 242 } 243 ?>
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 |
![]() |