-
Notifications
You must be signed in to change notification settings - Fork 19
/
BasicProduct.php
149 lines (128 loc) · 3.6 KB
/
BasicProduct.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
<?php declare(strict_types=1);
namespace MpApiClient\Article\Entity;
use Exception;
use JsonSerializable;
use MpApiClient\Article\Entity\Common\StatusEnum;
use MpApiClient\Common\Util\JsonSerializeEntityTrait;
final class BasicProduct implements JsonSerializable
{
use JsonSerializeEntityTrait;
private string $id;
private int $productId;
private string $title;
private StatusEnum $status;
private ProductStageEnum $stage;
private int $inStock;
private string $categoryId;
private float $price;
private ?float $fairPrice;
private float $purchasePrice;
private float $rrp;
private int $variantsCount;
private bool $hasVariants;
private function __construct(
string $id,
int $productId,
string $title,
StatusEnum $status,
ProductStageEnum $stage,
int $inStock,
string $categoryId,
float $price,
?float $fairPrice,
float $purchasePrice,
float $rrp,
int $variantsCount,
bool $hasVariants
) {
$this->id = $id;
$this->productId = $productId;
$this->title = $title;
$this->status = $status;
$this->stage = $stage;
$this->inStock = $inStock;
$this->categoryId = $categoryId;
$this->price = $price;
$this->fairPrice = $fairPrice;
$this->purchasePrice = $purchasePrice;
$this->rrp = $rrp;
$this->variantsCount = $variantsCount;
$this->hasVariants = $hasVariants;
}
/**
* @param array<string, mixed> $data
*
* @throws Exception
* @internal
*/
public static function createFromApi(array $data): self
{
return new self(
(string) $data['id'],
(int) $data['product_id'],
(string) $data['title'],
new StatusEnum((string) $data[StatusEnum::KEY_NAME]),
new ProductStageEnum((string) $data[ProductStageEnum::KEY_NAME]),
(int) $data['in_stock'],
(string) $data['category_id'],
(float) $data['price'],
isset($data['fair_price']) ? (float) $data['fair_price'] : null,
(float) $data['purchase_price'],
(float) $data['rrp'],
(int) $data['variants_count'],
(bool) $data['has_variants'],
);
}
public function getId(): string
{
return $this->id;
}
public function getProductId(): int
{
return $this->productId;
}
public function getTitle(): string
{
return $this->title;
}
public function getStatus(): StatusEnum
{
return $this->status;
}
public function getStage(): ProductStageEnum
{
return $this->stage;
}
public function getInStock(): int
{
return $this->inStock;
}
public function getCategoryId(): string
{
return $this->categoryId;
}
public function getPrice(): float
{
return $this->price;
}
public function getFairPrice(): ?float
{
return $this->fairPrice;
}
public function getPurchasePrice(): float
{
return $this->purchasePrice;
}
public function getRrp(): float
{
return $this->rrp;
}
public function getVariantsCount(): int
{
return $this->variantsCount;
}
public function hasVariants(): bool
{
return $this->hasVariants;
}
}