This repository has been archived by the owner on Jan 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexport-orders.php
121 lines (101 loc) · 2.67 KB
/
export-orders.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
<?php
/**
* User: noff
* Date: 22/07/14
* Time: 23:22
* This is an example of mass export orders to REES46 procedure.
*
* Assumes you have tables in database:
* orders:
* id:integer
* user_id:integer
* total_sum:integer
* created_at:datetime
* order_items:
* order_id:integer
* item_id:integer
* price:integer
* amount:integer
* items:
* id:integer
* price:integer
* category_id:integer
* is_available:boolean
*
*/
// Edit these parameters according to your shop credentials
//define('SHOP_ID', 'b6ef5e0003904ba8245eb7aac0c286');
//define('SHOP_SECRET', '14fd926018b405cbb18c24b6724a5ad8');
// Here prepare your orders data from your database.
// In this example we just prepare array of data instead of database data.
// So you need to change this code according your shop architecture.
$orders = array(
array(
'id' => 'order3',
'user_id' => 334,
'date' => 1406057494,
'items' => array(
array(
'id' => 105,
'price' => 3400,
'category_uniqid' => 14,
'is_available' => 1,
'amount' => 2
),
array(
'id' => 106,
'price' => 3100,
'category_uniqid' => 19,
'is_available' => 1,
'amount' => 1
)
)
),
array(
'id' => 'order4',
'user_id' => 18,
'date' => 1406057499,
'items' => array(
array(
'id' => 107,
'price' => 3400,
'category_uniqid' => 14,
'is_available' => 1,
'amount' => 1
)
)
)
);
define('SHOP_ID', '3519c7e25292c23664766e6050e2d1');
define('SHOP_SECRET', '086dcc7eb9886e18de0314e6c2006dcf');
// ** Prepare CURL object
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_URL, 'http://api.rees46.com/import/orders');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
// Split orders by 1000 per request
$chunks = array_chunk($orders, 1000);
foreach($chunks as $key => $chunk) {
$data = array(
'shop_id' => SHOP_ID,
'shop_secret' => SHOP_SECRET,
'orders' => $chunk
);
$body = json_encode($data);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
$response = curl_exec($ch);
$response_info = curl_getinfo($ch);
if($response_info['http_code'] < 200 || $response_info['http_code'] >= 300) {
$data_as_string = var_export($data, true);
$response_as_string = var_export($response_info, true);
error_log("Error request \n\nData:\n'{$data_as_string}'\n\nResponse Info:\n{$response_as_string}\n\nResponse:\n'{$response_body->message}'");
exit(1);
} else {
echo 'Chunk ' . ($key+1) . ' done. Response: ' . $response . PHP_EOL;
}
}
// ** Close all connections and clean
curl_close($ch);
echo 'Done.' . PHP_EOL;