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 +318 -157 1.3.12.1 View file →
@@ -9,14 +9,23 @@
9 9
10 10 namespace Packetery\Module\Order;
11 11
12 12 use Packetery\Core;
13 -use Packetery\Core\Helper;
14 -use Packetery\Module\Carrier;
15 -use PacketeryLatte\Engine;
16 -use PacketeryNette\Http\Request;
17 -use Packetery\Module;
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;
22 +use Packetery\Module\Plugin;
23 +use Packetery\Nette\Http\Request;
24 +use WC_Order;
18 25
26 +use function esc_html;
27 +
19 28 /**
20 29 * Class GridExtender.
21 30 *
22 31 * @package Packetery\Order
@@ -22,25 +31,18 @@
22 31 * @package Packetery\Order
23 32 */
24 33 class GridExtender {
25 34
26 - 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';
27 36
28 37 /**
29 - * Generic Helper.
38 + * Generic CoreHelper.
30 39 *
31 - * @var Helper
40 + * @var CoreHelper
32 41 */
33 - private $helper;
42 + private $coreHelper;
34 43
35 44 /**
36 - * Carrier repository.
37 - *
38 - * @var Carrier\Repository
39 - */
40 - private $carrierRepository;
41 -
42 - /**
43 45 * Latte Engine.
44 46 *
45 47 * @var Engine
46 48 */
@@ -53,88 +55,170 @@
53 55 */
54 56 private $httpRequest;
55 57
56 58 /**
57 - * Controller router.
59 + * Order repository.
58 60 *
59 - * @var ControllerRouter
61 + * @var Repository
60 62 */
61 - private $orderControllerRouter;
63 + private $orderRepository;
62 64
63 65 /**
64 - * Order repository.
66 + * Order Validator.
65 67 *
66 - * @var Repository
68 + * @var Core\Validator\Order
67 69 */
68 - private $orderRepository;
70 + private $orderValidator;
69 71
70 72 /**
73 + * Context resolver.
74 + *
75 + * @var ContextResolver
76 + */
77 + private $contextResolver;
78 +
79 + /**
80 + * Carrier options factory.
81 + *
82 + * @var CarrierOptionsFactory
83 + */
84 + private $carrierOptionsFactory;
85 +
86 + /**
87 + * WordPress Adapter.
88 + *
89 + * @var WpAdapter
90 + */
91 + private $wpAdapter;
92 +
93 + /**
94 + * Module helper
95 + *
96 + * @var ModuleHelper
97 + */
98 + private $moduleHelper;
99 +
100 + /**
101 + * @var SizeFactory
102 + */
103 + private $sizeFactory;
104 +
105 + /**
106 + * @var PacketStatusResolver
107 + */
108 + private $packetStatusResolver;
109 +
110 + /**
71 111 * GridExtender constructor.
72 112 *
73 - * @param Helper $helper Helper.
74 - * @param Carrier\Repository $carrierRepository Carrier repository.
75 - * @param Engine $latteEngine Latte Engine.
76 - * @param Request $httpRequest Http Request.
77 - * @param ControllerRouter $orderControllerRouter Order controller router.
78 - * @param Repository $orderRepository Order repository.
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.
79 124 */
80 125 public function __construct(
81 - Helper $helper,
82 - Carrier\Repository $carrierRepository,
126 + CoreHelper $coreHelper,
83 127 Engine $latteEngine,
84 128 Request $httpRequest,
85 - ControllerRouter $orderControllerRouter,
86 - Repository $orderRepository
129 + Repository $orderRepository,
130 + OrderValidatorFactory $orderValidatorFactory,
131 + ContextResolver $contextResolver,
132 + CarrierOptionsFactory $carrierOptionsFactory,
133 + WpAdapter $wpAdapter,
134 + ModuleHelper $moduleHelper,
135 + SizeFactory $sizeFactory,
136 + PacketStatusResolver $packetStatusResolver
87 137 ) {
88 - $this->helper = $helper;
89 - $this->carrierRepository = $carrierRepository;
138 + $this->coreHelper = $coreHelper;
90 139 $this->latteEngine = $latteEngine;
91 140 $this->httpRequest = $httpRequest;
92 - $this->orderControllerRouter = $orderControllerRouter;
93 141 $this->orderRepository = $orderRepository;
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;
94 149 }
95 150
96 151 /**
97 152 * Adds custom filtering links to order grid.
98 153 *
99 - * @param array $var Array of html links.
154 + * @param string[] $htmlLinks Array of html links.
100 155 *
101 - * @return array
156 + * @return string[]
102 157 */
103 - public function addFilterLinks( array $var ): array {
104 - $latteParams = [
105 - 'link' => add_query_arg(
106 - [
107 - 'post_type' => 'shop_order',
108 - 'filter_action' => 'packetery_filter_link',
109 - 'packetery_to_submit' => '1',
110 - 'packetery_to_print' => false,
111 - ],
112 - admin_url( 'edit.php' )
113 - ),
114 - 'title' => __( 'Packeta orders to submit', 'packeta' ),
115 - 'orderCount' => $this->orderRepository->countOrdersToSubmit(),
116 - 'active' => ( $this->httpRequest->getQuery( 'packetery_to_submit' ) === '1' ),
117 - ];
118 - $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 + }
119 169
120 - $latteParams = [
121 - 'link' => add_query_arg(
122 - [
123 - 'post_type' => 'shop_order',
124 - 'filter_action' => 'packetery_filter_link',
125 - 'packetery_to_submit' => false,
126 - 'packetery_to_print' => '1',
127 - ],
128 - admin_url( 'edit.php' )
129 - ),
130 - 'title' => __( 'Packeta orders to print', 'packeta' ),
131 - 'orderCount' => $this->orderRepository->countOrdersToPrint(),
132 - 'active' => ( $this->httpRequest->getQuery( 'packetery_to_print' ) === '1' ),
133 - ];
134 - $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 + }
135 188
136 - 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;
137 221 }
138 222
139 223 /**
140 224 * Adds select to order grid.
@@ -139,19 +223,19 @@
139 223 /**
140 224 * Adds select to order grid.
141 225 */
142 226 public function renderOrderTypeSelect(): void {
143 - if ( ! $this->isOrderGridPage() ) {
227 + if ( $this->contextResolver->isOrderGridPage() === false ) {
144 228 return;
145 229 }
146 230
147 231 $linkFilters = [];
148 232
149 - if ( null !== $this->httpRequest->getQuery( 'packetery_to_submit' ) ) {
233 + if ( $this->httpRequest->getQuery( 'packetery_to_submit' ) !== null ) {
150 234 $linkFilters['packetery_to_submit'] = '1';
151 235 }
152 236
153 - if ( null !== $this->httpRequest->getQuery( 'packetery_to_print' ) ) {
237 + if ( $this->httpRequest->getQuery( 'packetery_to_print' ) !== null ) {
154 238 $linkFilters['packetery_to_print'] = '1';
155 239 }
156 240
157 241 $this->latteEngine->render(
@@ -186,30 +270,67 @@
186 270 * Gets weight cell content.
187 271 *
188 272 * @param Core\Entity\Order $order Order.
189 273 *
190 - * @return array
274 + * @return array{orderNumber: null|string, weight: null|float}
191 275 */
192 276 private function getWeightCellContentParams( Core\Entity\Order $order ): array {
193 277 return [
194 278 'orderNumber' => $order->getNumber(),
195 - 'weight' => $order->getWeight(),
279 + 'weight' => $order->getFinalWeight(),
196 280 ];
197 281 }
198 282
199 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 + /**
200 302 * Fills custom order list columns.
201 303 *
202 - * @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.
203 306 */
204 - public function fillCustomOrderListColumns( string $column ): void {
205 - global $post;
307 + public function fillCustomOrderListColumns( $column, $wcOrder ): void {
308 + if ( is_string( $column ) === false ) {
309 + return;
310 + }
206 311
207 - $order = $this->orderRepository->getById( $post->ID );
208 - if ( null === $order ) {
312 + if ( $wcOrder instanceof WC_Order ) {
313 + $orderId = $wcOrder->get_id();
314 + } elseif ( is_numeric( $wcOrder ) ) {
315 + $orderId = (int) $wcOrder;
316 + } else {
209 317 return;
210 318 }
211 319
320 + try {
321 + $order = $this->getOrderByIdCached( $orderId );
322 + } catch ( InvalidCarrierException $exception ) {
323 + if ( $column === 'packetery' ) {
324 + echo esc_html( $exception->getMessage() );
325 + }
326 +
327 + return;
328 + }
329 + if ( $order === null ) {
330 + return;
331 + }
332 +
212 333 switch ( $column ) {
213 334 case 'packetery_weight':
214 335 $this->latteEngine->render(
215 336 self::TEMPLATE_GRID_COLUMN_WEIGHT,
@@ -214,103 +335,140 @@
214 335 $this->latteEngine->render(
215 336 self::TEMPLATE_GRID_COLUMN_WEIGHT,
216 337 $this->getWeightCellContentParams( $order )
217 338 );
339 +
218 340 break;
219 341 case 'packetery_destination':
220 342 $pickupPoint = $order->getPickupPoint();
221 - if ( null !== $pickupPoint ) {
222 - $pointName = $pickupPoint->getName();
223 - $pointId = $pickupPoint->getId();
224 - $country = $order->getShippingCountry();
225 - $internalCountries = array_keys( $this->carrierRepository->getZpointCarriers() );
226 - if ( in_array( $country, $internalCountries, true ) ) {
343 + if ( $pickupPoint !== null ) {
344 + $pointName = $pickupPoint->getName();
345 + $pointId = $pickupPoint->getId();
346 + if ( ! $order->isExternalCarrier() ) {
227 347 echo esc_html( "$pointName ($pointId)" );
228 348 } else {
229 349 echo esc_html( $pointName );
230 350 }
351 +
231 352 break;
232 353 }
233 - $homeDeliveryCarrier = $this->carrierRepository->getById( (int) $order->getCarrierId() );
234 - if ( $homeDeliveryCarrier ) {
235 - $homeDeliveryCarrierEntity = new Carrier\Entity( $homeDeliveryCarrier );
236 - echo esc_html( $homeDeliveryCarrierEntity->getFinalName() );
237 - }
354 +
355 + $homeDeliveryCarrierOptions = $this->carrierOptionsFactory->createByCarrierId( $order->getCarrier()->getId() );
356 + echo esc_html( $homeDeliveryCarrierOptions->getName() );
357 +
238 358 break;
239 359 case 'packetery_packet_id':
240 - $packetId = $order->getPacketId();
241 - if ( $packetId ) {
242 - 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 );
243 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 +
244 384 break;
245 385 case 'packetery':
246 - $packetSubmitUrl = add_query_arg( [], $this->orderControllerRouter->getRouteUrl( Controller::PATH_SUBMIT_TO_API ) );
247 - $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(
248 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 + [
249 401 'page' => LabelPrint::MENU_SLUG,
250 402 LabelPrint::LABEL_TYPE_PARAM => ( $order->isExternalCarrier() ? LabelPrint::ACTION_CARRIER_LABELS : LabelPrint::ACTION_PACKETA_LABELS ),
251 403 'id' => $order->getNumber(),
252 404 'packet_id' => $order->getPacketId(),
253 405 'offset' => 0,
406 + PacketActionsCommonLogic::PARAM_ORDER_GRID_PARAMS => $encodedOrderGridParams,
254 407 ],
255 408 admin_url( 'admin.php' )
256 409 );
410 + $packetCancelLink = add_query_arg(
411 + [
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,
418 + ],
419 + admin_url( 'admin.php' )
420 + );
421 +
257 422 $this->latteEngine->render(
258 423 PACKETERY_PLUGIN_DIR . '/template/order/grid-column-packetery.latte',
259 424 [
260 - 'order' => $order,
261 - 'hasOrderWeight' => ( null !== $order->getWeight() && $order->getWeight() > 0 ),
262 - 'packetSubmitUrl' => $packetSubmitUrl,
263 - 'restNonce' => wp_create_nonce( 'wp_rest' ),
264 - 'printLink' => $printLink,
265 - 'translations' => [
266 - 'printLabel' => __( 'Print label', 'packeta' ),
267 - 'setPacketWeight' => __( 'Set packet weight', 'packeta' ),
268 - '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' ),
444 + // translators: %s: Order number.
445 + 'reallyCancelPacketHeading' => sprintf( __( 'Order #%s', 'packeta' ), $order->getCustomNumber() ),
446 + // translators: %s: Packet number.
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' ),
269 451 ],
270 452 ]
271 453 );
454 +
272 455 break;
273 - // TODO: Packet status sync.
274 - }
275 - }
456 + case 'packetery_packet_status':
457 + echo esc_html( $this->packetStatusResolver->getTranslatedName( $order->getPacketStatus() ) );
276 458
277 - /**
278 - * Gets code text translated.
279 - *
280 - * @param string|null $packetStatus Packet status.
281 - *
282 - * @return string|null
283 - */
284 - public function getPacketStatusTranslated( ?string $packetStatus ): string {
285 - switch ( $packetStatus ) {
286 - case 'received data':
287 - return __( 'Data received', 'packeta' );
288 - case 'arrived':
289 - return __( 'Submitted', 'packeta' );
290 - case 'prepared for departure':
291 - return __( 'Prepared for departure', 'packeta' );
292 - case 'departed':
293 - return __( 'Departed', 'packeta' );
294 - case 'ready for pickup':
295 - return __( 'Ready for pickup', 'packeta' );
296 - case 'handed to carrier':
297 - return __( 'Handed to carrier', 'packeta' );
298 - case 'delivered':
299 - return __( 'Delivered', 'packeta' );
300 - case 'posted back':
301 - return __( 'Posted back', 'packeta' );
302 - case 'returned':
303 - return __( 'Returned', 'packeta' );
304 - case 'cancelled':
305 - return __( 'Cancelled', 'packeta' );
306 - case 'collected':
307 - return __( 'Collected', 'packeta' );
308 - case 'unknown':
309 - return __( 'Unknown', 'packeta' );
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;
310 470 }
311 -
312 - return (string) $packetStatus;
313 471 }
314 472
315 473 /**
316 474 * Add order list columns.
@@ -319,32 +477,35 @@
319 477 *
320 478 * @return string[] All columns.
321 479 */
322 480 public function addOrderListColumns( array $columns ): array {
323 - $new_columns = array();
481 + $newColumns = array();
324 482
325 - foreach ( $columns as $column_name => $column_info ) {
326 - $new_columns[ $column_name ] = $column_info;
483 + foreach ( $columns as $columnName => $columnInfo ) {
484 + $newColumns[ $columnName ] = $columnInfo;
327 485
328 - if ( 'order_total' === $column_name ) {
329 - $new_columns['packetery_weight'] = __( 'Weight', 'packeta' );
330 - // TODO: Packet status sync.
331 - $new_columns['packetery'] = __( 'Packeta', 'packeta' );
332 - $new_columns['packetery_packet_id'] = __( 'Barcode', 'packeta' );
333 - $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' );
334 493 }
335 494 }
336 495
337 - return $new_columns;
496 + return $newColumns;
338 497 }
339 498
340 499 /**
341 - * Checks if current admin page is order grid using WP globals.
500 + * Add order list sortable columns.
342 501 *
343 - * @return bool
502 + * @param string[] $columns Order list columns.
503 + *
504 + * @return string[] All columns.
344 505 */
345 - public function isOrderGridPage(): bool {
346 - global $pagenow, $typenow;
506 + public function makeOrderListSpecificColumnsSortable( array $columns ): array {
507 + $metaKey = 'packetery_packet_stored_until';
347 508
348 - return ( 'edit.php' === $pagenow && 'shop_order' === $typenow );
509 + return wp_parse_args( [ 'packetery_packet_stored_until' => $metaKey ], $columns );
349 510 }
350 511 }