1
|
<?php
|
2
|
/* --------------------------------------------------------------
|
3
|
ot_coupon.php 2015-09-17
|
4
|
Gambio GmbH
|
5
|
http://www.gambio.de
|
6
|
Copyright (c) 2015 Gambio GmbH
|
7
|
Released under the GNU General Public License (Version 2)
|
8
|
[http://www.gnu.org/licenses/gpl-2.0.html]
|
9
|
--------------------------------------------------------------
|
10
|
|
11
|
|
12
|
based on:
|
13
|
(c) 2000-2001 The Exchange Project (earlier name of osCommerce)
|
14
|
(c) 2002-2003 osCommerce(ot_coupon.php,v 1.1.2.37.3); www.oscommerce.com
|
15
|
(c) 2003 XT-Commerce - community made shopping http://www.xt-commerce.com ($Id: ot_coupon.php 1322 2005-10-27 13:58:22Z mz $)
|
16
|
|
17
|
Released under the GNU General Public License
|
18
|
-----------------------------------------------------------------------------------------
|
19
|
Third Party contributions:
|
20
|
|
21
|
Credit Class/Gift Vouchers/Discount Coupons (Version 5.10)
|
22
|
http://www.oscommerce.com/community/contributions,282
|
23
|
Copyright (c) Strider | Strider@oscworks.com
|
24
|
Copyright (c Nick Stanko of UkiDev.com, nick@ukidev.com
|
25
|
Copyright (c) Andre ambidex@gmx.net
|
26
|
Copyright (c) 2001,2002 Ian C Wilson http://www.phesis.org
|
27
|
|
28
|
Released under the GNU General Public License
|
29
|
--------------------------------------------------------------------------------------- */
|
30
|
|
31
|
require_once(DIR_FS_INC . 'xtc_get_currencies_values.inc.php');
|
32
|
|
33
|
class ot_coupon_ORIGIN
|
34
|
{
|
35
|
var $title, $output;
|
36
|
|
37
|
public function __construct()
|
38
|
{
|
39
|
global $xtPrice;
|
40
|
|
41
|
$this->code = 'ot_coupon';
|
42
|
$this->header = MODULE_ORDER_TOTAL_COUPON_HEADER;
|
43
|
$this->title = MODULE_ORDER_TOTAL_COUPON_TITLE;
|
44
|
$this->description = MODULE_ORDER_TOTAL_COUPON_DESCRIPTION;
|
45
|
$this->user_prompt = '';
|
46
|
$this->enabled = MODULE_ORDER_TOTAL_COUPON_STATUS;
|
47
|
$this->sort_order = MODULE_ORDER_TOTAL_COUPON_SORT_ORDER;
|
48
|
$this->include_shipping = MODULE_ORDER_TOTAL_COUPON_INC_SHIPPING;
|
49
|
$this->include_tax = MODULE_ORDER_TOTAL_COUPON_INC_TAX;
|
50
|
$this->calculate_tax = MODULE_ORDER_TOTAL_COUPON_CALC_TAX;
|
51
|
$this->tax_class = MODULE_ORDER_TOTAL_COUPON_TAX_CLASS;
|
52
|
$this->credit_class = true;
|
53
|
$this->output = array();
|
54
|
}
|
55
|
|
56
|
function process()
|
57
|
{
|
58
|
global $order, $xtPrice;
|
59
|
|
60
|
$t_gm_check_coupon = xtc_db_query("SELECT coupon_id
|
61
|
FROM " . TABLE_COUPONS . "
|
62
|
WHERE
|
63
|
coupon_id = '" . (int)$_SESSION['cc_id'] . "'
|
64
|
AND coupon_active = 'Y'");
|
65
|
if(xtc_db_num_rows($t_gm_check_coupon) == 1)
|
66
|
{
|
67
|
$order_total = $this->get_order_total();
|
68
|
$od_amount = $this->calculate_credit($order_total);
|
69
|
$tod_amount = 0.0; //Fred
|
70
|
$this->deduction = $od_amount;
|
71
|
|
72
|
if($this->calculate_tax != 'None') //Fred - changed from 'none' to 'None'!
|
73
|
{
|
74
|
$tod_amount = $this->calculate_tax_deduction($order_total, $this->deduction, $this->calculate_tax);
|
75
|
}
|
76
|
|
77
|
if($od_amount > 0)
|
78
|
{
|
79
|
if($_SESSION['customers_status']['customers_status_show_price_tax'] == 0 && $_SESSION['gm_coupon_type'] != 'P')
|
80
|
{
|
81
|
$od_amount -= $tod_amount;
|
82
|
}
|
83
|
unset($_SESSION['gm_coupon_type']);
|
84
|
|
85
|
$order->info['subtotal'] = $order->info['subtotal'] - round($od_amount, 2);
|
86
|
$order->info['total'] = $order->info['total'] - round($od_amount, 2);
|
87
|
$order->info['deduction'] = $od_amount;
|
88
|
$this->output[] = array('title' => $this->title . ': ' . $this->coupon_code . ':',
|
89
|
'text' => '-' . $xtPrice->xtcFormat($od_amount, true),
|
90
|
'value' => $od_amount * -1); //Fred added hyphen
|
91
|
}
|
92
|
}
|
93
|
}
|
94
|
|
95
|
function selection_test()
|
96
|
{
|
97
|
return false;
|
98
|
}
|
99
|
|
100
|
function pre_confirmation_check($order_total)
|
101
|
{
|
102
|
|
103
|
return $this->calculate_credit($order_total);
|
104
|
}
|
105
|
|
106
|
function use_credit_amount()
|
107
|
{
|
108
|
return $output_string;
|
109
|
}
|
110
|
|
111
|
function credit_selection()
|
112
|
{
|
113
|
return false;
|
114
|
}
|
115
|
|
116
|
function collect_posts()
|
117
|
{
|
118
|
global $xtPrice;
|
119
|
|
120
|
if($_POST['gv_redeem_code'])
|
121
|
{
|
122
|
// get some info from the coupon table
|
123
|
$coupon_query = xtc_db_query("SELECT
|
124
|
coupon_id,
|
125
|
coupon_amount,
|
126
|
coupon_type,
|
127
|
coupon_minimum_order,
|
128
|
uses_per_coupon,
|
129
|
uses_per_user,
|
130
|
restrict_to_products,
|
131
|
restrict_to_categories
|
132
|
FROM " . TABLE_COUPONS . "
|
133
|
WHERE
|
134
|
coupon_code = '" . xtc_db_input($_POST['gv_redeem_code']) . "' AND
|
135
|
coupon_active = 'Y'");
|
136
|
$coupon_result = xtc_db_fetch_array($coupon_query);
|
137
|
|
138
|
// SS ?
|
139
|
if($coupon_result['coupon_type'] != 'G')
|
140
|
{
|
141
|
|
142
|
if(xtc_db_num_rows($coupon_query) == 0)
|
143
|
{
|
144
|
xtc_redirect(xtc_href_link(FILENAME_CHECKOUT_PAYMENT, 'error_message=' . urlencode(ERROR_NO_INVALID_REDEEM_COUPON), 'SSL'));
|
145
|
}
|
146
|
|
147
|
$date_query = xtc_db_query("SELECT coupon_start_date
|
148
|
FROM " . TABLE_COUPONS . "
|
149
|
WHERE
|
150
|
coupon_start_date <= now() AND
|
151
|
coupon_code='" . xtc_db_input($_POST['gv_redeem_code']) . "'");
|
152
|
|
153
|
if(xtc_db_num_rows($date_query) == 0)
|
154
|
{
|
155
|
xtc_redirect(xtc_href_link(FILENAME_CHECKOUT_PAYMENT, 'error_message=' . urlencode(ERROR_INVALID_STARTDATE_COUPON), 'SSL'));
|
156
|
}
|
157
|
|
158
|
$date_query = xtc_db_query("SELECT coupon_expire_date
|
159
|
FROM " . TABLE_COUPONS . "
|
160
|
WHERE
|
161
|
coupon_expire_date >= now() AND
|
162
|
coupon_code='" . xtc_db_input($_POST['gv_redeem_code']) . "'");
|
163
|
|
164
|
if(xtc_db_num_rows($date_query) == 0)
|
165
|
{
|
166
|
xtc_redirect(xtc_href_link(FILENAME_CHECKOUT_PAYMENT, 'error_message=' . urlencode(ERROR_INVALID_FINISDATE_COUPON), 'SSL'));
|
167
|
}
|
168
|
|
169
|
$coupon_count = xtc_db_query("SELECT coupon_id FROM " . TABLE_COUPON_REDEEM_TRACK . " WHERE coupon_id = '" . $coupon_result['coupon_id'] . "'");
|
170
|
$coupon_count_customer = xtc_db_query("SELECT coupon_id
|
171
|
FROM " . TABLE_COUPON_REDEEM_TRACK . "
|
172
|
WHERE
|
173
|
coupon_id = '" . $coupon_result['coupon_id'] . "' AND
|
174
|
customer_id = '" . $_SESSION['customer_id'] . "'");
|
175
|
|
176
|
if(xtc_db_num_rows($coupon_count) >= $coupon_result['uses_per_coupon'] && $coupon_result['uses_per_coupon'] > 0)
|
177
|
{
|
178
|
xtc_redirect(xtc_href_link(FILENAME_CHECKOUT_PAYMENT, 'error_message=' . urlencode(ERROR_INVALID_USES_COUPON . $coupon_result['uses_per_coupon'] . TIMES), 'SSL'));
|
179
|
}
|
180
|
|
181
|
if(xtc_db_num_rows($coupon_count_customer) >= $coupon_result['uses_per_user'] && $coupon_result['uses_per_user'] > 0)
|
182
|
{
|
183
|
xtc_redirect(xtc_href_link(FILENAME_CHECKOUT_PAYMENT, 'error_message=' . urlencode(ERROR_INVALID_USES_USER_COUPON . $coupon_result['uses_per_user'] . TIMES), 'SSL'));
|
184
|
}
|
185
|
|
186
|
if($coupon_result['coupon_type'] == 'S')
|
187
|
{
|
188
|
$coupon_amount = $order->info['shipping_cost'];
|
189
|
}
|
190
|
else
|
191
|
{
|
192
|
$coupon_amount = $xtPrice->xtcFormat($coupon_result['coupon_amount'], true) . ' ';
|
193
|
}
|
194
|
|
195
|
if($coupon_result['coupon_type'] == 'P')
|
196
|
{
|
197
|
$coupon_amount = $coupon_result['coupon_amount'] . '% ';
|
198
|
}
|
199
|
|
200
|
if($coupon_result['coupon_minimum_order'] > 0)
|
201
|
{
|
202
|
$t_gm_currency_array = array();
|
203
|
$t_gm_currency_array = xtc_get_currencies_values($_SESSION['currency']);
|
204
|
if(!empty($t_gm_currency_array['value']))
|
205
|
{
|
206
|
$coupon_result['coupon_minimum_order'] = (double)$coupon_result['coupon_minimum_order'] * (double)$t_gm_currency_array['value'];
|
207
|
$coupon_result['coupon_minimum_order'] = round($coupon_result['coupon_minimum_order'], 2);
|
208
|
}
|
209
|
$coupon_amount .= 'on orders greater than ' . $coupon_result['coupon_minimum_order'];
|
210
|
}
|
211
|
|
212
|
$_SESSION['cc_id'] = $coupon_result['coupon_id']; //Fred ADDED, set the global and session variable
|
213
|
}
|
214
|
|
215
|
if($_POST['submit_redeem_coupon_x'] && !$_POST['gv_redeem_code'])
|
216
|
{
|
217
|
xtc_redirect(xtc_href_link(FILENAME_CHECKOUT_PAYMENT, 'error_message=' . urlencode(ERROR_NO_REDEEM_CODE), 'SSL'));
|
218
|
}
|
219
|
}
|
220
|
}
|
221
|
|
222
|
function calculate_credit($amount)
|
223
|
{
|
224
|
global $order;
|
225
|
|
226
|
$od_amount = 0;
|
227
|
if(isset($_SESSION['cc_id']))
|
228
|
{
|
229
|
$coupon_query = xtc_db_query("SELECT coupon_code FROM " . TABLE_COUPONS . " WHERE coupon_id = '" . $_SESSION['cc_id'] . "'");
|
230
|
$t_order_total = $this->get_order_total();
|
231
|
|
232
|
if(xtc_db_num_rows($coupon_query) != 0)
|
233
|
{
|
234
|
$coupon_result = xtc_db_fetch_array($coupon_query);
|
235
|
$this->coupon_code = $coupon_result['coupon_code'];
|
236
|
$coupon_get = xtc_db_query("SELECT
|
237
|
coupon_amount,
|
238
|
coupon_minimum_order,
|
239
|
restrict_to_products,
|
240
|
restrict_to_categories,
|
241
|
coupon_type
|
242
|
FROM " . TABLE_COUPONS . "
|
243
|
WHERE coupon_code = '" . $coupon_result['coupon_code'] . "'");
|
244
|
$get_result = xtc_db_fetch_array($coupon_get);
|
245
|
$c_deduct = $get_result['coupon_amount'];
|
246
|
|
247
|
if($get_result['coupon_type'] != 'P')
|
248
|
{
|
249
|
$t_gm_currency_array = array();
|
250
|
$t_gm_currency_array = xtc_get_currencies_values($_SESSION['currency']);
|
251
|
|
252
|
if(!empty($t_gm_currency_array['value']))
|
253
|
{
|
254
|
$c_deduct *= (double)$t_gm_currency_array['value'];
|
255
|
$c_deduct = round($c_deduct, 2);
|
256
|
}
|
257
|
}
|
258
|
|
259
|
$t_gm_currency_array = array();
|
260
|
$t_gm_currency_array = xtc_get_currencies_values($_SESSION['currency']);
|
261
|
|
262
|
if(!empty($t_gm_currency_array['value']))
|
263
|
{
|
264
|
$get_result['coupon_minimum_order'] = (double)$get_result['coupon_minimum_order'] * (double)$t_gm_currency_array['value'];
|
265
|
$get_result['coupon_minimum_order'] = round($get_result['coupon_minimum_order'], 2);
|
266
|
}
|
267
|
|
268
|
if($get_result['coupon_minimum_order'] <= $t_order_total)
|
269
|
{
|
270
|
if($get_result['restrict_to_products'] || $get_result['restrict_to_categories'])
|
271
|
{
|
272
|
for($i = 0; $i < sizeof($order->products); $i++)
|
273
|
{
|
274
|
if($get_result['restrict_to_products'])
|
275
|
{
|
276
|
$pr_ids = explode(',', $get_result['restrict_to_products']);
|
277
|
|
278
|
for($ii = 0; $ii < count($pr_ids); $ii++)
|
279
|
{
|
280
|
if($pr_ids[$ii] == xtc_get_prid($order->products[$i]['id']))
|
281
|
{
|
282
|
if($get_result['coupon_type'] == 'P')
|
283
|
{
|
284
|
$pr_c = $this->product_price($order->products[$i]['id']); //Fred 2003-10-28, fix for the row above, otherwise the discount is calc based on price excl VAT!
|
285
|
$pod_amount = round($pr_c * 10) / 10 * $c_deduct / 100;
|
286
|
$od_amount = $od_amount + $pod_amount;
|
287
|
}
|
288
|
else
|
289
|
{
|
290
|
$t_gm_price_total += $this->product_price($order->products[$i]['id']);
|
291
|
if($t_gm_price_total < $c_deduct)
|
292
|
{
|
293
|
$od_amount = $t_gm_price_total;
|
294
|
}
|
295
|
else
|
296
|
{
|
297
|
$od_amount = $c_deduct;
|
298
|
}
|
299
|
}
|
300
|
}
|
301
|
}
|
302
|
}
|
303
|
else
|
304
|
{
|
305
|
$cat_ids = explode(',', $get_result['restrict_to_categories']);
|
306
|
|
307
|
for($i = 0; $i < sizeof($order->products); $i++)
|
308
|
{
|
309
|
$t_categories_array = array();
|
310
|
|
311
|
$t_sql = 'SELECT categories_index FROM categories_index WHERE products_id = "' . xtc_get_prid($order->products[$i]['id']) . '"';
|
312
|
$t_result = xtc_db_query($t_sql);
|
313
|
|
314
|
if(xtc_db_num_rows($t_result) == 1)
|
315
|
{
|
316
|
$t_row = xtc_db_fetch_array($t_result);
|
317
|
preg_match_all('-(\d+)-', $t_row['categories_index'], $t_matches);
|
318
|
foreach($t_matches[1] AS $t_products_categorie_id)
|
319
|
{
|
320
|
if($t_products_categorie_id != 0)
|
321
|
{
|
322
|
$t_categories_array[] = $t_products_categorie_id;
|
323
|
}
|
324
|
}
|
325
|
}
|
326
|
|
327
|
for($iii = 0; $iii < count($t_categories_array); $iii++)
|
328
|
{
|
329
|
for($ii = 0; $ii < count($cat_ids); $ii++)
|
330
|
{
|
331
|
if($t_categories_array[$iii] == $cat_ids[$ii])
|
332
|
{
|
333
|
if($get_result['coupon_type'] == 'P')
|
334
|
{
|
335
|
$pr_c = $this->product_price($order->products[$i]['id']); //Fred 2003-10-28, fix for the row above, otherwise the discount is calc based on price excl VAT!
|
336
|
$pod_amount = round($pr_c * 10) / 10 * $c_deduct / 100;
|
337
|
$od_amount = $od_amount + $pod_amount;
|
338
|
continue 3; // v5.13a Tanaka 2005-4-30: to prevent double counting of a product discount
|
339
|
}
|
340
|
else
|
341
|
{
|
342
|
$t_gm_price_total += $this->product_price($order->products[$i]['id']);
|
343
|
|
344
|
if($t_gm_price_total < $c_deduct)
|
345
|
{
|
346
|
$od_amount = $t_gm_price_total;
|
347
|
}
|
348
|
else
|
349
|
{
|
350
|
$od_amount = $c_deduct;
|
351
|
}
|
352
|
continue 3;
|
353
|
}
|
354
|
}
|
355
|
}
|
356
|
}
|
357
|
}
|
358
|
}
|
359
|
}
|
360
|
}
|
361
|
elseif($get_result['coupon_type'] != 'P')
|
362
|
{
|
363
|
$od_amount = $c_deduct;
|
364
|
}
|
365
|
else
|
366
|
{
|
367
|
$od_amount = $amount * $get_result['coupon_amount'] / 100;
|
368
|
}
|
369
|
}
|
370
|
}
|
371
|
|
372
|
if($get_result['coupon_type'] == 'S' && $get_result['coupon_minimum_order'] <= $t_order_total)
|
373
|
{
|
374
|
$od_amount += $order->info['shipping_cost'];
|
375
|
}
|
376
|
|
377
|
if($od_amount > $amount && $get_result['coupon_type'] == 'S')
|
378
|
{
|
379
|
if($this->include_shipping == 'true')
|
380
|
{
|
381
|
$amount -= $order->info['shipping_cost'];
|
382
|
}
|
383
|
|
384
|
if($od_amount > ($amount + $order->info['shipping_cost']))
|
385
|
{
|
386
|
$od_amount = $amount + $order->info['shipping_cost'];
|
387
|
}
|
388
|
}
|
389
|
else if($od_amount > $amount)
|
390
|
{
|
391
|
$od_amount = $amount;
|
392
|
}
|
393
|
}
|
394
|
|
395
|
return $od_amount;
|
396
|
}
|
397
|
|
398
|
function calculate_tax_deduction($amount, $od_amount, $method)
|
399
|
{
|
400
|
global $order;
|
401
|
|
402
|
$coo_gm_main = new main();
|
403
|
$t_gm_tax_before_deduction = $order->info['tax'];
|
404
|
|
405
|
$coupon_query = xtc_db_query("SELECT coupon_code FROM " . TABLE_COUPONS . " WHERE coupon_id = '" . $_SESSION['cc_id'] . "'");
|
406
|
if(xtc_db_num_rows($coupon_query) != 0)
|
407
|
{
|
408
|
$coupon_result = xtc_db_fetch_array($coupon_query);
|
409
|
$coupon_get = xtc_db_query("SELECT
|
410
|
coupon_amount,
|
411
|
coupon_minimum_order,
|
412
|
restrict_to_products,
|
413
|
restrict_to_categories,
|
414
|
coupon_type
|
415
|
FROM " . TABLE_COUPONS . "
|
416
|
WHERE coupon_code = '" . $coupon_result['coupon_code'] . "'");
|
417
|
$get_result = xtc_db_fetch_array($coupon_get);
|
418
|
$_SESSION['gm_coupon_type'] = $get_result['coupon_type'];
|
419
|
|
420
|
//RESTRICTION--------------------------------
|
421
|
if($get_result['restrict_to_products'] || $get_result['restrict_to_categories'])
|
422
|
{
|
423
|
// What to do here.
|
424
|
// Loop through all products and build a list of all product_ids, price, tax class
|
425
|
// at the same time create total net amount.
|
426
|
// then
|
427
|
// for percentage discounts. simply reduce tax group per product by discount percentage
|
428
|
// or
|
429
|
// for fixed payment amount
|
430
|
// calculate ratio based on total net
|
431
|
// for each product reduce tax group per product by ratio amount.
|
432
|
$products = $_SESSION['cart']->get_products();
|
433
|
|
434
|
$valid_product = false;
|
435
|
$valid_array = array();
|
436
|
|
437
|
for($i = 0; $i < sizeof($products); $i++)
|
438
|
{
|
439
|
$valid_product = false;
|
440
|
|
441
|
$t_prid = xtc_get_prid($products[$i]['id']);
|
442
|
$cc_query = xtc_db_query("SELECT products_tax_class_id FROM " . TABLE_PRODUCTS . " WHERE products_id = '" . $t_prid . "'");
|
443
|
$cc_result = xtc_db_fetch_array($cc_query);
|
444
|
|
445
|
if($get_result['restrict_to_products'])
|
446
|
{
|
447
|
$pr_ids = explode(',', $get_result['restrict_to_products']);
|
448
|
for($p = 0; $p < sizeof($pr_ids); $p++)
|
449
|
{
|
450
|
if($pr_ids[$p] == $t_prid)
|
451
|
{
|
452
|
$valid_product = true;
|
453
|
}
|
454
|
}
|
455
|
}
|
456
|
|
457
|
if($get_result['restrict_to_categories'])
|
458
|
{
|
459
|
// v5.13a Tanaka 2005-4-30: New code, this correctly identifies valid products in subcategories
|
460
|
$cat_ids = explode(',', $get_result['restrict_to_categories']);
|
461
|
$my_path = xtc_get_product_path($t_prid);
|
462
|
$sub_cat_ids = explode('_', $my_path);
|
463
|
for($iii = 0; $iii < count($sub_cat_ids); $iii++)
|
464
|
{
|
465
|
for($ii = 0; $ii < count($cat_ids); $ii++)
|
466
|
{
|
467
|
if($sub_cat_ids[$iii] == $cat_ids[$ii])
|
468
|
{
|
469
|
$valid_product = true;
|
470
|
continue 2;
|
471
|
}
|
472
|
}
|
473
|
}
|
474
|
}
|
475
|
|
476
|
if($valid_product)
|
477
|
{
|
478
|
$price_excl_vat = $products[$i]['final_price'] * $products[$i]['quantity'];
|
479
|
$valid_array[] = array('product_id' => $t_prid,
|
480
|
'products_price' => $price_excl_vat,
|
481
|
'products_tax_class' => $cc_result['products_tax_class_id']);
|
482
|
$total_price += $price_excl_vat;
|
483
|
}
|
484
|
}
|
485
|
|
486
|
if(sizeof($valid_array) > 0)
|
487
|
{
|
488
|
if($get_result['coupon_type'] == 'P')
|
489
|
{
|
490
|
$ratio = $get_result['coupon_amount'] / 100;
|
491
|
}
|
492
|
else
|
493
|
{
|
494
|
$ratio = $od_amount / $total_price;
|
495
|
}
|
496
|
|
497
|
if($get_result['coupon_type'] == 'S')
|
498
|
{
|
499
|
$ratio = 1;
|
500
|
}
|
501
|
|
502
|
if($method == 'Credit Note')
|
503
|
{
|
504
|
$tax_rate = xtc_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
|
505
|
$tax_desc = $coo_gm_main->getTaxInfo($tax_rate);
|
506
|
|
507
|
if($get_result['coupon_type'] == 'S')
|
508
|
{
|
509
|
$t_gm_od_amount = $od_amount - $order->info['shipping_cost'];
|
510
|
$t_gm_shipping_tax_rate = ($order->info['shipping_cost'] / $_SESSION['shipping']['cost'] - 1) * 100;
|
511
|
$t_gm_shipping_tax_desc = $coo_gm_main->getTaxInfo($t_gm_shipping_tax_rate);
|
512
|
$order->info['tax_groups'][$t_gm_shipping_tax_desc] = $order->info['tax_groups'][$t_gm_shipping_tax_desc] - ((($order->info['shipping_cost'] / (1 + $t_gm_shipping_tax_rate / 100)) - $order->info['shipping_cost']) * (-1));
|
513
|
$order->info['tax'] = $order->info['tax'] - ((($order->info['shipping_cost'] / (1 + $t_gm_shipping_tax_rate / 100)) - $order->info['shipping_cost']) * (-1));
|
514
|
}
|
515
|
else
|
516
|
{
|
517
|
$t_gm_od_amount = $od_amount;
|
518
|
}
|
519
|
|
520
|
$order->info['tax_groups'][$tax_desc] = $order->info['tax_groups'][$tax_desc] - ((($t_gm_od_amount / (1 + $tax_rate / 100)) - $t_gm_od_amount) * (-1));
|
521
|
$order->info['tax'] = $order->info['tax'] - ((($t_gm_od_amount / (1 + $tax_rate / 100)) - $t_gm_od_amount) * (-1));
|
522
|
}
|
523
|
else
|
524
|
{
|
525
|
for($p = 0; $p < sizeof($valid_array); $p++)
|
526
|
{
|
527
|
$tax_rate = xtc_get_tax_rate($valid_array[$p]['products_tax_class'], $order->delivery['country']['id'], $order->delivery['zone_id']);
|
528
|
$tax_desc = $coo_gm_main->getTaxInfo($tax_rate);
|
529
|
|
530
|
$t_gm_ratio = ((100 / $total_price) * $valid_array[$p]['products_price']) / 100;
|
531
|
|
532
|
if($tax_rate > 0)
|
533
|
{
|
534
|
if($get_result['coupon_type'] == 'S' && $_SESSION['shipping']['cost'] == $order->info['shipping_cost'])
|
535
|
{
|
536
|
$order->info['tax_groups'][$tax_desc] -= $_SESSION['shipping']['cost'] * ($tax_rate / 100);
|
537
|
$order->info['tax'] -= $_SESSION['shipping']['cost'] * ($tax_rate / 100);
|
538
|
$t_gm_reduced_price = $valid_array[$p]['products_price'] + $_SESSION['shipping']['cost'] * $t_gm_ratio;
|
539
|
}
|
540
|
else
|
541
|
{
|
542
|
$t_gm_reduced_price = $valid_array[$p]['products_price'] - $od_amount * $t_gm_ratio;
|
543
|
}
|
544
|
|
545
|
|
546
|
if($_SESSION['customers_status']['customers_status_show_price_tax'] === '1')
|
547
|
{
|
548
|
$t_gm_reduced_price_tax = (($t_gm_reduced_price / (1 + $tax_rate / 100)) - $t_gm_reduced_price) * (-1);
|
549
|
$t_gm_reduce_tax = ((($valid_array[$p]['products_price'] / (1 + $tax_rate / 100)) - $valid_array[$p]['products_price']) * (-1)) - $t_gm_reduced_price_tax;
|
550
|
}
|
551
|
else
|
552
|
{
|
553
|
$t_gm_reduced_price_tax = $t_gm_reduced_price * ($tax_rate / 100);
|
554
|
$t_gm_reduce_tax = ($valid_array[$p]['products_price'] * ($tax_rate / 100)) - $t_gm_reduced_price_tax;
|
555
|
}
|
556
|
|
557
|
$order->info['tax_groups'][$tax_desc] -= $t_gm_reduce_tax;
|
558
|
$order->info['tax'] -= $t_gm_reduced_price_tax;
|
559
|
|
560
|
if($order->info['tax_groups'][$tax_desc] < 0.005)
|
561
|
{
|
562
|
$order->info['tax_groups'][$tax_desc] = 0;
|
563
|
}
|
564
|
if($order->info['tax'] < 0.005)
|
565
|
{
|
566
|
$order->info['tax'] = 0;
|
567
|
}
|
568
|
}
|
569
|
}
|
570
|
}
|
571
|
}
|
572
|
}
|
573
|
else //NO RESTRICTION--------------------------------
|
574
|
{
|
575
|
if($get_result['coupon_type'] == 'F' || $get_result['coupon_type'] == 'S')
|
576
|
{
|
577
|
$tod_amount = 0;
|
578
|
|
579
|
if($method == 'Credit Note')
|
580
|
{
|
581
|
$tax_rate = xtc_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
|
582
|
$tax_desc = $coo_gm_main->getTaxInfo($tax_rate);
|
583
|
|
584
|
if($get_result['coupon_type'] == 'S')
|
585
|
{
|
586
|
$t_gm_od_amount = $od_amount - $order->info['shipping_cost'];
|
587
|
$t_gm_shipping_tax_rate = ($order->info['shipping_cost'] / $_SESSION['shipping']['cost'] - 1) * 100;
|
588
|
$t_gm_shipping_tax_desc = $coo_gm_main->getTaxInfo($t_gm_shipping_tax_rate);
|
589
|
$order->info['tax_groups'][$t_gm_shipping_tax_desc] = $order->info['tax_groups'][$t_gm_shipping_tax_desc] - ((($order->info['shipping_cost'] / (1 + $t_gm_shipping_tax_rate / 100)) - $order->info['shipping_cost']) * (-1));
|
590
|
$order->info['tax'] = $order->info['tax'] - ((($order->info['shipping_cost'] / (1 + $t_gm_shipping_tax_rate / 100)) - $order->info['shipping_cost']) * (-1));
|
591
|
}
|
592
|
else
|
593
|
{
|
594
|
$t_gm_od_amount = $od_amount;
|
595
|
}
|
596
|
|
597
|
$order->info['tax_groups'][$tax_desc] = $order->info['tax_groups'][$tax_desc] - ((($t_gm_od_amount / (1 + $tax_rate / 100)) - $t_gm_od_amount) * (-1));
|
598
|
$order->info['tax'] = $order->info['tax'] - ((($t_gm_od_amount / (1 + $tax_rate / 100)) - $t_gm_od_amount) * (-1));
|
599
|
}
|
600
|
else
|
601
|
{
|
602
|
$t_gm_tax_class = array();
|
603
|
$t_gm_tax_class[] = 0;
|
604
|
|
605
|
if(empty($_SESSION['cart']->tax))
|
606
|
{
|
607
|
$t_gm_cart_tax = array();
|
608
|
$t_gm_cart_products = $order->products;
|
609
|
|
610
|
for($i = 0; $i < count($t_gm_cart_products); $i++)
|
611
|
{
|
612
|
if(!isset($t_gm_cart_tax[$t_gm_cart_products[$i]['tax_class_id']]) && $t_gm_cart_products[$i]['tax_class_id'] != 0)
|
613
|
{
|
614
|
$t_gm_cart_tax[$t_gm_cart_products[$i]['tax_class_id']] = array();
|
615
|
$t_gm_cart_tax_desc = $coo_gm_main->getTaxInfo($t_gm_cart_products[$i]['tax']);
|
616
|
$t_gm_cart_tax[$t_gm_cart_products[$i]['tax_class_id']]['value'] = $t_gm_cart_products[$i]['final_price'] * ($t_gm_cart_products[$i]['tax'] / 100);
|
617
|
$t_gm_cart_tax[$t_gm_cart_products[$i]['tax_class_id']]['desc'] = $t_gm_cart_tax_desc;
|
618
|
}
|
619
|
else if($t_gm_cart_products[$i]['tax_class_id'] != 0)
|
620
|
{
|
621
|
$t_gm_cart_tax[$t_gm_cart_products[$i]['tax_class_id']]['value'] += $t_gm_cart_products[$i]['final_price'] * ($t_gm_cart_products[$i]['tax'] / 100);
|
622
|
}
|
623
|
}
|
624
|
}
|
625
|
else
|
626
|
{
|
627
|
$t_gm_cart_tax = $_SESSION['cart']->tax;
|
628
|
}
|
629
|
|
630
|
foreach($t_gm_cart_tax AS $t_gm_key => $t_gm_value)
|
631
|
{
|
632
|
$t_gm_tax_class[] = $t_gm_key;
|
633
|
}
|
634
|
|
635
|
$t_gm_products = array();
|
636
|
$t_gm_total = 0;
|
637
|
|
638
|
foreach($t_gm_tax_class AS $t_gm_tax_class_id)
|
639
|
{
|
640
|
for($i = 0; $i < count($order->products); $i++)
|
641
|
{
|
642
|
if($order->products[$i]['tax_class_id'] == $t_gm_tax_class_id)
|
643
|
{
|
644
|
if($_SESSION['customers_status']['customers_status_show_price_tax'] == 1)
|
645
|
{
|
646
|
$t_gm_products[$t_gm_tax_class_id]['PRICE'] += $order->products[$i]['final_price'];
|
647
|
$t_gm_total += $order->products[$i]['final_price'];
|
648
|
}
|
649
|
else
|
650
|
{
|
651
|
$t_gm_products[$t_gm_tax_class_id]['PRICE'] += $order->products[$i]['final_price'] + $order->products[$i]['final_price'] * $order->products[$i]['tax'] / 100;
|
652
|
$t_gm_total += $order->products[$i]['final_price'] + $order->products[$i]['final_price'] * $order->products[$i]['tax'] / 100;
|
653
|
}
|
654
|
|
655
|
$t_gm_products[$t_gm_tax_class_id]['TAX_RATE'] = $order->products[$i]['tax'];
|
656
|
$t_gm_products[$t_gm_tax_class_id]['TAX_DESC'] = $_SESSION['cart']->tax[$order->products[$i]['tax_class_id']]['desc'];
|
657
|
}
|
658
|
}
|
659
|
}
|
660
|
|
661
|
if($get_result['coupon_type'] == 'S')
|
662
|
{
|
663
|
$od_amount = $od_amount - round($order->info['shipping_cost'], 2);
|
664
|
if($od_amount > $t_gm_total)
|
665
|
{
|
666
|
$od_amount = $t_gm_total;
|
667
|
}
|
668
|
}
|
669
|
|
670
|
foreach($t_gm_products AS $t_gm_key => $t_gm_value)
|
671
|
{
|
672
|
$t_gm_products[$t_gm_key]['RATIO'] = (100 / $t_gm_total) * $t_gm_products[$t_gm_key]['PRICE'];
|
673
|
|
674
|
if($t_gm_products[$t_gm_key]['TAX_RATE'] != 0 && $t_gm_products[$t_gm_key]['PRICE'] != 0)
|
675
|
{
|
676
|
$t_gm_products[$t_gm_key]['TAX'] = ((($t_gm_products[$t_gm_key]['PRICE'] / (1 + $t_gm_products[$t_gm_key]['TAX_RATE'] / 100)) - $t_gm_products[$t_gm_key]['PRICE']) * (-1));
|
677
|
$t_gm_products[$t_gm_key]['TAX_AFTER_DEDUCTION'] = (((($t_gm_products[$t_gm_key]['PRICE'] - round($od_amount * ($t_gm_products[$t_gm_key]['RATIO'] / 100), 2)) / (1 + $t_gm_products[$t_gm_key]['TAX_RATE'] / 100)) - ($t_gm_products[$t_gm_key]['PRICE'] - round($od_amount * ($t_gm_products[$t_gm_key]['RATIO'] / 100), 2))) * (-1));
|
678
|
$t_gm_products[$t_gm_key]['TAX_DEDUCTION'] = $t_gm_products[$t_gm_key]['TAX'] - $t_gm_products[$t_gm_key]['TAX_AFTER_DEDUCTION'];
|
679
|
|
680
|
if($t_gm_products[$t_gm_key]['TAX_AFTER_DEDUCTION'] < 0)
|
681
|
{
|
682
|
$t_gm_products[$t_gm_key]['TAX_AFTER_DEDUCTION'] = 0;
|
683
|
$t_gm_products[$t_gm_key]['TAX_DEDUCTION'] = $t_gm_products[$t_gm_key]['TAX'];
|
684
|
}
|
685
|
|
686
|
$order->info['tax_groups'][$t_gm_products[$t_gm_key]['TAX_DESC']] -= $t_gm_products[$t_gm_key]['TAX_DEDUCTION'];
|
687
|
$order->info['tax'] -= $t_gm_products[$t_gm_key]['TAX_DEDUCTION'];
|
688
|
|
689
|
if($get_result['coupon_type'] == 'S' && $_SESSION['shipping']['cost'] * ( 1 + ($t_gm_products[$t_gm_key]['TAX_RATE'] / 100)) == $order->info['shipping_cost'])
|
690
|
{
|
691
|
$order->info['tax_groups'][$t_gm_products[$t_gm_key]['TAX_DESC']] -= $_SESSION['shipping']['cost'] * ($t_gm_products[$t_gm_key]['TAX_RATE'] / 100);
|
692
|
$order->info['tax'] -= $_SESSION['shipping']['cost'] * ($t_gm_products[$t_gm_key]['TAX_RATE'] / 100);
|
693
|
}
|
694
|
|
695
|
if($_SESSION['shipping']['cost'] * ( 1 + ($t_gm_products[$t_gm_key]['TAX_RATE'] / 100)) == $order->info['shipping_cost'] && $t_gm_total < $od_amount)
|
696
|
{
|
697
|
$t_shipping_costs_reduction = $od_amount - $t_gm_total;
|
698
|
if($t_shipping_costs_reduction > 0)
|
699
|
{
|
700
|
$t_gm_shipping_costs = round($order->info['shipping_cost'], 2);
|
701
|
$t_gm_shipping_costs_tax_old = ($t_gm_shipping_costs / (1 + ($t_gm_products[$t_gm_key]['TAX_RATE'] / 100)) - $t_gm_shipping_costs) * (-1);
|
702
|
$t_gm_shipping_costs -= $t_shipping_costs_reduction;
|
703
|
$t_gm_shipping_costs_tax_new = ($t_gm_shipping_costs / (1 + ($t_gm_products[$t_gm_key]['TAX_RATE'] / 100)) - $t_gm_shipping_costs) * (-1);
|
704
|
$order->info['tax_groups'][$t_gm_products[$t_gm_key]['TAX_DESC']] = $order->info['tax_groups'][$t_gm_products[$t_gm_key]['TAX_DESC']] - $t_gm_shipping_costs_tax_old + $t_gm_shipping_costs_tax_new;
|
705
|
$order->info['tax'] = $order->info['tax'] - $t_gm_shipping_costs_tax_old + $t_gm_shipping_costs_tax_new;
|
706
|
}
|
707
|
else
|
708
|
{
|
709
|
$order->info['tax'] -= $order->info['tax_groups'][$t_gm_products[$t_gm_key]['TAX_DESC']];
|
710
|
$order->info['tax_groups'][$t_gm_products[$t_gm_key]['TAX_DESC']] = 0;
|
711
|
}
|
712
|
}
|
713
|
|
714
|
if($order->info['tax_groups'][$t_gm_products[$t_gm_key]['TAX_DESC']] < 0.005)
|
715
|
{
|
716
|
$order->info['tax_groups'][$t_gm_products[$t_gm_key]['TAX_DESC']] = 0;
|
717
|
}
|
718
|
|
719
|
if($order->info['tax'] < 0.005)
|
720
|
{
|
721
|
$order->info['tax'] = 0;
|
722
|
}
|
723
|
}
|
724
|
else
|
725
|
{
|
726
|
$t_gm_products[$t_gm_key]['TAX'] = 0;
|
727
|
$t_gm_products[$t_gm_key]['TAX_AFTER_DEDUCTION'] = 0;
|
728
|
$t_gm_products[$t_gm_key]['TAX_DEDUCTION'] = 0;
|
729
|
$t_gm_reduced_price = ((100 / $t_gm_total) * $t_gm_products[$t_gm_key]['PRICE']) * $t_gm_products[$t_gm_key]['PRICE'];
|
730
|
}
|
731
|
}
|
732
|
}
|
733
|
}
|
734
|
|
735
|
if($get_result['coupon_type'] == 'P')
|
736
|
{
|
737
|
$tod_amount = 0;
|
738
|
|
739
|
if($method == 'Credit Note')
|
740
|
{
|
741
|
$t_gm_tax_rate = xtc_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
|
742
|
$tax_desc = $coo_gm_main->getTaxInfo($t_gm_tax_rate);
|
743
|
|
744
|
if($get_result['coupon_type'] == 'S')
|
745
|
{
|
746
|
$t_gm_od_amount = $od_amount - $order->info['shipping_cost'];
|
747
|
$t_gm_shipping_tax_rate = ($order->info['shipping_cost'] / $_SESSION['shipping']['cost'] - 1) * 100;
|
748
|
$t_gm_shipping_tax_desc = $coo_gm_main->getTaxInfo($t_gm_shipping_tax_rate);
|
749
|
$order->info['tax_groups'][$t_gm_shipping_tax_desc] = $order->info['tax_groups'][$t_gm_shipping_tax_desc] - ((($order->info['shipping_cost'] / (1 + $t_gm_shipping_tax_rate / 100)) - $order->info['shipping_cost']) * (-1));
|
750
|
$order->info['tax'] = $order->info['tax'] - ((($order->info['shipping_cost'] / (1 + $t_gm_shipping_tax_rate / 100)) - $order->info['shipping_cost']) * (-1));
|
751
|
}
|
752
|
else
|
753
|
{
|
754
|
$_SESSION['gm_coupon_type'] = $get_result['coupon_type'];
|
755
|
$t_gm_od_amount = $od_amount;
|
756
|
}
|
757
|
|
758
|
if($_SESSION['customers_status']['customers_status_show_price_tax'] == 0)
|
759
|
{
|
760
|
$order->info['tax_groups'][$tax_desc] -= ($t_gm_od_amount * ($t_gm_tax_rate / 100));
|
761
|
$order->info['tax'] -= ($t_gm_od_amount * ($t_gm_tax_rate / 100));
|
762
|
}
|
763
|
else
|
764
|
{
|
765
|
$order->info['tax_groups'][$tax_desc] = $order->info['tax_groups'][$tax_desc] - ((($t_gm_od_amount / (1 + $t_gm_tax_rate / 100)) - $t_gm_od_amount) * (-1));
|
766
|
$order->info['tax'] = $order->info['tax'] - ((($t_gm_od_amount / (1 + $t_gm_tax_rate / 100)) - $t_gm_od_amount) * (-1));
|
767
|
}
|
768
|
}
|
769
|
else
|
770
|
{
|
771
|
reset($order->info['tax_groups']);
|
772
|
|
773
|
while(list ($key, $value) = each($order->info['tax_groups']))
|
774
|
{
|
775
|
$_SESSION['gm_coupon_type'] = $get_result['coupon_type'];
|
776
|
$gm_tax_class = 0;
|
777
|
|
778
|
foreach($_SESSION['cart']->tax AS $gm_key => $gm_value)
|
779
|
{
|
780
|
if($gm_value[desc] == $key)
|
781
|
{
|
782
|
$gm_tax_class = $gm_key;
|
783
|
}
|
784
|
}
|
785
|
|
786
|
$tax_rate = xtc_get_tax_rate($gm_tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
|
787
|
|
788
|
if(!empty($tax_rate))
|
789
|
{
|
790
|
$order->info['tax_groups'][$key] *= (100 - $get_result['coupon_amount']) / 100;
|
791
|
$order->info['tax'] *= (100 - $get_result['coupon_amount']) / 100;
|
792
|
}
|
793
|
}
|
794
|
}
|
795
|
}
|
796
|
}
|
797
|
}
|
798
|
|
799
|
if(empty($tod_amount) && $_SESSION['customers_status']['customers_status_add_tax_ot'] == 0)
|
800
|
{
|
801
|
$tod_amount = $t_gm_tax_before_deduction - $order->info['tax'];
|
802
|
}
|
803
|
|
804
|
return $tod_amount;
|
805
|
}
|
806
|
|
807
|
function update_credit_account($i)
|
808
|
{
|
809
|
return false;
|
810
|
}
|
811
|
|
812
|
function apply_credit()
|
813
|
{
|
814
|
global $insert_id;
|
815
|
|
816
|
if($this->deduction != 0)
|
817
|
{
|
818
|
$t_ip = '';
|
819
|
if(gm_get_conf('GM_LOG_IP') == '1' && gm_get_conf('GM_CONFIRM_IP') == 0)
|
820
|
{
|
821
|
$t_ip = xtc_get_ip_address();
|
822
|
}
|
823
|
|
824
|
xtc_db_query("INSERT INTO " . TABLE_COUPON_REDEEM_TRACK . " (coupon_id, redeem_date, redeem_ip, customer_id, order_id)
|
825
|
VALUES ('" . $_SESSION['cc_id'] . "', now(), '" . $t_ip . "', '" . $_SESSION['customer_id'] . "', '" . $insert_id . "')");
|
826
|
}
|
827
|
|
828
|
unset($_SESSION['cc_id']);
|
829
|
}
|
830
|
|
831
|
function get_order_total()
|
832
|
{
|
833
|
global $order, $xtPrice;
|
834
|
|
835
|
$order_total = $order->info['total'];
|
836
|
|
837
|
// Check if gift voucher is in cart and adjust total
|
838
|
$products = $_SESSION['cart']->get_products();
|
839
|
for($i = 0; $i < sizeof($products); $i++)
|
840
|
{
|
841
|
$t_prid = xtc_get_prid($products[$i]['id']);
|
842
|
$gv_query = xtc_db_query("SELECT
|
843
|
products_price,
|
844
|
products_tax_class_id,
|
845
|
products_model
|
846
|
FROM " . TABLE_PRODUCTS . "
|
847
|
WHERE products_id = '" . $t_prid . "'");
|
848
|
$gv_result = xtc_db_fetch_array($gv_query);
|
849
|
|
850
|
if(preg_match('/^GIFT/', $gv_result['products_model']))
|
851
|
{
|
852
|
$qty = $_SESSION['cart']->get_quantity($t_prid);
|
853
|
$products_tax = $xtPrice->TAX[$gv_result['products_tax_class_id']];
|
854
|
|
855
|
if($this->include_tax == 'false')
|
856
|
{
|
857
|
$gv_amount = $gv_result['products_price'] * $qty;
|
858
|
}
|
859
|
else
|
860
|
{
|
861
|
$gv_amount = ($gv_result['products_price'] + $xtPrice->calcTax($gv_result['products_price'], $products_tax)) * $qty;
|
862
|
}
|
863
|
|
864
|
$order_total = $order_total - $gv_amount;
|
865
|
}
|
866
|
}
|
867
|
|
868
|
if($this->include_tax == 'false')
|
869
|
{
|
870
|
$order_total = $order_total - $order->info['tax'];
|
871
|
}
|
872
|
|
873
|
if($this->include_shipping == 'false')
|
874
|
{
|
875
|
$order_total = $order_total - $order->info['shipping_cost'];
|
876
|
}
|
877
|
|
878
|
// OK thats fine for global coupons but what about restricted coupons
|
879
|
// where you can only redeem against certain products/categories.
|
880
|
// and I though this was going to be easy !!!
|
881
|
$coupon_query = xtc_db_query("SELECT coupon_code FROM " . TABLE_COUPONS . " WHERE coupon_id='" . $_SESSION['cc_id'] . "'");
|
882
|
if(xtc_db_num_rows($coupon_query) != 0)
|
883
|
{
|
884
|
$coupon_result = xtc_db_fetch_array($coupon_query);
|
885
|
$coupon_get = xtc_db_query("SELECT
|
886
|
coupon_amount,
|
887
|
coupon_minimum_order,
|
888
|
restrict_to_products,
|
889
|
restrict_to_categories,
|
890
|
coupon_type
|
891
|
FROM " . TABLE_COUPONS . "
|
892
|
WHERE coupon_code = '" . $coupon_result['coupon_code'] . "'");
|
893
|
$get_result = xtc_db_fetch_array($coupon_get);
|
894
|
|
895
|
$in_cat = true;
|
896
|
if($get_result['restrict_to_categories'])
|
897
|
{
|
898
|
$cat_ids = explode(',', $get_result['restrict_to_categories']);
|
899
|
$in_cat = false;
|
900
|
|
901
|
for($i = 0; $i < count($cat_ids); $i++)
|
902
|
{
|
903
|
if(is_array($this->contents))
|
904
|
{
|
905
|
reset($this->contents);
|
906
|
while(list ($products_id, ) = each($this->contents))
|
907
|
{
|
908
|
$cat_query = xtc_db_query("SELECT products_id
|
909
|
FROM products_to_categories
|
910
|
WHERE
|
911
|
products_id = '" . $products_id . "' AND
|
912
|
categories_id = '" . $cat_ids[$i] . "'");
|
913
|
if(xtc_db_num_rows($cat_query) != 0)
|
914
|
{
|
915
|
$in_cat = true;
|
916
|
$total_price += $this->get_product_price($products_id);
|
917
|
}
|
918
|
}
|
919
|
}
|
920
|
}
|
921
|
}
|
922
|
|
923
|
$in_cart = true;
|
924
|
if($get_result['restrict_to_products'])
|
925
|
{
|
926
|
$pr_ids = explode(',', $get_result['restrict_to_products']);
|
927
|
$in_cart = false;
|
928
|
$products_array = $_SESSION['cart']->get_products();
|
929
|
|
930
|
for($i = 0; $i < sizeof($pr_ids); $i++)
|
931
|
{
|
932
|
for($ii = 1; $ii <= sizeof($products_array); $ii++)
|
933
|
{
|
934
|
if(xtc_get_prid($products_array[$ii - 1]['id']) == $pr_ids[$i])
|
935
|
{
|
936
|
$in_cart = true;
|
937
|
$total_price += $this->get_product_price($products_array[$ii - 1]['id']);
|
938
|
}
|
939
|
}
|
940
|
}
|
941
|
|
942
|
$order_total = $total_price;
|
943
|
}
|
944
|
}
|
945
|
|
946
|
return $order_total;
|
947
|
}
|
948
|
|
949
|
function get_product_price($product_id)
|
950
|
{
|
951
|
global $order, $xtPrice;
|
952
|
|
953
|
$qty = $_SESSION['cart']->contents[$product_id]['qty'];
|
954
|
$basket_products_id = $product_id;
|
955
|
$products_id = xtc_get_prid($product_id);
|
956
|
|
957
|
// products price
|
958
|
$product_query = xtc_db_query("SELECT
|
959
|
products_id,
|
960
|
products_price,
|
961
|
products_tax_class_id,
|
962
|
products_weight
|
963
|
FROM " . TABLE_PRODUCTS . "
|
964
|
WHERE products_id='" . (int)$products_id . "'");
|
965
|
if(xtc_db_num_rows($product_query) > 0)
|
966
|
{
|
967
|
$product = xtc_db_fetch_array($product_query);
|
968
|
$prid = $product['products_id'];
|
969
|
|
970
|
if($this->include_tax == 'true')
|
971
|
{
|
972
|
$total_price += $qty * $xtPrice->xtcGetPrice($basket_products_id, $format = false, 1, $product['products_tax_class_id'], $product['products_price'], 1,0,true,true);
|
973
|
$_SESSION['total_price'] = $total_price;
|
974
|
}
|
975
|
else
|
976
|
{
|
977
|
$total_price += $qty * $xtPrice->xtcGetPrice($basket_products_id, $format = false, 1, 0, $product['products_price'], 1,0,true,true);
|
978
|
}
|
979
|
|
980
|
$products_tax = $xtPrice->TAX[$product['products_tax_class_id']];
|
981
|
|
982
|
// attributes price
|
983
|
if(isset($_SESSION['cart']->contents[$product_id]['attributes']))
|
984
|
{
|
985
|
reset($_SESSION['cart']->contents[$product_id]['attributes']);
|
986
|
while(list ($option, $value) = each($_SESSION['cart']->contents[$product_id]['attributes']))
|
987
|
{
|
988
|
$attribute_price_query = xtc_db_query("SELECT
|
989
|
options_values_price,
|
990
|
price_prefix
|
991
|
FROM " . TABLE_PRODUCTS_ATTRIBUTES . "
|
992
|
WHERE
|
993
|
products_id = '" . $prid . "' AND
|
994
|
options_id = '" . $option . "' AND
|
995
|
options_values_id = '" . $value . "'");
|
996
|
$attribute_price = xtc_db_fetch_array($attribute_price_query);
|
997
|
|
998
|
if($attribute_price['price_prefix'] == '+')
|
999
|
{
|
1000
|
if($this->include_tax == 'true')
|
1001
|
{
|
1002
|
$total_price += $qty * ($attribute_price['options_values_price'] + xtc_calculate_tax($attribute_price['options_values_price'], $products_tax));
|
1003
|
}
|
1004
|
else
|
1005
|
{
|
1006
|
$total_price += $qty * ($attribute_price['options_values_price']);
|
1007
|
}
|
1008
|
}
|
1009
|
else
|
1010
|
{
|
1011
|
if($this->include_tax == 'true')
|
1012
|
{
|
1013
|
$total_price -= $qty * ($attribute_price['options_values_price'] + xtc_calculate_tax($attribute_price['options_values_price'], $products_tax));
|
1014
|
}
|
1015
|
else
|
1016
|
{
|
1017
|
$total_price -= $qty * ($attribute_price['options_values_price']);
|
1018
|
}
|
1019
|
}
|
1020
|
}
|
1021
|
}
|
1022
|
}
|
1023
|
|
1024
|
if($_SESSION['customers_status']['customers_status_ot_discount_flag'] == 1)
|
1025
|
{
|
1026
|
$total_price -= $total_price / 100 * $_SESSION['customers_status']['customers_status_ot_discount'];
|
1027
|
}
|
1028
|
|
1029
|
if($this->include_shipping == 'true')
|
1030
|
{
|
1031
|
$total_price += $order->info['shipping_cost'];
|
1032
|
}
|
1033
|
|
1034
|
return $total_price;
|
1035
|
}
|
1036
|
|
1037
|
function product_price($product_id)
|
1038
|
{
|
1039
|
global $order;
|
1040
|
|
1041
|
$total_price = $this->get_product_price($product_id);
|
1042
|
|
1043
|
if($this->include_shipping == 'true')
|
1044
|
{
|
1045
|
$total_price -= $order->info['shipping_cost'];
|
1046
|
}
|
1047
|
|
1048
|
return $total_price;
|
1049
|
}
|
1050
|
|
1051
|
function check()
|
1052
|
{
|
1053
|
if(!isset($this->check))
|
1054
|
{
|
1055
|
$check_query = xtc_db_query("SELECT configuration_value FROM " . TABLE_CONFIGURATION . " WHERE configuration_key = 'MODULE_ORDER_TOTAL_COUPON_STATUS'");
|
1056
|
$this->check = xtc_db_num_rows($check_query);
|
1057
|
}
|
1058
|
|
1059
|
return $this->check;
|
1060
|
}
|
1061
|
|
1062
|
function keys()
|
1063
|
{
|
1064
|
return array('MODULE_ORDER_TOTAL_COUPON_STATUS',
|
1065
|
'MODULE_ORDER_TOTAL_COUPON_SORT_ORDER',
|
1066
|
'MODULE_ORDER_TOTAL_COUPON_INC_SHIPPING',
|
1067
|
'MODULE_ORDER_TOTAL_COUPON_INC_TAX',
|
1068
|
'MODULE_ORDER_TOTAL_COUPON_CALC_TAX',
|
1069
|
'MODULE_ORDER_TOTAL_COUPON_TAX_CLASS');
|
1070
|
}
|
1071
|
|
1072
|
function install()
|
1073
|
{
|
1074
|
xtc_db_query("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_id, configuration_key, configuration_value, configuration_group_id, sort_order, set_function, date_added) VALUES ('', 'MODULE_ORDER_TOTAL_COUPON_STATUS', 'true', '6', '1','gm_cfg_select_option(array(\'true\', \'false\'), ', now())");
|
1075
|
xtc_db_query("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_id, configuration_key, configuration_value, configuration_group_id, sort_order, date_added) VALUES ('', 'MODULE_ORDER_TOTAL_COUPON_SORT_ORDER', '70', '6', '2', now())");
|
1076
|
xtc_db_query("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_id, configuration_key, configuration_value, configuration_group_id, sort_order, set_function, date_added) VALUES ('', 'MODULE_ORDER_TOTAL_COUPON_INC_SHIPPING', 'true', '6', '5', 'gm_cfg_select_option(array(\'true\', \'false\'), ', now())");
|
1077
|
xtc_db_query("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_id, configuration_key, configuration_value, configuration_group_id, sort_order, set_function, date_added) VALUES ('', 'MODULE_ORDER_TOTAL_COUPON_INC_TAX', 'true', '6', '6','gm_cfg_select_option(array(\'true\', \'false\'), ', now())");
|
1078
|
xtc_db_query("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_id, configuration_key, configuration_value, configuration_group_id, sort_order, set_function, date_added) VALUES ('', 'MODULE_ORDER_TOTAL_COUPON_CALC_TAX', 'None', '6', '7','xtc_cfg_select_option(array(\'None\', \'Standard\', \'Credit Note\'), ', now())");
|
1079
|
xtc_db_query("INSERT INTO " . TABLE_CONFIGURATION . " (configuration_id, configuration_key, configuration_value, configuration_group_id, sort_order, use_function, set_function, date_added) VALUES ('', 'MODULE_ORDER_TOTAL_COUPON_TAX_CLASS', '0', '6', '0', 'xtc_get_tax_class_title', 'xtc_cfg_pull_down_tax_classes(', now())");
|
1080
|
|
1081
|
xtc_db_query("UPDATE " . TABLE_CONFIGURATION . " SET configuration_value = 'true' WHERE configuration_key = 'MODULE_ORDER_TOTAL_GV_INC_SHIPPING'");
|
1082
|
}
|
1083
|
|
1084
|
function remove()
|
1085
|
{
|
1086
|
$keys = '';
|
1087
|
$keys_array = $this->keys();
|
1088
|
|
1089
|
for($i = 0; $i < sizeof($keys_array); $i++)
|
1090
|
{
|
1091
|
$keys .= "'" . $keys_array[$i] . "',";
|
1092
|
}
|
1093
|
|
1094
|
$keys = substr($keys, 0, -1);
|
1095
|
|
1096
|
xtc_db_query("DELETE FROM " . TABLE_CONFIGURATION . " WHERE configuration_key IN (" . $keys . ")");
|
1097
|
}
|
1098
|
|
1099
|
}
|
1100
|
|
1101
|
MainFactory::load_origin_class('ot_coupon');
|