forked from mallgroup/mpapi-client-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShippingLabelRequest.php
79 lines (65 loc) · 1.79 KB
/
ShippingLabelRequest.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
<?php declare(strict_types=1);
namespace MpApiClient\Order\DTO;
final class ShippingLabelRequest
{
public const TYPE_PDF = 'pdf';
public const TYPE_ZPL = 'zpl';
private string $labelType;
private int $firstPosition;
private int $labelsPerPage;
/**
* @var array<int, int>
*/
private array $labels = [];
public function __construct(string $labelType, int $firstPosition, int $labelsPerPage)
{
$this->labelType = $labelType;
$this->firstPosition = $firstPosition;
$this->labelsPerPage = $labelsPerPage;
}
/**
* @return array<string, mixed>
*/
public function getArrayForApi(): array
{
$labels = [];
foreach ($this->getLabels() as $orderId => $parcelCount) {
$labels[] = ['order_id' => $orderId, 'parcel_count' => $parcelCount];
}
return [
'labels_type' => $this->getLabelType(),
'first_position' => $this->getFirstPosition(),
'labels_per_page' => $this->getLabelsPerPage(),
'labels' => $labels,
];
}
public function addLabel(int $orderId, int $parcelCount): void
{
$this->labels[$orderId] = $parcelCount;
}
public function removeLabel(int $orderId): void
{
if (isset($this->labels[$orderId])) {
unset($this->labels[$orderId]);
}
}
public function getLabelType(): string
{
return $this->labelType;
}
public function getFirstPosition(): int
{
return $this->firstPosition;
}
public function getLabelsPerPage(): int
{
return $this->labelsPerPage;
}
/**
* @return array<int, int>
*/
public function getLabels(): array
{
return $this->labels;
}
}