PluginProbe
Tiered Pricing Table for WooCommerce / 7.1.4
Tiered Pricing Table for WooCommerce v7.1.4
8.0.2 7.1.7 7.1.5 7.1.4 7.1.1 6.5.0 6.4.0 6.1.0 trunk 1.0 1.1 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0 2.3.1 2.3.2 2.3.3 All 91 releases
tier-pricing-table / src / Integrations / Plugins / WPAllImport.php

WPAllImport.php in Tiered Pricing Table for WooCommerce 7.1.4, at src/Integrations/Plugins/WPAllImport.php

894 lines 24.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php namespace TierPricingTable\Integrations\Plugins;
2
3 use TierPricingTable\TierPricingTablePlugin;
4 use PMXI_API, XmlImportParser;
5 use function \extract as allowedExtract;
6
7 class WPAllImport extends PluginIntegrationAbstract {
8
9 public $name;
10
11 public $slug;
12
13 public $fields;
14
15 public $options = array();
16
17 public $logger = null;
18
19 protected $isWizard = false;
20
21 private $active_post_types;
22
23 public function getAuthorURL(): string {
24 return 'https://wordpress.org/plugins/wp-all-import/';
25 }
26
27 public function getIconURL(): string {
28 return $this->getContainer()->getFileManager()->locateAsset( 'admin/integrations/wpallimport-icon.png' );
29 }
30
31 public function run() {
32
33 $this->name = 'Tiered Pricing Table';
34
35 $this->slug = 'tier-pricing-table';
36
37 $this->add_option( 'update_tiered_pricing', '1' );
38
39 $this->process();
40 }
41
42 public function addFields() {
43
44 foreach ( $this->getFieldsToImport() as $slug => $field ) {
45
46 if ( empty( $field ) ) {
47 continue;
48 }
49
50 $this->add_field( $slug, $field['title'], $field['type'], null, $field['description'], true, '',
51 isset( $field['role'] ) ? $field['role'] : '' );
52 }
53 }
54
55 public function processImport( $post_id, $data, $import_options, $article ) {
56
57 $this->log( '------------- Tiered Pricing Table START -------------' );
58
59 foreach ( $this->getFieldsToImport() as $fieldSlug => $fieldData ) {
60
61 if ( empty( $article['ID'] ) || $this->can_update_meta( $fieldSlug, $import_options ) ) {
62
63 // System key
64 if ( substr( $fieldSlug, 0, 2 ) === '__' ) {
65 continue;
66 }
67
68 $roleKey = $this->getRoleKey( $fieldSlug );
69
70 // role is not enabled
71 if ( $roleKey && empty( $data[ '__' . $roleKey . '_enabled' ] ) ) {
72 continue;
73 }
74
75 $fieldValue = $fieldData['unSerialize']( $data[ $fieldSlug ] );
76
77 $this->log( sprintf( 'Field %s updated with value %s', $fieldSlug, json_encode( $fieldValue ) ) );
78
79 update_post_meta( $post_id, $fieldSlug, $fieldValue );
80 }
81 }
82
83 $this->log( '------------- Tiered Pricing Table END -------------' );
84 }
85
86 public function getRoleKey( $key ) {
87
88 foreach ( wp_roles()->roles as $role => $roleData ) {
89 if ( strpos( $key, $role ) !== false ) {
90 return $role;
91 }
92 }
93
94 return '';
95 }
96
97 public function getFieldsToImport() {
98
99 $fields = array(
100
101 '_fixed_price_rules' => array(
102 'title' => __( 'Fixed Tiered prices', 'tier-pricing-table' ),
103 'type' => 'text',
104 'unSerialize' => array( $this, 'unSerializeRules' ),
105 'description' => __( 'The format for the rules must be the following: quantity:price,quantity:price. For example: "10:5,20:15" where 10 and 20 are quantities and 5 and 15 are prices for those quantities.',
106 'tier-pricing-table' ),
107 ),
108 '_percentage_price_rules' => array(
109 'title' => __( 'Percentage Tiered prices', 'tier-pricing-table' ),
110 'type' => 'text',
111 'unSerialize' => array( $this, 'unSerializeRules' ),
112 'description' => __( 'Format for the rules must be the following: quantity:percent_discount,quantity:percent_discount. For example: "10:5,20:15" where 10 and 20 are quantities and 5 and 15 are amounts of discount.',
113 'tier-pricing-table' ),
114 ),
115 '_tiered_price_rules_type' => array(
116 'title' => __( 'Tiered pricing type', 'tier-pricing-table' ),
117 'type' => 'text',
118 'unSerialize' => function ( $data ) {
119 if ( in_array( $data, array( 'fixed', 'percentage' ) ) ) {
120 return $data;
121 }
122
123 return 'fixed';
124 },
125 'description' => __( 'The field must be either "fixed" or "percentage".', 'tier-pricing-table' ),
126 ),
127 '_tiered_price_minimum_qty' => array(
128 'title' => __( 'Minimum product quantity', 'tier-pricing-table' ),
129 'type' => 'text',
130 'unSerialize' => function ( $min ) {
131 return (int) $min;
132 },
133 'description' => __( 'The field must contain an integer value.', 'tier-pricing-table' ),
134 ),
135 );
136
137 foreach ( wp_roles()->roles as $role => $roleData ) {
138
139 $fields[ '__' . $role . '_enabled' ] = array(
140 'title' => '',
141 'description' => '',
142 'type' => 'is_enabled_role_field',
143 'role' => $role,
144 'is_sub_field' => true,
145 );
146
147 $fields[ '_' . $role . '_tiered_price_pricing_type' ] = array(
148 'title' => __( 'Pricing type', 'tier-pricing-table' ),
149 'type' => 'role_field',
150 'role' => $role,
151 'is_sub_field' => true,
152 'unSerialize' => function ( $type ) {
153 return 'fixed' === $type ? 'flat' : 'percentage';
154 },
155 'description' => __( 'The field must be either "fixed" or "percentage". This affect what fields will be used to grant a discount: sale and regular prices or percentage discount.',
156 'tier-pricing-table' ),
157 );
158
159 $fields[ '_' . $role . '_tiered_price_regular_price' ] = array(
160 'title' => __( 'Regular price', 'tier-pricing-table' ),
161 'type' => 'role_field',
162 'role' => $role,
163 'is_sub_field' => true,
164 'unSerialize' => array( $this, 'unSerializePrice' ),
165 'description' => __( 'Regular price for the role', 'tier-pricing-table' ),
166 );
167
168 $fields[ '_' . $role . '_tiered_price_sale_price' ] = array(
169 'title' => __( 'Sale price', 'tier-pricing-table' ),
170 'type' => 'role_field',
171 'role' => $role,
172 'is_sub_field' => true,
173 'unSerialize' => array( $this, 'unSerializePrice' ),
174 'description' => __( 'Sale price for the role', 'tier-pricing-table' ),
175 );
176
177 $fields[ '_' . $role . '_tiered_price_discount' ] = array(
178 'title' => __( 'Discount (%)', 'tier-pricing-table' ),
179 'type' => 'role_field',
180 'role' => $role,
181 'is_sub_field' => true,
182 'unSerialize' => function ( $discount ) {
183 if ( '' === $discount ) {
184 return null;
185 }
186
187 $discount = $discount ? (float) $discount : null;
188
189 if ( ! $discount ) {
190 return null;
191 }
192
193 $discount = max( 0, $discount );
194
195 return min( 100, $discount );
196 },
197 'description' => __( 'Percentage discount for the role.', 'tier-pricing-table' ),
198 );
199
200
201 $fields[ '_' . $role . '_fixed_price_rules' ] = array(
202 'title' => __( 'Fixed Tiered prices', 'tier-pricing-table' ),
203 'type' => 'role_field',
204 'role' => $role,
205 'is_sub_field' => true,
206 'unSerialize' => array( $this, 'unSerializeRules' ),
207 'description' => __( 'The format for the rules must be the following: quantity:price,quantity:price. For example: "10:5,20:15" where 10 and 20 are quantities and 5 and 15 are prices for those quantities.',
208 'tier-pricing-table' ),
209 );
210
211 $fields[ '_' . $role . '_percentage_price_rules' ] = array(
212 'title' => __( 'Percentage Tiered prices', 'tier-pricing-table' ),
213 'type' => 'role_field',
214 'is_sub_field' => true,
215 'role' => $role,
216 'unSerialize' => array( $this, 'unSerializeRules' ),
217 'description' => __( 'Format for the rules must be the following: quantity:percent_discount,quantity:percent_discount. For example: "10:5,20:15" where 10 and 20 are quantities and 5 and 15 are amounts of discount.',
218 'tier-pricing-table' ),
219 );
220
221 $fields[ '_' . $role . '_tiered_price_rules_type' ] = array(
222 'title' => __( 'Tiered pricing type', 'tier-pricing-table' ),
223 'type' => 'role_field',
224 'is_sub_field' => true,
225 'role' => $role,
226 'unSerialize' => function ( $data ) {
227 if ( in_array( $data, array( 'fixed', 'percentage' ) ) ) {
228 return $data;
229 }
230
231 return 'fixed';
232 },
233 'description' => __( 'The field must be either "fixed" or "percentage".', 'tier-pricing-table' ),
234 );
235
236 $fields[ '_' . $role . '_tiered_price_minimum_qty' ] = array(
237 'title' => __( 'Minimum product quantity', 'tier-pricing-table' ),
238 'type' => 'role_field',
239 'is_sub_field' => true,
240 'role' => $role,
241 'unSerialize' => function ( $min ) {
242 return (int) $min;
243 },
244 'description' => __( 'The field must contain an integer value.', 'tier-pricing-table' ),
245 );
246
247 }
248
249 return $fields;
250 }
251
252 public function unSerializePrice( $price ) {
253 if ( '' === $price ) {
254 return null;
255 }
256
257 return $price ? (float) $price : null;
258 }
259
260 /**
261 * UnSerialize rules
262 *
263 * @param mixed $data
264 *
265 * @return mixed
266 */
267 public function unSerializeRules( $data ) {
268
269 $rules = explode( TierPricingTablePlugin::getRulesSeparator(), $data );
270
271 $data = array();
272
273 if ( $rules ) {
274 foreach ( $rules as $rule ) {
275 $rule = explode( ':', $rule );
276
277 if ( isset( $rule[0] ) && isset( $rule[1] ) ) {
278 $data[ intval( $rule[0] ) ] = $rule[1];
279 }
280 }
281
282 }
283
284 $data = array_filter( $data );
285
286 $data = array_filter( $data, function ( $itemKey ) {
287 return is_numeric( $itemKey ) && $itemKey > 1;
288 }, ARRAY_FILTER_USE_KEY );
289
290 return ! empty( $data ) ? $data : array();
291 }
292
293 public function is_active_addon( $post_type = null ) {
294
295 if ( ! is_plugin_active( 'wp-all-import-pro/wp-all-import-pro.php' ) && ! is_plugin_active( 'wp-all-import/plugin.php' ) ) {
296 return false;
297 }
298
299 if ( null !== $post_type ) {
300 if ( @in_array( $post_type, $this->active_post_types ) || empty( $this->active_post_types ) ) {
301 return true;
302 }
303
304 return false;
305 }
306
307 return true;
308 }
309
310 public function process() {
311
312 $this->active_post_types = array( 'product', 'variation' );
313
314 add_action( 'init', array( $this, 'addFields' ), 10 );
315
316 add_filter( 'pmxi_addons', array( $this, 'wpai_api_register' ) );
317 add_filter( 'wp_all_import_addon_parse', array( $this, 'wpai_api_parse' ) );
318 add_filter( 'wp_all_import_addon_import', array( $this, 'wpai_api_import' ) );
319 add_filter( 'pmxi_options_options', array( $this, 'wpai_api_options' ) );
320 add_action( 'pmxi_extend_options_featured', array( $this, 'wpai_api_metabox' ), 10, 2 );
321
322 add_action( 'admin_init', array( $this, 'admin_notice_ignore' ) );
323
324 add_action( 'pmxi_reimport', function ( $post_type, $post ) {
325 if ( 'product' !== $post_type && empty( $post['is_override_post_type'] ) ) {
326 return false;
327 }
328 ?>
329 <div class="input">
330 <input type="hidden" name="update_tiered_pricing" value="0"/>
331 <input type="checkbox" id="update_tiered_pricing" name="update_tiered_pricing"
332 value="1" <?php checked( $post['update_tiered_pricing'] ); ?> />
333 <label for="update_tiered_pricing">
334 <?php
335 esc_html_e( 'Tiered Pricing', 'tier-pricing-table' )
336 ?>
337 </label>
338 </div>
339 <?php
340 }, 10, 2 );
341 }
342
343 public function parse( $data ) {
344
345 if ( ! $this->is_active_addon( $data['import']->options['custom_type'] ) ) {
346 return false;
347 }
348
349 return $this->helper_parse( $data, $this->options_array() );
350 }
351
352
353 public function add_field(
354 $field_slug,
355 $field_name,
356 $field_type,
357 $enum_values = null,
358 $tooltip = '',
359 $is_html = true,
360 $default_text = '',
361 $role = ''
362 ) {
363
364 $field = array(
365 'name' => $field_name,
366 'type' => $field_type,
367 'enum_values' => $enum_values,
368 'tooltip' => $tooltip,
369 'is_sub_field' => false,
370 'is_main_field' => false,
371 'is_html' => $is_html,
372 'default_text' => $default_text,
373 'role' => $role,
374 'slug' => $field_slug,
375 );
376
377 $this->fields[ $field_slug ] = $field;
378
379 if ( ! empty( $enum_values ) ) {
380 foreach ( $enum_values as $key => $value ) {
381 if ( is_array( $value ) ) {
382 if ( 'accordion' === $field['type'] ) {
383 $this->fields[ $value['slug'] ]['is_sub_field'] = true;
384 } else {
385 foreach ( $value as $n => $param ) {
386 if ( is_array( $param ) && ! empty( $this->fields[ $param['slug'] ] ) ) {
387 $this->fields[ $param['slug'] ]['is_sub_field'] = true;
388 }
389 }
390 }
391 }
392 }
393 }
394
395 return $field;
396 }
397
398 /**
399 *
400 * Add an option to WP All Import options list
401 *
402 * @param string $slug - option name
403 * @param string $default_value - default option value
404 *
405 */
406 public function add_option( $slug, $default_value = '' ) {
407 $this->options[ $slug ] = $default_value;
408 }
409
410 public function options_array() {
411
412 $options_list = array();
413
414 if ( ! empty( $this->fields ) ) {
415
416 foreach ( $this->fields as $field_slug => $field_params ) {
417 if ( in_array( $field_params['type'], array( 'title', 'plain_text', 'acf' ) ) ) {
418 continue;
419 }
420 $default_value = '';
421 if ( ! empty( $field_params['enum_values'] ) ) {
422 foreach ( $field_params['enum_values'] as $key => $value ) {
423 $default_value = $key;
424 break;
425 }
426 }
427 $options_list[ $field_slug ] = $default_value;
428 }
429
430 }
431
432 if ( ! empty( $this->options ) ) {
433 foreach ( $this->options as $slug => $value ) {
434 $options_arr[ $slug ] = $value;
435 }
436 }
437
438 $options_arr[ $this->slug ] = $options_list;
439 $options_arr['rapid_addon'] = plugin_basename( __FILE__ );
440
441 return $options_arr;
442
443 }
444
445 public function wpai_api_options( $all_options ) {
446
447 $all_options = $all_options + $this->options_array();
448
449 return $all_options;
450
451 }
452
453 public function wpai_api_register( $addons ) {
454
455 if ( empty( $addons[ $this->slug ] ) ) {
456 $addons[ $this->slug ] = 1;
457 }
458
459 return $addons;
460 }
461
462
463 public function wpai_api_parse( $functions ) {
464
465 $functions[ $this->slug ] = array( $this, 'parse' );
466
467 return $functions;
468
469 }
470
471 public function wpai_api_import( $functions ) {
472
473 $functions[ $this->slug ] = array( $this, 'import' );
474
475 return $functions;
476
477 }
478
479 public function import( $importData, $parsedData ) {
480
481 if ( ! $this->is_active_addon( $importData['post_type'] ) ) {
482 return;
483 }
484
485 $import_options = false;
486
487 if ( ! empty( $importData['import']['options'][ $this->slug ] ) ) {
488 $import_options = $importData['import']['options'][ $this->slug ];
489 }
490
491 if ( ! empty( $parsedData ) ) {
492
493 $this->logger = $importData['logger'];
494
495 $post_id = $importData['pid'];
496 $index = $importData['i'];
497 $data = array();
498
499 if ( ! empty( $this->fields ) ) {
500 foreach ( $this->fields as $field_slug => $field_params ) {
501
502 if ( in_array( $field_params['type'], array( 'title', 'plain_text' ) ) ) {
503 continue;
504 }
505
506 $data[ $field_slug ] = $parsedData[ $field_slug ][ $index ];
507
508 if ( $import_options ) {
509 // apply mapping rules if they exist
510 if ( ! empty( $import_options['mapping'][ $field_slug ] ) ) {
511 $mapping_rules = json_decode( $import_options['mapping'][ $field_slug ], true );
512
513 if ( ! empty( $mapping_rules ) && is_array( $mapping_rules ) ) {
514 foreach ( $mapping_rules as $rule_number => $map_to ) {
515 if ( isset( $map_to[ trim( $data[ $field_slug ] ) ] ) ) {
516 $data[ $field_slug ] = trim( $map_to[ trim( $data[ $field_slug ] ) ] );
517 break;
518 }
519 }
520 }
521 }
522 }
523 }
524 }
525
526 $this->processImport( $post_id, $data, $importData['import'], $importData['articleData'] );
527 }
528 }
529
530 public function wpai_api_metabox( $post_type, $current_values ) {
531
532 if ( ! $this->is_active_addon( $post_type ) ) {
533 return;
534 }
535
536 $this->helper_metabox_top( $this->name );
537
538 $visible_fields = 0;
539
540 foreach ( $this->fields as $field_slug => $field_params ) {
541
542 if ( $field_params['is_sub_field'] ) {
543 continue;
544 }
545
546 $visible_fields ++;
547 }
548
549
550 $counter = 0;
551
552 foreach ( $this->fields as $field_slug => $field_params ) {
553
554 // do not render sub fields
555 if ( $field_params['is_sub_field'] || 'role_field' === $field_params['type'] || 'is_enabled_role_field' === $field_params['type'] ) {
556 continue;
557 }
558
559 $counter ++;
560
561 $this->render_field( $field_params, $field_slug, $current_values, $visible_fields == $counter );
562 }
563
564 ?>
565 <div>
566 <h3><?php esc_attr_e( 'Role-based import', 'tier-pricing-table' ); ?>: </h3>
567 <?php foreach ( wp_roles()->roles as $WPRole => $role_data ) : ?>
568
569 <?php
570
571 global $wp_roles;
572 $roleName = isset( $wp_roles->role_names[ $WPRole ] ) ? translate_user_role( $wp_roles->role_names[ $WPRole ] ) : $WPRole;
573 ?>
574
575 <div class="tiered-pricing-import-role-block">
576 <div class="tiered-pricing-import-role-block__header">
577 <h4>
578 <label for="<?php echo esc_attr( $WPRole . '__enabled' ); ?>">
579 <input type="checkbox" data-role-based-import
580
581 <?php checked( ! empty( $current_values[ $this->slug ][ '__' . $WPRole . '_enabled' ] ) ); ?>
582
583 id="<?php echo esc_attr( $WPRole . '__enabled' ); ?>"
584 name="<?php echo esc_attr( $this->slug . '[__' . $WPRole . '_enabled]' ); ?>">
585 <?php echo esc_attr( $roleName ); ?>
586 </label>
587 </h4>
588 </div>
589 <div class="tiered-pricing-import-role-block__body">
590 <?php
591 foreach ( $this->fields as $field_slug => $field_params ) {
592
593 if ( 'role_field' === $field_params['type'] && $field_params['role'] === $WPRole ) {
594 $this->render_field( $field_params, $field_slug, $current_values,
595 $visible_fields == $counter, $WPRole );
596 }
597 }
598
599 ?>
600 </div>
601 </div>
602 <?php endforeach; ?>
603 </div>
604 <?php
605
606 $this->helper_metabox_bottom();
607 }
608
609 public function render_field( $field_params, $field_slug, $current_values, $in_the_bottom = false, $role = false ) {
610
611 if ( ! isset( $current_values[ $this->slug ][ $field_slug ] ) ) {
612 $current_values[ $this->slug ][ $field_slug ] = isset( $field_params['default_text'] ) ? $field_params['default_text'] : '';
613 }
614
615 PMXI_API::add_field( 'simple', $field_params['name'], array(
616 'tooltip' => $field_params['tooltip'],
617 'field_name' => $this->slug . '[' . $field_slug . ']',
618 'field_value' => ( '' == $current_values[ $this->slug ][ $field_slug ] && $this->isWizard ) ? $field_params['default_text'] : $current_values[ $this->slug ][ $field_slug ],
619 ) );
620 }
621
622 public function helper_metabox_top( $name ) {
623 ?>
624 <style type="text/css">
625
626 .wpallimport-plugin .tiered-pricing-import-role-block__header {
627 padding: 0 20px;
628 cursor: pointer;
629 border: 1px solid #f5f5f5;
630 }
631
632 .wpallimport-plugin .tiered-pricing-import-role-block__body {
633 padding: 20px;
634 background: #f5f5f5;
635 display: none;
636 }
637
638 .wpallimport-plugin .wpallimport-addon div.input {
639 margin-bottom: 15px;
640 }
641
642 .wpallimport-plugin .wpallimport-addon .custom-params tr td.action {
643 width: auto !important;
644 }
645
646 .wpallimport-plugin .wpallimport-addon .wpallimport-custom-fields-actions {
647 right: 0 !important;
648 }
649
650 .wpallimport-plugin .wpallimport-addon table tr td.wpallimport-enum-input-wrapper {
651 width: 80%;
652 }
653
654 .wpallimport-plugin .wpallimport-addon table tr td.wpallimport-enum-input-wrapper input {
655 width: 100%;
656 }
657
658 .wpallimport-plugin .wpallimport-addon .wpallimport-custom-fields-actions {
659 float: right;
660 right: 30px;
661 position: relative;
662 border: 1px solid #ddd;
663 margin-bottom: 10px;
664 }
665
666 .wpallimport-plugin .wpallimport-addon .wpallimport-sub-options {
667 margin-bottom: 15px;
668 margin-top: -16px;
669 }
670
671 .wpallimport-plugin .wpallimport-addon .wpallimport-sub-options .wpallimport-content-section {
672 padding-bottom: 8px;
673 margin: 0;
674 border: none;
675 padding-top: 1px;
676 background: #f1f2f2;
677 }
678
679 .wpallimport-plugin .wpallimport-addon .wpallimport-sub-options .wpallimport-collapsed-header {
680 padding-left: 13px;
681 }
682
683 .wpallimport-plugin .wpallimport-addon .wpallimport-sub-options .wpallimport-collapsed-header h3 {
684 font-size: 14px;
685 margin: 6px 0;
686 }
687
688 .wpallimport-plugin .wpallimport-addon .wpallimport-sub-options-full-width {
689 bottom: -40px;
690 margin-bottom: 0;
691 margin-left: -25px;
692 margin-right: -25px;
693 position: relative;
694 }
695
696 .wpallimport-plugin .wpallimport-addon .wpallimport-sub-options-full-width .wpallimport-content-section {
697 margin: 0;
698 border-top: 1px solid #ddd;
699 border-bottom: none;
700 border-right: none;
701 border-left: none;
702 background: #f1f2f2;
703 }
704
705 .wpallimport-plugin .wpallimport-addon .wpallimport-sub-options-full-width .wpallimport-collapsed-header h3 {
706 margin: 14px 0;
707 }
708
709 .wpallimport-plugin .wpallimport-addon .wpallimport-dependent-options {
710 margin-left: 1px;
711 margin-right: -1px;
712 }
713
714 .wpallimport-plugin .wpallimport-addon .wpallimport-dependent-options .wpallimport-content-section {
715 border: 1px solid #ddd;
716 border-top: none;
717 }
718
719 .wpallimport-plugin .wpallimport-addon .wpallimport-full-with-bottom {
720 margin-left: -25px;
721 margin-right: -25px;
722 }
723
724 .wpallimport-plugin .wpallimport-addon .wpallimport-full-with-not-bottom {
725 margin: 25px -1px 25px 1px;
726 }
727
728 .wpallimport-plugin .wpallimport-addon .wpallimport-full-with-not-bottom .wpallimport-content-section {
729 border: 1px solid #ddd;
730 }
731
732 .wpallimport-plugin .wpallimport-addon .wpallimport-add-on-options-title {
733 font-size: 14px;
734 margin: 45px 0 15px 0;
735 }
736 </style>
737 <script>
738 jQuery(document).ready(function ($) {
739 $('.tiered-pricing-import-role-block__header').click(function (e) {
740
741 if (e && e.target.hasAttribute('data-role-based-import')) {
742 return;
743 }
744
745 var checkbox = $(this).find('[data-role-based-import]');
746
747 checkbox.prop('checked', !checkbox.is(':checked')).trigger('change');
748 });
749
750 $('[data-role-based-import]').change(function (e) {
751 if ($(e.target).is(':checked')) {
752 $(this).closest('.tiered-pricing-import-role-block').find('.tiered-pricing-import-role-block__body').show();
753 } else {
754 $(this).closest('.tiered-pricing-import-role-block').find('.tiered-pricing-import-role-block__body').hide();
755 }
756 }).trigger('change');
757 });
758
759 </script>
760
761 <div class="wpallimport-collapsed wpallimport-section wpallimport-addon ' . $this->slug . ' closed">
762 <div class="wpallimport-content-section">
763 <div class="wpallimport-collapsed-header">
764 <h3><?php esc_attr_e( $name, 'pmxi_plugin' ); ?></h3>
765 </div>
766 <div class="wpallimport-collapsed-content" style="padding: 0;">
767 <div class="wpallimport-collapsed-content-inner">
768 <table class="form-table" style="max-width:none;">
769 <tr>
770 <td colspan="3">
771 <?php
772 }
773
774
775 public function helper_metabox_bottom() {
776 ?>
777 </td>
778 </tr>
779 </table>
780 </div>
781 </div>
782 </div>
783 </div>
784 <?php
785 }
786
787 public function helper_parse( $parsingData, $options ) {
788 $data = array(); // parsed data
789
790 /**
791 * Extracted vars
792 *
793 * @var $import
794 * @var $xml
795 * @var string $xpath_prefix
796 * @var int $count
797 */
798
799 allowedExtract( $parsingData );
800
801 if ( ! empty( $import->options[ $this->slug ] ) ) {
802
803 $this->logger = $parsingData['logger'];
804
805 $cxpath = $xpath_prefix . $import->xpath;
806
807 $tmp_files = array();
808
809 foreach ( $options[ $this->slug ] as $option_name => $option_value ) {
810 if ( isset( $import->options[ $this->slug ][ $option_name ] ) && '' != $import->options[ $this->slug ][ $option_name ] ) {
811 if ( 'xpath' == $import->options[ $this->slug ][ $option_name ] ) {
812 if ( '' == $import->options[ $this->slug ]['xpaths'][ $option_name ] ) {
813 if ( $count ) {
814 $data[ $option_name ] = array_fill( 0, $count, '' );
815 }
816 } else {
817 $data[ $option_name ] = XmlImportParser::factory( $xml, $cxpath,
818 (string) $import->options[ $this->slug ]['xpaths'][ $option_name ], $file )->parse();
819 $tmp_files[] = $file;
820 }
821 } else {
822 $data[ $option_name ] = XmlImportParser::factory( $xml, $cxpath,
823 (string) $import->options[ $this->slug ][ $option_name ], $file )->parse();
824 $tmp_files[] = $file;
825 }
826
827
828 } else {
829 $data[ $option_name ] = array_fill( 0, $count, '' );
830 }
831
832 }
833
834 foreach ( $tmp_files as $file ) { // remove all temporary files created
835 unlink( $file );
836 }
837
838 }
839
840 return $data;
841 }
842
843 public function can_update_meta( $meta_key, $import_options ) {
844
845 $import_options = $import_options['options'];
846
847 if ( 'yes' == $import_options['update_all_data'] ) {
848 return true;
849 }
850
851 if ( ! $import_options['update_tiered_pricing'] ) {
852 $this->log( 'Tiered Pricing is disabled' );
853
854 return false;
855 }
856
857 if ( 'full_update' == $import_options['update_custom_fields_logic'] ) {
858 return true;
859 }
860
861 if ( 'only' == $import_options['update_custom_fields_logic'] ) {
862 return true;
863 }
864
865 if ( 'all_except' == $import_options['update_custom_fields_logic'] && ( empty( $import_options['custom_fields_list'] ) || ! in_array( $meta_key,
866 $import_options['custom_fields_list'] ) ) ) {
867 return true;
868 }
869
870 return false;
871 }
872
873 public function admin_notice_ignore() {
874 if ( isset( $_GET[ $this->slug . '_ignore' ] ) && '0' == $_GET[ $this->slug . '_ignore' ] ) {
875 update_option( $this->slug . '_ignore', 'true' );
876 }
877 }
878
879 public function log( $m = false ) {
880 $m && $this->logger && call_user_func( $this->logger, $m );
881 }
882
883 public function getTitle(): string {
884 return 'WP All Import';
885 }
886
887 public function getDescription(): string {
888 return __( 'Import and update tiered pricing rules using WP All Import.', 'tier-pricing-table' );
889 }
890
891 public function getSlug(): string {
892 return 'wpallimport';
893 }
894 }