| @@ -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 | */ |
| @@ -35,9 +42,9 @@ | ||
| 35 | 42 | |
| 36 | 43 | /** |
| 37 | 44 | * Order carrier object. |
| 38 | 45 | * |
| 39 | - * @var Carrier|null | |
| 46 | + * @var Carrier | |
| 40 | 47 | */ |
| 41 | 48 | private $carrier; |
| 42 | 49 | |
| 43 | 50 | /** |
| @@ -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,29 +158,46 @@ | ||
| 145 | 158 | */ |
| 146 | 159 | private $packetId; |
| 147 | 160 | |
| 148 | 161 | /** |
| 149 | - * Packet ID | |
| 162 | + * @var string|null | |
| 163 | + */ | |
| 164 | + private $packetTrackingUrl; | |
| 165 | + | |
| 166 | + /** | |
| 167 | + * Packet ID. | |
| 150 | 168 | * |
| 151 | 169 | * @var string|null |
| 152 | 170 | */ |
| 153 | - private $packetStatus; | |
| 171 | + private $packetClaimId; | |
| 154 | 172 | |
| 155 | 173 | /** |
| 156 | - * Carrier id. | |
| 174 | + * @var string|null | |
| 175 | + */ | |
| 176 | + private $packetClaimTrackingUrl; | |
| 177 | + | |
| 178 | + /** | |
| 179 | + * Packet password. | |
| 157 | 180 | * |
| 158 | - * @var string | |
| 181 | + * @var string|null | |
| 159 | 182 | */ |
| 160 | - private $carrierId; | |
| 183 | + private $packetClaimPassword; | |
| 161 | 184 | |
| 162 | 185 | /** |
| 163 | - * Internal carrier code. Null for orders with changed country. | |
| 186 | + * Z-BOX consign password from packetInfo. | |
| 164 | 187 | * |
| 165 | 188 | * @var string|null |
| 166 | 189 | */ |
| 167 | - private $carrierCode; | |
| 190 | + private $consignPassword; | |
| 168 | 191 | |
| 169 | 192 | /** |
| 193 | + * Packet ID | |
| 194 | + * | |
| 195 | + * @var string|null | |
| 196 | + */ | |
| 197 | + private $packetStatus; | |
| 198 | + | |
| 199 | + /** | |
| 170 | 200 | * Tells if is packet submitted. |
| 171 | 201 | * |
| 172 | 202 | * @var bool |
| 173 | 203 | */ |
| @@ -229,29 +259,97 @@ | ||
| 229 | 259 | */ |
| 230 | 260 | private $deliverOn; |
| 231 | 261 | |
| 232 | 262 | /** |
| 263 | + * Customs declaration. | |
| 264 | + * | |
| 265 | + * @var CustomsDeclaration|null | |
| 266 | + */ | |
| 267 | + private $customsDeclaration; | |
| 268 | + | |
| 269 | + /** | |
| 270 | + * Stored until. | |
| 271 | + * | |
| 272 | + * @var DateTimeImmutable|null | |
| 273 | + */ | |
| 274 | + private $storedUntil; | |
| 275 | + | |
| 276 | + /** | |
| 233 | 277 | * Order entity constructor. |
| 234 | 278 | * |
| 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. | |
| 279 | + * @param string $number Order id. | |
| 280 | + * @param Carrier $carrier Carrier entity. | |
| 239 | 281 | */ |
| 240 | 282 | public function __construct( |
| 241 | 283 | string $number, |
| 242 | - string $carrierId, | |
| 243 | - bool $isExported = false, | |
| 244 | - bool $isLabelPrinted = false | |
| 284 | + Carrier $carrier | |
| 245 | 285 | ) { |
| 246 | 286 | $this->number = $number; |
| 247 | - $this->carrierId = $carrierId; | |
| 248 | - $this->isExported = $isExported; | |
| 249 | - $this->isLabelPrinted = $isLabelPrinted; | |
| 287 | + $this->carrier = $carrier; | |
| 288 | + $this->isExported = false; | |
| 289 | + $this->isLabelPrinted = false; | |
| 250 | 290 | $this->addressValidated = false; |
| 251 | 291 | } |
| 252 | 292 | |
| 253 | 293 | /** |
| 294 | + * Gets Car Delivery id. | |
| 295 | + * | |
| 296 | + * @return string | |
| 297 | + */ | |
| 298 | + public function getCarDeliveryId(): ?string { | |
| 299 | + return $this->carDeliveryId; | |
| 300 | + } | |
| 301 | + | |
| 302 | + /** | |
| 303 | + * Sets Car Delivery id. | |
| 304 | + * | |
| 305 | + * @param string $carDeliveryId Car delivery ID. | |
| 306 | + * @return void | |
| 307 | + */ | |
| 308 | + public function setCarDeliveryId( string $carDeliveryId ): void { | |
| 309 | + $this->carDeliveryId = $carDeliveryId; | |
| 310 | + } | |
| 311 | + | |
| 312 | + /** | |
| 313 | + * Sets custom declaration. | |
| 314 | + * | |
| 315 | + * @param CustomsDeclaration|null $customsDeclaration Customs declaration. | |
| 316 | + * | |
| 317 | + * @return void | |
| 318 | + */ | |
| 319 | + public function setCustomsDeclaration( ?CustomsDeclaration $customsDeclaration ): void { | |
| 320 | + $this->customsDeclaration = $customsDeclaration; | |
| 321 | + } | |
| 322 | + | |
| 323 | + /** | |
| 324 | + * Gets customs declaration. | |
| 325 | + * | |
| 326 | + * @return CustomsDeclaration|null | |
| 327 | + */ | |
| 328 | + public function getCustomsDeclaration(): ?CustomsDeclaration { | |
| 329 | + return $this->customsDeclaration; | |
| 330 | + } | |
| 331 | + | |
| 332 | + /** | |
| 333 | + * Has customs declaration items. | |
| 334 | + * | |
| 335 | + * @return bool | |
| 336 | + */ | |
| 337 | + public function hasCustomsDeclaration(): bool { | |
| 338 | + return $this->customsDeclaration !== null && $this->customsDeclaration->getItems() !== []; | |
| 339 | + } | |
| 340 | + | |
| 341 | + /** | |
| 342 | + * Tells if customs declaration has to be filled to submit packet. | |
| 343 | + * | |
| 344 | + * @return bool | |
| 345 | + */ | |
| 346 | + public function hasToFillCustomsDeclaration(): bool { | |
| 347 | + return $this->carrier->requiresCustomsDeclarations() && | |
| 348 | + $this->hasCustomsDeclaration() === false; | |
| 349 | + } | |
| 350 | + | |
| 351 | + /** | |
| 254 | 352 | * Gets custom number. |
| 255 | 353 | * |
| 256 | 354 | * @return string|null |
| 257 | 355 | */ |
| @@ -295,18 +393,27 @@ | ||
| 295 | 393 | * |
| 296 | 394 | * @return bool |
| 297 | 395 | */ |
| 298 | 396 | public function isHomeDelivery(): bool { |
| 299 | - return ( null === $this->pickupPoint ); | |
| 397 | + return ( ! $this->carrier->hasPickupPoints() && ! $this->isCarDelivery() ); | |
| 300 | 398 | } |
| 301 | 399 | |
| 302 | 400 | /** |
| 401 | + * Checks if is home delivery. In that case pointId is not set. | |
| 402 | + * | |
| 403 | + * @return bool | |
| 404 | + */ | |
| 405 | + public function isCarDelivery(): bool { | |
| 406 | + return $this->carrier->isCarDelivery(); | |
| 407 | + } | |
| 408 | + | |
| 409 | + /** | |
| 303 | 410 | * Tells if order has to be shipped to pickup point, run by Packeta or an external carrier. |
| 304 | 411 | * |
| 305 | 412 | * @return bool |
| 306 | 413 | */ |
| 307 | 414 | public function isPickupPointDelivery(): bool { |
| 308 | - return ( null !== $this->pickupPoint ); | |
| 415 | + return $this->carrier->hasPickupPoints(); | |
| 309 | 416 | } |
| 310 | 417 | |
| 311 | 418 | /** |
| 312 | 419 | * Checks if order uses external carrier. |
| @@ -313,9 +420,9 @@ | ||
| 313 | 420 | * |
| 314 | 421 | * @return bool |
| 315 | 422 | */ |
| 316 | 423 | public function isExternalCarrier(): bool { |
| 317 | - return is_numeric( $this->getCarrierId() ); | |
| 424 | + return is_numeric( $this->getCarrier()->getId() ); | |
| 318 | 425 | } |
| 319 | 426 | |
| 320 | 427 | /** |
| 321 | 428 | * Check if delivery method is internal packetery pickup point |
| @@ -332,12 +439,12 @@ | ||
| 332 | 439 | * @return int|null |
| 333 | 440 | */ |
| 334 | 441 | public function getPickupPointOrCarrierId(): ?int { |
| 335 | 442 | if ( $this->isExternalCarrier() ) { |
| 336 | - return (int) $this->getCarrierId(); | |
| 443 | + return (int) $this->getCarrier()->getId(); | |
| 337 | 444 | } |
| 338 | 445 | |
| 339 | - if ( null === $this->pickupPoint ) { | |
| 446 | + if ( $this->pickupPoint === null ) { | |
| 340 | 447 | return null; |
| 341 | 448 | } |
| 342 | 449 | |
| 343 | 450 | // Typing to int is safe in case of internal pickup points. |
| @@ -343,15 +450,12 @@ | ||
| 343 | 450 | // Typing to int is safe in case of internal pickup points. |
| 344 | 451 | return (int) $this->pickupPoint->getId(); |
| 345 | 452 | } |
| 346 | 453 | |
| 347 | - /** | |
| 348 | - * Sets carrier. | |
| 349 | - * | |
| 350 | - * @param Carrier|null $carrier Carrier. | |
| 351 | - */ | |
| 352 | - public function setCarrier( ?Carrier $carrier ): void { | |
| 353 | - $this->carrier = $carrier; | |
| 454 | + public function hasPickupPointOrCarrierId(): bool { | |
| 455 | + $pickupPointOrCarrierId = $this->getPickupPointOrCarrierId(); | |
| 456 | + | |
| 457 | + return $pickupPointOrCarrierId !== null && $pickupPointOrCarrierId !== 0; | |
| 354 | 458 | } |
| 355 | 459 | |
| 356 | 460 | /** |
| 357 | 461 | * Sets pickup point. |
| @@ -435,26 +539,24 @@ | ||
| 435 | 539 | public function setPhone( string $phone ): void { |
| 436 | 540 | $this->phone = $phone; |
| 437 | 541 | } |
| 438 | 542 | |
| 439 | - /** | |
| 440 | - * Sets value. | |
| 441 | - * | |
| 442 | - * @param float|null $value Value. | |
| 443 | - */ | |
| 444 | - public function setValue( ?float $value ): void { | |
| 445 | - $this->value = $value; | |
| 543 | + public function setManualValue( ?float $value ): void { | |
| 544 | + $this->manualValue = $value; | |
| 446 | 545 | } |
| 447 | 546 | |
| 448 | - /** | |
| 449 | - * Sets COD. | |
| 450 | - * | |
| 451 | - * @param float|null $cod COD. | |
| 452 | - */ | |
| 453 | - public function setCod( ?float $cod ): void { | |
| 454 | - $this->cod = $cod; | |
| 547 | + public function setCalculatedValue( ?float $value ): void { | |
| 548 | + $this->calculatedValue = $value; | |
| 455 | 549 | } |
| 456 | 550 | |
| 551 | + public function setManualCod( ?float $cod ): void { | |
| 552 | + $this->manualCod = $cod; | |
| 553 | + } | |
| 554 | + | |
| 555 | + public function setCalculatedCod( ?float $cod ): void { | |
| 556 | + $this->calculatedCod = $cod; | |
| 557 | + } | |
| 558 | + | |
| 457 | 559 | /** |
| 458 | 560 | * Gets packet currency. |
| 459 | 561 | * |
| 460 | 562 | * @return string |
| @@ -492,26 +594,56 @@ | ||
| 492 | 594 | $this->adultContent = $adultContent; |
| 493 | 595 | } |
| 494 | 596 | |
| 495 | 597 | /** |
| 496 | - * Sets carrier id. | |
| 598 | + * Sets packet id. | |
| 497 | 599 | * |
| 498 | - * @param string|null $carrierId Carrier id. | |
| 600 | + * @param string|null $packetId Packet id. | |
| 499 | 601 | */ |
| 500 | - public function setCarrierId( ?string $carrierId ): void { | |
| 501 | - $this->carrierId = $carrierId; | |
| 602 | + public function setPacketId( ?string $packetId ): void { | |
| 603 | + $this->packetId = $packetId; | |
| 502 | 604 | } |
| 503 | 605 | |
| 606 | + public function setPacketTrackingUrl( ?string $trackingUrl ): void { | |
| 607 | + $this->packetTrackingUrl = $trackingUrl; | |
| 608 | + } | |
| 609 | + | |
| 504 | 610 | /** |
| 505 | - * Sets packet id. | |
| 611 | + * Sets packet claim ID. | |
| 506 | 612 | * |
| 507 | - * @param string|null $packetId Packet id. | |
| 613 | + * @param string|null $packetClaimId Packet claim ID. | |
| 614 | + * | |
| 615 | + * @return void | |
| 508 | 616 | */ |
| 509 | - public function setPacketId( ?string $packetId ): void { | |
| 510 | - $this->packetId = $packetId; | |
| 617 | + public function setPacketClaimId( ?string $packetClaimId ): void { | |
| 618 | + $this->packetClaimId = $packetClaimId; | |
| 511 | 619 | } |
| 512 | 620 | |
| 621 | + public function setPacketClaimTrackingUrl( ?string $trackingUrl ): void { | |
| 622 | + $this->packetClaimTrackingUrl = $trackingUrl; | |
| 623 | + } | |
| 624 | + | |
| 513 | 625 | /** |
| 626 | + * Packet claim password. | |
| 627 | + * | |
| 628 | + * @param string|null $packetClaimPassword Packet claim password. | |
| 629 | + * | |
| 630 | + * @return void | |
| 631 | + */ | |
| 632 | + public function setPacketClaimPassword( ?string $packetClaimPassword ): void { | |
| 633 | + $this->packetClaimPassword = $packetClaimPassword; | |
| 634 | + } | |
| 635 | + | |
| 636 | + /** | |
| 637 | + * @param string|null $consignPassword Consign password. | |
| 638 | + * | |
| 639 | + * @return void | |
| 640 | + */ | |
| 641 | + public function setConsignPassword( ?string $consignPassword ): void { | |
| 642 | + $this->consignPassword = $consignPassword; | |
| 643 | + } | |
| 644 | + | |
| 645 | + /** | |
| 514 | 646 | * Sets packet status. |
| 515 | 647 | * |
| 516 | 648 | * @param string|null $packetStatus Packet status. |
| 517 | 649 | * |
| @@ -521,8 +653,17 @@ | ||
| 521 | 653 | $this->packetStatus = $packetStatus; |
| 522 | 654 | } |
| 523 | 655 | |
| 524 | 656 | /** |
| 657 | + * Sets stored until date. | |
| 658 | + * | |
| 659 | + * @param \DateTimeImmutable|null $storedUntil Stored until. | |
| 660 | + */ | |
| 661 | + public function setStoredUntil( ?DateTimeImmutable $storedUntil ): void { | |
| 662 | + $this->storedUntil = $storedUntil; | |
| 663 | + } | |
| 664 | + | |
| 665 | + /** | |
| 525 | 666 | * Sets is exported flag. |
| 526 | 667 | * |
| 527 | 668 | * @param bool $isExported Packet id. |
| 528 | 669 | */ |
| @@ -559,9 +700,9 @@ | ||
| 559 | 700 | * |
| 560 | 701 | * @return void |
| 561 | 702 | */ |
| 562 | 703 | public function setWeight( ?float $weight ): void { |
| 563 | - $this->weight = Helper::simplifyWeight( $weight ); | |
| 704 | + $this->weight = CoreHelper::simplifyWeight( $weight ); | |
| 564 | 705 | } |
| 565 | 706 | |
| 566 | 707 | /** |
| 567 | 708 | * Sets calculated weight. |
| @@ -570,9 +711,9 @@ | ||
| 570 | 711 | * |
| 571 | 712 | * @return void |
| 572 | 713 | */ |
| 573 | 714 | public function setCalculatedWeight( ?float $weight ): void { |
| 574 | - $this->calculatedWeight = Helper::simplifyWeight( $weight ); | |
| 715 | + $this->calculatedWeight = $weight; | |
| 575 | 716 | } |
| 576 | 717 | |
| 577 | 718 | /** |
| 578 | 719 | * Sets shipping country. |
| @@ -581,9 +722,9 @@ | ||
| 581 | 722 | * |
| 582 | 723 | * @return void |
| 583 | 724 | */ |
| 584 | 725 | public function setShippingCountry( string $shippingCountry ): void { |
| 585 | - if ( '' === $shippingCountry ) { | |
| 726 | + if ( $shippingCountry === '' ) { | |
| 586 | 727 | $this->shippingCountry = null; |
| 587 | 728 | } else { |
| 588 | 729 | $this->shippingCountry = $shippingCountry; |
| 589 | 730 | } |
| @@ -611,11 +752,11 @@ | ||
| 611 | 752 | |
| 612 | 753 | /** |
| 613 | 754 | * Gets carrier object. |
| 614 | 755 | * |
| 615 | - * @return Carrier|null | |
| 756 | + * @return Carrier | |
| 616 | 757 | */ |
| 617 | - public function getCarrier(): ?Carrier { | |
| 758 | + public function getCarrier(): Carrier { | |
| 618 | 759 | return $this->carrier; |
| 619 | 760 | } |
| 620 | 761 | |
| 621 | 762 | /** |
| @@ -663,8 +804,59 @@ | ||
| 663 | 804 | return $this->packetId; |
| 664 | 805 | } |
| 665 | 806 | |
| 666 | 807 | /** |
| 808 | + * Packet barcode e.g Z123456789 | |
| 809 | + * | |
| 810 | + * @return string|null | |
| 811 | + */ | |
| 812 | + public function getPacketBarcode(): ?string { | |
| 813 | + return $this->packetId !== null ? 'Z' . $this->packetId : null; | |
| 814 | + } | |
| 815 | + | |
| 816 | + /** | |
| 817 | + * Packet Claim barcode e.g Z123456789 | |
| 818 | + * | |
| 819 | + * @return string|null | |
| 820 | + */ | |
| 821 | + public function getPacketClaimBarcode(): ?string { | |
| 822 | + return $this->packetClaimId !== null ? 'Z' . $this->packetClaimId : null; | |
| 823 | + } | |
| 824 | + | |
| 825 | + public function getPacketTrackingUrl(): ?string { | |
| 826 | + return $this->packetTrackingUrl; | |
| 827 | + } | |
| 828 | + | |
| 829 | + public function getPacketClaimTrackingUrl(): ?string { | |
| 830 | + return $this->packetClaimTrackingUrl; | |
| 831 | + } | |
| 832 | + | |
| 833 | + /** | |
| 834 | + * Gets packet claim ID. | |
| 835 | + * | |
| 836 | + * @return string|null | |
| 837 | + */ | |
| 838 | + public function getPacketClaimId(): ?string { | |
| 839 | + return $this->packetClaimId; | |
| 840 | + } | |
| 841 | + | |
| 842 | + /** | |
| 843 | + * Gets packet claim password. | |
| 844 | + * | |
| 845 | + * @return string|null | |
| 846 | + */ | |
| 847 | + public function getPacketClaimPassword(): ?string { | |
| 848 | + return $this->packetClaimPassword; | |
| 849 | + } | |
| 850 | + | |
| 851 | + /** | |
| 852 | + * @return string|null | |
| 853 | + */ | |
| 854 | + public function getConsignPassword(): ?string { | |
| 855 | + return $this->consignPassword; | |
| 856 | + } | |
| 857 | + | |
| 858 | + /** | |
| 667 | 859 | * Packet status. |
| 668 | 860 | * |
| 669 | 861 | * @return string|null |
| 670 | 862 | */ |
| @@ -672,22 +864,65 @@ | ||
| 672 | 864 | return $this->packetStatus; |
| 673 | 865 | } |
| 674 | 866 | |
| 675 | 867 | /** |
| 676 | - * Gets carrier id. | |
| 868 | + * Get stored until date. | |
| 677 | 869 | * |
| 678 | - * @return string | |
| 870 | + * @return \DateTimeImmutable|null | |
| 679 | 871 | */ |
| 680 | - public function getCarrierId(): string { | |
| 681 | - return $this->carrierId; | |
| 872 | + public function getStoredUntil(): ?\DateTimeImmutable { | |
| 873 | + return $this->storedUntil; | |
| 682 | 874 | } |
| 683 | 875 | |
| 684 | 876 | /** |
| 877 | + * Tells it's possible to extend the package pickup date. | |
| 878 | + * | |
| 879 | + * @return bool | |
| 880 | + */ | |
| 881 | + public function isPossibleExtendPacketPickUpDate(): bool { | |
| 882 | + return $this->packetStatus === PacketStatus::READY_FOR_PICKUP && | |
| 883 | + $this->storedUntil !== null && | |
| 884 | + $this->isPacketaInternalPickupPoint(); | |
| 885 | + } | |
| 886 | + | |
| 887 | + /** | |
| 888 | + * Tells if packet claim creation is possible. | |
| 889 | + * | |
| 890 | + * @return bool | |
| 891 | + */ | |
| 892 | + public function isPacketClaimCreationPossible(): bool { | |
| 893 | + return $this->packetStatus === PacketStatus::DELIVERED && | |
| 894 | + $this->packetClaimId === null; | |
| 895 | + } | |
| 896 | + | |
| 897 | + /** | |
| 898 | + * Determines whether a packet is a claim, or otherwise. | |
| 899 | + * | |
| 900 | + * @param string $packetId Packet id. | |
| 901 | + * | |
| 902 | + * @return bool | |
| 903 | + */ | |
| 904 | + public function isPacketClaim( string $packetId ): bool { | |
| 905 | + return $this->getPacketClaimId() === $packetId; | |
| 906 | + } | |
| 907 | + | |
| 908 | + /** | |
| 909 | + * Tells if packet claim label print is possible. | |
| 910 | + * | |
| 911 | + * @return bool | |
| 912 | + */ | |
| 913 | + public function isPacketClaimLabelPrintPossible(): bool { | |
| 914 | + return $this->packetClaimId !== null && | |
| 915 | + $this->isExternalCarrier() === false && | |
| 916 | + $this->pickupPoint !== null; | |
| 917 | + } | |
| 918 | + | |
| 919 | + /** | |
| 685 | 920 | * Tells if is packet submitted. |
| 686 | 921 | * |
| 687 | 922 | * @return bool |
| 688 | 923 | */ |
| 689 | - public function isExported(): ?bool { | |
| 924 | + public function isExported(): bool { | |
| 690 | 925 | return $this->isExported; |
| 691 | 926 | } |
| 692 | 927 | |
| 693 | 928 | /** |
| @@ -704,9 +939,9 @@ | ||
| 704 | 939 | * |
| 705 | 940 | * @return bool |
| 706 | 941 | */ |
| 707 | 942 | public function hasManualWeight(): bool { |
| 708 | - return null !== $this->weight; | |
| 943 | + return $this->weight !== null; | |
| 709 | 944 | } |
| 710 | 945 | |
| 711 | 946 | /** |
| 712 | 947 | * Gets final weight. |
| @@ -731,9 +966,9 @@ | ||
| 731 | 966 | * |
| 732 | 967 | * @return float|null |
| 733 | 968 | */ |
| 734 | 969 | public function getLength(): ?float { |
| 735 | - if ( empty( $this->size ) ) { | |
| 970 | + if ( $this->size === null ) { | |
| 736 | 971 | return null; |
| 737 | 972 | } |
| 738 | 973 | |
| 739 | 974 | return $this->size->getLength(); |
| @@ -744,9 +979,9 @@ | ||
| 744 | 979 | * |
| 745 | 980 | * @return float|null |
| 746 | 981 | */ |
| 747 | 982 | public function getWidth(): ?float { |
| 748 | - if ( empty( $this->size ) ) { | |
| 983 | + if ( $this->size === null ) { | |
| 749 | 984 | return null; |
| 750 | 985 | } |
| 751 | 986 | |
| 752 | 987 | return $this->size->getWidth(); |
| @@ -757,9 +992,9 @@ | ||
| 757 | 992 | * |
| 758 | 993 | * @return float|null |
| 759 | 994 | */ |
| 760 | 995 | public function getHeight(): ?float { |
| 761 | - if ( empty( $this->size ) ) { | |
| 996 | + if ( $this->size === null ) { | |
| 762 | 997 | return null; |
| 763 | 998 | } |
| 764 | 999 | |
| 765 | 1000 | return $this->size->getHeight(); |
| @@ -783,8 +1018,17 @@ | ||
| 783 | 1018 | return $this->number; |
| 784 | 1019 | } |
| 785 | 1020 | |
| 786 | 1021 | /** |
| 1022 | + * Has order id. | |
| 1023 | + * | |
| 1024 | + * @return bool | |
| 1025 | + */ | |
| 1026 | + public function hasNumber(): bool { | |
| 1027 | + return $this->number !== null && $this->number !== ''; | |
| 1028 | + } | |
| 1029 | + | |
| 1030 | + /** | |
| 787 | 1031 | * Gets customer name. |
| 788 | 1032 | * |
| 789 | 1033 | * @return string|null |
| 790 | 1034 | */ |
| @@ -792,8 +1036,17 @@ | ||
| 792 | 1036 | return $this->name; |
| 793 | 1037 | } |
| 794 | 1038 | |
| 795 | 1039 | /** |
| 1040 | + * Has customer name. | |
| 1041 | + * | |
| 1042 | + * @return bool | |
| 1043 | + */ | |
| 1044 | + public function hasName(): bool { | |
| 1045 | + return $this->name !== null && $this->name !== ''; | |
| 1046 | + } | |
| 1047 | + | |
| 1048 | + /** | |
| 796 | 1049 | * Gets customer surname. |
| 797 | 1050 | * |
| 798 | 1051 | * @return string|null |
| 799 | 1052 | */ |
| @@ -800,26 +1053,44 @@ | ||
| 800 | 1053 | public function getSurname(): ?string { |
| 801 | 1054 | return $this->surname; |
| 802 | 1055 | } |
| 803 | 1056 | |
| 804 | - /** | |
| 805 | - * Gets order value. | |
| 806 | - * | |
| 807 | - * @return float|null | |
| 808 | - */ | |
| 809 | - public function getValue(): ?float { | |
| 810 | - return $this->value; | |
| 1057 | + public function getManualValue(): ?float { | |
| 1058 | + return $this->manualValue; | |
| 811 | 1059 | } |
| 812 | 1060 | |
| 813 | - /** | |
| 814 | - * Gets order COD value. | |
| 815 | - * | |
| 816 | - * @return float|null | |
| 817 | - */ | |
| 818 | - public function getCod(): ?float { | |
| 819 | - return $this->cod; | |
| 1061 | + public function hasManualValue(): bool { | |
| 1062 | + return $this->manualValue !== null; | |
| 820 | 1063 | } |
| 821 | 1064 | |
| 1065 | + public function getCalculatedValue(): ?float { | |
| 1066 | + return $this->calculatedValue; | |
| 1067 | + } | |
| 1068 | + | |
| 1069 | + public function getFinalValue(): ?float { | |
| 1070 | + return $this->manualValue ?? $this->calculatedValue; | |
| 1071 | + } | |
| 1072 | + | |
| 1073 | + public function hasFinalValue(): bool { | |
| 1074 | + return $this->getFinalValue() !== null; | |
| 1075 | + } | |
| 1076 | + | |
| 1077 | + public function getManualCod(): ?float { | |
| 1078 | + return $this->manualCod; | |
| 1079 | + } | |
| 1080 | + | |
| 1081 | + public function hasManualCod(): bool { | |
| 1082 | + return $this->manualCod !== null; | |
| 1083 | + } | |
| 1084 | + | |
| 1085 | + public function getCalculatedCod(): ?float { | |
| 1086 | + return $this->calculatedCod; | |
| 1087 | + } | |
| 1088 | + | |
| 1089 | + public function getFinalCod(): ?float { | |
| 1090 | + return $this->manualCod ?? $this->calculatedCod; | |
| 1091 | + } | |
| 1092 | + | |
| 822 | 1093 | /** |
| 823 | 1094 | * Gets sender label. |
| 824 | 1095 | * |
| 825 | 1096 | * @return string|null |
| @@ -828,8 +1099,17 @@ | ||
| 828 | 1099 | return $this->eshop; |
| 829 | 1100 | } |
| 830 | 1101 | |
| 831 | 1102 | /** |
| 1103 | + * Has sender label. | |
| 1104 | + * | |
| 1105 | + * @return bool | |
| 1106 | + */ | |
| 1107 | + public function hasEshop(): bool { | |
| 1108 | + return $this->eshop !== null && $this->eshop !== ''; | |
| 1109 | + } | |
| 1110 | + | |
| 1111 | + /** | |
| 832 | 1112 | * Gets customer e-mail. |
| 833 | 1113 | * |
| 834 | 1114 | * @return string|null |
| 835 | 1115 | */ |
| @@ -881,38 +1161,22 @@ | ||
| 881 | 1161 | public function getShippingCountry(): ?string { |
| 882 | 1162 | return $this->shippingCountry; |
| 883 | 1163 | } |
| 884 | 1164 | |
| 885 | - /** | |
| 886 | - * Tells if order has COD. | |
| 887 | - * | |
| 888 | - * @return bool | |
| 889 | - */ | |
| 890 | 1165 | public function hasCod(): bool { |
| 891 | - return ( null !== $this->getCod() ); | |
| 1166 | + return $this->getFinalCod() !== null; | |
| 892 | 1167 | } |
| 893 | 1168 | |
| 894 | 1169 | /** |
| 895 | - * Setter for carrierCode. | |
| 1170 | + * Allows Adult Content | |
| 896 | 1171 | * |
| 897 | - * @param string|null $carrierCode Carrier code. | |
| 898 | - * | |
| 899 | - * @return void | |
| 1172 | + * @return bool | |
| 900 | 1173 | */ |
| 901 | - public function setCarrierCode( ?string $carrierCode ): void { | |
| 902 | - $this->carrierCode = $carrierCode; | |
| 1174 | + public function allowsAdultContent(): bool { | |
| 1175 | + return $this->isPacketaInternalPickupPoint() || $this->getCarrier()->supportsAgeVerification(); | |
| 903 | 1176 | } |
| 904 | 1177 | |
| 905 | 1178 | /** |
| 906 | - * Returns carrierId for external carriers or carrierCode. | |
| 907 | - * | |
| 908 | - * @return string|null | |
| 909 | - */ | |
| 910 | - public function getCarrierCode(): ?string { | |
| 911 | - return $this->carrierCode; | |
| 912 | - } | |
| 913 | - | |
| 914 | - /** | |
| 915 | 1179 | * Returns deliver on date |
| 916 | 1180 | * |
| 917 | 1181 | * @return DateTimeImmutable|null |
| 918 | 1182 | */ |
| @@ -957,8 +1221,11 @@ | ||
| 957 | 1221 | * @return void |
| 958 | 1222 | */ |
| 959 | 1223 | public function updateApiErrorMessage( ?string $errorMessage ): void { |
| 960 | 1224 | $this->setLastApiErrorMessage( $errorMessage ); |
| 961 | - $this->setLastApiErrorDateTime( $errorMessage ? Helper::now() : null ); | |
| 1225 | + $this->setLastApiErrorDateTime( $errorMessage !== null ? CoreHelper::now() : null ); | |
| 962 | 1226 | } |
| 963 | 1227 | |
| 1228 | + public function getCustomNumberOrNumber(): ?string { | |
| 1229 | + return $this->getCustomNumber() ?? $this->getNumber(); | |
| 1230 | + } | |
| 964 | 1231 | } |