-
Notifications
You must be signed in to change notification settings - Fork 1
/
TestOrder.php
151 lines (133 loc) · 3.87 KB
/
TestOrder.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
<?php
class AddInfo {
}
class SubArticle {
public $Comment; //String
public $Price; //String
public $Count; //String
}
class SubArticleList {
public $SubArticle; //array( SubArticle )
}
class Article {
public $Price; //String
public $ArticleSize; //String
public $ArticleName; //String
public $ArticleNo; //String
public $SubArticleList; //SubArticleList
public $Count; //String
}
class ArticleList {
public $Article; //Article
}
class StoreData {
public $StoreId; //String
public $StoreName; //String
}
class ServerData {
public $Agent; //String
public $CreateDateTime; //Date
public $Referer; //String
public $IpAddress; //String
}
class DeliveryAddress {
public $LastName; //String
public $AddAddress; //String
public $Company; //String
public $Zip; //String
public $Street; //String
public $Latitude; //String
public $Country; //String
public $Longitude; //String
public $HouseNo; //String
public $Title; //String
public $PhoneNo; //String
public $City; //String
}
class Customer {
public $DeliveryAddress; //DeliveryAddress
}
class Order {
public $AddInfo; //AddInfo
public $OrderID; //String
public $ArticleList; //ArticleList
public $StoreData; //StoreData
public $ServerData; //ServerData
public $Customer; //Customer
}
class OrderList {
public $Order; //array( Order )
public $CreateDateTime; //Date
}
class EShopOrder {
public $OrderList; //OrderList
}
function CreateNewOrder($OrderID) {
// construct a new order
$myOrder = new Order;
// OrderID should be your unique
$myOrder->OrderID = $OrderID;
// additional info
$myOrder->AddInfo = new AddInfo;
$myOrder->AddInfo->PaymentType = 'Barzahlung';
$myOrder->AddInfo->DiscountPercent = 10;
$myOrder->AddInfo->Total = 9.18;
// server data
$myOrder->ServerData = new ServerData;
$myOrder->ServerData->CreateDateTime = date( DateTime::RFC3339, time() );
$myOrder->ServerData->IpAddress = $_SERVER['REMOTE_ADDR'];
$myOrder->ServerData->Agent = $_SERVER['HTTP_USER_AGENT'];
// store data
$myOrder->StoreData = new StoreData;
$myOrder->StoreData->StoreName = 'My online-shop';
// customer deliver address
$myOrder->Customer = new Customer;
$myOrder->Customer->DeliveryAddress = new DeliveryAddress;
$myOrder->Customer->DeliveryAddress->LastName = 'Doe';
$myOrder->Customer->DeliveryAddress->FirstName = 'John';
$myOrder->Customer->DeliveryAddress->Street = 'Hoyaer Straße';
$myOrder->Customer->DeliveryAddress->HouseNo = '13';
$myOrder->Customer->DeliveryAddress->Zip = '28205';
$myOrder->Customer->DeliveryAddress->City = 'Bremen';
$myOrder->Customer->DeliveryAddress->EMail = '[email protected]';
$myOrder->Customer->DeliveryAddress->PhoneNo = '0421-2477828';
// add new main article with size/variant
$Article = new Article;
$Article->Count = 1;
$Article->ArticleName = 'Pizza Hawaii';
$Article->ArticleSize = 'Mittel (ca. 32cm)';
$Article->ArticleNo = 'P22';
$Article->Price = 7.8;
// first topping
$SubArticle1 = new SubArticle;
$SubArticle1->ArticleName = 'Schinken';
$SubArticle1->Count = 1;
$SubArticle1->Price = 0.9;
// second topping
$SubArticle2 = new SubArticle;
$SubArticle2->ArticleName = 'Putenbruststreifen';
$SubArticle2->Count = 1;
$SubArticle2->Price = 1.5;
// comment to the main article
$SubArticle3 = new SubArticle;
$SubArticle3->Comment = 'hot!';
$SubArticle3->Count = 1;
// comment to the order
$Comment = new Article;
$Comment->Count = 1;
$Comment->Comment = 'Testbestellung: Pronto Pronto!';
// add items to the article list
$Article->SubArticleList = new SubArticleList;
$Article->SubArticleList->SubArticle = array($SubArticle1, $SubArticle2, $SubArticle3);
$myOrder->ArticleList = new ArticleList;
$myOrder->ArticleList->Article = array($Article, $Comment);
// save as JSON
$json = json_encode($myOrder, JSON_PRETTY_PRINT);
file_put_contents("order_".$OrderID.".json", $json);
return $json;
}
$OrderID = uniqid();
$json = CreateNewOrder($OrderID);
header('Content-Type: application/json');
echo($json);
?>