|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Bpost\BpostApiClient\Bpost\ProductConfiguration; |
|
5
|
|
|
|
|
6
|
|
|
use SimpleXMLElement; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class Option |
|
10
|
|
|
*/ |
|
11
|
|
|
class Option |
|
12
|
|
|
{ |
|
13
|
|
|
private string $visibility; |
|
14
|
|
|
private int $price; |
|
15
|
|
|
private string $name; |
|
16
|
|
|
/** @var Characteristic[] */ |
|
17
|
|
|
private array $characteristics = []; |
|
18
|
|
|
|
|
19
|
|
|
public static function createFromXML(SimpleXMLElement $xml): self |
|
20
|
|
|
{ |
|
21
|
|
|
// Ex: <option visibility="NOT_VISIBLE_BY_CONSUMER_OPTIONAL" price="0" name="Cash on delivery"/> |
|
22
|
|
|
$attr = $xml->attributes(); |
|
23
|
|
|
$children = $xml->children(); |
|
24
|
|
|
|
|
25
|
|
|
$self = new self(); |
|
26
|
|
|
|
|
27
|
|
|
// visibility (supporte l’ancienne faute "visiblity") |
|
28
|
|
|
if (isset($attr['visibility'])) { |
|
29
|
|
|
$self->setVisibility((string) $attr['visibility']); |
|
30
|
|
|
} elseif (isset($attr['visiblity'])) { |
|
31
|
|
|
$self->setVisibility((string) $attr['visiblity']); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
if (isset($attr['price'])) { |
|
35
|
|
|
$self->setPrice((int) $attr['price']); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
if (isset($attr['name'])) { |
|
39
|
|
|
$self->setName((string) $attr['name']); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
// characteristics (supporte l’ancienne faute "chracteristic") |
|
43
|
|
|
if (isset($children->characteristic)) { |
|
44
|
|
|
foreach ($children->characteristic as $charXml) { |
|
45
|
|
|
$self->addCharacteristic(Characteristic::createFromXML($charXml)); |
|
|
|
|
|
|
46
|
|
|
} |
|
47
|
|
|
} elseif (isset($children->chracteristic)) { |
|
48
|
|
|
foreach ($children->chracteristic as $charXml) { |
|
49
|
|
|
$self->addCharacteristic(Characteristic::createFromXML($charXml)); |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
return $self; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function getVisibility(): string |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->visibility; |
|
59
|
|
|
} |
|
60
|
|
|
public function setVisibility(string $visibility): void |
|
61
|
|
|
{ |
|
62
|
|
|
$this->visibility = $visibility; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function getPrice(): int |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->price; |
|
68
|
|
|
} |
|
69
|
|
|
public function setPrice(int $price): void |
|
70
|
|
|
{ |
|
71
|
|
|
$this->price = $price; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function getName(): string |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->name; |
|
77
|
|
|
} |
|
78
|
|
|
public function setName(string $name): void |
|
79
|
|
|
{ |
|
80
|
|
|
$this->name = $name; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** @return Characteristic[] */ |
|
84
|
|
|
public function getCharacteristics(): array |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->characteristics; |
|
87
|
|
|
} |
|
88
|
|
|
public function addCharacteristic(Characteristic $characteristic): void |
|
89
|
|
|
{ |
|
90
|
|
|
$this->characteristics[] = $characteristic; |
|
91
|
|
|
} |
|
92
|
|
|
} |