-
Notifications
You must be signed in to change notification settings - Fork 19
/
Variant.php
57 lines (52 loc) · 2.06 KB
/
Variant.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
<?php declare(strict_types=1);
namespace MpApiClient\Article\Entity;
use Exception;
use MpApiClient\Article\Entity\Common\AbstractArticle;
use MpApiClient\Article\Entity\Common\Availability;
use MpApiClient\Article\Entity\Common\Dimensions;
use MpApiClient\Article\Entity\Common\LabelIterator;
use MpApiClient\Article\Entity\Common\MediaIterator;
use MpApiClient\Article\Entity\Common\OverrideIterator;
use MpApiClient\Article\Entity\Common\PackageSizeEnum;
use MpApiClient\Article\Entity\Common\ParameterIterator;
use MpApiClient\Article\Entity\Common\PromotionIterator;
use MpApiClient\Common\Util\InputDataUtil;
final class Variant extends AbstractArticle
{
/**
* @param array<string, mixed> $data
*
* @throws Exception
* @internal
*/
public static function createFromApi(array $data): self
{
/** @psalm-suppress DeprecatedClass */
return new self(
(string) $data['id'],
(int) $data['article_id'],
(string) $data['title'],
(string) $data['url'],
(string) $data['shortdesc'],
(string) $data['longdesc'],
(int) $data['priority'],
InputDataUtil::getNullableString($data, 'barcode'),
(float) $data['price'],
isset($data['fair_price']) ? (float) $data['fair_price'] : null,
(float) $data['purchase_price'],
(float) $data['rrp'],
MediaIterator::createFromApi($data['media']),
PromotionIterator::createFromApi($data['promotions']),
ParameterIterator::createFromApi($data['parameters']),
Dimensions::createFromApi($data['dimensions']),
Availability::createFromApi($data['availability']),
LabelIterator::createFromApi($data['labels']),
OverrideIterator::createFromApi($data['overrides']),
$data['recommended'],
(int) $data['delivery_delay'],
(bool) $data['free_delivery'],
new PackageSizeEnum($data['package_size']),
(bool) $data['mallbox_allowed'],
);
}
}