-
Notifications
You must be signed in to change notification settings - Fork 2
/
checkout_shipping.php
370 lines (302 loc) · 12.1 KB
/
checkout_shipping.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
<?php
/*
$Id$
osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com
Copyright (c) 2014 osCommerce
Released under the GNU General Public License
*/
require('includes/application_top.php');
require('includes/classes/http_client.php');
// if the customer is not logged on, redirect them to the login page
if (!isset($_SESSION['customer_id'])) {
$navigation->set_snapshot();
tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));
}
// if there is nothing in the customers cart, redirect them to the shopping cart page
if ($cart->count_contents() < 1) {
tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));
}
// if no shipping destination address was selected, use the customers own address as default
if (!isset($_SESSION['sendto'])) {
tep_session_register('sendto');
$sendto = $customer_default_address_id;
} else {
// verify the selected shipping address
if ( (is_array($sendto) && empty($sendto)) || is_numeric($sendto) ) {
$check_address_query = tep_db_query("select count(*) as total from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . (int)$customer_id . "' and address_book_id = '" . (int)$sendto . "'");
$check_address = tep_db_fetch_array($check_address_query);
if ($check_address['total'] != '1') {
$sendto = $customer_default_address_id;
if (isset($_SESSION['shipping'])) unset($_SESSION['shipping']);
}
}
}
require(DIR_WS_CLASSES . 'order.php');
$order = new order;
// register a random ID in the session to check throughout the checkout procedure
// against alterations in the shopping cart contents
if (!isset($_SESSION['cartID'])) {
tep_session_register('cartID');
} elseif (($cartID != $cart->cartID) && isset($_SESSION['shipping'])) {
unset($_SESSION['shipping']);
}
$cartID = $cart->cartID = $cart->generate_cart_id();
// if the order contains only virtual products, forward the customer to the billing page as
// a shipping address is not needed
if ($order->content_type == 'virtual') {
if (!isset($_SESSION['shipping'])) tep_session_register('shipping');
$shipping = false;
$sendto = false;
tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
}
$total_weight = $cart->show_weight();
$total_count = $cart->count_contents();
// load all enabled shipping modules
require(DIR_WS_CLASSES . 'shipping.php');
$shipping_modules = new shipping;
if ( defined('MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING') && (MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING == 'true') ) {
$pass = false;
switch (MODULE_ORDER_TOTAL_SHIPPING_DESTINATION) {
case 'national':
if ($order->delivery['country_id'] == STORE_COUNTRY) {
$pass = true;
}
break;
case 'international':
if ($order->delivery['country_id'] != STORE_COUNTRY) {
$pass = true;
}
break;
case 'both':
$pass = true;
break;
}
$free_shipping = false;
if ( ($pass == true) && ($order->info['total'] >= MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER) ) {
$free_shipping = true;
include(DIR_WS_LANGUAGES . $language . '/modules/order_total/ot_shipping.php');
}
} else {
$free_shipping = false;
}
// process the selected shipping method
if ( isset($_POST['action']) && ($_POST['action'] == 'process') && isset($_POST['formid']) && ($_POST['formid'] == $sessiontoken) ) {
if (!isset($_SESSION['comments'])) tep_session_register('comments');
if (tep_not_null($_POST['comments'])) {
$comments = tep_db_prepare_input($_POST['comments']);
}
if (!isset($_SESSION['shipping'])) tep_session_register('shipping');
if ( (tep_count_shipping_modules() > 0) || ($free_shipping == true) ) {
if ( (isset($_POST['shipping'])) && (strpos($_POST['shipping'], '_')) ) {
$shipping = $_POST['shipping'];
list($module, $method) = explode('_', $shipping);
if ( is_object($$module) || ($shipping == 'free_free') ) {
if ($shipping == 'free_free') {
$quote[0]['methods'][0]['title'] = FREE_SHIPPING_TITLE;
$quote[0]['methods'][0]['cost'] = '0';
} else {
$quote = $shipping_modules->quote($method, $module);
}
if (isset($quote['error'])) {
unset($_SESSION['shipping']);
} else {
if ( (isset($quote[0]['methods'][0]['title'])) && (isset($quote[0]['methods'][0]['cost'])) ) {
$shipping = array('id' => $shipping,
'title' => (($free_shipping == true) ? $quote[0]['methods'][0]['title'] : $quote[0]['module'] . ' (' . $quote[0]['methods'][0]['title'] . ')'),
'cost' => $quote[0]['methods'][0]['cost']);
tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
}
}
} else {
unset($_SESSION['shipping']);
}
}
} else {
if ( defined('SHIPPING_ALLOW_UNDEFINED_ZONES') && (SHIPPING_ALLOW_UNDEFINED_ZONES == 'False') ) {
unset($_SESSION['shipping']);
} else {
$shipping = false;
tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
}
}
}
// get all available shipping quotes
$quotes = $shipping_modules->quote();
// if no shipping method has been selected, automatically select the cheapest method.
// if the modules status was changed when none were available, to save on implementing
// a javascript force-selection method, also automatically select the cheapest shipping
// method if more than one module is now enabled
if ( !isset($_SESSION['shipping']) || ( isset($_SESSION['shipping']) && ($shipping == false) && (tep_count_shipping_modules() > 1) ) ) $shipping = $shipping_modules->cheapest();
require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_CHECKOUT_SHIPPING);
if ( defined('SHIPPING_ALLOW_UNDEFINED_ZONES') && (SHIPPING_ALLOW_UNDEFINED_ZONES == 'False') && ! isset($_SESSION['shipping']) && ($shipping == false) ) {
$messageStack->add_session('checkout_address', ERROR_NO_SHIPPING_AVAILABLE_TO_SHIPPING_ADDRESS);
tep_redirect(tep_href_link(FILENAME_CHECKOUT_SHIPPING_ADDRESS, '', 'SSL'));
}
$breadcrumb->add(NAVBAR_TITLE_1, tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
$breadcrumb->add(NAVBAR_TITLE_2, tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
require(DIR_WS_INCLUDES . 'template_top.php');
?>
<div class="page-header">
<h1><?php echo HEADING_TITLE; ?></h1>
</div>
<?php echo tep_draw_form('checkout_address', tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'), 'post', 'class="form-horizontal"', true) . tep_draw_hidden_field('action', 'process'); ?>
<div class="contentContainer">
<h2><?php echo TABLE_HEADING_SHIPPING_ADDRESS; ?></h2>
<div class="contentText row">
<div class="col-sm-8">
<div class="alert alert-warning">
<?php echo TEXT_CHOOSE_SHIPPING_DESTINATION; ?>
<div class="clearfix"></div>
<div class="pull-right">
<?php echo tep_draw_button(IMAGE_BUTTON_CHANGE_ADDRESS, 'glyphicon glyphicon-home', tep_href_link(FILENAME_CHECKOUT_SHIPPING_ADDRESS, '', 'SSL')); ?>
</div>
<div class="clearfix"></div>
</div>
</div>
<div class="col-sm-4">
<div class="panel panel-primary">
<div class="panel-heading"><?php echo TITLE_SHIPPING_ADDRESS; ?></div>
<div class="panel-body">
<?php echo tep_address_label($customer_id, $sendto, true, ' ', '<br />'); ?>
</div>
</div>
</div>
</div>
<div class="clearfix"></div>
<?php
if (tep_count_shipping_modules() > 0) {
?>
<h2><?php echo TABLE_HEADING_SHIPPING_METHOD; ?></h2>
<?php
if (sizeof($quotes) > 1 && sizeof($quotes[0]) > 1) {
?>
<div class="contentText">
<div class="alert alert-warning">
<div class="row">
<div class="col-xs-8">
<?php echo TEXT_CHOOSE_SHIPPING_METHOD; ?>
</div>
<div class="col-xs-4 text-right">
<?php echo '<strong>' . TITLE_PLEASE_SELECT . '</strong>'; ?>
</div>
</div>
</div>
</div>
<?php
} elseif ($free_shipping == false) {
?>
<div class="contentText">
<div class="alert alert-info"><?php echo TEXT_ENTER_SHIPPING_INFORMATION; ?></div>
</div>
<?php
}
?>
<div class="contentText">
<table class="table table-striped table-condensed table-hover">
<tbody>
<?php
if ($free_shipping == true) {
?>
<div class="contentText">
<div class="panel panel-success">
<div class="panel-heading"><strong><?php echo FREE_SHIPPING_TITLE; ?></strong> <?php echo $quotes[$i]['icon']; ?></div>
<div class="panel-body">
<?php echo sprintf(FREE_SHIPPING_DESCRIPTION, $currencies->format(MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER)) . tep_draw_hidden_field('shipping', 'free_free'); ?>
</div>
</div>
</div>
<?php
} else {
for ($i=0, $n=sizeof($quotes); $i<$n; $i++) {
for ($j=0, $n2=sizeof($quotes[$i]['methods']); $j<$n2; $j++) {
// set the radio button to be checked if it is the method chosen
$checked = (($quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id'] == $shipping['id']) ? true : false);
echo ' <tr>' . "\n";
?>
<td>
<strong><?php echo $quotes[$i]['module']; ?></strong>
<?php
if (isset($quotes[$i]['icon']) && tep_not_null($quotes[$i]['icon'])) echo ' ' . $quotes[$i]['icon'];
?>
<?php
if (isset($quotes[$i]['error'])) {
echo '<div class="help-block">' . $quotes[$i]['error'] . '</div>';
}
?>
<?php
if (tep_not_null($quotes[$i]['methods'][$j]['title'])) echo '<div class="help-block">' . $quotes[$i]['methods'][$j]['title'] . '</div>';
?>
</td>
<?php
if ( ($n > 1) || ($n2 > 1) ) {
?>
<td align="right">
<?php
if (isset($quotes[$i]['error'])) {
// nothing
echo ' ';
}
else {
echo $currencies->format(tep_add_tax($quotes[$i]['methods'][$j]['cost'], (isset($quotes[$i]['tax']) ? $quotes[$i]['tax'] : 0))); ?> <?php echo tep_draw_radio_field('shipping', $quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id'], $checked, 'required aria-required="true"');
}
?>
</td>
<?php
} else {
?>
<td align="right"><?php echo $currencies->format(tep_add_tax($quotes[$i]['methods'][$j]['cost'], (isset($quotes[$i]['tax']) ? $quotes[$i]['tax'] : 0))) . tep_draw_hidden_field('shipping', $quotes[$i]['id'] . '_' . $quotes[$i]['methods'][$j]['id']); ?></td>
<?php
}
?>
</tr>
<?php
}
}
}
?>
</tbody>
</table>
</div>
<?php
}
?>
<hr>
<div class="contentText">
<div class="form-group">
<label for="inputComments" class="control-label col-xs-4"><?php echo TABLE_HEADING_COMMENTS; ?></label>
<div class="col-xs-8">
<?php
echo tep_draw_textarea_field('comments', 'soft', 60, 5, $comments, 'id="inputComments" placeholder="' . TABLE_HEADING_COMMENTS . '"');
?>
</div>
</div>
</div>
<div class="buttonSet">
<div class="text-right"><?php echo tep_draw_button(IMAGE_BUTTON_CONTINUE, 'glyphicon glyphicon-chevron-right', null, 'primary'); ?></div>
</div>
<div class="clearfix"></div>
<div class="contentText">
<div class="stepwizard">
<div class="stepwizard-row">
<div class="stepwizard-step">
<button type="button" class="btn btn-primary btn-circle">1</button>
<p><?php echo CHECKOUT_BAR_DELIVERY; ?></p>
</div>
<div class="stepwizard-step">
<button type="button" class="btn btn-default btn-circle" disabled="disabled">2</button>
<p><?php echo CHECKOUT_BAR_PAYMENT; ?></p>
</div>
<div class="stepwizard-step">
<button type="button" class="btn btn-default btn-circle" disabled="disabled">3</button>
<p><?php echo CHECKOUT_BAR_CONFIRMATION; ?></p>
</div>
</div>
</div>
</div>
</div>
</form>
<?php
require(DIR_WS_INCLUDES . 'template_bottom.php');
require(DIR_WS_INCLUDES . 'application_bottom.php');
?>