PluginProbe
Packeta / 1.4.1
Packeta v1.4.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
packeta / src / Packetery / Module / Options / Page.php

Page.php in Packeta 1.4.1, at src/Packetery/Module/Options/Page.php

651 lines 22.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class Page
4 *
5 * @package Packetery\Options
6 */
7
8 declare( strict_types=1 );
9
10 namespace Packetery\Module\Options;
11
12 use Packetery\Core\Api\Soap\Request\SenderGetReturnRouting;
13 use Packetery\Core\Log;
14 use Packetery\Module\FormFactory;
15 use Packetery\Module\MessageManager;
16 use Packetery\Module\Order\PacketSynchronizer;
17 use PacketeryLatte\Engine;
18 use PacketeryNette\Forms\Form;
19
20 /**
21 * Class Page
22 *
23 * @package Packetery\Options
24 */
25 class Page {
26
27 private const FORM_FIELDS_CONTAINER = 'packetery';
28 private const FORM_FIELD_PACKETA_LABEL_FORMAT = 'packeta_label_format';
29 private const FORM_FIELD_CARRIER_LABEL_FORMAT = 'carrier_label_format';
30
31 public const ACTION_VALIDATE_SENDER = 'validate-sender';
32
33 public const SLUG = 'packeta-options';
34
35 public const TAB_GENERAL = 'general';
36 public const TAB_SUPPORT = 'support';
37 public const TAB_PACKET_STATUS_SYNC = 'packet-status-sync';
38
39 public const PARAM_TAB = 'tab';
40
41 /**
42 * PacketeryLatte_engine.
43 *
44 * @var Engine PacketeryLatte engine.
45 */
46 private $latte_engine;
47
48 /**
49 * Options Provider
50 *
51 * @var Provider
52 */
53 private $optionsProvider;
54
55 /**
56 * Form factory.
57 *
58 * @var FormFactory Form factory.
59 */
60 private $formFactory;
61
62 /**
63 * Packeta client.
64 *
65 * @var \Packetery\Core\Api\Soap\Client
66 */
67 private $packetaClient;
68
69 /**
70 * Logger
71 *
72 * @var Log\ILogger
73 */
74 private $logger;
75
76 /**
77 * Message manager.
78 *
79 * @var MessageManager
80 */
81 private $messageManager;
82
83 /**
84 * HTTP request.
85 *
86 * @var \PacketeryNette\Http\Request
87 */
88 private $httpRequest;
89
90 /**
91 * Packet synchronizer.
92 *
93 * @var PacketSynchronizer
94 */
95 private $packetSynchronizer;
96
97 /**
98 * Plugin constructor.
99 *
100 * @param Engine $latte_engine PacketeryLatte_engine.
101 * @param Provider $optionsProvider Options provider.
102 * @param FormFactory $formFactory Form factory.
103 * @param \Packetery\Core\Api\Soap\Client $packetaClient Packeta Client.
104 * @param Log\ILogger $logger Logger.
105 * @param MessageManager $messageManager Message manager.
106 * @param \PacketeryNette\Http\Request $httpRequest HTTP request.
107 * @param PacketSynchronizer $packetSynchronizer Packet synchronizer.
108 */
109 public function __construct( Engine $latte_engine, Provider $optionsProvider, FormFactory $formFactory, \Packetery\Core\Api\Soap\Client $packetaClient, Log\ILogger $logger, MessageManager $messageManager, \PacketeryNette\Http\Request $httpRequest, PacketSynchronizer $packetSynchronizer ) {
110 $this->latte_engine = $latte_engine;
111 $this->optionsProvider = $optionsProvider;
112 $this->formFactory = $formFactory;
113 $this->packetaClient = $packetaClient;
114 $this->logger = $logger;
115 $this->messageManager = $messageManager;
116 $this->httpRequest = $httpRequest;
117 $this->packetSynchronizer = $packetSynchronizer;
118 }
119
120 /**
121 * Registers WP callbacks.
122 */
123 public function register(): void {
124 add_action( 'admin_init', array( $this, 'admin_init' ) );
125 $icon = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDI1LjEuMCwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPgo8c3ZnIHZlcnNpb249IjEuMSIgaWQ9IlZyc3R2YV8xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB4PSIwcHgiIHk9IjBweCIKCSB2aWV3Qm94PSIwIDAgMzcgNDAiIHN0eWxlPSJmaWxsOiNhN2FhYWQiIHhtbDpzcGFjZT0icHJlc2VydmUiPgo8c3R5bGUgdHlwZT0idGV4dC9jc3MiPgoJLnN0MHtmaWxsLXJ1bGU6ZXZlbm9kZDtjbGlwLXJ1bGU6ZXZlbm9kZDtmaWxsOiAjYTdhYWFkO30KPC9zdHlsZT4KPHBhdGggY2xhc3M9InN0MCIgZD0iTTE5LjQsMTYuMWwtMC45LDAuNGwtMC45LTAuNGwtMTMtNi41bDYuMi0yLjRsMTMuNCw2LjVMMTkuNCwxNi4xeiBNMzIuNSw5LjZsLTQuNywyLjNsLTEzLjUtNmw0LjItMS42CglMMzIuNSw5LjZ6Ii8+CjxwYXRoIGNsYXNzPSJzdDAiIGQ9Ik0xOSwwbDE3LjIsNi42bC0yLjQsMS45bC0xNS4yLTZMMy4yLDguNkwwLjgsNi42TDE4LDBMMTksMEwxOSwweiBNMzQuMSw5LjFsMi44LTEuMWwtMi4xLDE3LjZsLTAuNCwwLjgKCUwxOS40LDQwbC0wLjUtMy4xbDEzLjQtMTJMMzQuMSw5LjF6IE0yLjUsMjYuNWwtMC40LTAuOEwwLDguMWwyLjgsMS4xbDEuOSwxNS43bDEzLjQsMTJMMTcuNiw0MEwyLjUsMjYuNXoiLz4KPHBhdGggY2xhc3M9InN0MCIgZD0iTTI4LjIsMTIuNGw0LjMtMi43bC0xLjcsMTQuMkwxOC42LDM1bDAuNi0xN2w1LjQtMy4zTDI0LjMsMjNsMy4zLTIuM0wyOC4yLDEyLjR6Ii8+CjxwYXRoIGNsYXNzPSJzdDAiIGQ9Ik0xNy43LDE3LjlsMC42LDE3bC0xMi4yLTExTDQuNCw5LjhMMTcuNywxNy45eiIvPgo8L3N2Zz4K';
126 add_menu_page(
127 __( 'Packeta', 'packeta' ),
128 __( 'Packeta', 'packeta' ),
129 'manage_options',
130 self::SLUG,
131 '',
132 $icon
133 );
134 add_submenu_page(
135 self::SLUG,
136 __( 'Settings', 'packeta' ),
137 __( 'Settings', 'packeta' ),
138 'manage_options',
139 self::SLUG,
140 array(
141 $this,
142 'render',
143 ),
144 1
145 );
146 add_action( 'admin_init', [ $this, 'processActions' ] );
147
148 add_filter( 'custom_menu_order', '__return_true' );
149 add_filter( 'menu_order', [ $this, 'customMenuOrder' ] );
150 }
151
152 /**
153 * Returns menu_order with Packeta item in last position.
154 *
155 * @param array $menuOrder WP $menu_order.
156 *
157 * @return array
158 */
159 public function customMenuOrder( array $menuOrder ): array {
160 $currentPosition = array_search( self::SLUG, $menuOrder, true );
161
162 if ( false !== $currentPosition ) {
163 unset( $menuOrder[ $currentPosition ] );
164 $menuOrder[] = self::SLUG;
165 }
166
167 return $menuOrder;
168 }
169
170 /**
171 * Get chosen keys by hashed choice data.
172 *
173 * @param array $choiceData Choice data.
174 * @param array $chosenHashedFormOrderStatuses Picked items.
175 *
176 * @return array
177 */
178 private function getChosenKeys( array $choiceData, array $chosenHashedFormOrderStatuses ): array {
179 $statuses = [];
180 foreach ( $chosenHashedFormOrderStatuses as $hash => $chosen ) {
181 if ( $chosen ) {
182 $statuses[] = $choiceData[ $hash ]['key'];
183 }
184 }
185
186 return $statuses;
187 }
188
189 /**
190 * Gets all packet statuses.
191 *
192 * @return array
193 */
194 public function getPacketStatusesChoiceData(): array {
195 $statuses = PacketSynchronizer::getPacketStatuses();
196
197 $result = [];
198
199 foreach ( $statuses as $status => $defaultValue ) {
200 $result[ md5( $status ) ] = [
201 'key' => $status,
202 'default' => $defaultValue,
203 'label' => $this->packetSynchronizer->getPacketStatusTranslated( $status ),
204 ];
205 }
206
207 return $result;
208 }
209
210 /**
211 * Gets order statuses for form.
212 *
213 * @return array
214 */
215 public static function getOrderStatusesChoiceData(): array {
216 $orderStatuses = wc_get_order_statuses();
217 $orderStatusesTransformed = [];
218
219 foreach ( $orderStatuses as $orderStatusKey => $orderStatusLabel ) {
220 $orderStatusesTransformed[ md5( $orderStatusKey ) ] = [
221 'key' => $orderStatusKey,
222 'label' => $orderStatusLabel,
223 ];
224 }
225
226 return $orderStatusesTransformed;
227 }
228
229 /**
230 * Creates settings form.
231 *
232 * @return Form
233 */
234 private function createPacketStatusSyncForm(): Form {
235 $form = $this->formFactory->create( 'packetery_packet_status_sync_form' );
236 $settings = $this->optionsProvider->data_to_array( Provider::OPTION_NAME_PACKETERY_SYNC );
237
238 $form->addText( 'max_status_syncing_packets', __( 'Number of orders synced during one cron call', 'packeta' ) )
239 ->setRequired( false )
240 ->addRule( Form::INTEGER )
241 ->addRule( Form::MIN, null, 0 )
242 ->setDefaultValue( Provider::MAX_STATUS_SYNCING_PACKETS_DEFAULT );
243
244 $form->addText( 'max_days_of_packet_status_syncing', __( 'Number of days for which the order status is checked', 'packeta' ) )
245 ->setRequired( false )
246 ->addRule( Form::INTEGER )
247 ->addRule( Form::MIN, null, 0 )
248 ->setDefaultValue( Provider::MAX_DAYS_OF_PACKET_STATUS_SYNCING_DEFAULT );
249
250 $orderStatusesTransformed = self::getOrderStatusesChoiceData();
251 $orderStatusesContainer = $form->addContainer( 'status_syncing_order_statuses' );
252
253 foreach ( $orderStatusesTransformed as $orderStatusKeyHash => $orderStatusData ) {
254 $item = $orderStatusesContainer->addCheckbox( $orderStatusKeyHash, $orderStatusData['label'] );
255 if ( isset( $settings['status_syncing_order_statuses'] ) && in_array( $orderStatusData['key'], $settings['status_syncing_order_statuses'], true ) ) {
256 $item->setDefaultValue( true );
257 }
258 }
259 unset( $settings['status_syncing_order_statuses'] );
260
261 $packetStatuses = $this->getPacketStatusesChoiceData();
262 $packetStatusesContainer = $form->addContainer( 'status_syncing_packet_statuses' );
263
264 foreach ( $packetStatuses as $packetStatusHash => $packetStatusData ) {
265 $item = $packetStatusesContainer->addCheckbox( $packetStatusHash, $packetStatusData['label'] );
266 if ( ! isset( $settings['status_syncing_packet_statuses'] ) ) {
267 $item->setDefaultValue( $packetStatusData['default'] );
268 } elseif ( in_array( $packetStatusData['key'], $settings['status_syncing_packet_statuses'], true ) ) {
269 $item->setDefaultValue( true );
270 }
271 }
272 unset( $settings['status_syncing_packet_statuses'] );
273
274 $form->setDefaults( $settings );
275
276 $form->addSubmit( 'save', __( 'Save changes', 'packeta' ) );
277
278 $form->onSuccess[] = [ $this, 'onPacketStatusSyncFormSuccess' ];
279
280 return $form;
281 }
282
283 /**
284 * On packet status sync form success.
285 *
286 * @param Form $form Form.
287 * @param array $values Values.
288 *
289 * @return void
290 */
291 public function onPacketStatusSyncFormSuccess( Form $form, array $values ): void {
292
293 $values['status_syncing_order_statuses'] = $this->getChosenKeys(
294 self::getOrderStatusesChoiceData(),
295 $values['status_syncing_order_statuses']
296 );
297 $values['status_syncing_packet_statuses'] = $this->getChosenKeys(
298 $this->getPacketStatusesChoiceData(),
299 $values['status_syncing_packet_statuses']
300 );
301
302 if ( '' === $values['max_status_syncing_packets'] ) {
303 unset( $values['max_status_syncing_packets'] );
304 }
305
306 if ( '' === $values['max_days_of_packet_status_syncing'] ) {
307 unset( $values['max_days_of_packet_status_syncing'] );
308 }
309
310 update_option( Provider::OPTION_NAME_PACKETERY_SYNC, $values );
311
312 if ( wp_safe_redirect( $this->createLink( self::TAB_PACKET_STATUS_SYNC ) ) ) {
313 exit;
314 }
315 }
316
317 /**
318 * Creates settings form.
319 *
320 * @return Form
321 */
322 public function create_form(): Form {
323 $form = $this->formFactory->create();
324 $form->setAction( 'options.php' );
325
326 $container = $form->addContainer( self::FORM_FIELDS_CONTAINER );
327 $container->addText( 'api_password', __( 'API password', 'packeta' ) )
328 ->setRequired()
329 ->addRule( $form::PATTERN, __( 'API password must be 32 characters long and must contain valid characters!', 'packeta' ), '[a-z\d]{32}' );
330 $container->addText( 'sender', __( 'Sender', 'packeta' ) )
331 ->setRequired();
332
333 $packetaLabelFormats = $this->optionsProvider->getPacketaLabelFormats();
334 $container->addSelect(
335 self::FORM_FIELD_PACKETA_LABEL_FORMAT,
336 __( 'Packeta Label Format', 'packeta' ),
337 $packetaLabelFormats
338 )->checkDefaultValue( false )->setDefaultValue( Provider::DEFAULT_VALUE_PACKETA_LABEL_FORMAT );
339
340 $carrierLabelFormats = $this->optionsProvider->getCarrierLabelFormat();
341 $container->addSelect(
342 self::FORM_FIELD_CARRIER_LABEL_FORMAT,
343 __( 'Carrier Label Format', 'packeta' ),
344 $carrierLabelFormats
345 )->checkDefaultValue( false )->setDefaultValue( Provider::DEFAULT_VALUE_CARRIER_LABEL_FORMAT );
346
347 $gateways = $this->getAvailablePaymentGateways();
348 $enabledGateways = [];
349 foreach ( $gateways as $gateway ) {
350 $enabledGateways[ $gateway->id ] = $gateway->get_method_title();
351 }
352 $container->addSelect(
353 'cod_payment_method',
354 __( 'Payment method that represents cash on delivery', 'packeta' ),
355 $enabledGateways
356 )->setPrompt( '--' )->checkDefaultValue( false );
357
358 $container->addText( 'packaging_weight', __( 'Weight of packaging material', 'packeta' ) . ' (kg)' )
359 ->setRequired( true )
360 ->addRule( Form::FLOAT )
361 ->addRule( Form::MIN, null, 0 )
362 ->setDefaultValue( 0 );
363
364 // TODO: Packet status sync.
365
366 $container->addCheckbox( 'replace_shipping_address_with_pickup_point_address', __( 'Replace shipping address with pickup point address', 'packeta' ) )
367 ->setRequired( false );
368
369 $container->addSelect(
370 'checkout_widget_button_location',
371 __( 'Widget button location in checkout', 'packeta' ),
372 [
373 'after_shipping_rate' => __( 'After shipping rate', 'packeta' ),
374 'after_transport_methods' => __( 'After transport methods', 'packeta' ),
375 ]
376 );
377
378 $container->addCheckbox( 'force_packet_cancel', __( 'Force order cancellation', 'packeta' ) )
379 ->setRequired( false )
380 ->setDefaultValue( Provider::FORCE_PACKET_CANCEL_DEFAULT );
381
382 if ( $this->optionsProvider->has_any( Provider::OPTION_NAME_PACKETERY ) ) {
383 $container->setDefaults( $this->optionsProvider->data_to_array( Provider::OPTION_NAME_PACKETERY ) );
384 }
385
386 return $form;
387 }
388
389 /**
390 * Get available gateways.
391 *
392 * @return \WC_Payment_Gateway[]
393 */
394 public function getAvailablePaymentGateways(): array {
395 $availableGateways = [];
396
397 foreach ( WC()->payment_gateways()->payment_gateways() as $gateway ) {
398 if ( 'yes' === $gateway->enabled ) {
399 $availableGateways[ $gateway->id ] = $gateway;
400 }
401 }
402
403 return array_filter( $availableGateways, [ $this, 'filterValidGatewayClass' ] );
404 }
405
406 /**
407 * Callback for array filter. Returns true if gateway is of correct type.
408 *
409 * @param object $gateway Gateway to check.
410 * @return bool
411 */
412 protected function filterValidGatewayClass( object $gateway ): bool {
413 return ( $gateway instanceof \WC_Payment_Gateway );
414 }
415
416 /**
417 * Admin_init callback.
418 */
419 public function admin_init(): void {
420 register_setting( self::FORM_FIELDS_CONTAINER, self::FORM_FIELDS_CONTAINER, array( $this, 'options_validate' ) );
421 add_settings_section( 'packetery_main', __( 'Main Settings', 'packeta' ), '', self::SLUG );
422 }
423
424 /**
425 * Validates options.
426 *
427 * @param array $options Packetery_options.
428 *
429 * @return array
430 */
431 public function options_validate( array $options ): array {
432 $form = $this->create_form();
433 $form[ self::FORM_FIELDS_CONTAINER ]->setValues( $options );
434 if ( $form->isValid() === false ) {
435 foreach ( $form[ self::FORM_FIELDS_CONTAINER ]->getControls() as $control ) {
436 if ( $control->hasErrors() === false ) {
437 continue;
438 }
439
440 add_settings_error( $control->getCaption(), esc_attr( $control->getName() ), $control->getError() );
441 $options[ $control->getName() ] = '';
442 }
443 }
444
445 $api_password = $form[ self::FORM_FIELDS_CONTAINER ]['api_password'];
446 if ( $api_password->hasErrors() === false ) {
447 $api_pass = $api_password->getValue();
448 $options['api_key'] = substr( $api_pass, 0, 16 );
449 $this->packetaClient->setApiPassword( $api_pass );
450 } else {
451 $options['api_key'] = '';
452 }
453
454 $this->validateSender( $options['sender'] );
455 $options['force_packet_cancel'] = (int) $form[ self::FORM_FIELDS_CONTAINER ]['force_packet_cancel']->getValue();
456
457 return $options;
458 }
459
460 /**
461 * Validates sender.
462 *
463 * @param string $senderLabel Sender lbel.
464 *
465 * @return bool|null
466 */
467 private function validateSender( string $senderLabel ): ?bool {
468 $senderValidationRequest = new SenderGetReturnRouting( $senderLabel );
469 $senderValidationResponse = $this->packetaClient->senderGetReturnRouting( $senderValidationRequest );
470
471 $senderValidationLog = new Log\Record();
472 $senderValidationLog->action = Log\Record::ACTION_SENDER_VALIDATION;
473
474 $senderValidationLog->status = Log\Record::STATUS_SUCCESS;
475 $senderValidationLog->title = __( 'Sender validation was successful', 'packeta' );
476
477 if ( $senderValidationResponse->hasFault() ) {
478 $senderValidationLog->status = Log\Record::STATUS_ERROR;
479 $senderValidationLog->params = [
480 'errorMessage' => $senderValidationResponse->getFaultString(),
481 ];
482 $senderValidationLog->title = __( 'Sender could not be validated', 'packeta' );
483 }
484
485 $this->logger->add( $senderValidationLog );
486
487 $senderExists = $senderValidationResponse->senderExists();
488
489 if ( false === $senderExists ) {
490 $this->messageManager->flash_message( __( 'Specified sender does not exist', 'packeta' ), MessageManager::TYPE_INFO, MessageManager::RENDERER_PACKETERY, 'plugin-options' );
491 }
492
493 if ( null === $senderExists ) {
494 $this->messageManager->flash_message( __( 'Unable to check specified sender', 'packeta' ), MessageManager::TYPE_INFO, MessageManager::RENDERER_PACKETERY, 'plugin-options' );
495 }
496
497 return $senderExists;
498 }
499
500 /**
501 * Process actions.
502 *
503 * @return void
504 */
505 public function processActions(): void {
506 $action = $this->httpRequest->getQuery( 'action' );
507 if ( self::ACTION_VALIDATE_SENDER === $action ) {
508 $result = $this->validateSender( $this->optionsProvider->get_sender() );
509
510 if ( true === $result ) {
511 $this->messageManager->flash_message( __( 'Specified sender has been validated.', 'packeta' ), MessageManager::TYPE_SUCCESS, MessageManager::RENDERER_PACKETERY, 'plugin-options' );
512 }
513
514 $doRedirect = wp_safe_redirect(
515 add_query_arg(
516 [
517 'page' => self::SLUG,
518 ],
519 get_admin_url( null, 'admin.php' )
520 )
521 );
522
523 if ( $doRedirect ) {
524 exit;
525 }
526 }
527
528 $packetStatusSyncForm = $this->createPacketStatusSyncForm();
529 if ( $packetStatusSyncForm['save']->isSubmittedBy() ) {
530 $packetStatusSyncForm->fireEvents();
531 }
532 }
533
534 /**
535 * Renders page.
536 */
537 public function render(): void {
538 $activeTab = ( $this->httpRequest->getQuery( self::PARAM_TAB ) ?? self::TAB_GENERAL );
539
540 $latteParams = [];
541 if ( self::TAB_PACKET_STATUS_SYNC === $activeTab ) {
542 $latteParams = [ 'form' => $this->createPacketStatusSyncForm() ];
543 } elseif ( self::TAB_GENERAL === $activeTab ) {
544 $latteParams = [ 'form' => $this->create_form() ];
545 }
546
547 if ( ! extension_loaded( 'soap' ) ) {
548 $latteParams['error'] = __( 'This plugin requires an active SOAP library for proper operation. Contact your web hosting administrator.', 'packeta' );
549 }
550
551 $latteParams['apiPasswordLink'] = trim( $this->latte_engine->renderToString( PACKETERY_PLUGIN_DIR . '/template/options/help-block-link.latte', [ 'href' => 'https://client.packeta.com/support' ] ) );
552
553 $latteParams['exportLink'] = add_query_arg(
554 [
555 'page' => self::SLUG,
556 'action' => Exporter::ACTION_EXPORT_SETTINGS,
557 ],
558 get_admin_url( null, 'admin.php' )
559 );
560
561 $latteParams['activeTab'] = ( $this->httpRequest->getQuery( self::PARAM_TAB ) ?? self::TAB_GENERAL );
562 $latteParams['generalTabLink'] = $this->createLink();
563 $latteParams['supportTabLink'] = $this->createLink( self::TAB_SUPPORT );
564 $latteParams['packetStatusSyncTabLink'] = $this->createLink( self::TAB_PACKET_STATUS_SYNC );
565
566 $latteParams['canValidateSender'] = (bool) $this->optionsProvider->get_sender();
567 $latteParams['senderValidationLink'] = add_query_arg(
568 [
569 'page' => self::SLUG,
570 'action' => self::ACTION_VALIDATE_SENDER,
571 ],
572 get_admin_url( null, 'admin.php' )
573 );
574
575 $lastExport = null;
576 $lastExportOption = get_option( Exporter::OPTION_LAST_SETTINGS_EXPORT );
577 if ( false !== $lastExportOption ) {
578 $date = \DateTime::createFromFormat( DATE_ATOM, $lastExportOption );
579 if ( false !== $date ) {
580 $date->setTimezone( wp_timezone() );
581 $lastExport = $date->format( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) );
582 }
583 }
584 if ( $lastExport ) {
585 $latteParams['lastExport'] = $lastExport;
586 }
587
588 $latteParams['forcePacketCancelDescription'] = __( 'Cancel the order even if the cancellation in the Packeta system will be unsuccessful', 'packeta' );
589 $latteParams['messages'] = $this->messageManager->renderToString( MessageManager::RENDERER_PACKETERY, 'plugin-options' );
590 $latteParams['translations'] = [
591 'packeta' => __( 'Packeta', 'packeta' ),
592 'options' => __( 'Options', 'packeta' ),
593 'general' => __( 'General', 'packeta' ),
594 // translators: %s represents URL, keep intact.
595 'apiPasswordCanBeFoundAt%sUrl' => __( 'API password can be found at %s', 'packeta' ),
596 'saveChanges' => __( 'Save changes', 'packeta' ),
597 'validateSender' => __( 'Validate sender', 'packeta' ),
598 'support' => __( 'Support', 'packeta' ),
599 'optionsExportInfo1' => __(
600 'By clicking the button, you will export the settings of your plugin into a separate file. The export does not contain any sensitive information about your e-shop. Please send the resulting file to the technical support of Packeta (you can find the e-mail address here:',
601 'packeta'
602 ),
603 'optionsExportInfo2' => __(
604 ') along with the description of your problem. For a better understanding of your problem, we recommend adding screenshots, which show the problem (if possible).',
605 'packeta'
606 ),
607 'exportPluginSettings' => __( 'Export the plugin settings', 'packeta' ),
608 'settingsExportDatetime' => __( 'Date and time of the last export of settings', 'packeta' ),
609 'settingsNotYetExported' => __( 'The settings have not been exported yet.', 'packeta' ),
610 'senderDescription' => sprintf(
611 /* translators: 1: emphasis start 2: emphasis end 3: client section link start 4: client section link end */
612 esc_html__( 'Fill here %1$ssender label%2$s - you will find it in %3$sclient section%4$s - user information - field \'Indication\'.', 'packeta' ),
613 '<strong>',
614 '</strong>',
615 '<a href="https://client.packeta.com/senders" target="_blank">',
616 '</a>'
617 ),
618 'packagingWeightDescription' => __( 'This parameter is used to determine the weight of the packaging material. This value is automatically added to the total weight of each order that contains products with non-zero weight. This value is also taken into account when evaluating the weight rules in the cart.', 'packeta' ),
619 'packetStatusSyncTabLinkLabel' => __( 'Packet status tracking', 'packeta' ),
620 'statusSyncingOrderStatusesLabel' => __( 'Order statuses, for which cron will check the packet status', 'packeta' ),
621 'statusSyncingOrderStatusesDescription' => __( 'Cron will automatically track all orders with these statuses and check if the shipment status has changed.', 'packeta' ),
622 'statusSyncingPacketStatusesLabel' => __( 'Packet statuses that are being checked', 'packeta' ),
623 'statusSyncingPacketStatusesDescription' => __( 'If an order has a shipment with one of these selected statuses, the shipment status will be tracked.', 'packeta' ),
624 'numberOfDaysToCheckDescription' => __( 'Number of days after the creation of an order, during which the order status will be checked.', 'packeta' ),
625 ];
626
627 $this->latte_engine->render( PACKETERY_PLUGIN_DIR . '/template/options/page.latte', $latteParams );
628 }
629
630 /**
631 * Creates tab link.
632 *
633 * @param string|null $tab Tab ID.
634 * @return string
635 */
636 public function createLink( ?string $tab = null ): string {
637 $params = [
638 'page' => self::SLUG,
639 ];
640
641 if ( null !== $tab ) {
642 $params[ self::PARAM_TAB ] = $tab;
643 }
644
645 return add_query_arg(
646 $params,
647 get_admin_url( null, 'admin.php' )
648 );
649 }
650 }
651