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/GridExtender.php +297 -148 1.42.1 View file →
@@ -9,15 +9,23 @@
9 9
10 10 namespace Packetery\Module\Order;
11 11
12 12 use Packetery\Core;
13 -use Packetery\Core\Entity;
14 -use Packetery\Core\Helper;
15 -use Packetery\Module\Carrier;
16 -use PacketeryLatte\Engine;
17 -use PacketeryNette\Http\Request;
13 +use Packetery\Core\CoreHelper;
14 +use Packetery\Latte\Engine;
15 +use Packetery\Module\Carrier\CarrierOptionsFactory;
16 +use Packetery\Module\ContextResolver;
17 +use Packetery\Module\EntityFactory\SizeFactory;
18 +use Packetery\Module\Exception\InvalidCarrierException;
19 +use Packetery\Module\Framework\WpAdapter;
20 +use Packetery\Module\Log\Purger;
21 +use Packetery\Module\ModuleHelper;
18 22 use Packetery\Module\Plugin;
23 +use Packetery\Nette\Http\Request;
24 +use WC_Order;
19 25
26 +use function esc_html;
27 +
20 28 /**
21 29 * Class GridExtender.
22 30 *
23 31 * @package Packetery\Order
@@ -23,146 +31,194 @@
23 31 * @package Packetery\Order
24 32 */
25 33 class GridExtender {
26 34
27 - const TEMPLATE_GRID_COLUMN_WEIGHT = PACKETERY_PLUGIN_DIR . '/template/order/grid-column-weight.latte';
35 + private const TEMPLATE_GRID_COLUMN_WEIGHT = PACKETERY_PLUGIN_DIR . '/template/order/grid-column-weight.latte';
28 36
29 37 /**
30 - * Order entity cache.
38 + * Generic CoreHelper.
31 39 *
32 - * @var Entity\Order|null
40 + * @var CoreHelper
33 41 */
34 - public static $orderCache;
42 + private $coreHelper;
35 43
36 44 /**
37 - * Generic Helper.
45 + * Latte Engine.
38 46 *
39 - * @var Helper
47 + * @var Engine
40 48 */
41 - private $helper;
49 + private $latteEngine;
42 50
43 51 /**
44 - * Carrier repository.
52 + * Http Request.
45 53 *
46 - * @var Carrier\Repository
54 + * @var Request
47 55 */
48 - private $carrierRepository;
56 + private $httpRequest;
49 57
50 58 /**
51 - * Latte Engine.
59 + * Order repository.
52 60 *
53 - * @var Engine
61 + * @var Repository
54 62 */
55 - private $latteEngine;
63 + private $orderRepository;
56 64
57 65 /**
58 - * Http Request.
66 + * Order Validator.
59 67 *
60 - * @var Request
68 + * @var Core\Validator\Order
61 69 */
62 - private $httpRequest;
70 + private $orderValidator;
63 71
64 72 /**
65 - * Controller router.
73 + * Context resolver.
66 74 *
67 - * @var ControllerRouter
75 + * @var ContextResolver
68 76 */
69 - private $orderControllerRouter;
77 + private $contextResolver;
70 78
71 79 /**
72 - * Order repository.
80 + * Carrier options factory.
73 81 *
74 - * @var Repository
82 + * @var CarrierOptionsFactory
75 83 */
76 - private $orderRepository;
84 + private $carrierOptionsFactory;
77 85
78 86 /**
79 - * Modal.
87 + * WordPress Adapter.
80 88 *
81 - * @var Modal
89 + * @var WpAdapter
82 90 */
83 - private $modal;
91 + private $wpAdapter;
84 92
85 93 /**
86 - * Packet synchronizer.
94 + * Module helper
87 95 *
88 - * @var PacketSynchronizer
96 + * @var ModuleHelper
89 97 */
90 - private $packetSynchronizer;
98 + private $moduleHelper;
91 99
92 100 /**
101 + * @var SizeFactory
102 + */
103 + private $sizeFactory;
104 +
105 + /**
106 + * @var PacketStatusResolver
107 + */
108 + private $packetStatusResolver;
109 +
110 + /**
93 111 * GridExtender constructor.
94 112 *
95 - * @param Helper $helper Helper.
96 - * @param Carrier\Repository $carrierRepository Carrier repository.
97 - * @param Engine $latteEngine Latte Engine.
98 - * @param Request $httpRequest Http Request.
99 - * @param ControllerRouter $orderControllerRouter Order controller router.
100 - * @param Repository $orderRepository Order repository.
101 - * @param Modal $modal Modal dialog.
102 - * @param PacketSynchronizer $packetSynchronizer Packet synchronizer.
113 + * @param CoreHelper $coreHelper CoreHelper.
114 + * @param Engine $latteEngine Latte Engine.
115 + * @param Request $httpRequest Http Request.
116 + * @param Repository $orderRepository Order repository.
117 + * @param OrderValidatorFactory $orderValidatorFactory Order validator.
118 + * @param ContextResolver $contextResolver Context resolver.
119 + * @param CarrierOptionsFactory $carrierOptionsFactory Carrier options factory.
120 + * @param WpAdapter $wpAdapter WordPress adapter.
121 + * @param ModuleHelper $moduleHelper Module helper.
122 + * @param SizeFactory $sizeFactory Size factory.
123 + * @param PacketStatusResolver $packetStatusResolver Packet status resolver.
103 124 */
104 125 public function __construct(
105 - Helper $helper,
106 - Carrier\Repository $carrierRepository,
126 + CoreHelper $coreHelper,
107 127 Engine $latteEngine,
108 128 Request $httpRequest,
109 - ControllerRouter $orderControllerRouter,
110 129 Repository $orderRepository,
111 - Modal $modal,
112 - PacketSynchronizer $packetSynchronizer
130 + OrderValidatorFactory $orderValidatorFactory,
131 + ContextResolver $contextResolver,
132 + CarrierOptionsFactory $carrierOptionsFactory,
133 + WpAdapter $wpAdapter,
134 + ModuleHelper $moduleHelper,
135 + SizeFactory $sizeFactory,
136 + PacketStatusResolver $packetStatusResolver
113 137 ) {
114 - $this->helper = $helper;
115 - $this->carrierRepository = $carrierRepository;
138 + $this->coreHelper = $coreHelper;
116 139 $this->latteEngine = $latteEngine;
117 140 $this->httpRequest = $httpRequest;
118 - $this->orderControllerRouter = $orderControllerRouter;
119 141 $this->orderRepository = $orderRepository;
120 - $this->modal = $modal;
121 - $this->packetSynchronizer = $packetSynchronizer;
142 + $this->orderValidator = $orderValidatorFactory->create();
143 + $this->contextResolver = $contextResolver;
144 + $this->carrierOptionsFactory = $carrierOptionsFactory;
145 + $this->wpAdapter = $wpAdapter;
146 + $this->moduleHelper = $moduleHelper;
147 + $this->sizeFactory = $sizeFactory;
148 + $this->packetStatusResolver = $packetStatusResolver;
122 149 }
123 150
124 151 /**
125 152 * Adds custom filtering links to order grid.
126 153 *
127 - * @param array $var Array of html links.
154 + * @param string[] $htmlLinks Array of html links.
128 155 *
129 - * @return array
156 + * @return string[]
130 157 */
131 - public function addFilterLinks( array $var ): array {
132 - $latteParams = [
133 - 'link' => add_query_arg(
134 - [
135 - 'post_type' => 'shop_order',
136 - 'filter_action' => 'packetery_filter_link',
137 - 'packetery_to_submit' => '1',
138 - 'packetery_to_print' => false,
139 - ],
140 - admin_url( 'edit.php' )
141 - ),
142 - 'title' => __( 'Packeta orders to submit', 'packeta' ),
143 - 'orderCount' => $this->orderRepository->countOrdersToSubmit(),
144 - 'active' => ( $this->httpRequest->getQuery( 'packetery_to_submit' ) === '1' ),
145 - ];
146 - $var[] = $this->latteEngine->renderToString( PACKETERY_PLUGIN_DIR . '/template/order/filter-link.latte', $latteParams );
158 + public function addFilterLinks( array $htmlLinks ): array {
159 + $linkConfig = new GridLinksConfig(
160 + $this->wpAdapter->__( 'Packeta orders to submit', 'packeta' ),
161 + $this->wpAdapter->__( 'Packeta orders to print', 'packeta' ),
162 + $this->wpAdapter->__( 'Run Packeta wizard', 'packeta' )
163 + );
164 + $originalLinkConfig = clone $linkConfig;
165 + $linkConfig = $this->wpAdapter->applyFilters( 'packeta_order_grid_links_settings', $linkConfig );
166 + if ( ! $linkConfig instanceof GridLinksConfig ) {
167 + $linkConfig = $originalLinkConfig;
168 + }
147 169
148 - $latteParams = [
149 - 'link' => add_query_arg(
150 - [
151 - 'post_type' => 'shop_order',
152 - 'filter_action' => 'packetery_filter_link',
153 - 'packetery_to_submit' => false,
154 - 'packetery_to_print' => '1',
155 - ],
156 - admin_url( 'edit.php' )
157 - ),
158 - 'title' => __( 'Packeta orders to print', 'packeta' ),
159 - 'orderCount' => $this->orderRepository->countOrdersToPrint(),
160 - 'active' => ( $this->httpRequest->getQuery( 'packetery_to_print' ) === '1' ),
161 - ];
162 - $var[] = $this->latteEngine->renderToString( PACKETERY_PLUGIN_DIR . '/template/order/filter-link.latte', $latteParams );
170 + if ( $linkConfig->isFilterOrdersToSubmitEnabled() === true ) {
171 + $latteParams = [
172 + 'link' => ModuleHelper::getOrderGridUrl(
173 + [
174 + 'filter_action' => 'packetery_filter_link',
175 + 'packetery_to_submit' => '1',
176 + 'packetery_to_print' => false,
177 + ]
178 + ),
179 + 'title' => $linkConfig->getFilterOrdersToSubmitTitle(),
180 + 'orderCount' => $this->orderRepository->countOrdersToSubmit(),
181 + 'active' => ( $this->httpRequest->getQuery( 'packetery_to_submit' ) === '1' ),
182 + ];
183 + $htmlLinks['js-wizard-packetery-filter-orders-to-submit'] = $this->latteEngine->renderToString(
184 + PACKETERY_PLUGIN_DIR . '/template/order/filter-link.latte',
185 + $latteParams
186 + );
187 + }
163 188
164 - return $var;
189 + if ( $linkConfig->isFilterOrdersToPrintEnabled() === true ) {
190 + $latteParams = [
191 + 'link' => ModuleHelper::getOrderGridUrl(
192 + [
193 + 'filter_action' => 'packetery_filter_link',
194 + 'packetery_to_submit' => false,
195 + 'packetery_to_print' => '1',
196 + ]
197 + ),
198 + 'title' => $linkConfig->getFilterOrdersToPrintTitle(),
199 + 'orderCount' => $this->orderRepository->countOrdersToPrint(),
200 + 'active' => ( $this->httpRequest->getQuery( 'packetery_to_print' ) === '1' ),
201 + ];
202 + $htmlLinks['js-wizard-packetery-filter-orders-to-print'] = $this->latteEngine->renderToString(
203 + PACKETERY_PLUGIN_DIR . '/template/order/filter-link.latte',
204 + $latteParams
205 + );
206 + }
207 +
208 + if ( $linkConfig->isOrderGridRunWizardEnabled() === true ) {
209 + $latteParams = [
210 + 'link' => $this->wpAdapter->adminUrl( 'admin.php?page=wc-orders&wizard-enabled=true&wizard-order-grid-enabled=true' ),
211 + 'title' => $this->wpAdapter->__( 'Use this link to start interactive tutorial', 'packeta' ),
212 + 'escapedText' => '▶ ' . htmlspecialchars( $linkConfig->getOrderGridRunWizardTitle() ),
213 + ];
214 + $htmlLinks['js-wizard-packetery-order-grid-run'] = $this->latteEngine->renderToString(
215 + PACKETERY_PLUGIN_DIR . '/template/order/unescaped-link.latte',
216 + $latteParams
217 + );
218 + }
219 +
220 + return $htmlLinks;
165 221 }
166 222
167 223 /**
168 224 * Adds select to order grid.
@@ -167,19 +223,19 @@
167 223 /**
168 224 * Adds select to order grid.
169 225 */
170 226 public function renderOrderTypeSelect(): void {
171 - if ( ! $this->isOrderGridPage() ) {
227 + if ( $this->contextResolver->isOrderGridPage() === false ) {
172 228 return;
173 229 }
174 230
175 231 $linkFilters = [];
176 232
177 - if ( null !== $this->httpRequest->getQuery( 'packetery_to_submit' ) ) {
233 + if ( $this->httpRequest->getQuery( 'packetery_to_submit' ) !== null ) {
178 234 $linkFilters['packetery_to_submit'] = '1';
179 235 }
180 236
181 - if ( null !== $this->httpRequest->getQuery( 'packetery_to_print' ) ) {
237 + if ( $this->httpRequest->getQuery( 'packetery_to_print' ) !== null ) {
182 238 $linkFilters['packetery_to_print'] = '1';
183 239 }
184 240
185 241 $this->latteEngine->render(
@@ -214,9 +270,9 @@
214 270 * Gets weight cell content.
215 271 *
216 272 * @param Core\Entity\Order $order Order.
217 273 *
218 - * @return array
274 + * @return array{orderNumber: null|string, weight: null|float}
219 275 */
220 276 private function getWeightCellContentParams( Core\Entity\Order $order ): array {
221 277 return [
222 278 'orderNumber' => $order->getNumber(),
@@ -224,24 +280,57 @@
224 280 ];
225 281 }
226 282
227 283 /**
284 + * Get Order Entity from cache
285 + *
286 + * @param int $orderId Order ID.
287 + *
288 + * @return Core\Entity\Order|null
289 + * @throws InvalidCarrierException InvalidCarrierException.
290 + */
291 + private function getOrderByIdCached( int $orderId ): ?Core\Entity\Order {
292 + static $ordersCache;
293 +
294 + if ( ! isset( $ordersCache[ $orderId ] ) ) {
295 + $ordersCache[ $orderId ] = $this->orderRepository->getById( $orderId );
296 + }
297 +
298 + return $ordersCache[ $orderId ] ?? null;
299 + }
300 +
301 + /**
228 302 * Fills custom order list columns.
229 303 *
230 - * @param string $column Current order column name.
304 + * @param string|mixed $column Current order column name.
305 + * @param WC_Order|int|mixed $wcOrder WC Order.
231 306 */
232 - public function fillCustomOrderListColumns( string $column ): void {
233 - global $post;
307 + public function fillCustomOrderListColumns( $column, $wcOrder ): void {
308 + if ( is_string( $column ) === false ) {
309 + return;
310 + }
234 311
235 - if ( ! isset( self::$orderCache ) || (int) self::$orderCache->getNumber() !== $post->ID ) {
236 - self::$orderCache = $this->orderRepository->getById( $post->ID );
237 - if ( null === self::$orderCache ) {
238 - return;
312 + if ( $wcOrder instanceof WC_Order ) {
313 + $orderId = $wcOrder->get_id();
314 + } elseif ( is_numeric( $wcOrder ) ) {
315 + $orderId = (int) $wcOrder;
316 + } else {
317 + return;
318 + }
319 +
320 + try {
321 + $order = $this->getOrderByIdCached( $orderId );
322 + } catch ( InvalidCarrierException $exception ) {
323 + if ( $column === 'packetery' ) {
324 + echo esc_html( $exception->getMessage() );
239 325 }
326 +
327 + return;
240 328 }
329 + if ( $order === null ) {
330 + return;
331 + }
241 332
242 - $order = self::$orderCache;
243 -
244 333 switch ( $column ) {
245 334 case 'packetery_weight':
246 335 $this->latteEngine->render(
247 336 self::TEMPLATE_GRID_COLUMN_WEIGHT,
@@ -246,53 +335,87 @@
246 335 $this->latteEngine->render(
247 336 self::TEMPLATE_GRID_COLUMN_WEIGHT,
248 337 $this->getWeightCellContentParams( $order )
249 338 );
339 +
250 340 break;
251 341 case 'packetery_destination':
252 342 $pickupPoint = $order->getPickupPoint();
253 - if ( null !== $pickupPoint ) {
254 - $pointName = $pickupPoint->getName();
255 - $pointId = $pickupPoint->getId();
256 - $country = $order->getShippingCountry();
257 - $internalCountries = array_keys( $this->carrierRepository->getZpointCarriers() );
258 - if ( in_array( $country, $internalCountries, true ) ) {
343 + if ( $pickupPoint !== null ) {
344 + $pointName = $pickupPoint->getName();
345 + $pointId = $pickupPoint->getId();
346 + if ( ! $order->isExternalCarrier() ) {
259 347 echo esc_html( "$pointName ($pointId)" );
260 348 } else {
261 349 echo esc_html( $pointName );
262 350 }
351 +
263 352 break;
264 353 }
265 - $homeDeliveryCarrier = $this->carrierRepository->getById( (int) $order->getCarrierId() );
266 - if ( $homeDeliveryCarrier ) {
267 - $homeDeliveryCarrierEntity = new Carrier\Entity( $homeDeliveryCarrier );
268 - echo esc_html( $homeDeliveryCarrierEntity->getFinalName() );
269 - }
354 +
355 + $homeDeliveryCarrierOptions = $this->carrierOptionsFactory->createByCarrierId( $order->getCarrier()->getId() );
356 + echo esc_html( $homeDeliveryCarrierOptions->getName() );
357 +
270 358 break;
271 359 case 'packetery_packet_id':
272 - $packetId = $order->getPacketId();
273 - if ( $packetId ) {
274 - echo '<a href="' . esc_attr( $this->helper->get_tracking_url( $packetId ) ) . '" target="_blank">Z' . esc_html( $packetId ) . '</a>';
360 + $packetId = $order->getPacketId();
361 + $packetClaimId = $order->getPacketClaimId();
362 + $latteParams = [
363 + 'order' => $order,
364 + 'packetIdTrackingUrl' => null,
365 + 'packetClaimIdTrackingUrl' => null,
366 + 'translations' => [
367 + 'packetClaimTracking' => __( 'Packet claim tracking', 'packeta' ),
368 + ],
369 + ];
370 +
371 + if ( $packetId !== null ) {
372 + $latteParams['packetIdTrackingUrl'] = $this->coreHelper->getTrackingUrl( $packetId );
275 373 }
374 +
375 + if ( $packetClaimId !== null ) {
376 + $latteParams['packetClaimIdTrackingUrl'] = $this->coreHelper->getTrackingUrl( $packetClaimId );
377 + }
378 +
379 + $this->latteEngine->render(
380 + PACKETERY_PLUGIN_DIR . '/template/order/grid-column-tracking.latte',
381 + $latteParams
382 + );
383 +
276 384 break;
277 385 case 'packetery':
278 - $packetSubmitUrl = add_query_arg( [], $this->orderControllerRouter->getRouteUrl( Controller::PATH_SUBMIT_TO_API ) );
279 - $printLink = add_query_arg(
386 + $orderGridParams = $this->httpRequest->getUrl()->getQueryParameters();
387 + unset( $orderGridParams['wizard-enabled'], $orderGridParams['wizard-order-grid-enabled'] );
388 + $encodedOrderGridParams = rawurlencode( http_build_query( $orderGridParams ) );
389 + $packetSubmitUrl = add_query_arg(
280 390 [
391 + PacketActionsCommonLogic::PARAM_ORDER_ID => $order->getNumber(),
392 + Plugin::PARAM_PACKETERY_ACTION => PacketActionsCommonLogic::ACTION_SUBMIT_PACKET,
393 + PacketActionsCommonLogic::PARAM_REDIRECT_TO => PacketActionsCommonLogic::REDIRECT_TO_ORDER_GRID,
394 + Plugin::PARAM_NONCE => wp_create_nonce( PacketActionsCommonLogic::createNonceAction( PacketActionsCommonLogic::ACTION_SUBMIT_PACKET, $order->getNumber() ) ),
395 + PacketActionsCommonLogic::PARAM_ORDER_GRID_PARAMS => $encodedOrderGridParams,
396 + ],
397 + admin_url( 'admin.php' )
398 + );
399 + $printLink = add_query_arg(
400 + [
281 401 'page' => LabelPrint::MENU_SLUG,
282 402 LabelPrint::LABEL_TYPE_PARAM => ( $order->isExternalCarrier() ? LabelPrint::ACTION_CARRIER_LABELS : LabelPrint::ACTION_PACKETA_LABELS ),
283 403 'id' => $order->getNumber(),
284 404 'packet_id' => $order->getPacketId(),
285 405 'offset' => 0,
406 + PacketActionsCommonLogic::PARAM_ORDER_GRID_PARAMS => $encodedOrderGridParams,
286 407 ],
287 408 admin_url( 'admin.php' )
288 409 );
289 - $packetCancelLink = add_query_arg(
410 + $packetCancelLink = add_query_arg(
290 411 [
291 - PacketCanceller::PARAM_ORDER_ID => $order->getNumber(),
292 - Plugin::PARAM_PACKETERY_ACTION => PacketCanceller::ACTION_CANCEL_PACKET,
293 - PacketCanceller::PARAM_REDIRECT_TO => PacketCanceller::REDIRECT_TO_ORDER_GRID,
294 - Plugin::PARAM_NONCE => wp_create_nonce( PacketCanceller::createNonceAction( PacketCanceller::ACTION_CANCEL_PACKET, $order->getNumber() ) ),
412 + PacketActionsCommonLogic::PARAM_ORDER_ID => $order->getNumber(),
413 + PacketActionsCommonLogic::PARAM_PACKET_ID => $order->getPacketId(),
414 + Plugin::PARAM_PACKETERY_ACTION => PacketActionsCommonLogic::ACTION_CANCEL_PACKET,
415 + PacketActionsCommonLogic::PARAM_REDIRECT_TO => PacketActionsCommonLogic::REDIRECT_TO_ORDER_GRID,
416 + Plugin::PARAM_NONCE => wp_create_nonce( PacketActionsCommonLogic::createNonceAction( PacketActionsCommonLogic::ACTION_CANCEL_PACKET, $order->getNumber() ) ),
417 + PacketActionsCommonLogic::PARAM_ORDER_GRID_PARAMS => $encodedOrderGridParams,
295 418 ],
296 419 admin_url( 'admin.php' )
297 420 );
298 421
@@ -298,30 +421,53 @@
298 421
299 422 $this->latteEngine->render(
300 423 PACKETERY_PLUGIN_DIR . '/template/order/grid-column-packetery.latte',
301 424 [
302 - 'order' => $order,
303 - 'showWarningIcon' => $this->modal->showWarningIcon( $order ),
304 - 'packetSubmitUrl' => $packetSubmitUrl,
305 - 'packetCancelLink' => $packetCancelLink,
306 - 'restNonce' => wp_create_nonce( 'wp_rest' ),
307 - 'printLink' => $printLink,
308 - 'translations' => [
309 - 'printLabel' => __( 'Print label', 'packeta' ),
310 - 'setAdditionalPacketInfo' => __( 'Set additional packet information', 'packeta' ),
311 - 'submitToPacketa' => __( 'Submit to packeta', 'packeta' ),
425 + 'order' => $order,
426 + 'dimensions' => $this->sizeFactory->createSizeInSetDimensionUnit( $order ),
427 + 'orderIsSubmittable' => $this->orderValidator->isValid( $order ),
428 + 'isPossibleExtendPacketPickUpDate' => $order->isPossibleExtendPacketPickUpDate(),
429 + 'storedUntil' => $this->coreHelper->getStringFromDateTime( $order->getStoredUntil(), CoreHelper::DATEPICKER_FORMAT ),
430 + 'orderWarningFields' => Form::getInvalidFieldsFromValidationResult( $this->orderValidator->validate( $order ) ),
431 + 'packetSubmitUrl' => $packetSubmitUrl,
432 + 'packetCancelLink' => $packetCancelLink,
433 + 'printLink' => $printLink,
434 + 'helper' => $this->coreHelper,
435 + 'datePickerFormat' => CoreHelper::DATEPICKER_FORMAT,
436 + 'logPurgerDatetimeModifier' => $this->wpAdapter->getOption( Purger::PURGER_OPTION_NAME, Purger::PURGER_MODIFIER_DEFAULT ),
437 + 'packetDeliverOn' => $this->coreHelper->getStringFromDateTime( $order->getDeliverOn(), CoreHelper::DATEPICKER_FORMAT ),
438 + 'translations' => [
439 + 'printLabel' => __( 'Print label', 'packeta' ),
440 + 'setAdditionalPacketInfo' => __( 'Set additional packet information', 'packeta' ),
441 + 'setStoredUntil' => __( 'Set the pickup date extension', 'packeta' ),
442 + 'packetSubmissionNotPossible' => __( 'It is not possible to submit the shipment because all the information required for this shipment is not filled.', 'packeta' ),
443 + 'submitToPacketa' => __( 'Submit to Packeta', 'packeta' ),
312 444 // translators: %s: Order number.
313 - 'reallyCancelPacketHeading' => sprintf( __( 'Order #%s', 'packeta' ), $order->getCustomNumber() ),
445 + 'reallyCancelPacketHeading' => sprintf( __( 'Order #%s', 'packeta' ), $order->getCustomNumber() ),
314 446 // translators: %s: Packet number.
315 - 'reallyCancelPacket' => sprintf( __( 'Do you really wish to cancel parcel number %s?', 'packeta' ), (string) $order->getPacketId() ),
316 - 'cancelPacket' => __( 'Cancel packet', 'packeta' ),
447 + 'reallyCancelPacket' => sprintf( __( 'Do you really wish to cancel parcel number %s?', 'packeta' ), (string) $order->getPacketId() ),
448 +
449 + 'cancelPacket' => __( 'Cancel packet', 'packeta' ),
450 + 'lastErrorFromApi' => __( 'Last error from Packeta API', 'packeta' ),
317 451 ],
318 452 ]
319 453 );
454 +
320 455 break;
321 456 case 'packetery_packet_status':
322 - echo esc_html( $this->packetSynchronizer->getPacketStatusTranslated( $order->getPacketStatus() ) );
457 + echo esc_html( $this->packetStatusResolver->getTranslatedName( $order->getPacketStatus() ) );
458 +
323 459 break;
460 + case 'packetery_packet_stored_until':
461 + $this->latteEngine->render(
462 + PACKETERY_PLUGIN_DIR . '/template/order/grid-column-stored-until.latte',
463 + [
464 + 'orderNumber' => $order->getNumber(),
465 + 'storedUntil' => $this->moduleHelper->getTranslatedStringFromDateTime( $order->getStoredUntil() ) ?? '',
466 + ]
467 + );
468 +
469 + break;
324 470 }
325 471 }
326 472
327 473 /**
@@ -331,32 +477,35 @@
331 477 *
332 478 * @return string[] All columns.
333 479 */
334 480 public function addOrderListColumns( array $columns ): array {
335 - $new_columns = array();
481 + $newColumns = array();
336 482
337 - foreach ( $columns as $column_name => $column_info ) {
338 - $new_columns[ $column_name ] = $column_info;
483 + foreach ( $columns as $columnName => $columnInfo ) {
484 + $newColumns[ $columnName ] = $columnInfo;
339 485
340 - if ( 'order_total' === $column_name ) {
341 - $new_columns['packetery_weight'] = __( 'Weight', 'packeta' );
342 - $new_columns['packetery_packet_status'] = __( 'Packeta packet status', 'packeta' );
343 - $new_columns['packetery'] = __( 'Packeta', 'packeta' );
344 - $new_columns['packetery_packet_id'] = __( 'Barcode', 'packeta' );
345 - $new_columns['packetery_destination'] = __( 'Pick up point or carrier', 'packeta' );
486 + if ( $columnName === 'order_total' ) {
487 + $newColumns['packetery_weight'] = __( 'Weight', 'packeta' );
488 + $newColumns['packetery'] = __( 'Packeta', 'packeta' );
489 + $newColumns['packetery_packet_id'] = __( 'Tracking No.', 'packeta' );
490 + $newColumns['packetery_packet_status'] = __( 'Packeta packet status', 'packeta' );
491 + $newColumns['packetery_packet_stored_until'] = __( 'Stored until', 'packeta' );
492 + $newColumns['packetery_destination'] = __( 'Pickup point or carrier', 'packeta' );
346 493 }
347 494 }
348 495
349 - return $new_columns;
496 + return $newColumns;
350 497 }
351 498
352 499 /**
353 - * Checks if current admin page is order grid using WP globals.
500 + * Add order list sortable columns.
354 501 *
355 - * @return bool
502 + * @param string[] $columns Order list columns.
503 + *
504 + * @return string[] All columns.
356 505 */
357 - public function isOrderGridPage(): bool {
358 - global $pagenow, $typenow;
506 + public function makeOrderListSpecificColumnsSortable( array $columns ): array {
507 + $metaKey = 'packetery_packet_stored_until';
359 508
360 - return ( 'edit.php' === $pagenow && 'shop_order' === $typenow );
509 + return wp_parse_args( [ 'packetery_packet_stored_until' => $metaKey ], $columns );
361 510 }
362 511 }