[ Index ] |
PHP Cross Reference of osCMax 2.0.4 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 $Id: ot_coupon.php 14 2006-07-28 17:42:07Z user $ 4 5 osCMax Power E-Commerce 6 http://oscdox.com 7 8 Copyright 2006 osCMax2005 osCMax, 2002 osCommerce 9 10 Released under the GNU General Public License 11 */ 12 13 class ot_coupon { 14 var $title, $output; 15 16 function ot_coupon() { 17 18 $this->code = 'ot_coupon'; 19 $this->header = MODULE_ORDER_TOTAL_COUPON_HEADER; 20 $this->title = MODULE_ORDER_TOTAL_COUPON_TITLE; 21 $this->description = MODULE_ORDER_TOTAL_COUPON_DESCRIPTION; 22 $this->user_prompt = ''; 23 $this->enabled = MODULE_ORDER_TOTAL_COUPON_STATUS; 24 $this->sort_order = MODULE_ORDER_TOTAL_COUPON_SORT_ORDER; 25 $this->include_shipping = MODULE_ORDER_TOTAL_COUPON_INC_SHIPPING; 26 $this->include_tax = MODULE_ORDER_TOTAL_COUPON_INC_TAX; 27 $this->calculate_tax = MODULE_ORDER_TOTAL_COUPON_CALC_TAX; 28 $this->tax_class = MODULE_ORDER_TOTAL_COUPON_TAX_CLASS; 29 $this->credit_class = true; 30 $this->output = array(); 31 32 } 33 34 function process() { 35 global $PHP_SELF, $order, $currencies; 36 37 38 $order_total=$this->get_order_total(); 39 $od_amount = $this->calculate_credit($order_total); 40 $tod_amount = 0.0; //Fred 41 $this->deduction = $od_amount; 42 if ($this->calculate_tax != 'None') { //Fred - changed from 'none' to 'None'! 43 $tod_amount = $this->calculate_tax_deduction($order_total, $this->deduction, $this->calculate_tax); 44 } 45 46 if ($od_amount > 0) { 47 $order->info['total'] = $order->info['total'] - $od_amount; 48 $this->output[] = array('title' => $this->title . ':' . $this->coupon_code .':','text' => '<b>-' . $currencies->format($od_amount) . '</b>', 'value' => $od_amount); //Fred added hyphen 49 50 //New code for tax recalculation fix 51 if ($tod_amount == 0 || $tod_amount == '') { 52 $pct = $order->info['tax'] / $order->info['subtotal']; 53 $order->info['tax'] = $order->info['tax'] - ($pct * $od_amount); 54 foreach ($order->info['tax_groups'] as $key => $value) { 55 $value = $value - ($pct * $od_amount); 56 $order->info['tax_groups'][$key] = $value; 57 $order->info['total'] -= ($pct * $od_amount); 58 } 59 } 60 //end new code 61 62 } 63 } 64 65 function selection_test() { 66 return false; 67 } 68 69 70 function pre_confirmation_check($order_total) { 71 global $customer_id; 72 return $this->calculate_credit($order_total); 73 } 74 75 function use_credit_amount() { 76 return $output_string; 77 } 78 79 80 function credit_selection() { 81 global $customer_id, $currencies, $language; 82 $selection_string = ''; 83 $selection_string .= '<tr>' . "\n"; 84 $selection_string .= ' <td width="10">' . tep_draw_separator('pixel_trans.gif', '10', '1') .'</td>'; 85 $selection_string .= ' <td class="main">' . "\n"; 86 $image_submit = '<input type="image" name="submit_redeem" onClick="submitFunction()" src="' . DIR_WS_LANGUAGES . $language . '/images/buttons/button_redeem.gif" border="0" alt="' . IMAGE_REDEEM_VOUCHER . '" title = "' . IMAGE_REDEEM_VOUCHER . '">'; 87 $selection_string .= TEXT_ENTER_COUPON_CODE . tep_draw_input_field('gv_redeem_code') . '</td>'; 88 $selection_string .= ' <td align="right">' . $image_submit . '</td>'; 89 $selection_string .= ' <td width="10">' . tep_draw_separator('pixel_trans.gif', '10', '1') . '</td>'; 90 $selection_string .= '</tr>' . "\n"; 91 return $selection_string; 92 } 93 94 95 function collect_posts() { 96 // All tep_redirect URL parameters modified for this function in v5.13 by Rigadin 97 global $HTTP_POST_VARS, $customer_id, $currencies, $cc_id; 98 if ($HTTP_POST_VARS['gv_redeem_code']) { 99 100 // get some info from the coupon table 101 $coupon_query=tep_db_query("select coupon_id, coupon_amount, coupon_type, coupon_minimum_order,uses_per_coupon, uses_per_user, restrict_to_products,restrict_to_categories from " . TABLE_COUPONS . " where coupon_code='".$HTTP_POST_VARS['gv_redeem_code']."' and coupon_active='Y'"); 102 $coupon_result=tep_db_fetch_array($coupon_query); 103 104 if ($coupon_result['coupon_type'] != 'G') { 105 106 if (tep_db_num_rows($coupon_query)==0) { 107 tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error='.$this->code.'&error=' . urlencode(ERROR_NO_INVALID_REDEEM_COUPON), 'SSL')); 108 } 109 110 $date_query=tep_db_query("select coupon_start_date from " . TABLE_COUPONS . " where coupon_start_date <= now() and coupon_code='".$HTTP_POST_VARS['gv_redeem_code']."'"); 111 112 if (tep_db_num_rows($date_query)==0) { 113 tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error='.$this->code.'&error=' . urlencode(ERROR_INVALID_STARTDATE_COUPON), 'SSL')); 114 } 115 116 $date_query=tep_db_query("select coupon_expire_date from " . TABLE_COUPONS . " where coupon_expire_date >= now() and coupon_code='".$HTTP_POST_VARS['gv_redeem_code']."'"); 117 118 if (tep_db_num_rows($date_query)==0) { 119 tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error='.$this->code.'&error=' . urlencode(ERROR_INVALID_FINISDATE_COUPON), 'SSL')); 120 } 121 122 $coupon_count = tep_db_query("select coupon_id from " . TABLE_COUPON_REDEEM_TRACK . " where coupon_id = '" . $coupon_result['coupon_id']."'"); 123 $coupon_count_customer = tep_db_query("select coupon_id from " . TABLE_COUPON_REDEEM_TRACK . " where coupon_id = '" . $coupon_result['coupon_id']."' and customer_id = '" . $customer_id . "'"); 124 125 if (tep_db_num_rows($coupon_count)>=$coupon_result['uses_per_coupon'] && $coupon_result['uses_per_coupon'] > 0) { 126 tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error='.$this->code.'&error=' . urlencode(ERROR_INVALID_USES_COUPON . $coupon_result['uses_per_coupon'] . TIMES ), 'SSL')); 127 } 128 129 if (tep_db_num_rows($coupon_count_customer)>=$coupon_result['uses_per_user'] && $coupon_result['uses_per_user'] > 0) { 130 tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error='.$this->code.'&error=' . urlencode(ERROR_INVALID_USES_USER_COUPON . $coupon_result['uses_per_user'] . TIMES ), 'SSL')); 131 } 132 if ($coupon_result['coupon_type']=='S') { 133 $coupon_amount = $order->info['shipping_cost']; 134 } else { 135 $coupon_amount = $currencies->format($coupon_result['coupon_amount']) . ' '; 136 } 137 if ($coupon_result['coupon_type']=='P') $coupon_amount = $coupon_result['coupon_amount'] . '% '; 138 if ($coupon_result['coupon_minimum_order']>0) $coupon_amount .= 'on orders greater than ' . $coupon_result['coupon_minimum_order']; 139 if (!tep_session_is_registered('cc_id')) tep_session_register('cc_id'); //Fred - this was commented out before 140 $cc_id = $coupon_result['coupon_id']; //Fred ADDED, set the global and session variable 141 // $_SESSION['cc_id'] = $coupon_result['coupon_id']; //Fred commented out, do not use $_SESSION[] due to backward comp. Reference the global var instead. 142 } 143 if ($HTTP_POST_VARS['submit_redeem_coupon_x'] && !$HTTP_POST_VARS['gv_redeem_code']) tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error='.$this->code.'&error=' . urlencode(ERROR_NO_REDEEM_CODE), 'SSL')); 144 } 145 } 146 147 function calculate_credit($amount) { 148 global $customer_id, $order, $cc_id; 149 //$cc_id = $_SESSION['cc_id']; //Fred commented out, do not use $_SESSION[] due to backward comp. Reference the global var instead. 150 $od_amount = 0; 151 if (isset($cc_id) ) { 152 $coupon_query = tep_db_query("select coupon_code from " . TABLE_COUPONS . " where coupon_id = '" . $cc_id . "'"); 153 if (tep_db_num_rows($coupon_query) !=0 ) { 154 $coupon_result = tep_db_fetch_array($coupon_query); 155 $this->coupon_code = $coupon_result['coupon_code']; 156 $coupon_get = tep_db_query("select coupon_amount, coupon_minimum_order, restrict_to_products, restrict_to_categories, coupon_type from " . TABLE_COUPONS ." where coupon_code = '". $coupon_result['coupon_code'] . "'"); 157 $get_result = tep_db_fetch_array($coupon_get); 158 $c_deduct = $get_result['coupon_amount']; 159 if ($get_result['coupon_type']=='S') $c_deduct = $order->info['shipping_cost']; 160 if ($get_result['coupon_minimum_order'] <= $this->get_order_total()) { 161 if ($get_result['restrict_to_products'] || $get_result['restrict_to_categories']) { 162 for ($i=0; $i<sizeof($order->products); $i++) { 163 if ($get_result['restrict_to_products']) { 164 $pr_ids = split("[,]", $get_result['restrict_to_products']); 165 for ($ii = 0; $ii < count($pr_ids); $ii++) { 166 if ($pr_ids[$ii] == tep_get_prid($order->products[$i]['id'])) { 167 if ($get_result['coupon_type'] == 'P') { 168 /* Fixes to Gift Voucher module 5.03 169 ================================= 170 Submitted by Rob Cote, [email protected] 171 172 original code: $od_amount = round($amount*10)/10*$c_deduct/100; 173 $pr_c = $order->products[$i]['final_price']*$order->products[$i]['qty']; 174 $pod_amount = round($pr_c*10)/10*$c_deduct/100; 175 */ 176 //$pr_c = $order->products[$i]['final_price']*$order->products[$i]['qty']; 177 //$pr_c = $this->product_price($pr_ids[$ii]); //Fred 2003-10-28, fix for the row above, otherwise the discount is calc based on price excl VAT! 178 $pr_c = $this->product_price($order->products[$i]['id']); //osCMax bugfix #47 179 $pod_amount = round($pr_c*10)/10*$c_deduct/100; 180 $od_amount = $od_amount + $pod_amount; 181 } else { 182 $od_amount = $c_deduct; 183 } 184 } 185 } 186 } else { 187 $cat_ids = split("[,]", $get_result['restrict_to_categories']); 188 for ($i=0; $i<sizeof($order->products); $i++) { 189 $my_path = tep_get_product_path(tep_get_prid($order->products[$i]['id'])); 190 $sub_cat_ids = split("[_]", $my_path); 191 for ($iii = 0; $iii < count($sub_cat_ids); $iii++) { 192 for ($ii = 0; $ii < count($cat_ids); $ii++) { 193 if ($sub_cat_ids[$iii] == $cat_ids[$ii]) { 194 if ($get_result['coupon_type'] == 'P') { 195 /* Category Restriction Fix to Gift Voucher module 5.04 196 Date: August 3, 2003 197 ================================= 198 Nick Stanko of UkiDev.com, [email protected] 199 200 original code: 201 $od_amount = round($amount*10)/10*$c_deduct/100; 202 $pr_c = $order->products[$i]['final_price']*$order->products[$i]['qty']; 203 $pod_amount = round($pr_c*10)/10*$c_deduct/100; 204 */ 205 //$od_amount = round($amount*10)/10*$c_deduct/100; 206 //$pr_c = $order->products[$i]['final_price']*$order->products[$i]['qty']; 207 //$pr_c = $this->product_price(tep_get_prid($order->products[$i]['id'])); //Fred 2003-10-28, fix for the row above, otherwise the discount is calc based on price excl VAT! 208 $pr_c = $this->product_price($order->products[$i]['id']); //osCMax bugfix #47 209 $pod_amount = round($pr_c*10)/10*$c_deduct/100; 210 $od_amount = $od_amount + $pod_amount; 211 } else { 212 $od_amount = $c_deduct; 213 } 214 } 215 } 216 } 217 } 218 } 219 } 220 } else { 221 if ($get_result['coupon_type'] !='P') { 222 $od_amount = $c_deduct; 223 } else { 224 $od_amount = $amount * $get_result['coupon_amount'] / 100; 225 } 226 } 227 } 228 } 229 if ($od_amount>$amount) $od_amount = $amount; 230 } 231 return $od_amount; 232 } 233 234 function calculate_tax_deduction($amount, $od_amount, $method) { 235 global $customer_id, $order, $cc_id, $cart; 236 //$cc_id = $_SESSION['cc_id']; //Fred commented out, do not use $_SESSION[] due to backward comp. Reference the global var instead. 237 $coupon_query = tep_db_query("select coupon_code from " . TABLE_COUPONS . " where coupon_id = '" . $cc_id . "'"); 238 if (tep_db_num_rows($coupon_query) !=0 ) { 239 $coupon_result = tep_db_fetch_array($coupon_query); 240 $coupon_get = tep_db_query("select coupon_amount, coupon_minimum_order, restrict_to_products, restrict_to_categories, coupon_type from " . TABLE_COUPONS . " where coupon_code = '". $coupon_result['coupon_code'] . "'"); 241 $get_result = tep_db_fetch_array($coupon_get); 242 if ($get_result['coupon_type'] != 'S') { 243 244 //RESTRICTION-------------------------------- 245 if ($get_result['restrict_to_products'] || $get_result['restrict_to_categories']) { 246 // What to do here. 247 // Loop through all products and build a list of all product_ids, price, tax class 248 // at the same time create total net amount. 249 // then 250 // for percentage discounts. simply reduce tax group per product by discount percentage 251 // or 252 // for fixed payment amount 253 // calculate ratio based on total net 254 // for each product reduce tax group per product by ratio amount. 255 $products = $cart->get_products(); 256 $valid_product = false; 257 for ($i=0; $i<sizeof($products); $i++) { 258 $valid_product = false; 259 $t_prid = tep_get_prid($products[$i]['id']); 260 $cc_query = tep_db_query("select products_tax_class_id from " . TABLE_PRODUCTS . " where products_id = '" . $t_prid . "'"); 261 $cc_result = tep_db_fetch_array($cc_query); 262 if ($get_result['restrict_to_products']) { 263 $pr_ids = split("[,]", $get_result['restrict_to_products']); 264 for ($p = 0; $p < sizeof($pr_ids); $p++) { 265 if ($pr_ids[$p] == $t_prid) $valid_product = true; 266 } 267 } 268 if ($get_result['restrict_to_categories']) { 269 $cat_ids = split("[,]", $get_result['restrict_to_categories']); 270 for ($c = 0; $c < sizeof($cat_ids); $c++) { 271 $cat_query = tep_db_query("select products_id from products_to_categories where products_id = '" . $products_id . "' and categories_id = '" . $cat_ids[$i] . "'"); 272 if (tep_db_num_rows($cat_query) !=0 ) $valid_product = true; 273 } 274 } 275 if ($valid_product) { 276 $price_excl_vat = $products[$i]['final_price'] * $products[$i]['quantity']; //Fred - added 277 $price_incl_vat = $this->product_price($t_prid); //Fred - added 278 $valid_array[] = array('product_id' => $t_prid, 'products_price' => $price_excl_vat, 'products_tax_class' => $cc_result['products_tax_class_id']); //jason //Fred - changed from $products[$i]['final_price'] 'products_tax_class' => $cc_result['products_tax_class_id']); 279 // $total_price += $price_incl_vat; //Fred - changed 280 $total_price += $price_excl_vat; // changed 281 } 282 } 283 if (sizeof($valid_array) > 0) { // if ($valid_product) { 284 if ($get_result['coupon_type'] == 'P') { 285 $ratio = $get_result['coupon_amount']/100; 286 } else { 287 $ratio = $od_amount / $total_price; 288 } 289 if ($get_result['coupon_type'] == 'S') $ratio = 1; 290 if ($method=='Credit Note') { 291 $tax_rate = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); 292 $tax_desc = tep_get_tax_description($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); 293 if ($get_result['coupon_type'] == 'P') { 294 $tod_amount = $od_amount / (100 + $tax_rate)* $tax_rate; 295 } else { 296 $tod_amount = $order->info['tax_groups'][$tax_desc] * $od_amount/100; 297 } 298 $order->info['tax_groups'][$tax_desc] -= $tod_amount; 299 $order->info['total'] -= $tod_amount; // need to modify total ...OLD 300 $order->info['tax'] -= $tod_amount; //Fred - added 301 } else { 302 for ($p=0; $p<sizeof($valid_array); $p++) { 303 $tax_rate = tep_get_tax_rate($valid_array[$p]['products_tax_class'], $order->delivery['country']['id'], $order->delivery['zone_id']); 304 $tax_desc = tep_get_tax_description($valid_array[$p]['products_tax_class'], $order->delivery['country']['id'], $order->delivery['zone_id']); 305 if ($tax_rate > 0) { 306 //Fred $tod_amount[$tax_desc] += ($valid_array[$p]['products_price'] * $tax_rate)/100 * $ratio; //OLD 307 $tod_amount = ($valid_array[$p]['products_price'] * $tax_rate)/100 * $ratio; // calc total tax Fred - added 308 $order->info['tax_groups'][$tax_desc] -= ($valid_array[$p]['products_price'] * $tax_rate)/100 * $ratio; 309 $order->info['total'] -= ($valid_array[$p]['products_price'] * $tax_rate)/100 * $ratio; // adjust total 310 $order->info['tax'] -= ($valid_array[$p]['products_price'] * $tax_rate)/100 * $ratio; // adjust tax -- Fred - added 311 } 312 } 313 } 314 } 315 //NO RESTRICTION-------------------------------- 316 } else { 317 if ($get_result['coupon_type'] =='F') { 318 $tod_amount = 0; 319 if ($method=='Credit Note') { 320 $tax_rate = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); 321 $tax_desc = tep_get_tax_description($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); 322 $tod_amount = $od_amount / (100 + $tax_rate)* $tax_rate; 323 $order->info['tax_groups'][$tax_desc] -= $tod_amount; 324 } else { 325 // $ratio1 = $od_amount/$amount; // this produces the wrong ratipo on fixed amounts 326 reset($order->info['tax_groups']); 327 while (list($key, $value) = each($order->info['tax_groups'])) { 328 $ratio1 = $od_amount/($amount-$order->info['tax_groups'][$key]); ////debug 329 $tax_rate = tep_get_tax_rate_from_desc($key); 330 $net = $tax_rate * $order->info['tax_groups'][$key]; 331 if ($net>0) { 332 $god_amount = $order->info['tax_groups'][$key] * $ratio1; 333 $tod_amount += $god_amount; 334 $order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount; 335 } 336 } 337 } 338 $order->info['total'] -= $tod_amount; //OLD 339 $order->info['tax'] -= $tod_amount; //Fred - added 340 } 341 if ($get_result['coupon_type'] =='P') { 342 $tod_amount=0; 343 if ($method=='Credit Note') { 344 $tax_desc = tep_get_tax_description($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); 345 $tod_amount = $order->info['tax_groups'][$tax_desc] * $od_amount/100; 346 $order->info['tax_groups'][$tax_desc] -= $tod_amount; 347 } else { 348 reset($order->info['tax_groups']); 349 while (list($key, $value) = each($order->info['tax_groups'])) { 350 $god_amount=0; 351 $tax_rate = tep_get_tax_rate_from_desc($key); 352 $net = $tax_rate * $order->info['tax_groups'][$key]; 353 if ($net>0) { 354 $god_amount = $order->info['tax_groups'][$key] * $get_result['coupon_amount']/100; 355 $tod_amount += $god_amount; 356 $order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount; 357 } 358 } 359 } 360 $order->info['total'] -= $tod_amount; // have to modify total also 361 $order->info['tax'] -= $tod_amount; 362 } 363 } 364 } 365 } 366 return $tod_amount; 367 } 368 369 function update_credit_account($i) { 370 return false; 371 } 372 373 function apply_credit() { 374 global $insert_id, $customer_id, $REMOTE_ADDR, $cc_id; 375 //$cc_id = $_SESSION['cc_id']; //Fred commented out, do not use $_SESSION[] due to backward comp. Reference the global var instead. 376 if ($this->deduction !=0) { 377 tep_db_query("insert into " . TABLE_COUPON_REDEEM_TRACK . " (coupon_id, redeem_date, redeem_ip, customer_id, order_id) values ('" . $cc_id . "', now(), '" . $REMOTE_ADDR . "', '" . $customer_id . "', '" . $insert_id . "')"); 378 } 379 tep_session_unregister('cc_id'); 380 } 381 382 function get_order_total() { 383 global $order, $cart, $customer_id, $cc_id; 384 //$cc_id = $_SESSION['cc_id']; //Fred commented out, do not use $_SESSION[] due to backward comp. Reference the global var instead. 385 $order_total = $order->info['total']; 386 // Check if gift voucher is in cart and adjust total 387 $products = $cart->get_products(); 388 for ($i=0; $i<sizeof($products); $i++) { 389 $t_prid = tep_get_prid($products[$i]['id']); 390 $gv_query = tep_db_query("select products_price, products_tax_class_id, products_model from " . TABLE_PRODUCTS . " where products_id = '" . $t_prid . "'"); 391 $gv_result = tep_db_fetch_array($gv_query); 392 if (ereg('^GIFT', addslashes($gv_result['products_model']))) { 393 $qty = $cart->get_quantity($t_prid); 394 $products_tax = tep_get_tax_rate($gv_result['products_tax_class_id']); 395 if ($this->include_tax =='false') { 396 $gv_amount = $gv_result['products_price'] * $qty; 397 } else { 398 $gv_amount = ($gv_result['products_price'] + tep_calculate_tax($gv_result['products_price'],$products_tax)) * $qty; 399 } 400 $order_total=$order_total - $gv_amount; 401 } 402 } 403 if ($this->include_tax == 'false') $order_total=$order_total-$order->info['tax']; 404 if ($this->include_shipping == 'false') $order_total=$order_total-$order->info['shipping_cost']; 405 // OK thats fine for global coupons but what about restricted coupons 406 // where you can only redeem against certain products/categories. 407 // and I though this was going to be easy !!! 408 $coupon_query=tep_db_query("select coupon_code from " . TABLE_COUPONS . " where coupon_id='".$cc_id."'"); 409 if (tep_db_num_rows($coupon_query) !=0) { 410 $coupon_result=tep_db_fetch_array($coupon_query); 411 $coupon_get=tep_db_query("select coupon_amount, coupon_minimum_order,restrict_to_products,restrict_to_categories, coupon_type from " . TABLE_COUPONS . " where coupon_code='".$coupon_result['coupon_code']."'"); 412 $get_result=tep_db_fetch_array($coupon_get); 413 $in_cat = true; 414 if ($get_result['restrict_to_categories']) { 415 $cat_ids = split("[,]", $get_result['restrict_to_categories']); 416 $in_cat=false; 417 for ($i = 0; $i < count($cat_ids); $i++) { 418 if (is_array($this->contents)) { 419 reset($this->contents); 420 while (list($products_id, ) = each($this->contents)) { 421 $cat_query = tep_db_query("select products_id from products_to_categories where products_id = '" . $products_id . "' and categories_id = '" . $cat_ids[$i] . "'"); 422 if (tep_db_num_rows($cat_query) !=0 ) { 423 $in_cat = true; 424 $total_price += $this->get_product_price($products_id); 425 } 426 } 427 } 428 } 429 } 430 $in_cart = true; 431 if ($get_result['restrict_to_products']) { 432 433 $pr_ids = split("[,]", $get_result['restrict_to_products']); 434 435 $in_cart=false; 436 $products_array = $cart->get_products(); 437 438 for ($i = 0; $i < sizeof($pr_ids); $i++) { 439 for ($ii = 1; $ii<=sizeof($products_array); $ii++) { 440 if (tep_get_prid($products_array[$ii-1]['id']) == $pr_ids[$i]) { 441 $in_cart=true; 442 $total_price += $this->get_product_price($products_array[$ii-1]['id']); 443 } 444 } 445 } 446 $order_total = $total_price; 447 } 448 } 449 return $order_total; 450 } 451 452 function get_product_price($product_id) { 453 global $cart, $order; 454 $products_id = tep_get_prid($product_id); 455 // products price 456 $qty = $cart->contents[$product_id]['qty']; 457 $product_query = tep_db_query("select products_id, products_price, products_tax_class_id, products_weight from " . TABLE_PRODUCTS . " where products_id='" . $product_id . "'"); 458 if ($product = tep_db_fetch_array($product_query)) { 459 $prid = $product['products_id']; 460 $products_tax = tep_get_tax_rate($product['products_tax_class_id']); 461 $products_price = $product['products_price']; 462 $specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . $prid . "' and status = '1'"); 463 if (tep_db_num_rows ($specials_query)) { 464 $specials = tep_db_fetch_array($specials_query); 465 $products_price = $specials['specials_new_products_price']; 466 } 467 if ($this->include_tax == 'true') { 468 $total_price += ($products_price + tep_calculate_tax($products_price, $products_tax)) * $qty; 469 // echo("total price = " . $total_price . " products_price = " . $products_price . " products_tax = " . $products_tax . "<br>"); 470 471 } else { 472 $total_price += $products_price * $qty; 473 } 474 475 // attributes price 476 if (isset($cart->contents[$product_id]['attributes'])) { 477 reset($cart->contents[$product_id]['attributes']); 478 while (list($option, $value) = each($cart->contents[$product_id]['attributes'])) { 479 $attribute_price_query = tep_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . $prid . "' and options_id = '" . $option . "' and options_values_id = '" . $value . "'"); 480 $attribute_price = tep_db_fetch_array($attribute_price_query); 481 if ($attribute_price['price_prefix'] == '+') { 482 if ($this->include_tax == 'true') { 483 $total_price += $qty * ($attribute_price['options_values_price'] + tep_calculate_tax($attribute_price['options_values_price'], $products_tax)); 484 } else { 485 $total_price += $qty * ($attribute_price['options_values_price']); 486 } 487 } else { 488 if ($this->include_tax == 'true') { 489 $total_price -= $qty * ($attribute_price['options_values_price'] + tep_calculate_tax($attribute_price['options_values_price'], $products_tax)); 490 } else { 491 $total_price -= $qty * ($attribute_price['options_values_price']); 492 } 493 } 494 } 495 } 496 } 497 if ($this->include_shipping == 'true') { 498 499 $total_price += $order->info['shipping_cost']; 500 } 501 return $total_price; 502 } 503 504 //Added by Fred -- BOF ----------------------------------------------------- 505 //JUST RETURN THE PRODUCT PRICE (INCL ATTRIBUTE PRICES) WITH OR WITHOUT TAX 506 function product_price($product_id) { 507 $total_price = $this->get_product_price($product_id); 508 if ($this->include_shipping == 'true') $total_price -= $order->info['shipping_cost']; 509 return $total_price; 510 } 511 //Added by Fred -- EOF ----------------------------------------------------- 512 513 // START added by Rigadin in v5.13, needed to show module errors on checkout_payment page 514 function get_error() { 515 global $HTTP_GET_VARS; 516 517 $error = array('title' => MODULE_ORDER_TOTAL_COUPON_TEXT_ERROR, 518 'error' => stripslashes(urldecode($HTTP_GET_VARS['error']))); 519 520 return $error; 521 } 522 // END added by Rigadin 523 524 function check() { 525 if (!isset($this->check)) { 526 $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_ORDER_TOTAL_COUPON_STATUS'"); 527 $this->check = tep_db_num_rows($check_query); 528 } 529 530 return $this->check; 531 } 532 533 function keys() { 534 return array('MODULE_ORDER_TOTAL_COUPON_STATUS', 'MODULE_ORDER_TOTAL_COUPON_SORT_ORDER', 'MODULE_ORDER_TOTAL_COUPON_INC_SHIPPING', 'MODULE_ORDER_TOTAL_COUPON_INC_TAX', 'MODULE_ORDER_TOTAL_COUPON_CALC_TAX', 'MODULE_ORDER_TOTAL_COUPON_TAX_CLASS'); 535 } 536 537 function install() { 538 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Display Total', 'MODULE_ORDER_TOTAL_COUPON_STATUS', 'true', 'Do you want to display the Discount Coupon value?', '6', '1','tep_cfg_select_option(array(\'true\', \'false\'), ', now())"); 539 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_ORDER_TOTAL_COUPON_SORT_ORDER', '9', 'Sort order of display.', '6', '2', now())"); 540 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function ,date_added) values ('Include Shipping', 'MODULE_ORDER_TOTAL_COUPON_INC_SHIPPING', 'true', 'Include Shipping in calculation', '6', '5', 'tep_cfg_select_option(array(\'true\', \'false\'), ', now())"); 541 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function ,date_added) values ('Include Tax', 'MODULE_ORDER_TOTAL_COUPON_INC_TAX', 'true', 'Include Tax in calculation.', '6', '6','tep_cfg_select_option(array(\'true\', \'false\'), ', now())"); 542 tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function ,date_added) values ('Re-calculate Tax', 'MODULE_ORDER_TOTAL_COUPON_CALC_TAX', 'None', 'Re-Calculate Tax', '6', '7','tep_cfg_select_option(array(\'None\', \'Standard\', \'Credit Note\'), ', now())"); 543 tep_db_query("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_ORDER_TOTAL_COUPON_TAX_CLASS', '0', 'Use the following tax class when treating Discount Coupon as Credit Note.', '6', '0', 'tep_get_tax_class_title', 'tep_cfg_pull_down_tax_classes(', now())"); 544 } 545 546 function remove() { 547 $keys = ''; 548 $keys_array = $this->keys(); 549 for ($i=0; $i<sizeof($keys_array); $i++) { 550 $keys .= "'" . $keys_array[$i] . "',"; 551 } 552 $keys = substr($keys, 0, -1); 553 554 tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in (" . $keys . ")"); 555 } 556 } 557 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Jan 1 13:43:16 2010 | Cross-referenced by PHPXref 0.7 |