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
packeta / src / Packetery / Module / Views / WizardAssetManager.php

WizardAssetManager.php in Packeta 2.3.2, at src/Packetery/Module/Views/WizardAssetManager.php

594 lines 31.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Packetery\Module\Views;
4
5 use Packetery\Module\ContextResolver;
6 use Packetery\Module\Framework\WcAdapter;
7 use Packetery\Module\Framework\WpAdapter;
8 use Packetery\Module\Options\OptionNames;
9 use Packetery\Module\Options\Page;
10 use Packetery\Module\Order\DetailCommonLogic;
11 use Packetery\Module\Shipping\ShippingProvider;
12 use Packetery\Nette\Http\Request;
13 use WC_Abstract_Order;
14
15 class WizardAssetManager {
16
17 /** @var WpAdapter */
18 private $wpAdapter;
19
20 /** @var AssetManager */
21 private $assetManager;
22
23 /** @var Request */
24 private $request;
25
26 /** @var ContextResolver */
27 private $contextResolver;
28
29 /** @var DetailCommonLogic */
30 private $detailCommonLogic;
31
32 /** @var WcAdapter */
33 private $wcAdapter;
34
35 public function __construct(
36 AssetManager $assetManager,
37 Request $request,
38 WpAdapter $wpAdapter,
39 ContextResolver $contextResolver,
40 DetailCommonLogic $detailCommonLogic,
41 WcAdapter $wcAdapter
42 ) {
43 $this->assetManager = $assetManager;
44 $this->request = $request;
45 $this->wpAdapter = $wpAdapter;
46 $this->contextResolver = $contextResolver;
47 $this->detailCommonLogic = $detailCommonLogic;
48 $this->wcAdapter = $wcAdapter;
49 }
50
51 public function enqueueWizardAssets(): void {
52 $page = $this->request->getQuery( 'page' );
53 $isWizardEnabled = $this->request->getQuery( 'wizard-enabled' ) === 'true';
54 $isItFirstRunOrderDetailEditPacket = (bool) $this->wpAdapter->getOption( OptionNames::PACKETERY_TUTORIAL_ORDER_DETAIL_EDIT_PACKET );
55 $isItFirstRunOrderOrderGridEditPacket = (bool) $this->wpAdapter->getOption( OptionNames::PACKETERY_TUTORIAL_ORDER_GRID_EDIT_PACKET );
56
57 if ( $isWizardEnabled || $isItFirstRunOrderDetailEditPacket || $isItFirstRunOrderOrderGridEditPacket ) {
58 $this->enqueueBaseAssets();
59 if ( $page === Page::SLUG ) {
60 $this->enqueueSettingsTours();
61 }
62
63 if ( $this->contextResolver->isOrderGridPage() ) {
64 $this->enqueueOrderGridTours( $isItFirstRunOrderOrderGridEditPacket );
65 }
66
67 if ( $this->detailCommonLogic->isPacketeryOrder() ) {
68 $this->enqueueOrderDetailTours( $isItFirstRunOrderDetailEditPacket );
69 }
70 }
71 }
72
73 private function enqueueBaseAssets(): void {
74 $this->assetManager->enqueueStyle( 'packetery-driverjs-css', 'public/libs/driverjs-1.3.4/driver.css' );
75 $this->assetManager->enqueueScript( 'packetery-driverjs', 'public/libs/driverjs-1.3.4/driver.js.iife.js', true );
76 $this->assetManager->enqueueStyle( 'packetery-driverjs-css-custom', 'public/css/driver.js.css' );
77 }
78
79 /**
80 * @return array<string, array<string, string|null>|string|null>
81 */
82 private function getBasicTranslations(): array {
83 return [
84 'next' => $this->wpAdapter->__( 'Next', 'packeta' ),
85 'previous' => $this->wpAdapter->__( 'Previous', 'packeta' ),
86 'close' => $this->wpAdapter->__( 'Close', 'packeta' ),
87 'of' => $this->wpAdapter->__( 'of', 'packeta' ),
88 'areYouSure' => $this->wpAdapter->__( 'Are you sure?', 'packeta' ),
89 'settingsSaveButton' => [
90 'title' => $this->wpAdapter->__( 'Save all changes', 'packeta' ),
91 'description' => $this->wpAdapter->__( 'Save with this button after all changes are made.', 'packeta' ),
92 ],
93 ];
94 }
95
96 private function enqueueSettingsTours(): void {
97 $basicTranslations = $this->getBasicTranslations();
98
99 if ( $this->request->getQuery( 'wizard-general-settings-tour-enabled' ) === 'true' ) {
100 $this->createGeneralSettingsTour( $basicTranslations );
101 }
102
103 if ( $this->request->getQuery( 'wizard-packet-status-tracking-tour-enabled' ) === 'true' ) {
104 $this->createPacketStatusTrackingTour( $basicTranslations );
105 }
106
107 if ( $this->request->getQuery( 'wizard-auto-submission-tour-enabled' ) === 'true' ) {
108 $this->createAutoSubmissionTour( $basicTranslations );
109 }
110
111 if ( $this->request->getQuery( 'wizard-advanced-tour-enabled' ) === 'true' ) {
112 $this->createAdvancedTour( $basicTranslations );
113 }
114 }
115
116 private function enqueueOrderGridTours( bool $isItFirstRunOrderOrderGridEditPacket ): void {
117 $basicTranslations = $this->getBasicTranslations();
118 if ( $this->request->getQuery( 'wizard-order-grid-edit-packet-enabled' ) === 'true' ||
119 $isItFirstRunOrderOrderGridEditPacket
120 ) {
121 if ( $this->hasTableGridOurShippingMethods() ) {
122 update_option( OptionNames::PACKETERY_TUTORIAL_ORDER_GRID_EDIT_PACKET, 0 );
123 $this->createOrderGridEditPacketTour( $basicTranslations );
124 }
125 }
126 if ( $this->request->getQuery( 'wizard-order-grid-enabled' ) === 'true' ) {
127 $this->createOrderGridTour( $basicTranslations );
128 }
129 }
130
131 private function enqueueOrderDetailTours( bool $isItFirstRunOrderDetailEditPacket ): void {
132 $basicTranslations = $this->getBasicTranslations();
133 if ( $this->request->getQuery( 'wizard-order-detail-edit-packet-enabled' ) === 'true' || $isItFirstRunOrderDetailEditPacket ) {
134 update_option( OptionNames::PACKETERY_TUTORIAL_ORDER_DETAIL_EDIT_PACKET, 0 );
135 $this->createOrderDetailEditPacketTour( $basicTranslations );
136 }
137 if ( $this->request->getQuery( 'wizard-order-detail-custom-declaration-enabled' ) === 'true' ) {
138 $this->createOrderDetailCustomDeclarationTour( $basicTranslations );
139 }
140 }
141
142 /**
143 * @param string $scriptName
144 * @param array<string, array<string, string|null>|string|null> $translations
145 */
146 private function enqueueTourScript( string $scriptName, array $translations ): void {
147 $this->assetManager->enqueueScript( 'packetery-admin-wizard-tour', 'public/js/tours/' . $scriptName, true, [ 'packetery-driverjs' ] );
148 $this->wpAdapter->localizeScript( 'packetery-admin-wizard-tour', 'wizardTourConfig', [ 'translations' => $translations ] );
149 }
150
151 /**
152 * @param array<string, array<string, string|null>|string|null> $basicTranslations
153 */
154 private function createGeneralSettingsTour( array $basicTranslations ): void {
155 $translations = [
156 'apiPassword' => [
157 'title' => $this->wpAdapter->__( 'API password', 'packeta' ),
158 'description' => sprintf(
159 $this->wpAdapter->__( 'API password can be found at %s', 'packeta' ),
160 '<a href="https://client.packeta.com/support" target="_blank">https://client.packeta.com/support<a/>'
161 ),
162 ],
163 'apiSender' => [
164 'title' => $this->wpAdapter->__( 'Sender', 'packeta' ),
165 'description' => sprintf(
166 /* translators: 1: emphasis start 2: emphasis end 3: client section link start 4: client section link end */
167 esc_html__( 'Fill in the %1$ssender label%2$s here - you will find it in %3$sclient section%4$s - user information - field \'Indication\'.', 'packeta' ),
168 '<strong>',
169 '</strong>',
170 '<a href="https://client.packeta.com/senders" target="_blank">',
171 '</a>'
172 ),
173 ],
174 'packetaLabelFormat' => [
175 'title' => $this->wpAdapter->__( 'Packeta Label Format', 'packeta' ),
176 'description' => $this->wpAdapter->__( 'Select the label print format for Packeta according to your printer.', 'packeta' ),
177 ],
178 'carrierLabelFormat' => [
179 'title' => $this->wpAdapter->__( 'Carrier Label Format', 'packeta' ),
180 'description' => $this->wpAdapter->__( 'Select the label print format for the carrier according to your printer.', 'packeta' ),
181 ],
182 'cod' => [
183 'title' => $this->wpAdapter->__( 'Payment methods that represent cash on delivery', 'packeta' ),
184 'description' => $this->wpAdapter->__( 'Select the payment method that will be set as cash on delivery. This information will be passed to the carrier to calculate surcharges.', 'packeta' ),
185 ],
186 'packagingWeight' => [
187 'title' => $this->wpAdapter->__( 'Weight of packaging material', 'packeta' ),
188 'description' => $this->wpAdapter->__( '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. It is also taken into account when evaluating weight rules in the cart.', 'packeta' ),
189 ],
190 'defaultWeightEnabled' => [
191 'title' => $this->wpAdapter->__( 'Enable default weight', 'packeta' ),
192 'description' => $this->wpAdapter->__( 'If no weight is set for the products in order, this value will be used.', 'packeta' ),
193 ],
194 'dimensionsUnit' => [
195 'title' => $this->wpAdapter->__( 'Units used for dimensions', 'packeta' ),
196 'description' => $this->wpAdapter->__( 'Units used for package dimensions, such as centimeters (cm) or millimeters (mm).', 'packeta' ),
197 ],
198 'dimensionsEnabled' => [
199 'title' => $this->wpAdapter->__( 'Enable default dimensions', 'packeta' ),
200 'description' => $this->wpAdapter->__( 'When enabled, these values will be automatically used for any order that contains products with zero dimensions.', 'packeta' ),
201 ],
202 'pickupPointAddress' => [
203 'title' => $this->wpAdapter->__( 'Replace shipping address with pickup point address', 'packeta' ),
204 'description' => $this->wpAdapter->__( 'If this option is enabled, the customers shipping address will automatically be replaced with the selected pickup point address.', 'packeta' ),
205 ],
206 'checkoutDetection' => [
207 'title' => $this->wpAdapter->__( 'Force checkout type', 'packeta' ),
208 'description' => $this->wpAdapter->__( 'If you have trouble displaying the widget button in the checkout, you can set what type of checkout you are using.', 'packeta' ),
209 ],
210 'widgetButtonLocation' => [
211 'title' => $this->wpAdapter->__( 'Widget button location in checkout', 'packeta' ),
212 'description' => $this->wpAdapter->__( 'Determines where the pickup point selection button will appear at checkout.', 'packeta' ),
213 ],
214 'hideLogo' => [
215 'title' => $this->wpAdapter->__( 'Hide Packeta checkout logo', 'packeta' ),
216 'description' => $this->wpAdapter->__( 'Hides the Packeta logo at checkout.', 'packeta' ),
217 ],
218 'emailHook' => [
219 'title' => $this->wpAdapter->__( 'Hook used to view information in email', 'packeta' ),
220 'description' => $this->wpAdapter->__( 'This option determines where the pickup point information will be displayed in the e-mail. Choose the appropriate option based on the structure of e-mails in your e-shop.', 'packeta' ),
221 ],
222 'forcePacketCancel' => [
223 'title' => $this->wpAdapter->__( 'Force order cancellation', 'packeta' ),
224 'description' => $this->wpAdapter->__( 'Cancel the packet for an order even if the cancellation in the Packeta system will not be successful.', 'packeta' ),
225 ],
226 'widgetAutoOpen' => [
227 'title' => $this->wpAdapter->__( 'Automatically open widget when shipping was selected', 'packeta' ),
228 'description' => $this->wpAdapter->__( 'If this option is active, the widget for selecting pickup points will open automatically after selecting the shipping method at the checkout.', 'packeta' ),
229 ],
230 'freeShippingShown' => [
231 'title' => $this->wpAdapter->__( 'Display the FREE shipping text in checkout', 'packeta' ),
232 'description' => $this->wpAdapter->__( 'If enabled, "FREE" will be displayed after the name of the shipping method, if free shipping is applied.', 'packeta' ),
233 ],
234 'pricesIncludeTax' => [
235 'title' => $this->wpAdapter->__( 'Prices include tax', 'packeta' ),
236 'description' => $this->wpAdapter->__( 'If enabled, VAT will not be added to shipping prices and surcharges.', 'packeta' ),
237 ],
238 'pickupPointValidationEnabled' => [
239 'title' => $this->wpAdapter->__( 'Validate the pickup point using the API before accepting the order', 'packeta' ),
240 'description' => $this->wpAdapter->__( 'If enabled, selected pickup point will be validated using the API to prevent bypassing widget restrictions.', 'packeta' ),
241 ],
242 'showConsignPasswordForZBox' => [
243 'title' => $this->wpAdapter->__( 'Show consignment code', 'packeta' ),
244 'description' => $this->wpAdapter->__( 'If enabled, the consignment code will be fetched after packet creation and displayed in the order metabox and on the AWB printout.', 'packeta' ),
245 ],
246 ];
247
248 $this->enqueueTourScript( 'admin-wizard-general-settings.js', array_merge( $translations, $basicTranslations ) );
249 }
250
251 /**
252 * @param array<string, array<string, string|null>|string|null> $basicTranslations
253 */
254 private function createPacketStatusTrackingTour( array $basicTranslations ): void {
255 $translations = [
256 'numberOrders' => [
257 'title' => $this->wpAdapter->__( 'Number of orders synced during one cron call', 'packeta' ),
258 'description' => $this->wpAdapter->__( 'The number of orders that will be checked during a single cron call.', 'packeta' ),
259 ],
260 'trackingDays' => [
261 'title' => $this->wpAdapter->__( 'Number of days for which the order status is checked', 'packeta' ),
262 'description' => $this->wpAdapter->__( 'Number of days after the creation of an order, during which the order status will be checked.', 'packeta' ),
263 ],
264 'orderStatus' => [
265 'title' => $this->wpAdapter->__( 'Order statuses, for which cron will check the packet status', 'packeta' ),
266 'description' => $this->wpAdapter->__( 'Cron will automatically track all orders with these statuses and check if the shipment status has changed.', 'packeta' ),
267 ],
268 'packetStatus' => [
269 'title' => $this->wpAdapter->__( 'Packet statuses that are being checked', 'packeta' ),
270 'description' => $this->wpAdapter->__( 'If an order has a shipment with one of these selected statuses, the shipment status will be tracked.', 'packeta' ),
271 ],
272 'enableChangeOrderStatus' => [
273 'title' => $this->wpAdapter->__( 'Allow order status change', 'packeta' ),
274 'description' => $this->wpAdapter->__( 'You can enable automatic change of order status here.', 'packeta' ),
275 ],
276 ];
277
278 $this->enqueueTourScript( 'admin-wizard-packet-status-tracking-settings.js', array_merge( $translations, $basicTranslations ) );
279 }
280
281 /**
282 * @param array<string, array<string, string|null>|string|null> $basicTranslations
283 */
284 private function createAutoSubmissionTour( array $basicTranslations ): void {
285 $translations = [
286 'autoSubmissionEnabled' => [
287 'title' => $this->wpAdapter->__( 'Allow packet auto-submission', 'packeta' ),
288 'description' => $this->wpAdapter->__( 'You can enable automatic submission of the shipment when the order status changes here.', 'packeta' ),
289 ],
290 'autoSubmissionMapping' => [
291 'title' => $this->wpAdapter->__( 'Status mapping', 'packeta' ),
292 'description' => $this->wpAdapter->__( 'Choose events for payment methods that will trigger packet submission', 'packeta' ),
293 ],
294 ];
295
296 $this->enqueueTourScript( 'admin-wizard-auto-submission-settings.js', array_merge( $translations, $basicTranslations ) );
297 }
298
299 /**
300 * @param array<string, array<string, string|null>|string|null> $basicTranslations
301 */
302 private function createAdvancedTour( array $basicTranslations ): void {
303 $translations = [
304 'newCarrierEnabled' => [
305 'title' => $this->wpAdapter->__( 'Advanced carrier settings', 'packeta' ),
306 'description' => $this->wpAdapter->__( 'You can enable the advanced carrier settings to get better support of WooCommerce features here.', 'packeta' ),
307 ],
308 ];
309
310 $this->enqueueTourScript( 'admin-wizard-advanced-settings.js', array_merge( $translations, $basicTranslations ) );
311 }
312
313 private function createOrderGridEditPacketTour( array $basicTranslations ): void {
314 $translations = [
315 'modalWeight' => [
316 'title' => $this->wpAdapter->__( 'Weight', 'packeta' ),
317 'description' => $this->wpAdapter->__( 'Here you see the shipment weight, calculated from the products in the order. If products don’t have a weight, the default value set in the plugin settings will be used. You can also adjust it manually.', 'packeta' ),
318 ],
319 'modalLength' => [
320 'title' => $this->wpAdapter->__( 'Length', 'packeta' ),
321 'description' => $this->wpAdapter->__( 'Enter the shipment length in mm or cm, depending on plugin settings. The length of the largest product in the order is used. If the product has no dimensions, the default from plugin settings is used. You can also adjust it manually.', 'packeta' ),
322 ],
323 'modalWidth' => [
324 'title' => $this->wpAdapter->__( 'Width', 'packeta' ),
325 'description' => $this->wpAdapter->__( 'Enter the shipment width in mm or cm, depending on plugin settings. The width of the largest product in the order is used. If the product has no dimensions, the default from plugin settings is used. You can also adjust it manually.', 'packeta' ),
326 ],
327 'modalHeight' => [
328 'title' => $this->wpAdapter->__( 'Height', 'packeta' ),
329 'description' => $this->wpAdapter->__( 'Enter the shipment height in mm or cm, depending on plugin settings. The height of the largest product in the order is used. If the product has no dimensions, the default from plugin settings is used. You can also adjust it manually.', 'packeta' ),
330 ],
331 'modalAdultContent' => [
332 'title' => $this->wpAdapter->__( 'Adult content', 'packeta' ),
333 'description' => $this->wpAdapter->__( 'Automatically checked for orders with adult products.', 'packeta' ),
334 ],
335 'modalCod' => [
336 'title' => $this->wpAdapter->__( 'COD', 'packeta' ),
337 'description' => $this->wpAdapter->__( 'You can edit the cash on delivery manually, otherwise the total order value is used.', 'packeta' ),
338 ],
339 'modalValue' => [
340 'title' => $this->wpAdapter->__( 'Value', 'packeta' ),
341 'description' => $this->wpAdapter->__( 'You can edit the packet value manually, otherwise the total order price is used.', 'packeta' ),
342 ],
343 'modalDeliverOn' => [
344 'title' => $this->wpAdapter->__( 'Deliver on', 'packeta' ),
345 'description' => $this->wpAdapter->__( 'Deferred delivery date – if set, the packet will be ready for pickup from this date onward.', 'packeta' ),
346 ],
347 ];
348 $this->enqueueTourScript( 'admin-wizard-create-packet-modal.js', array_merge( $translations, $basicTranslations ) );
349 }
350
351 private function createOrderDetailEditPacketTour( array $basicTranslations ): void {
352 $translations = [
353 'weight' => [
354 'title' => $this->wpAdapter->__( 'Weight', 'packeta' ),
355 'description' => $this->wpAdapter->__( 'Here you see the shipment weight, calculated from the products in the order. If products don’t have a weight, the default value set in the plugin settings will be used. You can also adjust it manually.', 'packeta' ),
356 ],
357 'length' => [
358 'title' => $this->wpAdapter->__( 'Length', 'packeta' ),
359 'description' => $this->wpAdapter->__( 'Enter the shipment length in mm or cm, depending on plugin settings. The length of the largest product in the order is used. If the product has no dimensions, the default from plugin settings is used. You can also adjust it manually.', 'packeta' ),
360 ],
361 'width' => [
362 'title' => $this->wpAdapter->__( 'Width', 'packeta' ),
363 'description' => $this->wpAdapter->__( 'Enter the shipment width in mm or cm, depending on plugin settings. The width of the largest product in the order is used. If the product has no dimensions, the default from plugin settings is used. You can also adjust it manually.', 'packeta' ),
364 ],
365 'height' => [
366 'title' => $this->wpAdapter->__( 'Height', 'packeta' ),
367 'description' => $this->wpAdapter->__( 'Enter the shipment height in mm or cm, depending on plugin settings. The height of the largest product in the order is used. If the product has no dimensions, the default from plugin settings is used. You can also adjust it manually.', 'packeta' ),
368 ],
369 'adultContent' => [
370 'title' => $this->wpAdapter->__( 'Adult content', 'packeta' ),
371 'description' => $this->wpAdapter->__( 'Automatically checked for orders with adult products.', 'packeta' ),
372 ],
373 'cod' => [
374 'title' => $this->wpAdapter->__( 'COD', 'packeta' ),
375 'description' => $this->wpAdapter->__( 'You can edit the cash on delivery manually, otherwise the total order value is used.', 'packeta' ),
376 ],
377 'value' => [
378 'title' => $this->wpAdapter->__( 'Value', 'packeta' ),
379 'description' => $this->wpAdapter->__( 'You can edit the packet value manually, otherwise the total order price is used.', 'packeta' ),
380 ],
381 'deliverOn' => [
382 'title' => $this->wpAdapter->__( 'Deliver on', 'packeta' ),
383 'description' => $this->wpAdapter->__( 'Deferred delivery date – if set, the packet will be ready for pickup from this date onward.', 'packeta' ),
384 ],
385 'pickupPoint' => [
386 'title' => $this->wpAdapter->__( 'Pickup point', 'packeta' ),
387 'description' => $this->wpAdapter->__( 'Here you can change the pickup point where the packet will be delivered.', 'packeta' ),
388 ],
389 'pickupAddress' => [
390 'title' => $this->wpAdapter->__( 'Pickup address', 'packeta' ),
391 'description' => $this->wpAdapter->__( 'Here you can change the delivery address of the packet via the widget.', 'packeta' ),
392 ],
393 'trackingUrl' => [
394 'title' => $this->wpAdapter->__( 'Tracking url', 'packeta' ),
395 'description' => $this->wpAdapter->__( 'Here you can find the URL to track the packet, you can click through to online tracking.', 'packeta' ),
396 ],
397 'zboxConsignPassword' => [
398 'title' => $this->wpAdapter->__( 'Consignment code', 'packeta' ),
399 'description' => $this->wpAdapter->__( 'Consignment code for submitting the packet. Shown only when enabled in general settings and after the consignment code has been fetched from Packeta.', 'packeta' ),
400 ],
401 'claimTrackingUrl' => [
402 'title' => $this->wpAdapter->__( 'Claim tracking url', 'packeta' ),
403 'description' => $this->wpAdapter->__( 'Here you can find the URL to track the claim packet (Claim Assistant), you can click through to online tracking.', 'packeta' ),
404 ],
405 'claimPassword' => [
406 'title' => $this->wpAdapter->__( 'Claim password', 'packeta' ),
407 'description' => $this->wpAdapter->__( 'Password required to submit the packet via Claim Assistant.', 'packeta' ),
408 ],
409 'buttonSubmitPacket' => [
410 'title' => $this->wpAdapter->__( 'Submit', 'packeta' ),
411 'description' => $this->wpAdapter->__( 'Use this button to submit the packet. Clicking it will send the packet to the Packeta system', 'packeta' ),
412 ],
413 'buttonCancel' => [
414 'title' => $this->wpAdapter->__( 'Cancel', 'packeta' ),
415 'description' => $this->wpAdapter->__( 'Button to cancel the packet. Clicking it will cancel the packet in the Packeta system, allowing you to submit it again.', 'packeta' ),
416 ],
417 'print' => [
418 'title' => $this->wpAdapter->__( 'Print', 'packeta' ),
419 'description' => $this->wpAdapter->__( 'Clicking this button opens a PDF of the label ready for printing.', 'packeta' ),
420 ],
421 'storedUnitl' => [
422 'title' => $this->wpAdapter->__( 'Stored until', 'packeta' ),
423 'description' => $this->wpAdapter->__( 'Here you can see the date until which the packet can be picked up (shown if shipment tracking is enabled and the packet is ready for pickup).', 'packeta' ),
424 ],
425 'claimUrl' => [
426 'title' => $this->wpAdapter->__( 'Claim url', 'packeta' ),
427 'description' => $this->wpAdapter->__( 'Here you can find the URL to track the packet, you can click through to online tracking.', 'packeta' ),
428 ],
429 'claimLabel' => [
430 'title' => $this->wpAdapter->__( 'Claim label', 'packeta' ),
431 'description' => $this->wpAdapter->__( 'Here you can find the URL to track the claim packet (claim assistant), you can click through to online tracking.', 'packeta' ),
432 ],
433 'cancelClaim' => [
434 'title' => $this->wpAdapter->__( 'Cancel claim', 'packeta' ),
435 'description' => $this->wpAdapter->__( 'Button to cancel a claim assistant packet. Clicking it will cancel the packet in the Packeta system, and you’ll be able to submit it again.', 'packeta' ),
436 ],
437 'packetStatus' => [
438 'title' => $this->wpAdapter->__( 'Packet status', 'packeta' ),
439 'description' => $this->wpAdapter->__( 'Here you can see the current stage of the packet (shown only if this option is enabled in the plugin settings).', 'packeta' ),
440 ],
441 'logsLink' => [
442 'title' => $this->wpAdapter->__( 'Logs', 'packeta' ),
443 'description' => $this->wpAdapter->__( 'Button that, when clicked, shows the logs for this order. This lets you easily check what actions have been taken on the order in the system.', 'packeta' ),
444 ],
445 ];
446 $this->enqueueTourScript( 'admin-wizard-create-packet-metabox.js', array_merge( $translations, $basicTranslations ) );
447 }
448
449 private function createOrderGridTour( array $basicTranslations ): void {
450 $translations = [
451 'bulkActions' => [
452 'title' => $this->wpAdapter->__( 'Bulk actions', 'packeta' ),
453 'description' => $this->wpAdapter->__( 'Here you can use Packeta bulk actions – submit packets, print labels, or print a packet list.', 'packeta' ),
454 ],
455 'orderType' => [
456 'title' => $this->wpAdapter->__( 'Packeta shipping method', 'packeta' ),
457 'description' => $this->wpAdapter->__( 'Filter to show Packeta orders sent either to pickup points or to a carrier.', 'packeta' ),
458 ],
459 'filterToSubmit' => [
460 'title' => $this->wpAdapter->__( 'Packeta orders to submit', 'packeta' ),
461 'description' => $this->wpAdapter->__( 'Shows Packeta orders that haven’t been submitted yet.', 'packeta' ),
462 ],
463 'filterToPrint' => [
464 'title' => $this->wpAdapter->__( 'Packeta orders to print', 'packeta' ),
465 'description' => $this->wpAdapter->__( 'Shows Packeta orders where the label hasn’t been printed yet', 'packeta' ),
466 ],
467 'weight' => [
468 'title' => $this->wpAdapter->__( 'Weight', 'packeta' ),
469 'description' => $this->wpAdapter->__( 'Total packet weight from the order, you can adjust it', 'packeta' ),
470 ],
471 'packeta' => [
472 'title' => $this->wpAdapter->__( 'Packeta', 'packeta' ),
473 'description' => $this->wpAdapter->__( 'Here you can find Packeta actions – submit packet, add details, or print labels (shown only when available).', 'packeta' ),
474 ],
475 'trackingNumber' => [
476 'title' => $this->wpAdapter->__( 'Tracking no.', 'packeta' ),
477 'description' => $this->wpAdapter->__( 'Here you can find the packet number assigned by Packeta, clickable for online tracking..', 'packeta' ),
478 ],
479 'status' => [
480 'title' => $this->wpAdapter->__( 'Packeta packet status', 'packeta' ),
481 'description' => $this->wpAdapter->__( 'Here you can see the current stage of the packet (shown only if this option is enabled in the plugin settings).', 'packeta' ),
482 ],
483 'storedUntil' => [
484 'title' => $this->wpAdapter->__( 'Stored until', 'packeta' ),
485 'description' => $this->wpAdapter->__( 'Here you can see the date until which the packet can be picked up (shown if shipment tracking is enabled and the packet is ready for pickup).', 'packeta' ),
486 ],
487 'pickupOrCarrier' => [
488 'title' => $this->wpAdapter->__( 'Pickup point or carrier', 'packeta' ),
489 'description' => $this->wpAdapter->__( 'Here you can see the name of the pickup point or the carrier.', 'packeta' ),
490 ],
491 ];
492 $this->enqueueTourScript( 'admin-wizard-order-grid.js', array_merge( $translations, $basicTranslations ) );
493 }
494
495 private function createOrderDetailCustomDeclarationTour( array $basicTranslations ): void {
496 $translations = [
497 'ead' => [
498 'title' => $this->wpAdapter->__( 'EAD', 'packeta' ),
499 'description' => $this->wpAdapter->__( 'European Administrative Document (EAD) for shipments outside the EU.', 'packeta' ),
500 ],
501 'cost' => [
502 'title' => $this->wpAdapter->__( 'Delivery cost', 'packeta' ),
503 'description' => $this->wpAdapter->__( 'Delivery cost included on the invoice', 'packeta' ),
504 ],
505 'number' => [
506 'title' => $this->wpAdapter->__( 'Invoice number', 'packeta' ),
507 'description' => $this->wpAdapter->__( 'Invoice number for the shipment.', 'packeta' ),
508 ],
509 'invoiceIssueDate' => [
510 'title' => $this->wpAdapter->__( 'Invoice issue date', 'packeta' ),
511 'description' => $this->wpAdapter->__( 'The date the invoice was issued.', 'packeta' ),
512 ],
513 'invoiceFile' => [
514 'title' => $this->wpAdapter->__( 'Invoice PDF file', 'packeta' ),
515 'description' => $this->wpAdapter->__( 'The date the invoice was issued.', 'packeta' ),
516 ],
517 'mrn' => [
518 'title' => $this->wpAdapter->__( 'MRN', 'packeta' ),
519 'description' => $this->wpAdapter->__( 'MRN – a unique reference code for customs shipments.', 'packeta' ),
520 ],
521 'eadFile' => [
522 'title' => $this->wpAdapter->__( 'EAD PDF file', 'packeta' ),
523 'description' => $this->wpAdapter->__( 'PDF file of the EAD document to attach to the shipment.', 'packeta' ),
524 ],
525 'customsCode' => [
526 'title' => $this->wpAdapter->__( 'Customs code', 'packeta' ),
527 'description' => $this->wpAdapter->__( 'Customs code of the product for the declaration.', 'packeta' ),
528 ],
529 'value' => [
530 'title' => $this->wpAdapter->__( 'Value', 'packeta' ),
531 'description' => $this->wpAdapter->__( 'Value of the product', 'packeta' ),
532 ],
533 'productNameEn' => [
534 'title' => $this->wpAdapter->__( 'Product name (EN)', 'packeta' ),
535 'description' => $this->wpAdapter->__( 'Product name in English.', 'packeta' ),
536 ],
537 'productName' => [
538 'title' => $this->wpAdapter->__( 'Product name', 'packeta' ),
539 'description' => $this->wpAdapter->__( 'Product name in your local language.', 'packeta' ),
540 ],
541 'unitsCount' => [
542 'title' => $this->wpAdapter->__( 'Units count', 'packeta' ),
543 'description' => $this->wpAdapter->__( 'Number of product units in the shipment.', 'packeta' ),
544 ],
545 'countryOfOrigin' => [
546 'title' => $this->wpAdapter->__( 'Country of origin code', 'packeta' ),
547 'description' => $this->wpAdapter->__( 'Country of origin code of the product.', 'packeta' ),
548 ],
549 'weight' => [
550 'title' => $this->wpAdapter->__( 'Weight (kg)', 'packeta' ),
551 'description' => $this->wpAdapter->__( 'Weight of the product in kilograms.', 'packeta' ),
552 ],
553 'isFoodOrBook' => [
554 'title' => $this->wpAdapter->__( 'Food or book?', 'packeta' ),
555 'description' => $this->wpAdapter->__( 'Check if the product is food or a book.', 'packeta' ),
556 ],
557 'isVOC' => [
558 'title' => $this->wpAdapter->__( 'Is VOC?', 'packeta' ),
559 'description' => $this->wpAdapter->__( 'Check if the product contains VOC (volatile organic compounds).', 'packeta' ),
560 ],
561 'addDeclaration' => [
562 'title' => $this->wpAdapter->__( 'Add item', 'packeta' ),
563 'description' => $this->wpAdapter->__( 'Add another item to the customs declaration.', 'packeta' ),
564 ],
565 ];
566 $this->enqueueTourScript( 'admin-wizard-custom-declaration-metabox.js', array_merge( $translations, $basicTranslations ) );
567 }
568
569 private function hasTableGridOurShippingMethods(): bool {
570 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Only reading paged parameter for listing
571 $page = isset( $_GET['paged'] ) ? max( 1, (int) $_GET['paged'] ) : 1;
572 $limit = get_option( 'edit_shop_order_per_page', 20 );
573
574 $orders = $this->wcAdapter->getOrdersWithoutPagination(
575 [
576 'limit' => $limit,
577 'page' => $page,
578 'status' => array_keys( wc_get_order_statuses() ),
579 'orderby' => 'date',
580 'order' => 'DESC',
581 ]
582 );
583 if ( is_array( $orders ) ) {
584 foreach ( $orders as $order ) {
585 if ( $order instanceof WC_Abstract_Order && ShippingProvider::wcOrderHasOurMethod( $order ) ) {
586 return true;
587 }
588 }
589 }
590
591 return false;
592 }
593 }
594