1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ups\Entity\Tradeability; |
4
|
|
|
|
5
|
|
|
use DOMDocument; |
6
|
|
|
use DOMElement; |
7
|
|
|
use Ups\NodeInterface; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class Product. |
11
|
|
|
*/ |
12
|
|
|
class Product implements NodeInterface |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
private $productName; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
private $productDescription; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
private $productCountryCodeOfOrigin; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var TariffInfo |
32
|
|
|
*/ |
33
|
|
|
private $tariffInfo; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var Quantity |
37
|
|
|
*/ |
38
|
|
|
private $quantity; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var UnitPrice |
42
|
|
|
*/ |
43
|
|
|
private $unitPrice; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var Weight |
47
|
|
|
*/ |
48
|
|
|
private $weight; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var int |
52
|
|
|
*/ |
53
|
|
|
private $tariffCodeAlert = 0; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param null|DOMDocument $document |
57
|
|
|
* |
58
|
|
|
* @return DOMElement |
59
|
|
|
*/ |
60
|
2 |
|
public function toNode(DOMDocument $document = null) |
61
|
|
|
{ |
62
|
2 |
|
if (null === $document) { |
63
|
|
|
$document = new DOMDocument(); |
64
|
|
|
} |
65
|
|
|
|
66
|
2 |
|
$node = $document->createElement('Product'); |
67
|
|
|
|
68
|
|
|
// Required |
69
|
2 |
|
if ($this->getTariffInfo() !== null) { |
70
|
1 |
|
$node->appendChild($this->getTariffInfo()->toNode($document)); |
71
|
1 |
|
} |
72
|
2 |
|
if ($this->getUnitPrice() !== null) { |
73
|
1 |
|
$node->appendChild($this->getUnitPrice()->toNode($document)); |
74
|
1 |
|
} |
75
|
2 |
|
if ($this->getQuantity() !== null) { |
76
|
1 |
|
$node->appendChild($this->getQuantity()->toNode($document)); |
77
|
1 |
|
} |
78
|
|
|
|
79
|
|
|
// Optional |
80
|
2 |
|
if ($this->getProductName() !== null) { |
81
|
1 |
|
$node->appendChild($document->createElement('ProductName', $this->getProductName())); |
82
|
1 |
|
} |
83
|
2 |
|
if ($this->getProductDescription() !== null) { |
84
|
|
|
$node->appendChild($document->createElement('ProductDescription', $this->getProductDescription())); |
85
|
|
|
} |
86
|
2 |
|
if ($this->getProductCountryCodeOfOrigin() !== null) { |
87
|
1 |
|
$node->appendChild( |
88
|
1 |
|
$document->createElement( |
89
|
1 |
|
'ProductCountryCodeOfOrigin', |
90
|
1 |
|
$this->getProductCountryCodeOfOrigin() |
91
|
1 |
|
) |
92
|
1 |
|
); |
93
|
1 |
|
} |
94
|
2 |
|
if ($this->getWeight() instanceof Weight) { |
95
|
1 |
|
$node->appendChild($this->getWeight()->toNode($document)); |
96
|
1 |
|
} |
97
|
2 |
|
if ($this->getTariffCodeAlert() !== null) { |
98
|
2 |
|
$node->appendChild($document->createElement('TariffCodeAlert', $this->getTariffCodeAlert())); |
99
|
2 |
|
} |
100
|
|
|
|
101
|
2 |
|
return $node; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @return TariffInfo |
106
|
|
|
*/ |
107
|
2 |
|
public function getTariffInfo() |
108
|
|
|
{ |
109
|
2 |
|
return $this->tariffInfo; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @param TariffInfo $tariffInfo |
114
|
|
|
* @return Product |
115
|
|
|
*/ |
116
|
1 |
|
public function setTariffInfo(TariffInfo $tariffInfo) |
117
|
|
|
{ |
118
|
1 |
|
$this->tariffInfo = $tariffInfo; |
119
|
|
|
|
120
|
1 |
|
return $this; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @return UnitPrice |
125
|
|
|
*/ |
126
|
2 |
|
public function getUnitPrice() |
127
|
|
|
{ |
128
|
2 |
|
return $this->unitPrice; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @param UnitPrice $unitPrice |
133
|
|
|
* @return Product |
134
|
|
|
*/ |
135
|
1 |
|
public function setUnitPrice($unitPrice) |
136
|
|
|
{ |
137
|
1 |
|
$this->unitPrice = $unitPrice; |
138
|
|
|
|
139
|
1 |
|
return $this; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @return Quantity |
144
|
|
|
*/ |
145
|
2 |
|
public function getQuantity() |
146
|
|
|
{ |
147
|
2 |
|
return $this->quantity; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @param Quantity $quantity |
152
|
|
|
* @return Product |
153
|
|
|
*/ |
154
|
1 |
|
public function setQuantity($quantity) |
155
|
|
|
{ |
156
|
1 |
|
$this->quantity = $quantity; |
157
|
|
|
|
158
|
1 |
|
return $this; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @return string |
163
|
|
|
*/ |
164
|
2 |
|
public function getProductName() |
165
|
|
|
{ |
166
|
2 |
|
return $this->productName; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @param string $productName |
171
|
|
|
* @return Product |
172
|
|
|
*/ |
173
|
1 |
|
public function setProductName($productName) |
174
|
|
|
{ |
175
|
1 |
|
$this->productName = $productName; |
176
|
|
|
|
177
|
1 |
|
return $this; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @return string |
182
|
|
|
*/ |
183
|
2 |
|
public function getProductDescription() |
184
|
|
|
{ |
185
|
2 |
|
return $this->productDescription; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @param string $productDescription |
190
|
|
|
* @return Product |
191
|
|
|
*/ |
192
|
|
|
public function setProductDescription($productDescription) |
193
|
|
|
{ |
194
|
|
|
$this->productDescription = $productDescription; |
195
|
|
|
|
196
|
|
|
return $this; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @return string |
201
|
|
|
*/ |
202
|
2 |
|
public function getProductCountryCodeOfOrigin() |
203
|
|
|
{ |
204
|
2 |
|
return $this->productCountryCodeOfOrigin; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @param string $productCountryCodeOfOrigin |
209
|
|
|
* @return Product |
210
|
|
|
*/ |
211
|
1 |
|
public function setProductCountryCodeOfOrigin($productCountryCodeOfOrigin) |
212
|
|
|
{ |
213
|
1 |
|
$this->productCountryCodeOfOrigin = $productCountryCodeOfOrigin; |
214
|
|
|
|
215
|
1 |
|
return $this; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* @return Weight |
220
|
|
|
*/ |
221
|
2 |
|
public function getWeight() |
222
|
|
|
{ |
223
|
2 |
|
return $this->weight; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* @param Weight $weight |
228
|
|
|
* @return Product |
229
|
|
|
*/ |
230
|
1 |
|
public function setWeight($weight) |
231
|
|
|
{ |
232
|
1 |
|
$this->weight = $weight; |
233
|
|
|
|
234
|
1 |
|
return $this; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @return int |
239
|
|
|
*/ |
240
|
2 |
|
public function getTariffCodeAlert() |
241
|
|
|
{ |
242
|
2 |
|
return $this->tariffCodeAlert; |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* @param int $tariffCodeAlert |
247
|
|
|
* @return Product |
248
|
|
|
*/ |
249
|
1 |
|
public function setTariffCodeAlert($tariffCodeAlert) |
250
|
|
|
{ |
251
|
1 |
|
$this->tariffCodeAlert = $tariffCodeAlert; |
252
|
|
|
|
253
|
1 |
|
return $this; |
254
|
|
|
} |
255
|
|
|
} |
256
|
|
|
|