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

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