1 <?php
2 /* --------------------------------------------------------------
3 OrderItem.php 2016-01-18
4 Gambio GmbH
5 http://www.gambio.de
6 Copyright (c) 2016 Gambio GmbH
7 Released under the GNU General Public License (Version 2)
8 [http://www.gnu.org/licenses/gpl-2.0.html]
9 --------------------------------------------------------------
10 */
11
12 MainFactory::load_class('OrderItemInterface');
13
14 /**
15 * Class OrderItem
16 *
17 * @category System
18 * @package Order
19 * @subpackage Entities
20 */
21 class OrderItem implements OrderItemInterface
22 {
23 /**
24 * Product model.
25 *
26 * @var string
27 */
28 protected $productModel = '';
29
30 /**
31 * Name.
32 *
33 * @var string
34 */
35 protected $name = '';
36
37 /**
38 * Price.
39 *
40 * @var float
41 */
42 protected $price = 0.0;
43
44 /**
45 * Quantity.
46 *
47 * @var float
48 */
49 protected $quantity = 0.0;
50
51 /**
52 * Tax amount.
53 *
54 * @var float
55 */
56 protected $tax = 0.0;
57
58 /**
59 * Tax allowed on this order item.
60 *
61 * @var bool
62 */
63 protected $taxAllowed = false;
64
65 /**
66 * Amount of discount made on this order item..
67 *
68 * @var float
69 */
70 protected $discountMade = 0.0;
71
72 /**
73 * Order item shipping time info text.
74 *
75 * @var string
76 */
77 protected $shippingTimeInfo = '';
78
79 /**
80 * Attributes of the order item.
81 *
82 * @var OrderItemAttributeCollection
83 */
84 protected $attributes;
85
86 /**
87 * Order item quantity unit name.
88 *
89 * @var string
90 */
91 protected $quantityUnitName = '';
92
93 /**
94 * Checkout information.
95 *
96 * @var string
97 */
98 protected $checkoutInformation = '';
99
100 /**
101 * Download information.
102 *
103 * @var OrderItemDownloadInformation
104 */
105 protected $downloadInformation;
106
107 /**
108 * Order item addon collection.
109 *
110 * @var EditableKeyValueCollection
111 */
112 protected $addonValues;
113
114
115 /**
116 * OrderItem constructor.
117 *
118 * @param StringType $name Order item name.
119 */
120 public function __construct(StringType $name)
121 {
122 $this->setName($name);
123
124 // Set empty download information
125 $this->downloadInformation = MainFactory::create('EmptyOrderItemDownloadInformation');
126
127 // Set addon values collection.
128 // Note, that there is no setter method for assign the addonValues collection.
129 $addonValues = MainFactory::create('EditableKeyValueCollection', array());
130 $this->addonValues = $addonValues;
131 }
132
133
134 /**
135 * Returns the product model of the order item.
136 *
137 * @return string Product model of the order item.
138 */
139 public function getProductModel()
140 {
141 return $this->productModel;
142 }
143
144
145 /**
146 * Returns the name of the order item.
147 *
148 * @return string Name of the order item.
149 */
150 public function getName()
151 {
152 return $this->name;
153 }
154
155
156 /**
157 * Returns the price of the order item.
158 *
159 * @return double Price of the order item.
160 */
161 public function getPrice()
162 {
163 return $this->price;
164 }
165
166
167 /**
168 * Returns the quantity of the order item.
169 *
170 * @return double Quantity of the order item.
171 */
172 public function getQuantity()
173 {
174 return $this->quantity;
175 }
176
177
178 /**
179 * Returns the final price of the order item.
180 *
181 * @return float Final price of the order item.
182 */
183 public function getFinalPrice()
184 {
185 return $this->price * $this->quantity;
186 }
187
188
189 /**
190 * Returns the tax of the order item.
191 *
192 * @return float Tax of the order item.
193 */
194 public function getTax()
195 {
196 return $this->tax;
197 }
198
199
200 /**
201 * Is tax of the order item allowed?
202 *
203 * @return bool Is tax of the order item allowed?
204 */
205 public function isTaxAllowed()
206 {
207 return $this->taxAllowed;
208 }
209
210
211 /**
212 * Returns the amount of discount of the order item.
213 *
214 * @return float Amount of discount of the order item.
215 */
216 public function getDiscountMade()
217 {
218 return $this->discountMade;
219 }
220
221
222 /**
223 * Returns the shipping time of the order item.
224 *
225 * @return string Shipping time of the order item.
226 */
227 public function getShippingTimeInfo()
228 {
229 return $this->shippingTimeInfo;
230 }
231
232
233 /**
234 * Returns the attributes of the order item.
235 *
236 * @return OrderItemAttributeCollection Attributes of the order item.
237 */
238 public function getAttributes()
239 {
240 // If no collection is set, create a new empty one.
241 if(null === $this->attributes)
242 {
243 $this->attributes = MainFactory::create('OrderItemAttributeCollection', array());
244 }
245
246 return $this->attributes;
247 }
248
249
250 /**
251 * Returns the name of quantity unit of the order item.
252 *
253 * @return string Name of quantity unit of the order item.
254 */
255 public function getQuantityUnitName()
256 {
257 return $this->quantityUnitName;
258 }
259
260
261 /**
262 * Returns the checkout information of the order item.
263 *
264 * @return string Checkout information of the order item.
265 */
266 public function getCheckoutInformation()
267 {
268 return $this->checkoutInformation;
269 }
270
271
272 /**
273 * Returns the download information of the order item.
274 *
275 * @return OrderItemDownloadInformation Download information of the order item.
276 */
277 public function getDownloadInformation()
278 {
279 return $this->downloadInformation;
280 }
281
282
283 /**
284 * Returns the addon collection of an order item.
285 *
286 * @return EditableKeyValueCollection Addon collection.
287 */
288 public function getAddonValues()
289 {
290 return $this->addonValues->getClone();
291 }
292
293
294 /**
295 * Returns the order addon key value from collection.
296 *
297 * @param StringType $key Addon key.
298 *
299 * @return string Addon value.
300 */
301 public function getAddonValue(StringType $key)
302 {
303 return $this->addonValues->getValue($key->asString());
304 }
305
306
307 /**
308 * Sets product model of the OrderItem.
309 *
310 * @param StringType $model Model of the OrderItem.
311 *
312 * @return OrderItem Same instance for method chaining.
313 */
314 public function setProductModel(StringType $model)
315 {
316 $this->productModel = $model->asString();
317
318 return $this;
319 }
320
321
322 /**
323 * Sets name of the OrderItem.
324 *
325 * @param StringType $name Name of the OrderItem.
326 *
327 * @return OrderItem Same instance for method chaining.
328 */
329 public function setName(StringType $name)
330 {
331 $this->name = $name->asString();
332
333 return $this;
334 }
335
336
337 /**
338 * Sets price of the OrderItem.
339 *
340 * @param DecimalType $price Price of the OrderItem.
341 *
342 * @return OrderItem Same instance for method chaining.
343 */
344 public function setPrice(DecimalType $price)
345 {
346 $this->price = $price->asDecimal();
347
348 return $this;
349 }
350
351
352 /**
353 * Sets quantity of the OrderItem.
354 *
355 * @param DecimalType $quantity Quantity of the OrderItem.
356 *
357 * @return OrderItem Same instance for method chaining.
358 */
359 public function setQuantity(DecimalType $quantity)
360 {
361 $this->quantity = $quantity->asDecimal();
362
363 return $this;
364 }
365
366
367 /**
368 * Sets tax of the OrderItem.
369 *
370 * @param DecimalType $tax Tax of the OrderItem.
371 *
372 * @return OrderItem Same instance for method chaining.
373 */
374 public function setTax(DecimalType $tax)
375 {
376 $this->tax = $tax->asDecimal();
377
378 return $this;
379 }
380
381
382 /**
383 * Sets whether tax of the OrderItem is allowed or not.
384 *
385 * @param BoolType $allow Tax allowed or not?
386 *
387 * @return OrderItem Same instance for method chaining.
388 */
389 public function setTaxAllowed(BoolType $allow)
390 {
391 $this->taxAllowed = $allow->asBool();
392
393 return $this;
394 }
395
396
397 /**
398 * Sets discount of the OrderItem.
399 *
400 * @param DecimalType $discount Discount of the OrderItem.
401 *
402 * @return OrderItem Same instance for method chaining.
403 */
404 public function setDiscountMade(DecimalType $discount)
405 {
406 $this->discountMade = $discount->asDecimal();
407
408 return $this;
409 }
410
411
412 /**
413 * Sets shipping time of the OrderItem.
414 *
415 * @param StringType $time Shipping time of the OrderItem.
416 *
417 * @return OrderItem Same instance for method chaining.
418 */
419 public function setShippingTimeInfo(StringType $time)
420 {
421 $this->shippingTimeInfo = $time->asString();
422
423 return $this;
424 }
425
426
427 /**
428 * Sets attributes of the OrderItem.
429 *
430 * @param OrderItemAttributeCollection $attributeCollection Attributes of the OrderItem.
431 *
432 * @return OrderItem Same instance for method chaining.
433 */
434 public function setAttributes(OrderItemAttributeCollection $attributeCollection)
435 {
436 $this->attributes = $attributeCollection;
437
438 return $this;
439 }
440
441
442 /**
443 * Sets name of quantity unit of the OrderItem.
444 *
445 * @param StringType $name Name of quantity unit of the OrderItem.
446 *
447 * @return OrderItem Same instance for method chaining.
448 */
449 public function setQuantityUnitName(StringType $name)
450 {
451 $this->quantityUnitName = $name->asString();
452
453 return $this;
454 }
455
456
457 /**
458 * Sets the checkout information.
459 *
460 * @param StringType $checkoutInformation Contains the checkout info of the order item.
461 *
462 * @return OrderItem Same instance for method chaining.
463 */
464 public function setCheckoutInformation(StringType $checkoutInformation)
465 {
466 $this->checkoutInformation = $checkoutInformation->asString();
467
468 return $this;
469 }
470
471
472 /**
473 * Sets the download information of the OrderItem.
474 *
475 * @param OrderItemDownloadInformation $download Download information.
476 *
477 * @return OrderItem Same instance for method chaining.
478 */
479 public function setDownloadInformation(OrderItemDownloadInformation $download)
480 {
481 $this->downloadInformation = $download;
482
483 return $this;
484 }
485
486
487 /**
488 * Adds/updates a key value in the addon value collection.
489 *
490 * @param StringType $key Addon key.
491 * @param StringType $value Addon value.
492 *
493 * @return OrderItem Same instance for method chaining.
494 */
495 public function setAddonValue(StringType $key, StringType $value)
496 {
497 $this->addonValues->setValue($key->asString(), $value->asString());
498
499 return $this;
500 }
501
502
503 /**
504 * Merges the existing addon values with new ones.
505 *
506 * @param KeyValueCollection $addonValues Contains the new addon values to be merged with the existing ones.
507 *
508 * @return OrderItem Same instance for method chaining.
509 */
510 public function addAddonValues(KeyValueCollection $addonValues)
511 {
512 $this->addonValues->addCollection($addonValues);
513
514 return $this;
515 }
516
517
518 /**
519 * Deletes a specific addon value entry by key.
520 *
521 * @param StringType $key Addon key.
522 *
523 * @return OrderItem Same instance for method chaining.
524 */
525 public function deleteAddonValue(StringType $key)
526 {
527 $this->addonValues->deleteValue($key->asString());
528
529 return $this;
530 }
531 }