PluginProbe
Tiered Pricing Table for WooCommerce / 6.1.0
Tiered Pricing Table for WooCommerce v6.1.0
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 / Admin / Import / WPAllImport.php

WPAllImport.php in Tiered Pricing Table for WooCommerce 6.1.0, at src/Admin/Import/WPAllImport.php

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