PluginProbe
Packeta / 2.0.9
Packeta v2.0.9
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 +49 -114 trunk2.0.9 View file →
@@ -19,9 +19,8 @@
19 19 use Packetery\Module\Framework\WpAdapter;
20 20 use Packetery\Module\Log\Purger;
21 21 use Packetery\Module\ModuleHelper;
22 22 use Packetery\Module\Plugin;
23 -use Packetery\Module\WcLogger;
24 23 use Packetery\Nette\Http\Request;
25 24 use WC_Order;
26 25
27 26 use function esc_html;
@@ -103,18 +102,8 @@
103 102 */
104 103 private $sizeFactory;
105 104
106 105 /**
107 - * @var PacketStatusResolver
108 - */
109 - private $packetStatusResolver;
110 -
111 - /**
112 - * @var Form
113 - */
114 - private $orderForm;
115 -
116 - /**
117 106 * GridExtender constructor.
118 107 *
119 108 * @param CoreHelper $coreHelper CoreHelper.
120 109 * @param Engine $latteEngine Latte Engine.
@@ -125,9 +114,8 @@
125 114 * @param CarrierOptionsFactory $carrierOptionsFactory Carrier options factory.
126 115 * @param WpAdapter $wpAdapter WordPress adapter.
127 116 * @param ModuleHelper $moduleHelper Module helper.
128 117 * @param SizeFactory $sizeFactory Size factory.
129 - * @param PacketStatusResolver $packetStatusResolver Packet status resolver.
130 118 */
131 119 public function __construct(
132 120 CoreHelper $coreHelper,
133 121 Engine $latteEngine,
@@ -137,11 +125,9 @@
137 125 ContextResolver $contextResolver,
138 126 CarrierOptionsFactory $carrierOptionsFactory,
139 127 WpAdapter $wpAdapter,
140 128 ModuleHelper $moduleHelper,
141 - SizeFactory $sizeFactory,
142 - PacketStatusResolver $packetStatusResolver,
143 - Form $orderForm
129 + SizeFactory $sizeFactory
144 130 ) {
145 131 $this->coreHelper = $coreHelper;
146 132 $this->latteEngine = $latteEngine;
147 133 $this->httpRequest = $httpRequest;
@@ -151,86 +137,46 @@
151 137 $this->carrierOptionsFactory = $carrierOptionsFactory;
152 138 $this->wpAdapter = $wpAdapter;
153 139 $this->moduleHelper = $moduleHelper;
154 140 $this->sizeFactory = $sizeFactory;
155 - $this->packetStatusResolver = $packetStatusResolver;
156 - $this->orderForm = $orderForm;
157 141 }
158 142
159 143 /**
160 144 * Adds custom filtering links to order grid.
161 145 *
162 - * @param string[]|mixed $htmlLinks Array of html links.
146 + * @param string[] $htmlLinks Array of html links.
163 147 *
164 - * @return string[]|mixed
148 + * @return string[]
165 149 */
166 - public function addFilterLinks( $htmlLinks ) {
167 - if ( ! is_array( $htmlLinks ) ) {
168 - WcLogger::logArgumentTypeError( __METHOD__, 'htmlLinks', 'array', $htmlLinks );
150 + public function addFilterLinks( array $htmlLinks ): array {
151 + $latteParams = [
152 + 'link' => ModuleHelper::getOrderGridUrl(
153 + [
154 + 'filter_action' => 'packetery_filter_link',
155 + 'packetery_to_submit' => '1',
156 + 'packetery_to_print' => false,
157 + ]
158 + ),
159 + 'title' => __( 'Packeta orders to submit', 'packeta' ),
160 + 'orderCount' => $this->orderRepository->countOrdersToSubmit(),
161 + 'active' => ( $this->httpRequest->getQuery( 'packetery_to_submit' ) === '1' ),
162 + ];
163 + $htmlLinks[] = $this->latteEngine->renderToString( PACKETERY_PLUGIN_DIR . '/template/order/filter-link.latte', $latteParams );
169 164
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 - }
165 + $latteParams = [
166 + 'link' => ModuleHelper::getOrderGridUrl(
167 + [
168 + 'filter_action' => 'packetery_filter_link',
169 + 'packetery_to_submit' => false,
170 + 'packetery_to_print' => '1',
171 + ]
172 + ),
173 + 'title' => __( 'Packeta orders to print', 'packeta' ),
174 + 'orderCount' => $this->orderRepository->countOrdersToPrint(),
175 + 'active' => ( $this->httpRequest->getQuery( 'packetery_to_print' ) === '1' ),
176 + ];
177 + $htmlLinks[] = $this->latteEngine->renderToString( PACKETERY_PLUGIN_DIR . '/template/order/filter-link.latte', $latteParams );
182 178
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 179 return $htmlLinks;
234 180 }
235 181
236 182 /**
@@ -353,14 +299,14 @@
353 299 break;
354 300 case 'packetery_destination':
355 301 $pickupPoint = $order->getPickupPoint();
356 302 if ( $pickupPoint !== null ) {
357 - $pointPlaceOrName = $pickupPoint->getPlace() ?? $pickupPoint->getName();
358 - $pointId = $pickupPoint->getId();
303 + $pointName = $pickupPoint->getName();
304 + $pointId = $pickupPoint->getId();
359 305 if ( ! $order->isExternalCarrier() ) {
360 - echo esc_html( "$pointPlaceOrName ($pointId)" );
306 + echo esc_html( "$pointName ($pointId)" );
361 307 } else {
362 - echo esc_html( $pointPlaceOrName );
308 + echo esc_html( $pointName );
363 309 }
364 310
365 311 break;
366 312 }
@@ -395,11 +341,9 @@
395 341 );
396 342
397 343 break;
398 344 case 'packetery':
399 - $orderGridParams = $this->httpRequest->getUrl()->getQueryParameters();
400 - unset( $orderGridParams['wizard-enabled'], $orderGridParams['wizard-order-grid-enabled'] );
401 - $encodedOrderGridParams = rawurlencode( http_build_query( $orderGridParams ) );
345 + $encodedOrderGridParams = rawurlencode( $this->httpRequest->getUrl()->getQuery() );
402 346 $packetSubmitUrl = add_query_arg(
403 347 [
404 348 PacketActionsCommonLogic::PARAM_ORDER_ID => $order->getNumber(),
405 349 Plugin::PARAM_PACKETERY_ACTION => PacketActionsCommonLogic::ACTION_SUBMIT_PACKET,
@@ -431,11 +375,8 @@
431 375 ],
432 376 admin_url( 'admin.php' )
433 377 );
434 378
435 - $invalidFields = $this->orderForm->getInvalidFieldsFromValidationResult( $this->orderValidator->validate( $order ) );
436 - $invalidFieldsMessage = $this->orderForm->getInvalidFieldsMessageFromValidationResult( $invalidFields, $order );
437 -
438 379 $this->latteEngine->render(
439 380 PACKETERY_PLUGIN_DIR . '/template/order/grid-column-packetery.latte',
440 381 [
441 382 'order' => $order,
@@ -442,10 +383,9 @@
442 383 'dimensions' => $this->sizeFactory->createSizeInSetDimensionUnit( $order ),
443 384 'orderIsSubmittable' => $this->orderValidator->isValid( $order ),
444 385 'isPossibleExtendPacketPickUpDate' => $order->isPossibleExtendPacketPickUpDate(),
445 386 'storedUntil' => $this->coreHelper->getStringFromDateTime( $order->getStoredUntil(), CoreHelper::DATEPICKER_FORMAT ),
446 - 'orderWarningFields' => $invalidFields,
447 - 'invalidFieldsMessage' => $invalidFieldsMessage,
387 + 'orderWarningFields' => Form::getInvalidFieldsFromValidationResult( $this->orderValidator->validate( $order ) ),
448 388 'packetSubmitUrl' => $packetSubmitUrl,
449 389 'packetCancelLink' => $packetCancelLink,
450 390 'printLink' => $printLink,
451 391 'helper' => $this->coreHelper,
@@ -452,19 +392,20 @@
452 392 'datePickerFormat' => CoreHelper::DATEPICKER_FORMAT,
453 393 'logPurgerDatetimeModifier' => $this->wpAdapter->getOption( Purger::PURGER_OPTION_NAME, Purger::PURGER_MODIFIER_DEFAULT ),
454 394 'packetDeliverOn' => $this->coreHelper->getStringFromDateTime( $order->getDeliverOn(), CoreHelper::DATEPICKER_FORMAT ),
455 395 'translations' => [
456 - 'printLabel' => __( 'Print label', 'packeta' ),
457 - 'setAdditionalPacketInfo' => __( 'Set additional packet information', 'packeta' ),
458 - 'setStoredUntil' => __( 'Set the pickup date extension', 'packeta' ),
459 - 'submitToPacketa' => __( 'Submit to Packeta', 'packeta' ),
396 + 'printLabel' => __( 'Print label', 'packeta' ),
397 + 'setAdditionalPacketInfo' => __( 'Set additional packet information', 'packeta' ),
398 + 'setStoredUntil' => __( 'Set the pickup date extension', 'packeta' ),
399 + 'packetSubmissionNotPossible' => __( 'It is not possible to submit the shipment because all the information required for this shipment is not filled.', 'packeta' ),
400 + 'submitToPacketa' => __( 'Submit to Packeta', 'packeta' ),
460 401 // translators: %s: Order number.
461 - 'reallyCancelPacketHeading' => sprintf( __( 'Order #%s', 'packeta' ), $order->getCustomNumber() ),
402 + 'reallyCancelPacketHeading' => sprintf( __( 'Order #%s', 'packeta' ), $order->getCustomNumber() ),
462 403 // translators: %s: Packet number.
463 - 'reallyCancelPacket' => sprintf( __( 'Do you really wish to cancel parcel number %s?', 'packeta' ), (string) $order->getPacketId() ),
404 + 'reallyCancelPacket' => sprintf( __( 'Do you really wish to cancel parcel number %s?', 'packeta' ), (string) $order->getPacketId() ),
464 405
465 - 'cancelPacket' => __( 'Cancel packet', 'packeta' ),
466 - 'lastErrorFromApi' => __( 'Last error from Packeta API', 'packeta' ),
406 + 'cancelPacket' => __( 'Cancel packet', 'packeta' ),
407 + 'lastErrorFromApi' => __( 'Last error from Packeta API', 'packeta' ),
467 408 ],
468 409 ]
469 410 );
470 411
@@ -469,9 +410,9 @@
469 410 );
470 411
471 412 break;
472 413 case 'packetery_packet_status':
473 - echo esc_html( $this->packetStatusResolver->getTranslatedName( $order->getPacketStatus() ) );
414 + echo esc_html( PacketStatusResolver::getTranslatedName( $order->getPacketStatus() ) );
474 415
475 416 break;
476 417 case 'packetery_packet_stored_until':
477 418 $this->latteEngine->render(
@@ -488,19 +429,13 @@
488 429
489 430 /**
490 431 * Add order list columns.
491 432 *
492 - * @param string[]|mixed $columns Order list columns.
433 + * @param string[] $columns Order list columns.
493 434 *
494 - * @return string[]|mixed All columns.
435 + * @return string[] All columns.
495 436 */
496 - public function addOrderListColumns( $columns ) {
497 - if ( ! is_array( $columns ) ) {
498 - WcLogger::logArgumentTypeError( __METHOD__, 'columns', 'array', $columns );
499 -
500 - return $columns;
501 - }
502 -
437 + public function addOrderListColumns( array $columns ): array {
503 438 $newColumns = array();
504 439
505 440 foreach ( $columns as $columnName => $columnInfo ) {
506 441 $newColumns[ $columnName ] = $columnInfo;