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/Module/Order/DetailCommonLogic.php +73 -26 1.6.12.1 View file →
@@ -9,11 +9,15 @@
9 9
10 10 namespace Packetery\Module\Order;
11 11
12 12 use Packetery\Core\Entity\Order;
13 +use Packetery\Core\Entity\PickupPoint;
13 14 use Packetery\Module;
14 -use Packetery\Module\Exception\InvalidCarrierException;
15 -use Packetery\Nette;
15 +use Packetery\Module\ContextResolver;
16 +use Packetery\Module\Framework\WcAdapter;
17 +use Packetery\Module\Options\OptionsProvider;
18 +use Packetery\Module\Shipping\ShippingProvider;
19 +use Packetery\Nette\Http;
16 20
17 21 /**
18 22 * Class DetailCommonLogic.
19 23 *
@@ -28,18 +32,14 @@
28 32 */
29 33 private $order;
30 34
31 35 /**
32 - * Context resolver.
33 - *
34 - * @var Module\ContextResolver
36 + * @var ContextResolver
35 37 */
36 38 private $contextResolver;
37 39
38 40 /**
39 - * Request.
40 - *
41 - * @var Nette\Http\Request
41 + * @var Http\Request
42 42 */
43 43 private $request;
44 44
45 45 /**
@@ -49,22 +49,29 @@
49 49 */
50 50 private $orderRepository;
51 51
52 52 /**
53 - * Constructor.
54 - *
55 - * @param Module\ContextResolver $contextResolver Context resolver.
56 - * @param Nette\Http\Request $request Request.
57 - * @param Repository $orderRepository Order repository.
53 + * @var OptionsProvider
58 54 */
55 + private $optionsProvider;
56 +
57 + /**
58 + * @var WcAdapter
59 + */
60 + private $wcAdapter;
61 +
59 62 public function __construct(
60 - Module\ContextResolver $contextResolver,
61 - Nette\Http\Request $request,
62 - Repository $orderRepository
63 + ContextResolver $contextResolver,
64 + Http\Request $request,
65 + Repository $orderRepository,
66 + OptionsProvider $optionsProvider,
67 + WcAdapter $wcAdapter
63 68 ) {
64 69 $this->contextResolver = $contextResolver;
65 70 $this->request = $request;
66 71 $this->orderRepository = $orderRepository;
72 + $this->optionsProvider = $optionsProvider;
73 + $this->wcAdapter = $wcAdapter;
67 74 }
68 75
69 76 /**
70 77 * Gets order.
@@ -71,22 +78,18 @@
71 78 *
72 79 * @return Order|null
73 80 */
74 81 public function getOrder(): ?Order {
75 - if ( null !== $this->order ) {
82 + if ( $this->order !== null ) {
76 83 return $this->order;
77 84 }
78 85
79 86 $orderId = $this->getOrderId();
80 - if ( null === $orderId ) {
87 + if ( $orderId === null ) {
81 88 return null;
82 89 }
83 90
84 - try {
85 - $this->order = $this->orderRepository->getById( $orderId );
86 - } catch ( InvalidCarrierException $invalidCarrierException ) {
87 - return null;
88 - }
91 + $this->order = $this->orderRepository->getByIdWithValidCarrier( $orderId );
89 92
90 93 return $this->order;
91 94 }
92 95
@@ -97,16 +100,60 @@
97 100 */
98 101 public function getOrderId(): ?int {
99 102 global $post;
100 103
101 - if ( false === $this->contextResolver->isOrderDetailPage() ) {
104 + if ( $this->contextResolver->isOrderDetailPage() === false ) {
102 105 return null;
103 106 }
104 107
105 108 $idParam = $this->request->getQuery( 'id' );
106 - if ( null !== $idParam && Module\Helper::isHposEnabled() ) {
109 + if ( $idParam !== null && Module\ModuleHelper::isHposEnabled() ) {
107 110 return (int) $idParam;
108 111 }
109 112
110 - return $post->ID;
113 + return (int) $post->ID;
114 + }
115 +
116 + /**
117 + * Checks if Packeta order detail is displayed.
118 + *
119 + * @return bool
120 + */
121 + public function isPacketeryOrder(): bool {
122 + $orderId = $this->getOrderId();
123 + if ( $orderId === null ) {
124 + return false;
125 + }
126 +
127 + $wcOrder = $this->orderRepository->getWcOrderById( $orderId );
128 + if ( $wcOrder === null ) {
129 + return false;
130 + }
131 +
132 + if ( ! ShippingProvider::wcOrderHasOurMethod( $wcOrder ) ) {
133 + return false;
134 + }
135 +
136 + return true;
137 + }
138 +
139 + /**
140 + * Tells if pickup point info should be displayed.
141 + *
142 + * @return bool
143 + */
144 + public function shouldDisplayPickupPointInfo(): bool {
145 + return (
146 + ! $this->optionsProvider->replaceShippingAddressWithPickupPointAddress() ||
147 + $this->wcAdapter->shipToBillingAddressOnly()
148 + );
149 + }
150 +
151 + /**
152 + * Determines if a Packeta order should be displayed.
153 + */
154 + public function shouldHidePacketaInfo( Order $order ): bool {
155 + $isPickupPointInfoVisible = $this->shouldDisplayPickupPointInfo() && $order->getPickupPoint() instanceof PickupPoint;
156 +
157 + return ( ! $isPickupPointInfoVisible ) && $order->isExported() === false;
111 158 }
112 159 }