|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Bpost\BpostApiClient\Bpost\ProductConfiguration; |
|
5
|
|
|
|
|
6
|
|
|
use Bpost\BpostApiClient\Exception\BpostLogicException\BpostInvalidWeightException; |
|
7
|
|
|
use SimpleXMLElement; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class Price |
|
11
|
|
|
*/ |
|
12
|
|
|
class Price |
|
13
|
|
|
{ |
|
14
|
|
|
private string $countryIso2; |
|
15
|
|
|
private int $priceLessThan2; |
|
16
|
|
|
private int $price2To5; |
|
17
|
|
|
private int $price5To10; |
|
18
|
|
|
private int $price10To20; |
|
19
|
|
|
private int $price20To30; |
|
20
|
|
|
|
|
21
|
|
|
public static function createFromXML(SimpleXMLElement $xml): self |
|
22
|
|
|
{ |
|
23
|
|
|
// <price price20To30="820" price10To20="720" price5To10="620" price2To5="520" priceLessThan2="420" countryIso2Code="BE"/> |
|
24
|
|
|
$a = $xml->attributes(); |
|
25
|
|
|
|
|
26
|
|
|
$self = new self(); |
|
27
|
|
|
$self->setCountryIso2((string) $a['countryIso2Code']); |
|
28
|
|
|
$self->setPriceLessThan2((int) $a['priceLessThan2']); |
|
29
|
|
|
$self->setPrice2To5((int) $a['price2To5']); |
|
30
|
|
|
$self->setPrice5To10((int) $a['price5To10']); |
|
31
|
|
|
$self->setPrice10To20((int) $a['price10To20']); |
|
32
|
|
|
$self->setPrice20To30((int) $a['price20To30']); |
|
33
|
|
|
|
|
34
|
|
|
return $self; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @throws BpostInvalidWeightException |
|
39
|
|
|
*/ |
|
40
|
|
|
public function getPriceByWeight(int $weight): int |
|
41
|
|
|
{ |
|
42
|
|
|
if ($weight <= 2000) { |
|
43
|
|
|
return $this->getPriceLessThan2(); |
|
44
|
|
|
} |
|
45
|
|
|
if ($weight <= 5000) { |
|
46
|
|
|
return $this->getPrice2To5(); |
|
47
|
|
|
} |
|
48
|
|
|
if ($weight <= 10000) { |
|
49
|
|
|
return $this->getPrice5To10(); |
|
50
|
|
|
} |
|
51
|
|
|
if ($weight <= 20000) { |
|
52
|
|
|
return $this->getPrice10To20(); |
|
53
|
|
|
} |
|
54
|
|
|
if ($weight <= 30000) { |
|
55
|
|
|
return $this->getPrice20To30(); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
throw new BpostInvalidWeightException($weight, 30); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function getCountryIso2(): string |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->countryIso2; |
|
64
|
|
|
} |
|
65
|
|
|
public function setCountryIso2(string $countryIso2): void |
|
66
|
|
|
{ |
|
67
|
|
|
$this->countryIso2 = $countryIso2; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function getPriceLessThan2(): int |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->priceLessThan2; |
|
73
|
|
|
} |
|
74
|
|
|
public function setPriceLessThan2(int $priceLessThan2): void |
|
75
|
|
|
{ |
|
76
|
|
|
$this->priceLessThan2 = $priceLessThan2; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function getPrice2To5(): int |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->price2To5; |
|
82
|
|
|
} |
|
83
|
|
|
public function setPrice2To5(int $price2To5): void |
|
84
|
|
|
{ |
|
85
|
|
|
$this->price2To5 = $price2To5; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function getPrice5To10(): int |
|
89
|
|
|
{ |
|
90
|
|
|
return $this->price5To10; |
|
91
|
|
|
} |
|
92
|
|
|
public function setPrice5To10(int $price5To10): void |
|
93
|
|
|
{ |
|
94
|
|
|
$this->price5To10 = $price5To10; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function getPrice10To20(): int |
|
98
|
|
|
{ |
|
99
|
|
|
return $this->price10To20; |
|
100
|
|
|
} |
|
101
|
|
|
public function setPrice10To20(int $price10To20): void |
|
102
|
|
|
{ |
|
103
|
|
|
$this->price10To20 = $price10To20; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function getPrice20To30(): int |
|
107
|
|
|
{ |
|
108
|
|
|
return $this->price20To30; |
|
109
|
|
|
} |
|
110
|
|
|
public function setPrice20To30(int $price20To30): void |
|
111
|
|
|
{ |
|
112
|
|
|
$this->price20To30 = $price20To30; |
|
113
|
|
|
} |
|
114
|
|
|
} |