PluginProbe
Packeta / 1.2.6
Packeta v1.2.6
2.3.2 2.3.1 trunk 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 All 56 releases
packeta / src / Packetery / Core / Entity / Order.php

Order.php in Packeta 1.2.6, at src/Packetery/Core/Entity/Order.php

779 lines 12.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class Order
4 *
5 * @package Packetery\Order
6 */
7
8 declare( strict_types=1 );
9
10 namespace Packetery\Core\Entity;
11
12 use Packetery\Core\Helper;
13
14 /**
15 * Class Order
16 *
17 * @package Packetery\Order
18 */
19 class Order {
20
21 /**
22 * Order id.
23 *
24 * @var string
25 */
26 private $number;
27
28 /**
29 * Order carrier object.
30 *
31 * @var Carrier|null
32 */
33 private $carrier;
34
35 /**
36 * Order pickup point object.
37 *
38 * @var PickupPoint|null
39 */
40 private $pickupPoint;
41
42 /**
43 * Customer name.
44 *
45 * @var string|null
46 */
47 private $name;
48
49 /**
50 * Customer surname.
51 *
52 * @var string|null
53 */
54 private $surname;
55
56 /**
57 * Customer e-mail.
58 *
59 * @var string|null
60 */
61 private $email;
62
63 /**
64 * Customer phone.
65 *
66 * @var string|null
67 */
68 private $phone;
69
70 /**
71 * Order value.
72 *
73 * @var float|null
74 */
75 private $value;
76
77 /**
78 * Sender label.
79 *
80 * @var string|null
81 */
82 private $eshop;
83
84 /**
85 * Address.
86 *
87 * @var Address|null
88 */
89 private $address;
90
91 /**
92 * Size.
93 *
94 * @var Size|null
95 */
96 private $size;
97
98 /**
99 * Package weight, set or calculated.
100 *
101 * @var float|null
102 */
103 private $weight;
104
105 /**
106 * Calculated package weight.
107 *
108 * @var float|null
109 */
110 private $calculatedWeight;
111
112 /**
113 * Cash on delivery value.
114 *
115 * @var float|null
116 */
117 private $cod;
118
119 /**
120 * Packet note.
121 *
122 * @var string|null
123 */
124 private $note;
125
126 /**
127 * Adult content presence flag.
128 *
129 * @var bool|null
130 */
131 private $adultContent;
132
133 /**
134 * Packet ID
135 *
136 * @var string|null
137 */
138 private $packetId;
139
140 /**
141 * Packet ID
142 *
143 * @var string|null
144 */
145 private $packetStatus;
146
147 /**
148 * Carrier id.
149 *
150 * @var string
151 */
152 private $carrierId;
153
154 /**
155 * Tells if is packet submitted.
156 *
157 * @var bool
158 */
159 private $isExported;
160
161 /**
162 * Tells if is packet submitted.
163 *
164 * @var bool
165 */
166 private $isLabelPrinted;
167
168 /**
169 * Packet currency.
170 *
171 * @var string
172 */
173 private $currency;
174
175 /**
176 * Carrier number..
177 *
178 * @var string|null
179 */
180 private $carrierNumber;
181
182 /**
183 * Address validated.
184 *
185 * @var bool
186 */
187 private $addressValidated;
188
189 /**
190 * ISO 3166-1 alpha-2 code, lowercase.
191 *
192 * @var string|null
193 */
194 private $shippingCountry;
195
196 /**
197 * Order entity constructor.
198 *
199 * @param string $number Order id.
200 * @param string $carrierId Sender label.
201 * @param bool $isExported Is exported.
202 * @param bool $isLabelPrinted Is label printed.
203 */
204 public function __construct(
205 string $number,
206 string $carrierId,
207 bool $isExported = false,
208 bool $isLabelPrinted = false
209 ) {
210 $this->number = $number;
211 $this->carrierId = $carrierId;
212 $this->isExported = $isExported;
213 $this->isLabelPrinted = $isLabelPrinted;
214 $this->addressValidated = false;
215 }
216
217 /**
218 * Is address validated?
219 *
220 * @return bool
221 */
222 public function isAddressValidated(): bool {
223 return $this->addressValidated;
224 }
225
226 /**
227 * Sets address validation flag.
228 *
229 * @param bool $addressValidated Address validated.
230 *
231 * @return void
232 */
233 public function setAddressValidated( bool $addressValidated ): void {
234 $this->addressValidated = $addressValidated;
235 }
236
237 /**
238 * Checks if is home delivery. In that case pointId is not set.
239 *
240 * @return bool
241 */
242 public function isHomeDelivery(): bool {
243 return ( null === $this->pickupPoint );
244 }
245
246 /**
247 * Tells if order has to be shipped to pickup point, run by Packeta or an external carrier.
248 *
249 * @return bool
250 */
251 public function isPickupPointDelivery(): bool {
252 return ( null !== $this->pickupPoint );
253 }
254
255 /**
256 * Checks if order uses external carrier.
257 *
258 * @return bool
259 */
260 public function isExternalCarrier(): bool {
261 return ( Carrier::INTERNAL_PICKUP_POINTS_ID !== $this->getCarrierId() );
262 }
263
264 /**
265 * Gets pickup point/carrier id.
266 *
267 * @return int|null
268 */
269 public function getPickupPointOrCarrierId(): ?int {
270 if ( $this->isExternalCarrier() ) {
271 return (int) $this->getCarrierId();
272 }
273
274 if ( null === $this->pickupPoint ) {
275 return null;
276 }
277
278 // Typing to int is safe in case of internal pickup points.
279 return (int) $this->pickupPoint->getId();
280 }
281
282 /**
283 * Sets carrier.
284 *
285 * @param Carrier|null $carrier Carrier.
286 */
287 public function setCarrier( ?Carrier $carrier ): void {
288 $this->carrier = $carrier;
289 }
290
291 /**
292 * Sets pickup point.
293 *
294 * @param PickupPoint $pickupPoint Pickup point.
295 */
296 public function setPickupPoint( PickupPoint $pickupPoint ): void {
297 $this->pickupPoint = $pickupPoint;
298 }
299
300 /**
301 * Sets delivery address.
302 *
303 * @param Address $address Delivery address.
304 */
305 public function setDeliveryAddress( Address $address ): void {
306 $this->address = $address;
307 }
308
309 /**
310 * Sets packet size.
311 *
312 * @param Size $size Size.
313 */
314 public function setSize( Size $size ): void {
315 $this->size = $size;
316 }
317
318 /**
319 * Sets number.
320 *
321 * @param string $number Number.
322 */
323 public function setNumber( string $number ): void {
324 $this->number = $number;
325 }
326
327 /**
328 * Sets phone.
329 *
330 * @param string $name Name.
331 */
332 public function setName( string $name ): void {
333 $this->name = $name;
334 }
335
336 /**
337 * Sets surname.
338 *
339 * @param string $surname Surname.
340 */
341 public function setSurname( string $surname ): void {
342 $this->surname = $surname;
343 }
344
345 /**
346 * Sets e-mail.
347 *
348 * @param string $email E-mail.
349 */
350 public function setEmail( string $email ): void {
351 $this->email = $email;
352 }
353
354 /**
355 * Sets eshop.
356 *
357 * @param string|null $eshop Eshop.
358 *
359 * @return void
360 */
361 public function setEshop( ?string $eshop ): void {
362 $this->eshop = $eshop;
363 }
364
365 /**
366 * Sets phone.
367 *
368 * @param string $phone Phone.
369 */
370 public function setPhone( string $phone ): void {
371 $this->phone = $phone;
372 }
373
374 /**
375 * Sets value.
376 *
377 * @param float $value Value.
378 */
379 public function setValue( float $value ): void {
380 $this->value = $value;
381 }
382
383 /**
384 * Sets COD.
385 *
386 * @param float $cod COD.
387 */
388 public function setCod( float $cod ): void {
389 $this->cod = $cod;
390 }
391
392 /**
393 * Gets packet currency.
394 *
395 * @return string
396 */
397 public function getCurrency(): string {
398 return $this->currency;
399 }
400
401 /**
402 * Sets packet currency.
403 *
404 * @param string $currency Currency.
405 *
406 * @return void
407 */
408 public function setCurrency( string $currency ): void {
409 $this->currency = $currency;
410 }
411
412 /**
413 * Sets packet note.
414 *
415 * @param string $note Packet note.
416 */
417 public function setNote( string $note ): void {
418 $this->note = $note;
419 }
420
421 /**
422 * Sets adult content presence flag.
423 *
424 * @param bool $adultContent Adult content presence flag.
425 */
426 public function setAdultContent( bool $adultContent ): void {
427 $this->adultContent = $adultContent;
428 }
429
430 /**
431 * Sets carrier id.
432 *
433 * @param string|null $carrierId Carrier id.
434 */
435 public function setCarrierId( ?string $carrierId ): void {
436 $this->carrierId = $carrierId;
437 }
438
439 /**
440 * Sets packet id.
441 *
442 * @param string|null $packetId Packet id.
443 */
444 public function setPacketId( ?string $packetId ): void {
445 $this->packetId = $packetId;
446 }
447
448 /**
449 * Sets packet status.
450 *
451 * @param string|null $packetStatus Packet status.
452 *
453 * @return void
454 */
455 public function setPacketStatus( ?string $packetStatus ): void {
456 $this->packetStatus = $packetStatus;
457 }
458
459 /**
460 * Sets is exported flag.
461 *
462 * @param bool $isExported Packet id.
463 */
464 public function setIsExported( bool $isExported ): void {
465 $this->isExported = $isExported;
466 }
467
468 /**
469 * Sets flag of label print.
470 *
471 * @param bool $isLabelPrinted Is label printed.
472 *
473 * @return void
474 */
475 public function setIsLabelPrinted( bool $isLabelPrinted ): void {
476 $this->isLabelPrinted = $isLabelPrinted;
477 }
478
479 /**
480 * Sets carrier number.
481 *
482 * @param string|null $carrierNumber Carrier number.
483 *
484 * @return void
485 */
486 public function setCarrierNumber( ?string $carrierNumber ): void {
487 $this->carrierNumber = $carrierNumber;
488 }
489
490 /**
491 * Sets weight.
492 *
493 * @param float|null $weight Weight.
494 *
495 * @return void
496 */
497 public function setWeight( ?float $weight ): void {
498 $this->weight = Helper::simplifyWeight( $weight );
499 }
500
501 /**
502 * Sets calculated weight.
503 *
504 * @param float|null $weight Weight.
505 *
506 * @return void
507 */
508 public function setCalculatedWeight( ?float $weight ): void {
509 $this->calculatedWeight = Helper::simplifyWeight( $weight );
510 }
511
512 /**
513 * Sets shipping country.
514 *
515 * @param string $shippingCountry ISO 3166-1 alpha-2 code, lowercase.
516 *
517 * @return void
518 */
519 public function setShippingCountry( $shippingCountry ): void {
520 $this->shippingCountry = $shippingCountry;
521 }
522
523 /**
524 * Gets carrier object.
525 *
526 * @return Carrier|null
527 */
528 public function getCarrier(): ?Carrier {
529 return $this->carrier;
530 }
531
532 /**
533 * Gets pickup point object.
534 *
535 * @return PickupPoint|null
536 */
537 public function getPickupPoint(): ?PickupPoint {
538 return $this->pickupPoint;
539 }
540
541 /**
542 * Gets delivery address object.
543 *
544 * @return Address|null
545 */
546 public function getDeliveryAddress(): ?Address {
547 return $this->address;
548 }
549
550 /**
551 * Gets validated delivery address object.
552 *
553 * @return Address|null
554 */
555 public function getValidatedDeliveryAddress(): ?Address {
556 return ( $this->addressValidated ? $this->address : null );
557 }
558
559 /**
560 * Gets size object.
561 *
562 * @return Size|null
563 */
564 public function getSize(): ?Size {
565 return $this->size;
566 }
567
568 /**
569 * Packet ID
570 *
571 * @return string|null
572 */
573 public function getPacketId(): ?string {
574 return $this->packetId;
575 }
576
577 /**
578 * Packet status.
579 *
580 * @return string|null
581 */
582 public function getPacketStatus(): ?string {
583 return $this->packetStatus;
584 }
585
586 /**
587 * Gets carrier id.
588 *
589 * @return string
590 */
591 public function getCarrierId(): string {
592 return $this->carrierId;
593 }
594
595 /**
596 * Tells if is packet submitted.
597 *
598 * @return bool
599 */
600 public function isExported(): ?bool {
601 return $this->isExported;
602 }
603
604 /**
605 * Gets weight.
606 *
607 * @return float|null
608 */
609 public function getWeight(): ?float {
610 return $this->weight;
611 }
612
613 /**
614 * Gets calculated weight.
615 *
616 * @return float|null
617 */
618 public function getCalculatedWeight(): ?float {
619 return $this->calculatedWeight;
620 }
621
622 /**
623 * Gets length.
624 *
625 * @return float|null
626 */
627 public function getLength(): ?float {
628 if ( empty( $this->size ) ) {
629 return null;
630 }
631
632 return $this->size->getLength();
633 }
634
635 /**
636 * Gets width.
637 *
638 * @return float|null
639 */
640 public function getWidth(): ?float {
641 if ( empty( $this->size ) ) {
642 return null;
643 }
644
645 return $this->size->getWidth();
646 }
647
648 /**
649 * Gets height.
650 *
651 * @return float|null
652 */
653 public function getHeight(): ?float {
654 if ( empty( $this->size ) ) {
655 return null;
656 }
657
658 return $this->size->getHeight();
659 }
660
661 /**
662 * Checks adult content presence.
663 *
664 * @return bool|null
665 */
666 public function containsAdultContent(): ?bool {
667 return $this->adultContent;
668 }
669
670 /**
671 * Gets order id.
672 *
673 * @return string|null
674 */
675 public function getNumber(): ?string {
676 return $this->number;
677 }
678
679 /**
680 * Gets customer name.
681 *
682 * @return string|null
683 */
684 public function getName(): ?string {
685 return $this->name;
686 }
687
688 /**
689 * Gets customer surname.
690 *
691 * @return string|null
692 */
693 public function getSurname(): ?string {
694 return $this->surname;
695 }
696
697 /**
698 * Gets order value.
699 *
700 * @return float|null
701 */
702 public function getValue(): ?float {
703 return $this->value;
704 }
705
706 /**
707 * Gets order COD value.
708 *
709 * @return float|null
710 */
711 public function getCod(): ?float {
712 return $this->cod;
713 }
714
715 /**
716 * Gets sender label.
717 *
718 * @return string|null
719 */
720 public function getEshop(): ?string {
721 return $this->eshop;
722 }
723
724 /**
725 * Gets customer e-mail.
726 *
727 * @return string|null
728 */
729 public function getEmail(): ?string {
730 return $this->email;
731 }
732
733 /**
734 * Gets delivery note.
735 *
736 * @return string|null
737 */
738 public function getNote(): ?string {
739 return $this->note;
740 }
741
742 /**
743 * Gets customer phone.
744 *
745 * @return string|null
746 */
747 public function getPhone(): ?string {
748 return $this->phone;
749 }
750
751 /**
752 * Is label printed?
753 *
754 * @return bool
755 */
756 public function isLabelPrinted(): bool {
757 return $this->isLabelPrinted;
758 }
759
760 /**
761 * Carrier number.
762 *
763 * @return string|null
764 */
765 public function getCarrierNumber(): ?string {
766 return $this->carrierNumber;
767 }
768
769 /**
770 * Gets shipping country.
771 *
772 * @return string|null
773 */
774 public function getShippingCountry(): ?string {
775 return $this->shippingCountry;
776 }
777
778 }
779