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