PluginProbe
Packeta / 1.5.1
Packeta v1.5.1
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.5.1, at src/Packetery/Core/Entity/Order.php

961 lines 15.5 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 use DateTimeImmutable;
14
15 /**
16 * Class Order
17 *
18 * @package Packetery\Order
19 */
20 class Order {
21
22 /**
23 * Order id.
24 *
25 * @var string
26 */
27 private $number;
28
29 /**
30 * Custom order number.
31 *
32 * @var string|null
33 */
34 private $customNumber;
35
36 /**
37 * Order carrier object.
38 *
39 * @var Carrier|null
40 */
41 private $carrier;
42
43 /**
44 * Order pickup point object.
45 *
46 * @var PickupPoint|null
47 */
48 private $pickupPoint;
49
50 /**
51 * Customer name.
52 *
53 * @var string|null
54 */
55 private $name;
56
57 /**
58 * Customer surname.
59 *
60 * @var string|null
61 */
62 private $surname;
63
64 /**
65 * Customer e-mail.
66 *
67 * @var string|null
68 */
69 private $email;
70
71 /**
72 * Customer phone.
73 *
74 * @var string|null
75 */
76 private $phone;
77
78 /**
79 * Order value.
80 *
81 * @var float|null
82 */
83 private $value;
84
85 /**
86 * Sender label.
87 *
88 * @var string|null
89 */
90 private $eshop;
91
92 /**
93 * Address.
94 *
95 * @var Address|null
96 */
97 private $address;
98
99 /**
100 * Size.
101 *
102 * @var Size|null
103 */
104 private $size;
105
106 /**
107 * Package weight, set or calculated.
108 *
109 * @var float|null
110 */
111 private $weight;
112
113 /**
114 * Calculated package weight.
115 *
116 * @var float|null
117 */
118 private $calculatedWeight;
119
120 /**
121 * Cash on delivery value.
122 *
123 * @var float|null
124 */
125 private $cod;
126
127 /**
128 * Packet note.
129 *
130 * @var string|null
131 */
132 private $note;
133
134 /**
135 * Adult content presence flag.
136 *
137 * @var bool|null
138 */
139 private $adultContent;
140
141 /**
142 * Packet ID
143 *
144 * @var string|null
145 */
146 private $packetId;
147
148 /**
149 * Packet ID
150 *
151 * @var string|null
152 */
153 private $packetStatus;
154
155 /**
156 * Carrier id.
157 *
158 * @var string
159 */
160 private $carrierId;
161
162 /**
163 * Internal carrier code.
164 *
165 * @var string
166 */
167 private $carrierCode;
168
169 /**
170 * Tells if is packet submitted.
171 *
172 * @var bool
173 */
174 private $isExported;
175
176 /**
177 * Tells if is packet submitted.
178 *
179 * @var bool
180 */
181 private $isLabelPrinted;
182
183 /**
184 * Packet currency.
185 *
186 * @var string
187 */
188 private $currency;
189
190 /**
191 * Carrier number.
192 *
193 * @var string|null
194 */
195 private $carrierNumber;
196
197 /**
198 * Address validated.
199 *
200 * @var bool
201 */
202 private $addressValidated;
203
204 /**
205 * ISO 3166-1 alpha-2 code, lowercase.
206 *
207 * @var string|null
208 */
209 private $shippingCountry;
210
211 /**
212 * Last message built from Packeta API response.
213 *
214 * @var string|null
215 */
216 private $lastApiErrorMessage;
217
218 /**
219 * Last API error datetime.
220 *
221 * @var \DateTimeImmutable|null
222 */
223 private $lastApiErrorDateTime;
224
225 /**
226 * Deliver on
227 *
228 * @var DateTimeImmutable|null
229 */
230 private $deliverOn;
231
232 /**
233 * Order entity constructor.
234 *
235 * @param string $number Order id.
236 * @param string $carrierId Sender label.
237 * @param bool $isExported Is exported.
238 * @param bool $isLabelPrinted Is label printed.
239 */
240 public function __construct(
241 string $number,
242 string $carrierId,
243 bool $isExported = false,
244 bool $isLabelPrinted = false
245 ) {
246 $this->number = $number;
247 $this->carrierId = $carrierId;
248 $this->isExported = $isExported;
249 $this->isLabelPrinted = $isLabelPrinted;
250 $this->addressValidated = false;
251 }
252
253 /**
254 * Gets custom number.
255 *
256 * @return string|null
257 */
258 public function getCustomNumber(): ?string {
259 return $this->customNumber;
260 }
261
262 /**
263 * Sets custom number.
264 *
265 * @param string|null $customNumber Custom number.
266 *
267 * @return void
268 */
269 public function setCustomNumber( ?string $customNumber ): void {
270 $this->customNumber = $customNumber;
271 }
272
273 /**
274 * Is address validated?
275 *
276 * @return bool
277 */
278 public function isAddressValidated(): bool {
279 return $this->addressValidated;
280 }
281
282 /**
283 * Sets address validation flag.
284 *
285 * @param bool $addressValidated Address validated.
286 *
287 * @return void
288 */
289 public function setAddressValidated( bool $addressValidated ): void {
290 $this->addressValidated = $addressValidated;
291 }
292
293 /**
294 * Checks if is home delivery. In that case pointId is not set.
295 *
296 * @return bool
297 */
298 public function isHomeDelivery(): bool {
299 return ( null === $this->pickupPoint );
300 }
301
302 /**
303 * Tells if order has to be shipped to pickup point, run by Packeta or an external carrier.
304 *
305 * @return bool
306 */
307 public function isPickupPointDelivery(): bool {
308 return ( null !== $this->pickupPoint );
309 }
310
311 /**
312 * Checks if order uses external carrier.
313 *
314 * @return bool
315 */
316 public function isExternalCarrier(): bool {
317 return is_numeric( $this->getCarrierId() );
318 }
319
320 /**
321 * Check if delivery method is internal packetery pickup point
322 *
323 * @return bool
324 */
325 public function isPacketaInternalPickupPoint(): bool {
326 return ! $this->isExternalCarrier() && $this->isPickupPointDelivery();
327 }
328
329 /**
330 * Gets pickup point/carrier id.
331 *
332 * @return int|null
333 */
334 public function getPickupPointOrCarrierId(): ?int {
335 if ( $this->isExternalCarrier() ) {
336 return (int) $this->getCarrierId();
337 }
338
339 if ( null === $this->pickupPoint ) {
340 return null;
341 }
342
343 // Typing to int is safe in case of internal pickup points.
344 return (int) $this->pickupPoint->getId();
345 }
346
347 /**
348 * Sets carrier.
349 *
350 * @param Carrier|null $carrier Carrier.
351 */
352 public function setCarrier( ?Carrier $carrier ): void {
353 $this->carrier = $carrier;
354 }
355
356 /**
357 * Sets pickup point.
358 *
359 * @param PickupPoint $pickupPoint Pickup point.
360 */
361 public function setPickupPoint( PickupPoint $pickupPoint ): void {
362 $this->pickupPoint = $pickupPoint;
363 }
364
365 /**
366 * Sets delivery address.
367 *
368 * @param Address $address Delivery address.
369 */
370 public function setDeliveryAddress( Address $address ): void {
371 $this->address = $address;
372 }
373
374 /**
375 * Sets packet size.
376 *
377 * @param Size $size Size.
378 */
379 public function setSize( Size $size ): void {
380 $this->size = $size;
381 }
382
383 /**
384 * Sets number.
385 *
386 * @param string $number Number.
387 */
388 public function setNumber( string $number ): void {
389 $this->number = $number;
390 }
391
392 /**
393 * Sets phone.
394 *
395 * @param string $name Name.
396 */
397 public function setName( string $name ): void {
398 $this->name = $name;
399 }
400
401 /**
402 * Sets surname.
403 *
404 * @param string $surname Surname.
405 */
406 public function setSurname( string $surname ): void {
407 $this->surname = $surname;
408 }
409
410 /**
411 * Sets e-mail.
412 *
413 * @param string $email E-mail.
414 */
415 public function setEmail( string $email ): void {
416 $this->email = $email;
417 }
418
419 /**
420 * Sets eshop.
421 *
422 * @param string|null $eshop Eshop.
423 *
424 * @return void
425 */
426 public function setEshop( ?string $eshop ): void {
427 $this->eshop = $eshop;
428 }
429
430 /**
431 * Sets phone.
432 *
433 * @param string $phone Phone.
434 */
435 public function setPhone( string $phone ): void {
436 $this->phone = $phone;
437 }
438
439 /**
440 * Sets value.
441 *
442 * @param float|null $value Value.
443 */
444 public function setValue( ?float $value ): void {
445 $this->value = $value;
446 }
447
448 /**
449 * Sets COD.
450 *
451 * @param float|null $cod COD.
452 */
453 public function setCod( ?float $cod ): void {
454 $this->cod = $cod;
455 }
456
457 /**
458 * Gets packet currency.
459 *
460 * @return string
461 */
462 public function getCurrency(): string {
463 return $this->currency;
464 }
465
466 /**
467 * Sets packet currency.
468 *
469 * @param string $currency Currency.
470 *
471 * @return void
472 */
473 public function setCurrency( string $currency ): void {
474 $this->currency = $currency;
475 }
476
477 /**
478 * Sets packet note.
479 *
480 * @param string $note Packet note.
481 */
482 public function setNote( string $note ): void {
483 $this->note = $note;
484 }
485
486 /**
487 * Sets adult content presence flag.
488 *
489 * @param bool|null $adultContent Adult content presence flag.
490 */
491 public function setAdultContent( ?bool $adultContent ): void {
492 $this->adultContent = $adultContent;
493 }
494
495 /**
496 * Sets carrier id.
497 *
498 * @param string|null $carrierId Carrier id.
499 */
500 public function setCarrierId( ?string $carrierId ): void {
501 $this->carrierId = $carrierId;
502 }
503
504 /**
505 * Sets packet id.
506 *
507 * @param string|null $packetId Packet id.
508 */
509 public function setPacketId( ?string $packetId ): void {
510 $this->packetId = $packetId;
511 }
512
513 /**
514 * Sets packet status.
515 *
516 * @param string|null $packetStatus Packet status.
517 *
518 * @return void
519 */
520 public function setPacketStatus( ?string $packetStatus ): void {
521 $this->packetStatus = $packetStatus;
522 }
523
524 /**
525 * Sets is exported flag.
526 *
527 * @param bool $isExported Packet id.
528 */
529 public function setIsExported( bool $isExported ): void {
530 $this->isExported = $isExported;
531 }
532
533 /**
534 * Sets flag of label print.
535 *
536 * @param bool $isLabelPrinted Is label printed.
537 *
538 * @return void
539 */
540 public function setIsLabelPrinted( bool $isLabelPrinted ): void {
541 $this->isLabelPrinted = $isLabelPrinted;
542 }
543
544 /**
545 * Sets carrier number.
546 *
547 * @param string|null $carrierNumber Carrier number.
548 *
549 * @return void
550 */
551 public function setCarrierNumber( ?string $carrierNumber ): void {
552 $this->carrierNumber = $carrierNumber;
553 }
554
555 /**
556 * Sets weight.
557 *
558 * @param float|null $weight Weight.
559 *
560 * @return void
561 */
562 public function setWeight( ?float $weight ): void {
563 $this->weight = Helper::simplifyWeight( $weight );
564 }
565
566 /**
567 * Sets calculated weight.
568 *
569 * @param float|null $weight Weight.
570 *
571 * @return void
572 */
573 public function setCalculatedWeight( ?float $weight ): void {
574 $this->calculatedWeight = Helper::simplifyWeight( $weight );
575 }
576
577 /**
578 * Sets shipping country.
579 *
580 * @param string $shippingCountry ISO 3166-1 alpha-2 code, lowercase.
581 *
582 * @return void
583 */
584 public function setShippingCountry( $shippingCountry ): void {
585 $this->shippingCountry = $shippingCountry;
586 }
587
588 /**
589 * Sets API response message.
590 *
591 * @param string|null $lastApiErrorMessage API response message.
592 *
593 * @return void
594 */
595 public function setLastApiErrorMessage( ?string $lastApiErrorMessage ): void {
596 $this->lastApiErrorMessage = $lastApiErrorMessage;
597 }
598
599 /**
600 * Sets API error date.
601 *
602 * @param \DateTimeImmutable|null $lastApiErrorDateTime API error date.
603 */
604 public function setLastApiErrorDateTime( ?\DateTimeImmutable $lastApiErrorDateTime ): void {
605 $this->lastApiErrorDateTime = $lastApiErrorDateTime;
606 }
607
608 /**
609 * Gets carrier object.
610 *
611 * @return Carrier|null
612 */
613 public function getCarrier(): ?Carrier {
614 return $this->carrier;
615 }
616
617 /**
618 * Gets pickup point object.
619 *
620 * @return PickupPoint|null
621 */
622 public function getPickupPoint(): ?PickupPoint {
623 return $this->pickupPoint;
624 }
625
626 /**
627 * Gets delivery address object.
628 *
629 * @return Address|null
630 */
631 public function getDeliveryAddress(): ?Address {
632 return $this->address;
633 }
634
635 /**
636 * Gets validated delivery address object.
637 *
638 * @return Address|null
639 */
640 public function getValidatedDeliveryAddress(): ?Address {
641 return ( $this->addressValidated ? $this->address : null );
642 }
643
644 /**
645 * Gets size object.
646 *
647 * @return Size|null
648 */
649 public function getSize(): ?Size {
650 return $this->size;
651 }
652
653 /**
654 * Packet ID
655 *
656 * @return string|null
657 */
658 public function getPacketId(): ?string {
659 return $this->packetId;
660 }
661
662 /**
663 * Packet status.
664 *
665 * @return string|null
666 */
667 public function getPacketStatus(): ?string {
668 return $this->packetStatus;
669 }
670
671 /**
672 * Gets carrier id.
673 *
674 * @return string
675 */
676 public function getCarrierId(): string {
677 return $this->carrierId;
678 }
679
680 /**
681 * Tells if is packet submitted.
682 *
683 * @return bool
684 */
685 public function isExported(): ?bool {
686 return $this->isExported;
687 }
688
689 /**
690 * Gets weight.
691 *
692 * @return float|null
693 */
694 public function getWeight(): ?float {
695 return $this->weight;
696 }
697
698 /**
699 * Tells if order has manual weight set.
700 *
701 * @return bool
702 */
703 public function hasManualWeight(): bool {
704 return null !== $this->weight;
705 }
706
707 /**
708 * Gets final weight.
709 *
710 * @return float|null
711 */
712 public function getFinalWeight(): ?float {
713 return $this->weight ?? $this->calculatedWeight;
714 }
715
716 /**
717 * Gets calculated weight.
718 *
719 * @return float|null
720 */
721 public function getCalculatedWeight(): ?float {
722 return $this->calculatedWeight;
723 }
724
725 /**
726 * Gets length.
727 *
728 * @return float|null
729 */
730 public function getLength(): ?float {
731 if ( empty( $this->size ) ) {
732 return null;
733 }
734
735 return $this->size->getLength();
736 }
737
738 /**
739 * Gets width.
740 *
741 * @return float|null
742 */
743 public function getWidth(): ?float {
744 if ( empty( $this->size ) ) {
745 return null;
746 }
747
748 return $this->size->getWidth();
749 }
750
751 /**
752 * Gets height.
753 *
754 * @return float|null
755 */
756 public function getHeight(): ?float {
757 if ( empty( $this->size ) ) {
758 return null;
759 }
760
761 return $this->size->getHeight();
762 }
763
764 /**
765 * Checks adult content presence.
766 *
767 * @return bool|null
768 */
769 public function containsAdultContent(): ?bool {
770 return $this->adultContent;
771 }
772
773 /**
774 * Gets order id.
775 *
776 * @return string|null
777 */
778 public function getNumber(): ?string {
779 return $this->number;
780 }
781
782 /**
783 * Gets customer name.
784 *
785 * @return string|null
786 */
787 public function getName(): ?string {
788 return $this->name;
789 }
790
791 /**
792 * Gets customer surname.
793 *
794 * @return string|null
795 */
796 public function getSurname(): ?string {
797 return $this->surname;
798 }
799
800 /**
801 * Gets order value.
802 *
803 * @return float|null
804 */
805 public function getValue(): ?float {
806 return $this->value;
807 }
808
809 /**
810 * Gets order COD value.
811 *
812 * @return float|null
813 */
814 public function getCod(): ?float {
815 return $this->cod;
816 }
817
818 /**
819 * Gets sender label.
820 *
821 * @return string|null
822 */
823 public function getEshop(): ?string {
824 return $this->eshop;
825 }
826
827 /**
828 * Gets customer e-mail.
829 *
830 * @return string|null
831 */
832 public function getEmail(): ?string {
833 return $this->email;
834 }
835
836 /**
837 * Gets delivery note.
838 *
839 * @return string|null
840 */
841 public function getNote(): ?string {
842 return $this->note;
843 }
844
845 /**
846 * Gets customer phone.
847 *
848 * @return string|null
849 */
850 public function getPhone(): ?string {
851 return $this->phone;
852 }
853
854 /**
855 * Is label printed?
856 *
857 * @return bool
858 */
859 public function isLabelPrinted(): bool {
860 return $this->isLabelPrinted;
861 }
862
863 /**
864 * Carrier number.
865 *
866 * @return string|null
867 */
868 public function getCarrierNumber(): ?string {
869 return $this->carrierNumber;
870 }
871
872 /**
873 * Gets shipping country.
874 *
875 * @return string|null
876 */
877 public function getShippingCountry(): ?string {
878 return $this->shippingCountry;
879 }
880
881 /**
882 * Tells if order has COD.
883 *
884 * @return bool
885 */
886 public function hasCod(): bool {
887 return ( null !== $this->getCod() );
888 }
889
890 /**
891 * Setter for carrierCode.
892 *
893 * @param string $carrierCode Carrier code.
894 *
895 * @return void
896 */
897 public function setCarrierCode( string $carrierCode ): void {
898 $this->carrierCode = $carrierCode;
899 }
900
901 /**
902 * Returns carrierId for external carriers or carrierCode.
903 *
904 * @return string
905 */
906 public function getCarrierCode():string {
907 return $this->carrierCode;
908 }
909
910 /**
911 * Returns deliver on date
912 *
913 * @return DateTimeImmutable|null
914 */
915 public function getDeliverOn(): ?DateTimeImmutable {
916 return $this->deliverOn;
917 }
918
919 /**
920 * Sets deliver on date
921 *
922 * @param DateTimeImmutable|null $deliverOn Deliver on.
923 *
924 * @return void
925 */
926 public function setDeliverOn( ?DateTimeImmutable $deliverOn ): void {
927 $this->deliverOn = $deliverOn;
928 }
929
930 /**
931 * Formatted API error message.
932 *
933 * @return string|null
934 */
935 public function getLastApiErrorMessage(): ?string {
936 return $this->lastApiErrorMessage;
937 }
938
939 /**
940 * Gets last API error message date.
941 *
942 * @return \DateTimeImmutable|null
943 */
944 public function getLastApiErrorDateTime(): ?\DateTimeImmutable {
945 return $this->lastApiErrorDateTime;
946 }
947
948 /**
949 * Updates API error message and sets error message date accordingly.
950 *
951 * @param string|null $errorMessage Error message.
952 *
953 * @return void
954 */
955 public function updateApiErrorMessage( ?string $errorMessage ): void {
956 $this->setLastApiErrorMessage( $errorMessage );
957 $this->setLastApiErrorDateTime( $errorMessage ? Helper::now() : null );
958 }
959
960 }
961