-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
120 lines (100 loc) · 3.49 KB
/
index.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
<?php
require_once 'inc/shopware-api.php';
$logfile = 'shopware.log';
$csvfile = '../shopwareOrder.csv';
//Get current date
date_default_timezone_set('Europe/Berlin');
$date = date('m/d/Y h:i:s a', time());
//The order number of the newest order
$orders = $client->get('orders', [
'limit' => 999,
'sort' => [
['property' => 'number', 'direction' => 'DESC']
]
]);
$current_order = $orders["data"][0]["number"];
//Read last order from file or transmit an order id
if(isset($_GET["id"])){
$last_order = $_GET["id"];
}
else{
$last_order = file_get_contents('last_order.txt');
}
//Only do something, if the csv file is non existent. Don't overwrite files.
if(!file_exists($csvfile)){
if($last_order < $current_order){
//Count order up
$last_order++;
//$call = "orders/12345?useNumberAsId=true";
$call = "orders/".$last_order."?useNumberAsId=true";
//Call for order details
$order_details = $client->get($call);
/*
echo "<pre>";
var_dump($order_details);
echo "</pre>";
*/
if(isset($order_details["data"])){
echo "<pre>";
var_dump($order_details["data"]);
echo "</pre>";
$list = array ( );
//Add headline to list
array_push($list, array(
"Bestellung", "Nettowert",
"Artikelnr", "Preis", "Anzahl",
"Zahlungsart", "Versandkosten",
"BillingFirma", "BillingStrasse", "BillingPLZ", "BillingOrt",
"BillingLand", "BillingLKZ", "ShippingFirma",
"ShipingStrasse", "ShippingPLZ", "ShippingOrt",
"ShippingLand", "ShippingLKZ", "Mail", "TransactionId", "Phone"
));
//Add content to list
$order_data = $order_details["data"];
$order_item = $order_details["data"]["details"];
$order_payment = $order_details["data"]["payment"];
$order_billing = $order_details["data"]["billing"];
$order_shipping = $order_details["data"]["shipping"];
/*
Notes:
Item-price is always net
*/
$billing_adress = trim($order_billing["company"]." ".$order_billing["firstName"]." ".$order_billing["lastName"]);
$shipping_adress = trim($order_shipping["company"]." ".$order_shipping["firstName"]." ".$order_shipping["lastName"]);
foreach($order_item as $item){
array_push($list, array(
$order_data["number"], $order_data['invoiceAmountNet'],
$item["articleNumber"], $item["price"], $item["quantity"],
$order_payment["description"], $order_data["invoiceShipping"],
$billing_adress, $order_billing["street"], $order_billing["zipCode"], $order_billing["city"],
$order_billing["country"]["name"], $order_billing["country"]["iso"],
$shipping_adress, $order_shipping["street"], $order_shipping["zipCode"], $order_shipping["city"],
$order_shipping["country"]["name"], $order_shipping["country"]["iso"],
$order_data["customer"]["email"], $order_data["transactionId"], $order_shipping["phone"]
));
}
$fp = fopen($csvfile, 'w');
for ($i = 0; $i < count($list); $i++) {
fputcsv($fp, $list[$i], ';');
}
fclose($fp);
$logmsg = "\r\n".$date." | Bestellung ".$order_data["number"]." von ".$shipping_adress." verarbeitet!";
echo $logmsg;
file_put_contents($logfile, $logmsg, FILE_APPEND | LOCK_EX);
}
//Write last order number to file
$myfile = fopen("last_order.txt", "w") or die("Unable to open file!");
fwrite($myfile, $last_order);
fclose($myfile);
}
else{
$logmsg = "\r\n".$date." | Keine neuen Bestellungen.";
echo $logmsg;
file_put_contents($logfile, $logmsg, FILE_APPEND | LOCK_EX);
}
}
else{
$logmsg = "\r\n".$date." | Vorhandene Bestellung wurde noch nicht verarbeitet!";
echo $logmsg;
file_put_contents($logfile, $logmsg, FILE_APPEND | LOCK_EX);
}