ebay_openbay.php
26 KB
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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
<?php
class ModelOpenbayEbayOpenbay extends Model{
public function importOrders($data) {
$this->default_shipped_id = $this->config->get('ebay_status_shipped_id');
$this->default_paid_id = $this->config->get('ebay_status_paid_id');
$this->default_refunded_id = $this->config->get('ebay_status_refunded_id');
$this->default_pending_id = $this->config->get('ebay_status_import_id');
$this->default_part_refunded_id = $this->config->get('ebay_status_partial_refund_id');
if ($this->default_part_refunded_id == null) {
$this->default_part_refunded_id = $this->default_paid_id;
}
$this->tax = ($this->config->get('ebay_tax') == '') ? '1' : (($this->config->get('ebay_tax') / 100) + 1);
$this->tax_type = $this->config->get('ebay_tax_listing');
$data = unserialize($data);
if (isset($data->ordersV2)) {
if (!empty($data->ordersV2)) {
if (is_array($data->ordersV2)) {
foreach ($data->ordersV2 as $order) {
if (isset($order->smpId) && (int)$order->smpId != 0) {
$this->orderHandle($order);
}
}
} else {
if (isset($data->ordersV2->smpId) && (int)$data->ordersV2->smpId != 0) {
$this->orderHandle($data->ordersV2);
}
}
} else {
$this->openbay->ebay->log('Order object empty - no orders');
}
} else {
$this->openbay->ebay->log('Data failed to unserialize');
}
}
public function orderHandle($order) {
$this->load->model('checkout/order');
$this->load->model('openbay/ebay_order');
$this->load->language('openbay/ebay_order');
if ($this->model_openbay_ebay_order->lockExists($order->smpId) == true) {
return;
}
if (!is_array($order->txn)) {
$order->txn = array($order->txn);
}
$ebay_order = $this->openbay->ebay->getOrderBySmpId($order->smpId);
if (isset($ebay_order['order_id'])) {
$order_id = $ebay_order['order_id'];
} else {
$order_id = false;
}
$created_hours = (int)$this->config->get('ebay_created_hours');
if ($created_hours == 0 || $created_hours == '') {
$created_hours = 24;
}
$from = date("Y-m-d H:i:00", mktime(date("H")-(int)$created_hours, date("i"), date("s"), date("m"), date("d"), date("y")));
$this->openbay->ebay->log('Accepting orders newer than: ' . $from);
if ($order_id != false) {
$order_loaded = $this->model_checkout_order->getOrder($order_id);
$order_history = $this->model_openbay_ebay_order->getHistory($order_id);
$this->openbay->ebay->log('Order ID: ' . $order_id . ' -> Updating');
/* check user details to see if we have now been passed the user info */
/* if we have these details then we have the rest of the delivery info */
if (!empty($order->address->name) && !empty($order->address->street1)) {
$this->openbay->ebay->log('User info found');
if ($this->model_openbay_ebay_order->hasAddress($order_id) == false) {
$this->updateOrderWithConfirmedData($order_id, $order);
$this->openbay->ebay->log('Order ID: ' . $order_id . ' -> Updated with user info');
}
} else {
$this->openbay->ebay->log('No user info');
}
if ($order->shipping->status == 'Shipped' && ($order_loaded['order_status_id'] != $this->default_shipped_id) && $order->payment->status == 'Paid') {
$this->model_openbay_ebay_order->update($order_id, $this->default_shipped_id);
$this->openbay->ebay->log('Order ID: ' . $order_id . ' -> Shipped');
} elseif ($order->payment->status == 'Paid' && isset($order->payment->date) && $order->shipping->status != 'Shipped' && ($order_loaded['order_status_id'] != $this->default_paid_id)) {
$this->model_openbay_ebay_order->update($order_id, $this->default_paid_id);
$this->model_openbay_ebay_order->updatePaymentDetails($order_id, $order);
if ($this->config->get('ebay_stock_allocate') == 1) {
$this->openbay->ebay->log('Stock allocation is set to allocate stock when an order is paid');
$this->model_openbay_ebay_order->addOrderLines($order, $order_id);
}
$this->openbay->ebay->log('Order ID: ' . $order_id . ' -> Paid');
} elseif (($order->payment->status == 'Refunded' || $order->payment->status == 'Unpaid') && ($order_loaded['order_status_id'] != $this->default_refunded_id) && in_array($this->default_paid_id, $order_history)) {
$this->model_openbay_ebay_order->update($order_id, $this->default_refunded_id);
$this->model_openbay_ebay_order->cancel($order_id);
$this->openbay->ebay->log('Order ID: ' . $order_id . ' -> Refunded');
} elseif ($order->payment->status == 'Part-Refunded' && ($order_loaded['order_status_id'] != $this->default_part_refunded_id) && in_array($this->default_paid_id, $order_history)) {
$this->model_openbay_ebay_order->update($order_id, $this->default_part_refunded_id);
$this->openbay->ebay->log('Order ID: ' . $order_id . ' -> Part Refunded');
} else {
$this->openbay->ebay->log('Order ID: ' . $order_id . ' -> No Update');
}
} else {
$this->openbay->ebay->log('Created: ' . $order->order->created);
if (isset($order->order->checkoutstatus)) {
$this->openbay->ebay->log('Checkout: ' . $order->order->checkoutstatus);
}
if (isset($order->payment->date)) {
$this->openbay->ebay->log('Paid date: ' . $order->payment->date);
}
/**
* FOLLOWING ORDER STATE TESTS REQUIRED
*
* - single item order, not checked out but then marked as paid. i.e. user wants to pay by manual method such as cheque
* - multi item order, same as above. Is this possible? i dont think the order will combine if checkout not done.
*/
if ($this->config->get('ebay_import_unpaid') == 1) {
$this->openbay->ebay->log('Set to import unpaid orders');
} else {
$this->openbay->ebay->log('Ignore unpaid orders');
}
if (($order->order->created >= $from || (isset($order->payment->date) && $order->payment->date >= $from)) && (isset($order->payment->date) || $this->config->get('ebay_import_unpaid') == 1)) {
$this->openbay->ebay->log('Creating new order');
/* need to create the order without creating customer etc */
$order_id = $this->create($order);
$this->openbay->ebay->log('Order ID: ' . $order_id . ' -> Created . ');
/* add link */
$this->model_openbay_ebay_order->orderLinkCreate((int)$order_id, (int)$order->smpId);
/* check user details to see if we have now been passed the user info, if we have these details then we have the rest of the delivery info */
if (!empty($order->address->name) && !empty($order->address->street1)) {
$this->openbay->ebay->log('User info found . ');
if ($this->model_openbay_ebay_order->hasAddress($order_id) == false) {
$this->updateOrderWithConfirmedData($order_id, $order);
$this->openbay->ebay->log('Order ID: ' . $order_id . ' -> Updated with user info . ');
}
} else {
$this->openbay->ebay->log('No user information.');
}
$default_import_message = $this->language->get('text_smp_id') . (int)$order->smpId . "\r\n";
$default_import_message .= $this->language->get('text_buyer') . (string)$order->user->userid . "\r\n";
//new order, set to pending initially.
$this->model_openbay_ebay_order->confirm($order_id, $this->default_pending_id, $default_import_message);
$this->openbay->ebay->log('Order ID: ' . $order_id . ' -> Pending');
$order_status_id = $this->default_pending_id;
//order has been paid
if ($order->payment->status == 'Paid') {
$this->model_openbay_ebay_order->update($order_id, $this->default_paid_id);
$this->openbay->ebay->log('Order ID: ' . $order_id . ' -> Paid');
$order_status_id = $this->default_paid_id;
if ($this->config->get('ebay_stock_allocate') == 1) {
$this->openbay->ebay->log('Stock allocation is set to allocate stock when an order is paid');
$this->model_openbay_ebay_order->addOrderLines($order, $order_id);
}
}
//order has been refunded
if ($order->payment->status == 'Refunded') {
$this->model_openbay_ebay_order->update($order_id, $this->default_refunded_id);
$this->model_openbay_ebay_order->cancel($order_id);
$this->openbay->ebay->log('Order ID: ' . $order_id . ' -> Refunded');
$order_status_id = $this->default_refunded_id;
}
//order is part refunded
if ($order->payment->status == 'Part-Refunded') {
$this->model_openbay_ebay_order->update($order_id, $this->default_part_refunded_id);
$this->openbay->ebay->log('Order ID: ' . $order_id . ' -> Part Refunded');
$order_status_id = $this->default_part_refunded_id;
}
//order payment is clearing
if ($order->payment->status == 'Clearing') {
$this->model_openbay_ebay_order->update($order_id, $this->default_pending_id);
$this->openbay->ebay->log('Order ID: ' . $order_id . ' -> Clearing');
$order_status_id = $this->default_pending_id;
}
//order is marked shipped
if ($order->shipping->status == 'Shipped') {
$this->model_openbay_ebay_order->update($order_id, $this->default_shipped_id);
$this->openbay->ebay->log('Order ID: ' . $order_id . ' -> Shipped');
$order_status_id = $this->default_shipped_id;
}
// Admin Alert Mail
if ($this->config->get('ebay_confirmadmin_notify') == 1) {
$this->openbay->newOrderAdminNotify($order_id, $order_status_id);
}
}
if ($this->config->get('ebay_stock_allocate') == 0) {
$this->openbay->ebay->log('Stock allocation is set to allocate stock when an item is bought');
$this->model_openbay_ebay_order->addOrderLines($order, $order_id);
}
}
if (!empty($order->cancelled)) {
$this->openbay->ebay->log('There are cancelled items in the order');
$this->model_openbay_ebay_order->removeOrderLines($order->cancelled, $order_id);
}
//remove the lock.
$this->model_openbay_ebay_order->lockDelete($order->smpId);
}
private function create($order) {
if ($this->openbay->addonLoad('openstock')) {
$openstock = true;
} else {
$openstock = false;
}
$this->load->model('localisation/currency');
$this->load->model('catalog/product');
if (isset($order->order->currency_id) && !empty($order->order->currency_id)) {
$currency = $this->model_localisation_currency->getCurrencyByCode($order->order->currency_id);
}
if (empty($currency)) {
$currency = $this->model_localisation_currency->getCurrencyByCode($this->config->get('ebay_def_currency'));
}
if ($this->config->get('ebay_create_date') == 1) {
$created_date_obj = new DateTime((string)$order->order->created);
$offset = ($this->config->get('ebay_time_offset') != '') ? (int)$this->config->get('ebay_time_offset') : (int)0;
$created_date_obj->modify($offset . ' hour');
$created_date = $created_date_obj->format('Y-m-d H:i:s');
} else {
$created_date = date("Y-m-d H:i:s");
$offset = 0;
}
$this->openbay->ebay->log('create() - Order date: ' . $created_date);
$this->openbay->ebay->log('create() - Original date: ' . (string)$order->order->created);
$this->openbay->ebay->log('create() - Offset: ' . $offset);
$this->openbay->ebay->log('create() - Server time: ' . date("Y-m-d H:i:s"));
$this->db->query("INSERT INTO `" . DB_PREFIX . "order` SET
`store_id` = '" . (int)$this->config->get('config_store_id') . "',
`store_name` = '" . $this->db->escape($this->config->get('config_name') . ' / eBay') . "',
`store_url` = '" . $this->db->escape($this->config->get('config_url')) . "',
`invoice_prefix` = '" . $this->db->escape($this->config->get('config_invoice_prefix')) . "',
`comment` = '" . $this->db->escape((string)$order->order->message) . "',
`total` = '" . (double)$order->order->total . "',
`affiliate_id` = '0',
`commission` = '0',
`language_id` = '" . (int)$this->config->get('config_language_id') . "',
`currency_id` = '" . (int)$currency['currency_id'] . "',
`currency_code` = '" . $this->db->escape($currency['code']) . "',
`currency_value` = '" . (double)$currency['value'] . "',
`ip` = '',
`date_added` = '" . $this->db->escape($created_date) . "',
`date_modified` = NOW(),
`customer_id` = 0
");
$order_id = $this->db->getLastId();
foreach ($order->txn as $txn) {
$product_id = $this->openbay->ebay->getProductId($txn->item->id);
if ($product_id != false) {
$this->openbay->ebay->log('create() - Product ID: "' . $product_id . '" from ebay item: ' . $txn->item->id . ' was returned');
if (!empty($txn->item->variantsku) && $openstock == true) {
$model_number = $this->openbay->getProductModelNumber($product_id, $txn->item->variantsku);
} else {
$model_number = $this->openbay->getProductModelNumber($product_id);
}
} else {
$this->openbay->ebay->log('create() - No product ID from ebay item: ' . $txn->item->id . ' was returned');
$model_number = '';
}
$qty = (int)$txn->item->qty;
$price = (double)$txn->item->price;
$this->openbay->ebay->log('create() - Item price: ' . $price);
if ($this->tax_type == 1) {
//calculate taxes that come in from eBay
$this->openbay->ebay->log('create() - Using tax rates from eBay');
$price_net = $price;
$this->openbay->ebay->log('create() - Net price: ' . $price_net);
$total_net = $price * $qty;
$this->openbay->ebay->log('create() - Total net price: ' . $total_net);
$tax = number_format((double)$txn->item->tax->item, 4, '.', '');
$this->openbay->ebay->log('create() - Tax: ' . $tax);
} else {
//use the store pre-set tax-rate for everything
$this->openbay->ebay->log('create() - Using tax rates from store');
$price_net = $price / $this->tax;
$this->openbay->ebay->log('create() - Net price: ' . $price_net);
$total_net = $price_net * $qty;
$this->openbay->ebay->log('create() - Total net price: ' . $total_net);
$tax = number_format(($price - $price_net), 4, '.', '');
$this->openbay->ebay->log('create() - Tax: ' . $tax);
}
$txn->item->name = stripslashes($txn->item->name);
$txn->item->varianttitle = stripslashes($txn->item->varianttitle);
$txn->item->sku = stripslashes($txn->item->sku);
$txn->item->variantsku = stripslashes($txn->item->variantsku);
$this->db->query("INSERT INTO `" . DB_PREFIX . "order_product` SET
`order_id` = '" . (int)$order_id . "',
`product_id` = '" . (int)$product_id . "',
`name` = '" . $this->db->escape((isset($txn->item->varianttitle) && !empty($txn->item->varianttitle)) ? $txn->item->varianttitle : $txn->item->name) . "',
`model` = '" . $this->db->escape($model_number) . "',
`quantity` = '" . (int)$qty . "',
`price` = '" . (double)$price_net . "',
`total` = '" . (double)$total_net . "',
`tax` = '" . (double)$tax . "'
");
$order_product_id = $this->db->getLastId();
$this->openbay->ebay->log('create() - Added order product id ' . $order_product_id);
if ($openstock == true) {
$this->openbay->ebay->log('create() - OpenStock enabled');
if (!empty($txn->item->variantsku)) {
$this->openbay->ebay->log($txn->item->variantsku);
if ($product_id != false) {
$sku_parts = explode(':', $txn->item->variantsku);
$p_options = array();
foreach ($sku_parts as $part) {
$sql = "SELECT
`pv`.`product_option_id`,
`pv`.`product_option_value_id`,
`od`.`name`,
`ovd`.`name` as `value`,
`o`.`option_id`,
`o`.`type`
FROM `" . DB_PREFIX . "product_option_value` `pv`
LEFT JOIN `" . DB_PREFIX . "option_value` `ov` ON (`pv`.`option_value_id` = `ov`.`option_value_id`)
LEFT JOIN `" . DB_PREFIX . "option_value_description` `ovd` ON (`ovd`.`option_value_id` = `ov`.`option_value_id`)
LEFT JOIN `" . DB_PREFIX . "option_description` `od` ON (`ov`.`option_id` = `od`.`option_id`)
LEFT JOIN `" . DB_PREFIX . "option` `o` ON (`o`.`option_id` = `od`.`option_id`)
WHERE `pv`.`product_option_value_id` = '" . (int)$part . "'
AND `pv`.`product_id` = '" . (int)$product_id . "'";
$option_qry = $this->db->query($sql);
if (!empty($option_qry->row)) {
$p_options[] = array(
'product_option_id' => $option_qry->row['product_option_id'],
'product_option_value_id' => $option_qry->row['product_option_value_id'],
'name' => $option_qry->row['name'],
'value' => $option_qry->row['value'],
'type' => $option_qry->row['type'],
);
}
}
//insert into order_option table
foreach ($p_options as $option) {
$this->db->query("
INSERT INTO `" . DB_PREFIX . "order_option`
SET
`order_id` = '" . (int)$order_id . "',
`order_product_id` = '" . (int)$order_product_id . "',
`product_option_id` = '" . (int)$option['product_option_id'] . "',
`product_option_value_id` = '" . (int)$option['product_option_value_id'] . "',
`name` = '" . $this->db->escape($option['name']) . "',
`value` = '" . $this->db->escape($option['value']) . "',
`type` = '" . $this->db->escape($option['type']) . "'
");
}
}
} else {
$this->openbay->ebay->log('create() - No variant sku');
}
}
}
return $order_id;
}
private function updateOrderWithConfirmedData($order_id, $order) {
$this->load->model('localisation/currency');
$this->load->model('catalog/product');
$totals_language = $this->load->language('openbay/ebay_order');
$name_parts = $this->openbay->splitName((string)$order->address->name);
$user = array();
$user['fname'] = $name_parts['firstname'];
$user['lname'] = $name_parts['surname'];
/** get the iso2 code from the data and pull out the correct country for the details. */
if (!empty($order->address->iso2)) {
$country_qry = $this->db->query("SELECT * FROM `" . DB_PREFIX . "country` WHERE `iso_code_2` = '" . $this->db->escape($order->address->iso2) . "'");
}
if (!empty($country_qry->num_rows)) {
$user['country'] = $country_qry->row['name'];
$user['country_id'] = $country_qry->row['country_id'];
} else {
$user['country'] = (string)$order->address->iso2;
$user['country_id'] = '';
}
$user['email'] = (string)$order->user->email;
$user['id'] = $this->openbay->getUserByEmail($user['email']);
$currency = $this->model_localisation_currency->getCurrencyByCode($this->config->get('ebay_def_currency'));
$address_format = $this->model_openbay_ebay_order->getCountryAddressFormat((string)$order->address->iso2);
//try to get zone id - this will only work if the zone name and country id exist in the DB.
$zone_id = $this->openbay->getZoneId($order->address->state, $user['country_id']);
if (empty($address_format)) {
$address_format = (string)$this->config->get('ebay_default_addressformat');
}
//try to get the friendly name for the shipping service
$shipping_service = $this->openbay->ebay->getShippingServiceInfo($order->shipping->service);
if ($shipping_service != false) {
$shipping_service_name = $shipping_service['description'];
} else {
$shipping_service_name = $order->shipping->service;
}
$this->db->query("
UPDATE `" . DB_PREFIX . "order`
SET
`customer_id` = '" . (int)$user['id'] . "',
`firstname` = '" . $this->db->escape($user['fname']) . "',
`lastname` = '" . $this->db->escape($user['lname']) . "',
`email` = '" . $this->db->escape($order->user->email) . "',
`telephone` = '" . $this->db->escape($order->address->phone) . "',
`shipping_firstname` = '" . $this->db->escape($user['fname']) . "',
`shipping_lastname` = '" . $this->db->escape($user['lname']) . "',
`shipping_address_1` = '" . $this->db->escape($order->address->street1) . "',
`shipping_address_2` = '" . $this->db->escape($order->address->street2) . "',
`shipping_city` = '" . $this->db->escape($order->address->city) . "',
`shipping_postcode` = '" . $this->db->escape($order->address->postcode) . "',
`shipping_country` = '" . $this->db->escape($user['country']) . "',
`shipping_country_id` = '" . (int)$user['country_id'] . "',
`shipping_zone` = '" . $this->db->escape($order->address->state) . "',
`shipping_zone_id` = '" . (int)$zone_id . "',
`shipping_method` = '" . $this->db->escape($shipping_service_name) . "',
`shipping_address_format` = '" . $this->db->escape($address_format) . "',
`payment_firstname` = '" . $this->db->escape($user['fname']) . "',
`payment_lastname` = '" . $this->db->escape($user['lname']) . "',
`payment_address_1` = '" . $this->db->escape($order->address->street1) . "',
`payment_address_2` = '" . $this->db->escape($order->address->street2) . "',
`payment_city` = '" . $this->db->escape($order->address->city) . "',
`payment_postcode` = '" . $this->db->escape($order->address->postcode) . "',
`payment_country` = '" . $this->db->escape($user['country']) . "',
`payment_country_id` = '" . (int)$user['country_id'] . "',
`payment_zone` = '" . $this->db->escape($order->address->state) . "',
`payment_zone_id` = '" . (int)$zone_id . "',
`comment` = '" . $this->db->escape($order->order->message) . "',
`payment_method` = '" . $this->db->escape($order->payment->method) . "',
`payment_address_format` = '" . $address_format . "',
`total` = '" . (double)$order->order->total . "',
`date_modified` = NOW()
WHERE `order_id` = '" . $order_id . "'
");
$total_tax = 0;
$total_net = 0;
/* force array type */
if (!is_array($order->txn)) {
$order->txn = array($order->txn);
}
foreach ($order->txn as $txn) {
$qty = (int)$txn->item->qty;
$price = (double)$txn->item->price;
if ($this->tax_type == 1) {
//calculate taxes that come in from eBay
$this->openbay->ebay->log('updateOrderWithConfirmedData() - Using tax rates from eBay');
$total_tax += (double)$txn->item->tax->total;
$total_net += $price * $qty;
} else {
//use the store pre-set tax-rate for everything
$this->openbay->ebay->log('updateOrderWithConfirmedData() - Using tax rates from store');
$item_net = $price / $this->tax;
$item_tax = $price - $item_net;
$line_net = $item_net * $qty;
$line_tax = $item_tax * $qty;
$total_tax += number_format($line_tax, 4, '.', '');
$total_net += $line_net;
}
}
if ($this->tax_type == 1) {
$discount_net = (double)$order->order->discount;
$shipping_net = (double)$order->shipping->cost;
$tax = number_format($total_tax, 4, '.', '');
} else {
$discount_net = (double)$order->order->discount / $this->tax;
$discount_tax = (double)$order->order->discount - $discount_net;
$shipping_net = (double)$order->shipping->cost / $this->tax;
$shipping_tax = (double)$order->shipping->cost - $shipping_net;
$tax = number_format($shipping_tax + $total_tax + $discount_tax, 4, '.', '');
}
$totals = number_format((double)$total_net + (double)$shipping_net + (double)$tax + (double)$discount_net, 4, '.', '');
$data = array();
$data['totals'][0] = array(
'code' => 'sub_total',
'title' => $totals_language['text_total_sub'],
'value' => number_format((double)$total_net, 4, '.', ''),
'sort_order' => '1'
);
$data['totals'][1] = array(
'code' => 'shipping',
'title' => $totals_language['text_total_shipping'],
'value' => number_format((double)$shipping_net, 4, '.', ''),
'sort_order' => '3'
);
if ($discount_net != 0.00) {
$data['totals'][2] = array(
'code' => 'coupon',
'title' => $totals_language['text_total_discount'],
'value' => number_format((double)$discount_net, 4, '.', ''),
'sort_order' => '4'
);
}
$data['totals'][3] = array(
'code' => 'tax',
'title' => $totals_language['text_total_tax'],
'value' => number_format((double)$tax, 3, '.', ''),
'sort_order' => '5'
);
$data['totals'][4] = array(
'code' => 'total',
'title' => $totals_language['text_total'],
'value' => $totals,
'sort_order' => '6'
);
foreach ($data['totals'] as $total) {
$this->db->query("INSERT INTO `" . DB_PREFIX . "order_total` SET `order_id` = '" . (int)$order_id . "', `code` = '" . $this->db->escape($total['code']) . "', `title` = '" . $this->db->escape($total['title']) . "', `value` = '" . (double)$total['value'] . "', `sort_order` = '" . (int)$total['sort_order'] . "'");
}
}
public function outputLog() {
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private', false);
header('Content-Type: application/force-download');
header('Content-Length: ' . filesize(DIR_LOGS . "ebaylog.log"));
header('Content-Disposition: attachment; filename="ebaylog.log"');
header('Content-Transfer-Encoding: binary');
header('Connection: close');
readfile(DIR_LOGS . "ebaylog.log");
exit();
}
public function updateLog() {
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private', false);
header('Content-Type: application/force-download');
header('Content-Length: ' . filesize(DIR_LOGS . "update.log"));
header('Content-Disposition: attachment; filename="update.log"');
header('Content-Transfer-Encoding: binary');
header('Connection: close');
readfile(DIR_LOGS . "update.log");
exit();
}
}