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 +287 -134 1.5.32.3.2 View file →
@@ -9,16 +9,24 @@
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 Packetery\Module\Carrier\PacketaPickupPointsConfig;
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;
16 20 use Packetery\Module\Log\Purger;
17 -use PacketeryLatte\Engine;
18 -use PacketeryNette\Http\Request;
21 +use Packetery\Module\ModuleHelper;
19 22 use Packetery\Module\Plugin;
23 +use Packetery\Module\WcLogger;
24 +use Packetery\Nette\Http\Request;
25 +use WC_Order;
20 26
27 +use function esc_html;
28 +
21 29 /**
22 30 * Class GridExtender.
23 31 *
24 32 * @package Packetery\Order
@@ -24,25 +32,18 @@
24 32 * @package Packetery\Order
25 33 */
26 34 class GridExtender {
27 35
28 - 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';
29 37
30 38 /**
31 - * Generic Helper.
39 + * Generic CoreHelper.
32 40 *
33 - * @var Helper
41 + * @var CoreHelper
34 42 */
35 - private $helper;
43 + private $coreHelper;
36 44
37 45 /**
38 - * Carrier repository.
39 - *
40 - * @var Carrier\EntityRepository
41 - */
42 - private $carrierRepository;
43 -
44 - /**
45 46 * Latte Engine.
46 47 *
47 48 * @var Engine
48 49 */
@@ -69,84 +70,168 @@
69 70 */
70 71 private $orderValidator;
71 72
72 73 /**
73 - * Internal pickup points config.
74 + * Context resolver.
74 75 *
75 - * @var PacketaPickupPointsConfig
76 + * @var ContextResolver
76 77 */
77 - private $pickupPointsConfig;
78 + private $contextResolver;
78 79
79 80 /**
81 + * Carrier options factory.
82 + *
83 + * @var CarrierOptionsFactory
84 + */
85 + private $carrierOptionsFactory;
86 +
87 + /**
88 + * WordPress Adapter.
89 + *
90 + * @var WpAdapter
91 + */
92 + private $wpAdapter;
93 +
94 + /**
95 + * Module helper
96 + *
97 + * @var ModuleHelper
98 + */
99 + private $moduleHelper;
100 +
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 + /**
80 117 * GridExtender constructor.
81 118 *
82 - * @param Helper $helper Helper.
83 - * @param Carrier\EntityRepository $carrierRepository Carrier repository.
84 - * @param Engine $latteEngine Latte Engine.
85 - * @param Request $httpRequest Http Request.
86 - * @param Repository $orderRepository Order repository.
87 - * @param Core\Validator\Order $orderValidator Order validator.
88 - * @param PacketaPickupPointsConfig $pickupPointsConfig Internal pickup points config.
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.
89 130 */
90 131 public function __construct(
91 - Helper $helper,
92 - Carrier\EntityRepository $carrierRepository,
132 + CoreHelper $coreHelper,
93 133 Engine $latteEngine,
94 134 Request $httpRequest,
95 135 Repository $orderRepository,
96 - Core\Validator\Order $orderValidator,
97 - PacketaPickupPointsConfig $pickupPointsConfig
136 + OrderValidatorFactory $orderValidatorFactory,
137 + ContextResolver $contextResolver,
138 + CarrierOptionsFactory $carrierOptionsFactory,
139 + WpAdapter $wpAdapter,
140 + ModuleHelper $moduleHelper,
141 + SizeFactory $sizeFactory,
142 + PacketStatusResolver $packetStatusResolver,
143 + Form $orderForm
98 144 ) {
99 - $this->helper = $helper;
100 - $this->carrierRepository = $carrierRepository;
101 - $this->latteEngine = $latteEngine;
102 - $this->httpRequest = $httpRequest;
103 - $this->orderRepository = $orderRepository;
104 - $this->orderValidator = $orderValidator;
105 - $this->pickupPointsConfig = $pickupPointsConfig;
145 + $this->coreHelper = $coreHelper;
146 + $this->latteEngine = $latteEngine;
147 + $this->httpRequest = $httpRequest;
148 + $this->orderRepository = $orderRepository;
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;
106 157 }
107 158
108 159 /**
109 160 * Adds custom filtering links to order grid.
110 161 *
111 - * @param array $var Array of html links.
162 + * @param string[]|mixed $htmlLinks Array of html links.
112 163 *
113 - * @return array
164 + * @return string[]|mixed
114 165 */
115 - public function addFilterLinks( array $var ): array {
116 - $latteParams = [
117 - 'link' => add_query_arg(
118 - [
119 - 'post_type' => 'shop_order',
120 - 'filter_action' => 'packetery_filter_link',
121 - 'packetery_to_submit' => '1',
122 - 'packetery_to_print' => false,
123 - ],
124 - admin_url( 'edit.php' )
125 - ),
126 - 'title' => __( 'Packeta orders to submit', 'packeta' ),
127 - 'orderCount' => $this->orderRepository->countOrdersToSubmit(),
128 - 'active' => ( $this->httpRequest->getQuery( 'packetery_to_submit' ) === '1' ),
129 - ];
130 - $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 );
131 169
132 - $latteParams = [
133 - 'link' => add_query_arg(
134 - [
135 - 'post_type' => 'shop_order',
136 - 'filter_action' => 'packetery_filter_link',
137 - 'packetery_to_submit' => false,
138 - 'packetery_to_print' => '1',
139 - ],
140 - admin_url( 'edit.php' )
141 - ),
142 - 'title' => __( 'Packeta orders to print', 'packeta' ),
143 - 'orderCount' => $this->orderRepository->countOrdersToPrint(),
144 - 'active' => ( $this->httpRequest->getQuery( 'packetery_to_print' ) === '1' ),
145 - ];
146 - $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 + }
147 182
148 - 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;
149 234 }
150 235
151 236 /**
152 237 * Adds select to order grid.
@@ -151,19 +236,19 @@
151 236 /**
152 237 * Adds select to order grid.
153 238 */
154 239 public function renderOrderTypeSelect(): void {
155 - if ( ! $this->isOrderGridPage() ) {
240 + if ( $this->contextResolver->isOrderGridPage() === false ) {
156 241 return;
157 242 }
158 243
159 244 $linkFilters = [];
160 245
161 - if ( null !== $this->httpRequest->getQuery( 'packetery_to_submit' ) ) {
246 + if ( $this->httpRequest->getQuery( 'packetery_to_submit' ) !== null ) {
162 247 $linkFilters['packetery_to_submit'] = '1';
163 248 }
164 249
165 - if ( null !== $this->httpRequest->getQuery( 'packetery_to_print' ) ) {
250 + if ( $this->httpRequest->getQuery( 'packetery_to_print' ) !== null ) {
166 251 $linkFilters['packetery_to_print'] = '1';
167 252 }
168 253
169 254 $this->latteEngine->render(
@@ -198,9 +283,9 @@
198 283 * Gets weight cell content.
199 284 *
200 285 * @param Core\Entity\Order $order Order.
201 286 *
202 - * @return array
287 + * @return array{orderNumber: null|string, weight: null|float}
203 288 */
204 289 private function getWeightCellContentParams( Core\Entity\Order $order ): array {
205 290 return [
206 291 'orderNumber' => $order->getNumber(),
@@ -210,40 +295,54 @@
210 295
211 296 /**
212 297 * Get Order Entity from cache
213 298 *
214 - * @param int $postId Post ID.
299 + * @param int $orderId Order ID.
215 300 *
216 301 * @return Core\Entity\Order|null
302 + * @throws InvalidCarrierException InvalidCarrierException.
217 303 */
218 - private function getOrderByPostId( int $postId ): ?Core\Entity\Order {
219 - global $posts;
304 + private function getOrderByIdCached( int $orderId ): ?Core\Entity\Order {
220 305 static $ordersCache;
221 306
222 - if ( ! isset( $ordersCache ) ) {
223 - $orderIds = [];
224 - foreach ( $posts as $order ) {
225 - $orderIds[] = $order->ID;
226 - }
227 - $ordersCache = $this->orderRepository->getByIds( $orderIds );
307 + if ( ! isset( $ordersCache[ $orderId ] ) ) {
308 + $ordersCache[ $orderId ] = $this->orderRepository->getById( $orderId );
228 309 }
229 310
230 - return $ordersCache[ $postId ] ?? null;
311 + return $ordersCache[ $orderId ] ?? null;
231 312 }
232 313
233 314 /**
234 315 * Fills custom order list columns.
235 316 *
236 - * @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.
237 319 */
238 - public function fillCustomOrderListColumns( string $column ): void {
239 - global $post;
320 + public function fillCustomOrderListColumns( $column, $wcOrder ): void {
321 + if ( is_string( $column ) === false ) {
322 + return;
323 + }
240 324
241 - $order = $this->getOrderByPostId( $post->ID );
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 + }
242 332
243 - if ( null === $order ) {
333 + try {
334 + $order = $this->getOrderByIdCached( $orderId );
335 + } catch ( InvalidCarrierException $exception ) {
336 + if ( $column === 'packetery' ) {
337 + echo esc_html( $exception->getMessage() );
338 + }
339 +
244 340 return;
245 341 }
342 + if ( $order === null ) {
343 + return;
344 + }
246 345
247 346 switch ( $column ) {
248 347 case 'packetery_weight':
249 348 $this->latteEngine->render(
@@ -249,35 +348,58 @@
249 348 $this->latteEngine->render(
250 349 self::TEMPLATE_GRID_COLUMN_WEIGHT,
251 350 $this->getWeightCellContentParams( $order )
252 351 );
352 +
253 353 break;
254 354 case 'packetery_destination':
255 355 $pickupPoint = $order->getPickupPoint();
256 - if ( null !== $pickupPoint ) {
257 - $pointName = $pickupPoint->getName();
258 - $pointId = $pickupPoint->getId();
259 - $country = $order->getShippingCountry();
260 - $internalCountries = $this->pickupPointsConfig->getInternalCountries();
261 - if ( in_array( $country, $internalCountries, true ) ) {
262 - 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)" );
263 361 } else {
264 - echo esc_html( $pointName );
362 + echo esc_html( $pointPlaceOrName );
265 363 }
364 +
266 365 break;
267 366 }
268 367
269 - $homeDeliveryCarrierOptions = Carrier\Options::createByCarrierId( $order->getCarrierId() );
368 + $homeDeliveryCarrierOptions = $this->carrierOptionsFactory->createByCarrierId( $order->getCarrier()->getId() );
270 369 echo esc_html( $homeDeliveryCarrierOptions->getName() );
370 +
271 371 break;
272 372 case 'packetery_packet_id':
273 - $packetId = $order->getPacketId();
274 - if ( $packetId ) {
275 - 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 );
276 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 +
277 397 break;
278 398 case 'packetery':
279 - $encodedOrderGridParams = rawurlencode( $this->httpRequest->getUrl()->getQuery() );
399 + $orderGridParams = $this->httpRequest->getUrl()->getQueryParameters();
400 + unset( $orderGridParams['wizard-enabled'], $orderGridParams['wizard-order-grid-enabled'] );
401 + $encodedOrderGridParams = rawurlencode( http_build_query( $orderGridParams ) );
280 402 $packetSubmitUrl = add_query_arg(
281 403 [
282 404 PacketActionsCommonLogic::PARAM_ORDER_ID => $order->getNumber(),
283 405 Plugin::PARAM_PACKETERY_ACTION => PacketActionsCommonLogic::ACTION_SUBMIT_PACKET,
@@ -300,8 +422,9 @@
300 422 );
301 423 $packetCancelLink = add_query_arg(
302 424 [
303 425 PacketActionsCommonLogic::PARAM_ORDER_ID => $order->getNumber(),
426 + PacketActionsCommonLogic::PARAM_PACKET_ID => $order->getPacketId(),
304 427 Plugin::PARAM_PACKETERY_ACTION => PacketActionsCommonLogic::ACTION_CANCEL_PACKET,
305 428 PacketActionsCommonLogic::PARAM_REDIRECT_TO => PacketActionsCommonLogic::REDIRECT_TO_ORDER_GRID,
306 429 Plugin::PARAM_NONCE => wp_create_nonce( PacketActionsCommonLogic::createNonceAction( PacketActionsCommonLogic::ACTION_CANCEL_PACKET, $order->getNumber() ) ),
307 430 PacketActionsCommonLogic::PARAM_ORDER_GRID_PARAMS => $encodedOrderGridParams,
@@ -308,38 +431,59 @@
308 431 ],
309 432 admin_url( 'admin.php' )
310 433 );
311 434
435 + $invalidFields = $this->orderForm->getInvalidFieldsFromValidationResult( $this->orderValidator->validate( $order ) );
436 + $invalidFieldsMessage = $this->orderForm->getInvalidFieldsMessageFromValidationResult( $invalidFields, $order );
437 +
312 438 $this->latteEngine->render(
313 439 PACKETERY_PLUGIN_DIR . '/template/order/grid-column-packetery.latte',
314 440 [
315 - 'order' => $order,
316 - 'orderIsSubmittable' => $this->orderValidator->validate( $order ),
317 - 'packetSubmitUrl' => $packetSubmitUrl,
318 - 'packetCancelLink' => $packetCancelLink,
319 - 'printLink' => $printLink,
320 - 'helper' => new Helper(),
321 - 'datePickerFormat' => Helper::DATEPICKER_FORMAT,
322 - 'logPurgerDatetimeModifier' => get_option( Purger::PURGER_OPTION_NAME, Purger::PURGER_MODIFIER_DEFAULT ),
323 - 'packetDeliverOn' => $this->helper->getStringFromDateTime( $order->getDeliverOn(), Helper::DATEPICKER_FORMAT ),
324 - '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' => [
325 456 'printLabel' => __( 'Print label', 'packeta' ),
326 457 'setAdditionalPacketInfo' => __( 'Set additional packet information', 'packeta' ),
327 - 'submitToPacketa' => __( 'Submit to packeta', 'packeta' ),
458 + 'setStoredUntil' => __( 'Set the pickup date extension', 'packeta' ),
459 + 'submitToPacketa' => __( 'Submit to Packeta', 'packeta' ),
328 460 // translators: %s: Order number.
329 461 'reallyCancelPacketHeading' => sprintf( __( 'Order #%s', 'packeta' ), $order->getCustomNumber() ),
330 462 // translators: %s: Packet number.
331 463 'reallyCancelPacket' => sprintf( __( 'Do you really wish to cancel parcel number %s?', 'packeta' ), (string) $order->getPacketId() ),
464 +
332 465 'cancelPacket' => __( 'Cancel packet', 'packeta' ),
333 466 'lastErrorFromApi' => __( 'Last error from Packeta API', 'packeta' ),
334 467 ],
335 468 ]
336 469 );
470 +
337 471 break;
338 472 case 'packetery_packet_status':
339 - $statuses = PacketSynchronizer::getPacketStatuses();
340 - echo esc_html( isset( $statuses[ $order->getPacketStatus() ] ) ? $statuses[ $order->getPacketStatus() ]->getTranslatedName() : $order->getPacketStatus() );
473 + echo esc_html( $this->packetStatusResolver->getTranslatedName( $order->getPacketStatus() ) );
474 +
341 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;
342 486 }
343 487 }
344 488
345 489 /**
@@ -344,37 +488,46 @@
344 488
345 489 /**
346 490 * Add order list columns.
347 491 *
348 - * @param string[] $columns Order list columns.
492 + * @param string[]|mixed $columns Order list columns.
349 493 *
350 - * @return string[] All columns.
494 + * @return string[]|mixed All columns.
351 495 */
352 - public function addOrderListColumns( array $columns ): array {
353 - $new_columns = array();
496 + public function addOrderListColumns( $columns ) {
497 + if ( ! is_array( $columns ) ) {
498 + WcLogger::logArgumentTypeError( __METHOD__, 'columns', 'array', $columns );
354 499
355 - foreach ( $columns as $column_name => $column_info ) {
356 - $new_columns[ $column_name ] = $column_info;
500 + return $columns;
501 + }
357 502
358 - if ( 'order_total' === $column_name ) {
359 - $new_columns['packetery_weight'] = __( 'Weight', 'packeta' );
360 - $new_columns['packetery'] = __( 'Packeta', 'packeta' );
361 - $new_columns['packetery_packet_id'] = __( 'Barcode', 'packeta' );
362 - $new_columns['packetery_packet_status'] = __( 'Packeta packet status', 'packeta' );
363 - $new_columns['packetery_destination'] = __( 'Pickup 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' );
364 515 }
365 516 }
366 517
367 - return $new_columns;
518 + return $newColumns;
368 519 }
369 520
370 521 /**
371 - * Checks if current admin page is order grid using WP globals.
522 + * Add order list sortable columns.
372 523 *
373 - * @return bool
524 + * @param string[] $columns Order list columns.
525 + *
526 + * @return string[] All columns.
374 527 */
375 - public function isOrderGridPage(): bool {
376 - global $pagenow, $typenow;
528 + public function makeOrderListSpecificColumnsSortable( array $columns ): array {
529 + $metaKey = 'packetery_packet_stored_until';
377 530
378 - return ( 'edit.php' === $pagenow && 'shop_order' === $typenow );
531 + return wp_parse_args( [ 'packetery_packet_stored_until' => $metaKey ], $columns );
379 532 }
380 533 }