-
Notifications
You must be signed in to change notification settings - Fork 19
/
Label.php
44 lines (35 loc) · 1.08 KB
/
Label.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
<?php declare(strict_types=1);
use MpApiClient\Common\Authenticators\ClientIdAuthenticator;
use MpApiClient\Exception\MpApiException;
use MpApiClient\MpApiClient;
use MpApiClient\MpApiClientOptions;
require '../vendor/autoload.php';
$options = new MpApiClientOptions(
new ClientIdAuthenticator('my-client-id')
);
$client = MpApiClient::createFromOptions('my-app-name', $options);
//
// Get label list
//
try {
$labelList = $client->label()->list();
// Print all labels as json object
echo json_encode($labelList, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
// Get all labels as array
// [
// [
// 'id' => 'SALE',
// 'title' => 'Výprodej'
// ],
// ...
// ]
var_dump($labelList->jsonSerialize());
// Iterate over the returned list
foreach ($labelList as $label) {
echo 'Label id: ' . $label->getId() . PHP_EOL;
echo 'Title: ' . $label->getTitle() . PHP_EOL;
echo PHP_EOL;
}
} catch (MpApiException $e) {
echo 'Unexpected error occurred while loading label list: ' . $e->getMessage();
}