forked from D1ol/apilo-api-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExampleApiOrdersGet.php
More file actions
81 lines (68 loc) · 2.37 KB
/
Copy pathExampleApiOrdersGet.php
File metadata and controls
81 lines (68 loc) · 2.37 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
<?php
use Dotenv\Dotenv;
use Apilo\Configuration;
use Apilo\Model\RestOrderItemsDTO;
require_once(__DIR__ . '/../vendor/autoload.php');
require_once(__DIR__ . '/../../src/vendor/autoload.php');
loadEnv();
// Configure HTTP basic authorization: BasicAuth
$config = (new Configuration())
->setAccessToken(getenv('ACCESS_TOKEN'))
->setHost(getenv('HOST'))
;
$apiInstance = new Apilo\Api\OrderApi(
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
// This is optional, `GuzzleHttp\Client` will be used as default.
new GuzzleHttp\Client(['verify' => false]),
$config
);
try {
$statusMap = [];
$statusNew = null;
foreach ($apiInstance->restApiOrdersStatusMapGet() as $status) {
echo sprintf(
"status name: %s, id: %d\n",
$status->getName(),
$status->getId()
);
$statusMap[$status->getId()] = $status;
if($status->getName() === 'Nowy') {
$statusNew = $status;
}
}
if($statusNew) {
$createdAfter = new DateTime('- 31 days');
$orderedAfter = new DateTime('- 45 days');
$orders = $apiInstance->restApiOrdersGet(
$createdAfter->format(DateTimeInterface::ATOM),
null,
$orderedAfter->format(DateTimeInterface::ATOM),
null,
null,
null,
null,
null,
null,
$statusNew->getId()
);
foreach ($orders->getOrders() as $order) {
echo sprintf(
"Order %s, id external: %s, status %s, created at %s, items quantity sum: %d, customer email: %s\n",
$order->getId(),
$order->getIdExternal(),
!empty($statusMap[$order->getStatus()]) ? $statusMap[$order->getStatus()]->getName() : '-',
$order->getCreatedAt()->format('Y-m-d, H:i:s'),
array_reduce($order->getOrderItems(), function ($qty, RestOrderItemsDTO $item) {
return $qty + $item->getQuantity();
}),
$order->getAddressCustomer()->getEmail(),
);
}
}
} catch (Exception $e) {
echo 'Exception when calling AuthorizationApi->restAuthTokenPost: ', $e->getMessage(), PHP_EOL;
}
function loadEnv(): void
{
(Dotenv::createUnsafeImmutable(__DIR__ . '/../'))->Load();
}