PluginProbe
Packeta / 2.1
Packeta v2.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
← All changes | src/Packetery/Core/Entity/Order.php +230 -60 1.6.12.1 View file →
@@ -8,10 +8,10 @@
8 8 declare( strict_types=1 );
9 9
10 10 namespace Packetery\Core\Entity;
11 11
12 -use Packetery\Core\Helper;
13 12 use DateTimeImmutable;
13 +use Packetery\Core\CoreHelper;
14 14
15 15 /**
16 16 * Class Order
17 17 *
@@ -26,8 +26,15 @@
26 26 */
27 27 private $number;
28 28
29 29 /**
30 + * Car Delivery id.
31 + *
32 + * @var string
33 + */
34 + private $carDeliveryId;
35 +
36 + /**
30 37 * Custom order number.
31 38 *
32 39 * @var string|null
33 40 */
@@ -75,15 +82,18 @@
75 82 */
76 83 private $phone;
77 84
78 85 /**
79 - * Order value.
80 - *
81 86 * @var float|null
82 87 */
83 - private $value;
88 + private $calculatedValue;
84 89
85 90 /**
91 + * @var float|null
92 + */
93 + private $manualValue;
94 +
95 + /**
86 96 * Sender label.
87 97 *
88 98 * @var string|null
89 99 */
@@ -117,15 +127,18 @@
117 127 */
118 128 private $calculatedWeight;
119 129
120 130 /**
121 - * Cash on delivery value.
122 - *
123 131 * @var float|null
124 132 */
125 - private $cod;
133 + private $calculatedCod;
126 134
127 135 /**
136 + * @var float|null
137 + */
138 + private $manualCod;
139 +
140 + /**
128 141 * Packet note.
129 142 *
130 143 * @var string|null
131 144 */
@@ -145,8 +158,13 @@
145 158 */
146 159 private $packetId;
147 160
148 161 /**
162 + * @var string|null
163 + */
164 + private $packetTrackingUrl;
165 +
166 + /**
149 167 * Packet ID.
150 168 *
151 169 * @var string|null
152 170 */
@@ -152,8 +170,13 @@
152 170 */
153 171 private $packetClaimId;
154 172
155 173 /**
174 + * @var string|null
175 + */
176 + private $packetClaimTrackingUrl;
177 +
178 + /**
156 179 * Packet password.
157 180 *
158 181 * @var string|null
159 182 */
@@ -236,8 +259,15 @@
236 259 */
237 260 private $customsDeclaration;
238 261
239 262 /**
263 + * Stored until.
264 + *
265 + * @var DateTimeImmutable|null
266 + */
267 + private $storedUntil;
268 +
269 + /**
240 270 * Order entity constructor.
241 271 *
242 272 * @param string $number Order id.
243 273 * @param Carrier $carrier Carrier entity.
@@ -253,8 +283,27 @@
253 283 $this->addressValidated = false;
254 284 }
255 285
256 286 /**
287 + * Gets Car Delivery id.
288 + *
289 + * @return string
290 + */
291 + public function getCarDeliveryId(): ?string {
292 + return $this->carDeliveryId;
293 + }
294 +
295 + /**
296 + * Sets Car Delivery id.
297 + *
298 + * @param string $carDeliveryId Car delivery ID.
299 + * @return void
300 + */
301 + public function setCarDeliveryId( string $carDeliveryId ): void {
302 + $this->carDeliveryId = $carDeliveryId;
303 + }
304 +
305 + /**
257 306 * Sets custom declaration.
258 307 *
259 308 * @param CustomsDeclaration|null $customsDeclaration Customs declaration.
260 309 *
@@ -278,9 +327,9 @@
278 327 *
279 328 * @return bool
280 329 */
281 330 public function hasCustomsDeclaration(): bool {
282 - return null !== $this->customsDeclaration && [] !== $this->customsDeclaration->getItems();
331 + return $this->customsDeclaration !== null && $this->customsDeclaration->getItems() !== [];
283 332 }
284 333
285 334 /**
286 335 * Tells if customs declaration has to be filled to submit packet.
@@ -288,9 +337,9 @@
288 337 * @return bool
289 338 */
290 339 public function hasToFillCustomsDeclaration(): bool {
291 340 return $this->carrier->requiresCustomsDeclarations() &&
292 - false === $this->hasCustomsDeclaration();
341 + $this->hasCustomsDeclaration() === false;
293 342 }
294 343
295 344 /**
296 345 * Gets custom number.
@@ -337,18 +386,27 @@
337 386 *
338 387 * @return bool
339 388 */
340 389 public function isHomeDelivery(): bool {
341 - return ( null === $this->pickupPoint );
390 + return ( ! $this->carrier->hasPickupPoints() && ! $this->isCarDelivery() );
342 391 }
343 392
344 393 /**
394 + * Checks if is home delivery. In that case pointId is not set.
395 + *
396 + * @return bool
397 + */
398 + public function isCarDelivery(): bool {
399 + return $this->carrier->isCarDelivery();
400 + }
401 +
402 + /**
345 403 * Tells if order has to be shipped to pickup point, run by Packeta or an external carrier.
346 404 *
347 405 * @return bool
348 406 */
349 407 public function isPickupPointDelivery(): bool {
350 - return ( null !== $this->pickupPoint );
408 + return $this->carrier->hasPickupPoints();
351 409 }
352 410
353 411 /**
354 412 * Checks if order uses external carrier.
@@ -377,9 +435,9 @@
377 435 if ( $this->isExternalCarrier() ) {
378 436 return (int) $this->getCarrier()->getId();
379 437 }
380 438
381 - if ( null === $this->pickupPoint ) {
439 + if ( $this->pickupPoint === null ) {
382 440 return null;
383 441 }
384 442
385 443 // Typing to int is safe in case of internal pickup points.
@@ -385,8 +443,14 @@
385 443 // Typing to int is safe in case of internal pickup points.
386 444 return (int) $this->pickupPoint->getId();
387 445 }
388 446
447 + public function hasPickupPointOrCarrierId(): bool {
448 + $pickupPointOrCarrierId = $this->getPickupPointOrCarrierId();
449 +
450 + return $pickupPointOrCarrierId !== null && $pickupPointOrCarrierId !== 0;
451 + }
452 +
389 453 /**
390 454 * Sets pickup point.
391 455 *
392 456 * @param PickupPoint $pickupPoint Pickup point.
@@ -468,26 +532,24 @@
468 532 public function setPhone( string $phone ): void {
469 533 $this->phone = $phone;
470 534 }
471 535
472 - /**
473 - * Sets value.
474 - *
475 - * @param float|null $value Value.
476 - */
477 - public function setValue( ?float $value ): void {
478 - $this->value = $value;
536 + public function setManualValue( ?float $value ): void {
537 + $this->manualValue = $value;
479 538 }
480 539
481 - /**
482 - * Sets COD.
483 - *
484 - * @param float|null $cod COD.
485 - */
486 - public function setCod( ?float $cod ): void {
487 - $this->cod = $cod;
540 + public function setCalculatedValue( ?float $value ): void {
541 + $this->calculatedValue = $value;
488 542 }
489 543
544 + public function setManualCod( ?float $cod ): void {
545 + $this->manualCod = $cod;
546 + }
547 +
548 + public function setCalculatedCod( ?float $cod ): void {
549 + $this->calculatedCod = $cod;
550 + }
551 +
490 552 /**
491 553 * Gets packet currency.
492 554 *
493 555 * @return string
@@ -533,8 +595,12 @@
533 595 public function setPacketId( ?string $packetId ): void {
534 596 $this->packetId = $packetId;
535 597 }
536 598
599 + public function setPacketTrackingUrl( ?string $trackingUrl ): void {
600 + $this->packetTrackingUrl = $trackingUrl;
601 + }
602 +
537 603 /**
538 604 * Sets packet claim ID.
539 605 *
540 606 * @param string|null $packetClaimId Packet claim ID.
@@ -544,8 +610,12 @@
544 610 public function setPacketClaimId( ?string $packetClaimId ): void {
545 611 $this->packetClaimId = $packetClaimId;
546 612 }
547 613
614 + public function setPacketClaimTrackingUrl( ?string $trackingUrl ): void {
615 + $this->packetClaimTrackingUrl = $trackingUrl;
616 + }
617 +
548 618 /**
549 619 * Packet claim password.
550 620 *
551 621 * @param string|null $packetClaimPassword Packet claim password.
@@ -567,8 +637,17 @@
567 637 $this->packetStatus = $packetStatus;
568 638 }
569 639
570 640 /**
641 + * Sets stored until date.
642 + *
643 + * @param \DateTimeImmutable|null $storedUntil Stored until.
644 + */
645 + public function setStoredUntil( ?DateTimeImmutable $storedUntil ): void {
646 + $this->storedUntil = $storedUntil;
647 + }
648 +
649 + /**
571 650 * Sets is exported flag.
572 651 *
573 652 * @param bool $isExported Packet id.
574 653 */
@@ -605,9 +684,9 @@
605 684 *
606 685 * @return void
607 686 */
608 687 public function setWeight( ?float $weight ): void {
609 - $this->weight = Helper::simplifyWeight( $weight );
688 + $this->weight = CoreHelper::simplifyWeight( $weight );
610 689 }
611 690
612 691 /**
613 692 * Sets calculated weight.
@@ -616,9 +695,9 @@
616 695 *
617 696 * @return void
618 697 */
619 698 public function setCalculatedWeight( ?float $weight ): void {
620 - $this->calculatedWeight = Helper::simplifyWeight( $weight );
699 + $this->calculatedWeight = $weight;
621 700 }
622 701
623 702 /**
624 703 * Sets shipping country.
@@ -627,9 +706,9 @@
627 706 *
628 707 * @return void
629 708 */
630 709 public function setShippingCountry( string $shippingCountry ): void {
631 - if ( '' === $shippingCountry ) {
710 + if ( $shippingCountry === '' ) {
632 711 $this->shippingCountry = null;
633 712 } else {
634 713 $this->shippingCountry = $shippingCountry;
635 714 }
@@ -714,20 +793,28 @@
714 793 *
715 794 * @return string|null
716 795 */
717 796 public function getPacketBarcode(): ?string {
718 - return $this->packetId ? 'Z' . $this->packetId : null;
797 + return $this->packetId !== null ? 'Z' . $this->packetId : null;
719 798 }
720 799
721 800 /**
722 - * Get packet tracking url
801 + * Packet Claim barcode e.g Z123456789
723 802 *
724 803 * @return string|null
725 804 */
805 + public function getPacketClaimBarcode(): ?string {
806 + return $this->packetClaimId !== null ? 'Z' . $this->packetClaimId : null;
807 + }
808 +
726 809 public function getPacketTrackingUrl(): ?string {
727 - return $this->packetId ? sprintf( Helper::TRACKING_URL, $this->packetId ) : null;
810 + return $this->packetTrackingUrl;
728 811 }
729 812
813 + public function getPacketClaimTrackingUrl(): ?string {
814 + return $this->packetClaimTrackingUrl;
815 + }
816 +
730 817 /**
731 818 * Gets packet claim ID.
732 819 *
733 820 * @return string|null
@@ -754,26 +841,57 @@
754 841 return $this->packetStatus;
755 842 }
756 843
757 844 /**
845 + * Get stored until date.
846 + *
847 + * @return \DateTimeImmutable|null
848 + */
849 + public function getStoredUntil(): ?\DateTimeImmutable {
850 + return $this->storedUntil;
851 + }
852 +
853 + /**
854 + * Tells it's possible to extend the package pickup date.
855 + *
856 + * @return bool
857 + */
858 + public function isPossibleExtendPacketPickUpDate(): bool {
859 + return $this->packetStatus === PacketStatus::READY_FOR_PICKUP &&
860 + $this->storedUntil !== null &&
861 + $this->isPacketaInternalPickupPoint();
862 + }
863 +
864 + /**
758 865 * Tells if packet claim creation is possible.
759 866 *
760 867 * @return bool
761 868 */
762 869 public function isPacketClaimCreationPossible(): bool {
763 - return PacketStatus::DELIVERED === $this->packetStatus &&
764 - null === $this->packetClaimId;
870 + return $this->packetStatus === PacketStatus::DELIVERED &&
871 + $this->packetClaimId === null;
765 872 }
766 873
767 874 /**
875 + * Determines whether a packet is a claim, or otherwise.
876 + *
877 + * @param string $packetId Packet id.
878 + *
879 + * @return bool
880 + */
881 + public function isPacketClaim( string $packetId ): bool {
882 + return $this->getPacketClaimId() === $packetId;
883 + }
884 +
885 + /**
768 886 * Tells if packet claim label print is possible.
769 887 *
770 888 * @return bool
771 889 */
772 890 public function isPacketClaimLabelPrintPossible(): bool {
773 - return null !== $this->packetClaimId &&
774 - false === $this->isExternalCarrier() &&
775 - null !== $this->pickupPoint;
891 + return $this->packetClaimId !== null &&
892 + $this->isExternalCarrier() === false &&
893 + $this->pickupPoint !== null;
776 894 }
777 895
778 896 /**
779 897 * Tells if is packet submitted.
@@ -779,9 +897,9 @@
779 897 * Tells if is packet submitted.
780 898 *
781 899 * @return bool
782 900 */
783 - public function isExported(): ?bool {
901 + public function isExported(): bool {
784 902 return $this->isExported;
785 903 }
786 904
787 905 /**
@@ -798,9 +916,9 @@
798 916 *
799 917 * @return bool
800 918 */
801 919 public function hasManualWeight(): bool {
802 - return null !== $this->weight;
920 + return $this->weight !== null;
803 921 }
804 922
805 923 /**
806 924 * Gets final weight.
@@ -825,9 +943,9 @@
825 943 *
826 944 * @return float|null
827 945 */
828 946 public function getLength(): ?float {
829 - if ( empty( $this->size ) ) {
947 + if ( $this->size === null ) {
830 948 return null;
831 949 }
832 950
833 951 return $this->size->getLength();
@@ -838,9 +956,9 @@
838 956 *
839 957 * @return float|null
840 958 */
841 959 public function getWidth(): ?float {
842 - if ( empty( $this->size ) ) {
960 + if ( $this->size === null ) {
843 961 return null;
844 962 }
845 963
846 964 return $this->size->getWidth();
@@ -851,9 +969,9 @@
851 969 *
852 970 * @return float|null
853 971 */
854 972 public function getHeight(): ?float {
855 - if ( empty( $this->size ) ) {
973 + if ( $this->size === null ) {
856 974 return null;
857 975 }
858 976
859 977 return $this->size->getHeight();
@@ -877,8 +995,17 @@
877 995 return $this->number;
878 996 }
879 997
880 998 /**
999 + * Has order id.
1000 + *
1001 + * @return bool
1002 + */
1003 + public function hasNumber(): bool {
1004 + return $this->number !== null && $this->number !== '';
1005 + }
1006 +
1007 + /**
881 1008 * Gets customer name.
882 1009 *
883 1010 * @return string|null
884 1011 */
@@ -886,8 +1013,17 @@
886 1013 return $this->name;
887 1014 }
888 1015
889 1016 /**
1017 + * Has customer name.
1018 + *
1019 + * @return bool
1020 + */
1021 + public function hasName(): bool {
1022 + return $this->name !== null && $this->name !== '';
1023 + }
1024 +
1025 + /**
890 1026 * Gets customer surname.
891 1027 *
892 1028 * @return string|null
893 1029 */
@@ -894,26 +1030,44 @@
894 1030 public function getSurname(): ?string {
895 1031 return $this->surname;
896 1032 }
897 1033
898 - /**
899 - * Gets order value.
900 - *
901 - * @return float|null
902 - */
903 - public function getValue(): ?float {
904 - return $this->value;
1034 + public function getManualValue(): ?float {
1035 + return $this->manualValue;
905 1036 }
906 1037
907 - /**
908 - * Gets order COD value.
909 - *
910 - * @return float|null
911 - */
912 - public function getCod(): ?float {
913 - return $this->cod;
1038 + public function hasManualValue(): bool {
1039 + return $this->manualValue !== null;
914 1040 }
915 1041
1042 + public function getCalculatedValue(): ?float {
1043 + return $this->calculatedValue;
1044 + }
1045 +
1046 + public function getFinalValue(): ?float {
1047 + return $this->manualValue ?? $this->calculatedValue;
1048 + }
1049 +
1050 + public function hasFinalValue(): bool {
1051 + return $this->getFinalValue() !== null;
1052 + }
1053 +
1054 + public function getManualCod(): ?float {
1055 + return $this->manualCod;
1056 + }
1057 +
1058 + public function hasManualCod(): bool {
1059 + return $this->manualCod !== null;
1060 + }
1061 +
1062 + public function getCalculatedCod(): ?float {
1063 + return $this->calculatedCod;
1064 + }
1065 +
1066 + public function getFinalCod(): ?float {
1067 + return $this->manualCod ?? $this->calculatedCod;
1068 + }
1069 +
916 1070 /**
917 1071 * Gets sender label.
918 1072 *
919 1073 * @return string|null
@@ -922,8 +1076,17 @@
922 1076 return $this->eshop;
923 1077 }
924 1078
925 1079 /**
1080 + * Has sender label.
1081 + *
1082 + * @return bool
1083 + */
1084 + public function hasEshop(): bool {
1085 + return $this->eshop !== null && $this->eshop !== '';
1086 + }
1087 +
1088 + /**
926 1089 * Gets customer e-mail.
927 1090 *
928 1091 * @return string|null
929 1092 */
@@ -975,15 +1138,19 @@
975 1138 public function getShippingCountry(): ?string {
976 1139 return $this->shippingCountry;
977 1140 }
978 1141
1142 + public function hasCod(): bool {
1143 + return $this->getFinalCod() !== null;
1144 + }
1145 +
979 1146 /**
980 - * Tells if order has COD.
1147 + * Allows Adult Content
981 1148 *
982 1149 * @return bool
983 1150 */
984 - public function hasCod(): bool {
985 - return ( null !== $this->getCod() );
1151 + public function allowsAdultContent(): bool {
1152 + return $this->isPacketaInternalPickupPoint() || $this->getCarrier()->supportsAgeVerification();
986 1153 }
987 1154
988 1155 /**
989 1156 * Returns deliver on date
@@ -1031,8 +1198,11 @@
1031 1198 * @return void
1032 1199 */
1033 1200 public function updateApiErrorMessage( ?string $errorMessage ): void {
1034 1201 $this->setLastApiErrorMessage( $errorMessage );
1035 - $this->setLastApiErrorDateTime( $errorMessage ? Helper::now() : null );
1202 + $this->setLastApiErrorDateTime( $errorMessage !== null ? CoreHelper::now() : null );
1036 1203 }
1037 1204
1205 + public function getCustomNumberOrNumber(): ?string {
1206 + return $this->getCustomNumber() ?? $this->getNumber();
1207 + }
1038 1208 }