1 | <?php |
||
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 | 1 | public function toNode(DOMDocument $document = null) |
|
61 | { |
||
62 | 1 | if (null === $document) { |
|
63 | $document = new DOMDocument(); |
||
64 | } |
||
65 | |||
66 | 1 | $node = $document->createElement('Product'); |
|
67 | |||
68 | // Required |
||
69 | 1 | if ($this->getTariffInfo() !== null) { |
|
70 | $node->appendChild($this->getTariffInfo()->toNode($document)); |
||
71 | } |
||
72 | 1 | if ($this->getUnitPrice() !== null) { |
|
73 | $node->appendChild($this->getUnitPrice()->toNode($document)); |
||
74 | } |
||
75 | 1 | if ($this->getQuantity() !== null) { |
|
76 | $node->appendChild($this->getQuantity()->toNode($document)); |
||
77 | } |
||
78 | |||
79 | // Optional |
||
80 | 1 | if ($this->getProductName() !== null) { |
|
81 | $node->appendChild($document->createElement('ProductName', $this->getProductName())); |
||
82 | } |
||
83 | 1 | if ($this->getProductDescription() !== null) { |
|
84 | $node->appendChild($document->createElement('ProductDescription', $this->getProductDescription())); |
||
85 | } |
||
86 | 1 | if ($this->getProductCountryCodeOfOrigin() !== null) { |
|
87 | $node->appendChild( |
||
88 | $document->createElement( |
||
89 | 'ProductCountryCodeOfOrigin', |
||
90 | $this->getProductCountryCodeOfOrigin() |
||
91 | ) |
||
92 | ); |
||
93 | } |
||
94 | 1 | if ($this->getWeight() instanceof Weight) { |
|
95 | $node->appendChild($this->getWeight()->toNode($document)); |
||
96 | } |
||
97 | 1 | if ($this->getTariffCodeAlert() !== null) { |
|
98 | 1 | $node->appendChild($document->createElement('TariffCodeAlert', $this->getTariffCodeAlert())); |
|
99 | 1 | } |
|
100 | |||
101 | 1 | return $node; |
|
102 | } |
||
103 | |||
104 | /** |
||
105 | * @return TariffInfo |
||
106 | */ |
||
107 | 1 | public function getTariffInfo() |
|
111 | |||
112 | /** |
||
113 | * @param TariffInfo $tariffInfo |
||
114 | * @return Product |
||
115 | */ |
||
116 | public function setTariffInfo(TariffInfo $tariffInfo) |
||
117 | { |
||
118 | $this->tariffInfo = $tariffInfo; |
||
119 | |||
120 | return $this; |
||
121 | } |
||
122 | |||
123 | /** |
||
124 | * @return UnitPrice |
||
125 | */ |
||
126 | 1 | public function getUnitPrice() |
|
130 | |||
131 | /** |
||
132 | * @param UnitPrice $unitPrice |
||
133 | * @return Product |
||
134 | */ |
||
135 | public function setUnitPrice($unitPrice) |
||
136 | { |
||
137 | $this->unitPrice = $unitPrice; |
||
138 | |||
139 | return $this; |
||
140 | } |
||
141 | |||
142 | /** |
||
143 | * @return Quantity |
||
144 | */ |
||
145 | 1 | public function getQuantity() |
|
149 | |||
150 | /** |
||
151 | * @param Quantity $quantity |
||
152 | * @return Product |
||
153 | */ |
||
154 | public function setQuantity($quantity) |
||
155 | { |
||
156 | $this->quantity = $quantity; |
||
157 | |||
158 | return $this; |
||
159 | } |
||
160 | |||
161 | /** |
||
162 | * @return string |
||
163 | */ |
||
164 | 1 | public function getProductName() |
|
168 | |||
169 | /** |
||
170 | * @param string $productName |
||
171 | * @return Product |
||
172 | */ |
||
173 | public function setProductName($productName) |
||
174 | { |
||
175 | $this->productName = $productName; |
||
176 | |||
177 | return $this; |
||
178 | } |
||
179 | |||
180 | /** |
||
181 | * @return string |
||
182 | */ |
||
183 | 1 | public function getProductDescription() |
|
187 | |||
188 | /** |
||
189 | * @param string $productDescription |
||
190 | * @return Product |
||
191 | */ |
||
192 | public function setProductDescription($productDescription) |
||
198 | |||
199 | /** |
||
200 | * @return string |
||
201 | */ |
||
202 | 1 | public function getProductCountryCodeOfOrigin() |
|
206 | |||
207 | /** |
||
208 | * @param string $productCountryCodeOfOrigin |
||
209 | * @return Product |
||
210 | */ |
||
211 | public function setProductCountryCodeOfOrigin($productCountryCodeOfOrigin) |
||
212 | { |
||
213 | $this->productCountryCodeOfOrigin = $productCountryCodeOfOrigin; |
||
214 | |||
215 | return $this; |
||
216 | } |
||
217 | |||
218 | /** |
||
219 | * @return Weight |
||
220 | */ |
||
221 | 1 | public function getWeight() |
|
225 | |||
226 | /** |
||
227 | * @param Weight $weight |
||
228 | * @return Product |
||
229 | */ |
||
230 | public function setWeight($weight) |
||
231 | { |
||
232 | $this->weight = $weight; |
||
233 | |||
234 | return $this; |
||
235 | } |
||
236 | |||
237 | /** |
||
238 | * @return int |
||
239 | */ |
||
240 | 1 | public function getTariffCodeAlert() |
|
244 | |||
245 | /** |
||
246 | * @param int $tariffCodeAlert |
||
247 | * @return Product |
||
248 | */ |
||
249 | public function setTariffCodeAlert($tariffCodeAlert) |
||
250 | { |
||
251 | $this->tariffCodeAlert = $tariffCodeAlert; |
||
255 | } |
||
256 |