Import Products from any XML or CSV to WooCommerce - Version 1.2.2

Version Description

  • fixed import stock status for negative qty
  • fixed import shipping class when their slugs presented as numeric values
Download this release

Release Info

Developer soflyy
Plugin Icon 128x128 Import Products from any XML or CSV to WooCommerce
Version 1.2.2
Comparing to
See all releases

Code changes from version 1.2.1 to 1.2.2

actions/admin_notices.php CHANGED
@@ -31,7 +31,7 @@ function pmwi_admin_notices() {
31
 
32
  }
33
 
34
- if ( class_exists( 'PMXI_Plugin' ) and ( (version_compare(PMXI_VERSION, '4.0.0-beta1') < 0 ) and PMXI_EDITION == 'paid' or version_compare(PMXI_VERSION, '3.2.0') < 0 and PMXI_EDITION == 'free') ) {
35
  ?>
36
  <div class="error"><p>
37
  <?php printf(
31
 
32
  }
33
 
34
+ if ( class_exists( 'PMXI_Plugin' ) and ( (version_compare(PMXI_VERSION, '4.0.0-beta1') < 0 ) and PMXI_EDITION == 'paid' or version_compare(PMXI_VERSION, '3.2.8') < 0 and PMXI_EDITION == 'free') ) {
35
  ?>
36
  <div class="error"><p>
37
  <?php printf(
actions/pmxi_extend_options_main.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
- function pmwi_pmxi_extend_options_main($entry){
3
 
4
- if ($entry != 'product') return;
5
 
6
  $woo_controller = new PMWI_Admin_Import();
7
  $woo_controller->index();
1
  <?php
2
+ function pmwi_pmxi_extend_options_main($entry, $post = array()){
3
 
4
+ if ($entry != 'product' and empty($post['is_override_post_type'])) return;
5
 
6
  $woo_controller = new PMWI_Admin_Import();
7
  $woo_controller->index();
actions/pmxi_reimport.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  function pmwi_pmxi_reimport($entry, $post){
3
 
4
- if ( $entry != "product" ) return;
5
 
6
  $all_existing_attributes = array();
7
  $hide_taxonomies = array('product_type');
1
  <?php
2
  function pmwi_pmxi_reimport($entry, $post){
3
 
4
+ if ($entry != 'product' and empty($post['is_override_post_type'])) return;
5
 
6
  $all_existing_attributes = array();
7
  $hide_taxonomies = array('product_type');
classes/input.php CHANGED
@@ -19,7 +19,14 @@ class PMWI_Input {
19
  }
20
 
21
  public function get($paramName, $default = NULL) {
22
- return $this->read($_GET, $paramName, $default);
 
 
 
 
 
 
 
23
  }
24
 
25
  public function post($paramName, $default = NULL) {
19
  }
20
 
21
  public function get($paramName, $default = NULL) {
22
+ $this->addFilter('strip_tags');
23
+ $this->addFilter('htmlspecialchars');
24
+ $this->addFilter('esc_sql');
25
+ $result = $this->read($_GET, $paramName, $default);
26
+ $this->removeFilter('strip_tags');
27
+ $this->removeFilter('htmlspecialchars');
28
+ $this->removeFilter('esc_sql');
29
+ return $result;
30
  }
31
 
32
  public function post($paramName, $default = NULL) {
classes/updater.php DELETED
@@ -1,153 +0,0 @@
1
- <?php
2
-
3
- if( ! class_exists('PMWI_Updater') ) {
4
-
5
- class PMWI_Updater {
6
- private $api_url = '';
7
- private $api_data = array();
8
- private $name = '';
9
- private $slug = '';
10
-
11
- /**
12
- * Class constructor.
13
- *
14
- * @uses plugin_basename()
15
- * @uses hook()
16
- *
17
- * @param string $_api_url The URL pointing to the custom API endpoint.
18
- * @param string $_plugin_file Path to the plugin file.
19
- * @param array $_api_data Optional data to send with API calls.
20
- * @return void
21
- */
22
- function __construct( $_api_url, $_plugin_file, $_api_data = null ) {
23
- $this->api_url = trailingslashit( $_api_url );
24
- $this->api_data = urlencode_deep( $_api_data );
25
- $this->name = plugin_basename( $_plugin_file );
26
- $this->slug = basename( $_plugin_file, '.php');
27
- $this->version = $_api_data['version'];
28
-
29
- // Set up hooks.
30
- $this->hook();
31
- }
32
-
33
- /**
34
- * Set up Wordpress filters to hook into WP's update process.
35
- *
36
- * @uses add_filter()
37
- *
38
- * @return void
39
- */
40
- private function hook() {
41
- add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'pre_set_site_transient_update_plugins_filter' ) );
42
- add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 );
43
- add_filter( 'http_request_args', array( $this, 'http_request_args' ), 10, 2 );
44
- }
45
-
46
- /**
47
- * Check for Updates at the defined API endpoint and modify the update array.
48
- *
49
- * This function dives into the update api just when Wordpress creates its update array,
50
- * then adds a custom API call and injects the custom plugin data retrieved from the API.
51
- * It is reassembled from parts of the native Wordpress plugin update code.
52
- * See wp-includes/update.php line 121 for the original wp_update_plugins() function.
53
- *
54
- * @uses api_request()
55
- *
56
- * @param array $_transient_data Update array build by Wordpress.
57
- * @return array Modified update array with custom plugin data.
58
- */
59
- function pre_set_site_transient_update_plugins_filter( $_transient_data ) {
60
-
61
-
62
- if( empty( $_transient_data ) ) return $_transient_data;
63
-
64
- $to_send = array( 'slug' => $this->slug );
65
-
66
- $api_response = $this->api_request( 'plugin_latest_version', $to_send );
67
-
68
- if( false !== $api_response && is_object( $api_response ) && isset( $api_response->new_version ) ) {
69
- if( version_compare( $this->version, $api_response->new_version, '<' ) )
70
- $_transient_data->response[$this->name] = $api_response;
71
- }
72
- return $_transient_data;
73
- }
74
-
75
-
76
- /**
77
- * Updates information on the "View version x.x details" page with custom data.
78
- *
79
- * @uses api_request()
80
- *
81
- * @param mixed $_data
82
- * @param string $_action
83
- * @param object $_args
84
- * @return object $_data
85
- */
86
- function plugins_api_filter( $_data, $_action = '', $_args = null ) {
87
- if ( ( $_action != 'plugin_information' ) || !isset( $_args->slug ) || ( $_args->slug != $this->slug ) ) return $_data;
88
-
89
- $to_send = array( 'slug' => $this->slug );
90
-
91
- $api_response = $this->api_request( 'plugin_information', $to_send );
92
- if ( false !== $api_response ) $_data = $api_response;
93
-
94
- return $_data;
95
- }
96
-
97
-
98
- /**
99
- * Disable SSL verification in order to prevent download update failures
100
- *
101
- * @param array $args
102
- * @param string $url
103
- * @return object $array
104
- */
105
- function http_request_args( $args, $url ) {
106
- // If it is an https request and we are performing a package download, disable ssl verification
107
- if( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) {
108
- $args['sslverify'] = false;
109
- }
110
- return $args;
111
- }
112
-
113
- /**
114
- * Calls the API and, if successfull, returns the object delivered by the API.
115
- *
116
- * @uses get_bloginfo()
117
- * @uses wp_remote_post()
118
- * @uses is_wp_error()
119
- *
120
- * @param string $_action The requested action.
121
- * @param array $_data Parameters for the API action.
122
- * @return false||object
123
- */
124
- private function api_request( $_action, $_data ) {
125
-
126
- global $wp_version;
127
-
128
- $data = array_merge( $this->api_data, $_data );
129
-
130
- if( $data['slug'] != $this->slug )
131
- return;
132
-
133
- $api_params = array(
134
- 'edd_action' => 'get_version',
135
- 'license' => false,
136
- 'name' => $data['item_name'],
137
- 'slug' => $this->slug,
138
- 'author' => $data['author']
139
- );
140
- $request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) );
141
-
142
- if ( ! is_wp_error( $request ) ):
143
- $request = json_decode( wp_remote_retrieve_body( $request ) );
144
- if( $request && isset( $request->sections ) )
145
- $request->sections = maybe_unserialize( $request->sections );
146
- return $request;
147
- else:
148
- return false;
149
- endif;
150
- }
151
- }
152
-
153
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
filters/pmxi_article_data.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  function pmwi_pmxi_article_data($articleData, $import, $post_to_update){
3
- if ( $import->options['custom_type'] == 'product' and ! $import->options['is_update_product_type']){
4
  $articleData['post_type'] = $post_to_update->post_type;
5
  }
6
  return $articleData;
1
  <?php
2
  function pmwi_pmxi_article_data($articleData, $import, $post_to_update){
3
+ if ( $articleData['post_type'] == 'product' and $import->options['update_all_data'] == 'no' and ! $import->options['is_update_product_type']){
4
  $articleData['post_type'] = $post_to_update->post_type;
5
  }
6
  return $articleData;
helpers/pmwi_is_update_taxonomy.php CHANGED
@@ -2,6 +2,11 @@
2
  function pmwi_is_update_taxonomy( $articleData, $options, $tx_name ){
3
 
4
  if ( ! empty($articleData['ID']) ){
 
 
 
 
 
5
  if ($options['update_all_data'] == "no" and $options['update_categories_logic'] == "all_except" and !empty($options['taxonomies_list'])
6
  and is_array($options['taxonomies_list']) and in_array($tx_name, $options['taxonomies_list'])) return false;
7
  if ($options['update_all_data'] == "no" and $options['update_categories_logic'] == "only" and ((!empty($options['taxonomies_list'])
2
  function pmwi_is_update_taxonomy( $articleData, $options, $tx_name ){
3
 
4
  if ( ! empty($articleData['ID']) ){
5
+
6
+ if ($options['update_all_data'] == 'yes') return true;
7
+
8
+ if ( ! $options['is_update_categories'] ) return false;
9
+
10
  if ($options['update_all_data'] == "no" and $options['update_categories_logic'] == "all_except" and !empty($options['taxonomies_list'])
11
  and is_array($options['taxonomies_list']) and in_array($tx_name, $options['taxonomies_list'])) return false;
12
  if ($options['update_all_data'] == "no" and $options['update_categories_logic'] == "only" and ((!empty($options['taxonomies_list'])
models/import/record.php CHANGED
@@ -16,6 +16,17 @@ class PMWI_Import_Record extends PMWI_Model_Record {
16
  public $post_meta_to_insert;
17
  public $existing_meta_keys;
18
  public $articleData;
 
 
 
 
 
 
 
 
 
 
 
19
 
20
  /**
21
  * Initialize model instance
@@ -35,9 +46,7 @@ class PMWI_Import_Record extends PMWI_Model_Record {
35
  */
36
  public function parse($parsing_data = array()) { //$import, $count, $xml, $logger = NULL, $chunk = false, $xpath_prefix = ""
37
 
38
- extract($parsing_data);
39
-
40
- if ($import->options['custom_type'] != 'product') return;
41
 
42
  add_filter('user_has_cap', array($this, '_filter_has_cap_unfiltered_html')); kses_init(); // do not perform special filtering for imported content
43
 
@@ -53,7 +62,7 @@ class PMWI_Import_Record extends PMWI_Model_Record {
53
 
54
  // Composing product types
55
  if ($import->options['is_multiple_product_type'] != 'yes' and "" != $import->options['single_product_type']){
56
- $this->data['product_types'] = XmlImportParser::factory($xml, $cxpath, $import->options['single_product_type'], $file)->parse($records); $tmp_files[] = $file;
57
  }
58
  else{
59
  $count and $this->data['product_types'] = array_fill(0, $count, $import->options['multiple_product_type']);
@@ -228,7 +237,12 @@ class PMWI_Import_Record extends PMWI_Model_Record {
228
  elseif($import->options['product_stock_status'] == 'auto'){
229
  $count and $this->data['product_stock_status'] = array_fill(0, $count, $import->options['product_stock_status']);
230
  foreach ($this->data['product_stock_qty'] as $key => $value) {
231
- $this->data['product_stock_status'][$key] = ($value === 0) ? 'outofstock' : 'instock';
 
 
 
 
 
232
  }
233
  }
234
  else{
@@ -376,6 +390,45 @@ class PMWI_Import_Record extends PMWI_Model_Record {
376
  $count and $this->data['single_product_id_first_is_variation'] = array_fill(0, $count, "");
377
  }
378
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
379
  if ($import->options['matching_parent'] != "auto") {
380
  switch ($import->options['matching_parent']) {
381
  case 'first_is_parent_id':
@@ -415,8 +468,8 @@ class PMWI_Import_Record extends PMWI_Model_Record {
415
  $attribute_create_taxonomy_terms = array();
416
 
417
  if (!empty($import->options['attribute_name'][0])){
418
- foreach ($import->options['attribute_name'] as $j => $attribute_name) { if ($attribute_name == "") continue;
419
- $attribute_keys[$j] = XmlImportParser::factory($xml, $cxpath, $attribute_name, $file)->parse($records); $tmp_files[] = $file;
420
  $attribute_values[$j] = XmlImportParser::factory($xml, $cxpath, $import->options['attribute_value'][$j], $file)->parse($records); $tmp_files[] = $file;
421
  $attribute_in_variation[$j] = XmlImportParser::factory($xml, $cxpath, $import->options['in_variations'][$j], $file)->parse($records); $tmp_files[] = $file;
422
  $attribute_is_visible[$j] = XmlImportParser::factory($xml, $cxpath, $import->options['is_visible'][$j], $file)->parse($records); $tmp_files[] = $file;
@@ -448,6 +501,10 @@ class PMWI_Import_Record extends PMWI_Model_Record {
448
  unlink($file);
449
  }
450
 
 
 
 
 
451
  return $this->data;
452
  }
453
 
@@ -459,7 +516,7 @@ class PMWI_Import_Record extends PMWI_Model_Record {
459
 
460
  extract($importData);
461
 
462
- if ($this->options['custom_type'] != 'product') return;
463
 
464
  $cxpath = $xpath_prefix . $import->xpath;
465
 
@@ -472,10 +529,10 @@ class PMWI_Import_Record extends PMWI_Model_Record {
472
  // Get types
473
  $product_type = empty( $product_types[$i] ) ? 'simple' : sanitize_title( stripslashes( $product_types[$i] ) );
474
 
475
- if ( ! $this->options['is_update_product_type'] and ! $is_new_product ){
476
  $product = get_product($pid);
477
  $product_type = $product->product_type;
478
- }
479
 
480
  $this->existing_meta_keys = array();
481
  foreach (get_post_meta($pid, '') as $cur_meta_key => $cur_meta_val) $this->existing_meta_keys[] = $cur_meta_key;
@@ -490,15 +547,20 @@ class PMWI_Import_Record extends PMWI_Model_Record {
490
  $is_featured = $product_featured[$i];
491
 
492
  // Product type + Downloadable/Virtual
493
- if ($is_new_product or $this->options['is_update_product_type'])
494
- wp_set_object_terms( $pid, $product_type, 'product_type' );
 
 
 
 
 
495
 
496
  $this->pushmeta($pid, '_downloadable', ($is_downloadable == "yes") ? 'yes' : 'no' );
497
  $this->pushmeta($pid, '_virtual', ($is_virtual == "yes") ? 'yes' : 'no' );
498
 
499
  // Update post meta
500
- $this->pushmeta($pid, '_regular_price', stripslashes( $product_regular_price[$i] ) );
501
- $this->pushmeta($pid, '_sale_price', stripslashes( $product_sale_price[$i] ) );
502
  $this->pushmeta($pid, '_tax_status', stripslashes( $product_tax_status[$i] ) );
503
  $this->pushmeta($pid, '_tax_class', stripslashes( $product_tax_class[$i] ) );
504
  $this->pushmeta($pid, '_visibility', stripslashes( $product_visibility[$i] ) );
@@ -524,16 +586,45 @@ class PMWI_Import_Record extends PMWI_Model_Record {
524
 
525
  // Save shipping class
526
  if ( pmwi_is_update_taxonomy($articleData, $this->options, 'product_shipping_class') ){
527
- $pshipping_class = is_numeric($product_shipping_class[$i]) && $product_shipping_class[$i] > 0 && $product_type != 'external' ? absint( $product_shipping_class[$i] ) : $product_shipping_class[$i];
528
- if ($pshipping_class == "-1")
529
- wp_set_object_terms( $pid, NULL, 'product_shipping_class');
530
- else
531
- $this->associate_terms( $pid, array($pshipping_class), 'product_shipping_class' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
532
  }
533
 
534
  // Unique SKU
535
  $sku = ($is_new_product) ? '' : get_post_meta($pid, '_sku', true);
536
- $new_sku = esc_html( trim( stripslashes( $product_sku[$i] ) ) );
537
 
538
  if ( $new_sku == '' and $this->options['disable_auto_sku_generation'] ) {
539
  $this->pushmeta($pid, '_sku', '' );
@@ -574,7 +665,7 @@ class PMWI_Import_Record extends PMWI_Model_Record {
574
 
575
  $is_variation_attributes_defined = false;
576
 
577
- if ( $this->options['update_all_data'] == "yes" or ( $this->options['update_all_data'] == "no" and $this->options['is_update_attributes']) or $is_new_product): // Update Product Attributes
578
 
579
  $is_update_attributes = true;
580
 
@@ -584,18 +675,26 @@ class PMWI_Import_Record extends PMWI_Model_Record {
584
 
585
  $attr_names = array();
586
 
587
- foreach ($serialized_attributes as $anum => $attr_data) { $attr_name = strtolower($attr_data['names'][$i]);
 
 
 
 
588
 
589
  if (empty($attr_name) or in_array($attr_name, $attr_names)) continue;
590
 
591
- $attr_names[] = $attr_name;
592
 
593
  $is_visible = intval( $attr_data['is_visible'][$i] );
594
  $is_variation = intval( $attr_data['in_variation'][$i] );
595
  $is_taxonomy = intval( $attr_data['in_taxonomy'][$i] );
596
 
 
 
 
 
597
  // Update only these Attributes, leave the rest alone
598
- if ($this->options['update_all_data'] == "no" and $this->options['update_attributes_logic'] == 'only'){
599
  if ( ! empty($this->options['attributes_list']) and is_array($this->options['attributes_list'])) {
600
  if ( ! in_array( ( ($is_taxonomy) ? wc_attribute_taxonomy_name( $attr_name ) : $attr_name ) , array_filter($this->options['attributes_list'], 'trim'))){
601
  $attribute_position++;
@@ -609,7 +708,7 @@ class PMWI_Import_Record extends PMWI_Model_Record {
609
  }
610
 
611
  // Leave these attributes alone, update all other Attributes
612
- if ($this->options['update_all_data'] == "no" and $this->options['update_attributes_logic'] == 'all_except'){
613
  if ( ! empty($this->options['attributes_list']) and is_array($this->options['attributes_list'])) {
614
  if ( in_array( ( ($is_taxonomy) ? wc_attribute_taxonomy_name( $attr_name ) : $attr_name ) , array_filter($this->options['attributes_list'], 'trim'))){
615
  $attribute_position++;
@@ -680,8 +779,10 @@ class PMWI_Import_Record extends PMWI_Model_Record {
680
 
681
  } else {
682
 
683
- if ( taxonomy_exists( wc_attribute_taxonomy_name( $attr_name ) ))
684
- wp_set_object_terms( $pid, NULL, wc_attribute_taxonomy_name( $attr_name ) );
 
 
685
 
686
  if (!empty($attr_data['value'][$i])){
687
 
@@ -696,24 +797,24 @@ class PMWI_Import_Record extends PMWI_Model_Record {
696
  );
697
  }
698
 
699
- }
700
-
701
- if ( $is_variation and $attr_data['value'][$i] != "" ) {
702
- $is_variation_attributes_defined = true;
703
- }
704
 
705
  $attribute_position++;
706
  }
707
  }
708
 
709
- if ($is_new_product or $this->is_update_cf('_product_attributes') and $is_update_attributes) {
710
 
711
  $current_product_attributes = get_post_meta($pid, '_product_attributes', true);
712
 
713
- $this->pushmeta($pid, '_product_attributes', ( ! empty($current_product_attributes)) ? array_merge($current_product_attributes, $attributes) : $attributes );
714
  }
715
 
716
- endif; // is update attributes
 
 
 
 
717
 
718
  // Sales and prices
719
  if ( ! in_array( $product_type, array( 'grouped' ) ) ) {
@@ -742,18 +843,18 @@ class PMWI_Import_Record extends PMWI_Model_Record {
742
 
743
  // Update price if on sale
744
  if ( $product_sale_price[$i] != '' && $date_to == '' && $date_from == '' ){
745
- $this->pushmeta($pid, '_price', stripslashes( $product_sale_price[$i] ));
746
  }
747
  else{
748
- $this->pushmeta($pid, '_price', stripslashes( $product_regular_price[$i] ));
749
  }
750
 
751
  if ( $product_sale_price[$i] != '' && $date_from && strtotime( $date_from ) < strtotime( 'NOW', current_time( 'timestamp' ) ) ){
752
- $this->pushmeta($pid, '_price', stripslashes( $product_sale_price[$i] ));
753
  }
754
 
755
  if ( $date_to && strtotime( $date_to ) < strtotime( 'NOW', current_time( 'timestamp' ) ) ) {
756
- $this->pushmeta($pid, '_price', stripslashes( $product_regular_price[$i] ));
757
  $this->pushmeta($pid, '_sale_price_dates_from', '');
758
  $this->pushmeta($pid, '_sale_price_dates_to', '');
759
  }
@@ -834,50 +935,47 @@ class PMWI_Import_Record extends PMWI_Model_Record {
834
  }
835
 
836
  // Stock Data
837
- if ( strtolower($product_manage_stock[$i]) == 'yes' ) {
838
 
839
- if ( $product_type == 'grouped' ) {
 
 
840
 
841
- $this->pushmeta($pid, '_stock_status', stripslashes( $product_stock_status[$i] ));
842
- $this->pushmeta($pid, '_stock', '');
843
- $this->pushmeta($pid, '_manage_stock', 'no');
844
- $this->pushmeta($pid, '_backorders', 'no');
845
-
846
- } elseif ( $product_type == 'external' ) {
847
 
848
- $this->pushmeta($pid, '_stock_status', 'instock');
849
- $this->pushmeta($pid, '_stock', '');
850
- $this->pushmeta($pid, '_manage_stock', 'no');
851
- $this->pushmeta($pid, '_backorders', 'no');
852
-
853
- } elseif ( ! empty( $product_manage_stock[$i] ) ) {
854
 
855
- // Manage stock
856
- $this->pushmeta($pid, '_stock_status', stripslashes( $product_stock_status[$i] ));
857
- $this->pushmeta($pid, '_stock', (int) $product_stock_qty[$i]);
858
- $this->pushmeta($pid, '_manage_stock', 'yes');
859
- $this->pushmeta($pid, '_backorders', stripslashes( $product_allow_backorders[$i] ));
860
 
861
- // Check stock level
862
- if ( $product_type !== 'variable' && $product_allow_backorders[$i] == 'no' && (int) $product_stock_qty[$i] < 1 ){
863
- $this->pushmeta($pid, '_stock_status', 'outofstock');
 
 
 
864
  }
865
 
866
- } else {
 
 
 
 
 
 
867
 
868
- // Don't manage stock
869
- $this->pushmeta($pid, '_stock_status', stripslashes( $product_stock_status[$i] ));
870
- $this->pushmeta($pid, '_stock', '');
871
- $this->pushmeta($pid, '_manage_stock', 'no');
872
- $this->pushmeta($pid, '_backorders', stripslashes( $product_allow_backorders[$i] ));
873
 
 
 
 
 
874
  }
875
 
876
  } else {
877
-
878
- $this->pushmeta($pid, '_stock_status', stripslashes( $product_stock_status[$i] ));
879
-
880
- }
881
 
882
  // Upsells
883
  if ( !empty( $product_up_sells[$i] ) ) {
@@ -968,11 +1066,59 @@ class PMWI_Import_Record extends PMWI_Model_Record {
968
  if ( isset( $product_download_type[$i] ) )
969
  $this->pushmeta($pid, '_download_type', esc_attr( $product_download_type ));
970
 
971
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
972
 
973
- // prepare bulk SQL query
974
- //$this->executeSQL();
975
-
976
  }
977
 
978
  protected function executeSQL(){
@@ -1001,7 +1147,7 @@ class PMWI_Import_Record extends PMWI_Model_Record {
1001
 
1002
  //$table = _get_meta_table( 'post' );
1003
 
1004
- if ( empty($this->articleData['ID']) or $this->is_update_cf($meta_key)){
1005
 
1006
  update_post_meta($pid, $meta_key, $meta_value);
1007
 
@@ -1035,13 +1181,13 @@ class PMWI_Import_Record extends PMWI_Model_Record {
1035
  */
1036
  protected function is_update_cf( $meta_key ){
1037
 
1038
- if ($this->options['update_all_data'] == 'yes') return true;
1039
 
1040
  if ( ! $this->options['is_update_custom_fields'] ) return false;
1041
 
1042
- if ($this->options['update_custom_fields_logic'] == "full_update") return true;
1043
- if ($this->options['update_custom_fields_logic'] == "only" and ! empty($this->options['custom_fields_list']) and is_array($this->options['custom_fields_list']) and in_array($meta_key, $this->options['custom_fields_list']) ) return true;
1044
- if ($this->options['update_custom_fields_logic'] == "all_except" and ( empty($this->options['custom_fields_list']) or ! in_array($meta_key, $this->options['custom_fields_list']) )) return true;
1045
 
1046
  return false;
1047
 
@@ -1052,6 +1198,8 @@ class PMWI_Import_Record extends PMWI_Model_Record {
1052
  $terms = wp_get_object_terms( $pid, $tx_name );
1053
  $term_ids = array();
1054
 
 
 
1055
  if ( ! empty($terms) ){
1056
  if ( ! is_wp_error( $terms ) ) {
1057
  foreach ($terms as $term_info) {
@@ -1063,27 +1211,33 @@ class PMWI_Import_Record extends PMWI_Model_Record {
1063
  }
1064
  }
1065
 
1066
- if (empty($assign_taxes)) return;
 
 
 
1067
 
1068
- foreach ($assign_taxes as $tt) {
1069
  $this->wpdb->insert( $this->wpdb->term_relationships, array( 'object_id' => $pid, 'term_taxonomy_id' => $tt ) );
1070
  $this->wpdb->query( "UPDATE {$this->wpdb->term_taxonomy} SET count = count + 1 WHERE term_taxonomy_id = $tt" );
 
1071
  }
1072
 
1073
  $values = array();
1074
  $term_order = 0;
1075
- foreach ( $assign_taxes as $tt )
1076
  $values[] = $this->wpdb->prepare( "(%d, %d, %d)", $pid, $tt, ++$term_order);
 
1077
 
1078
 
1079
- if ( $values ){
1080
  if ( false === $this->wpdb->query( "INSERT INTO {$this->wpdb->term_relationships} (object_id, term_taxonomy_id, term_order) VALUES " . join( ',', $values ) . " ON DUPLICATE KEY UPDATE term_order = VALUES(term_order)" ) ){
1081
- $logger and call_user_func($logger, __('<b>ERROR</b> Could not insert term relationship into the database', 'pmxi_plugin') . ': '. $this->wpdb->last_error);
1082
- $logger and PMXI_Plugin::$session['pmxi_import']['errors'] = ++PMXI_Plugin::$session->data['pmxi_import']['errors'];
1083
  }
1084
- }
1085
 
1086
  wp_cache_delete( $pid, $tx_name . '_relationships' );
 
 
1087
  }
1088
 
1089
  protected function duplicate_post_meta( $new_id, $id ) {
@@ -1097,15 +1251,19 @@ class PMWI_Import_Record extends PMWI_Model_Record {
1097
  $sql_query = "INSERT INTO $table (post_id, meta_key, meta_value) ";
1098
  foreach ($post_meta_infos as $meta_info) {
1099
  if ($this->is_update_cf($meta_info->meta_key)){
1100
- $meta_key = $meta_info->meta_key;
1101
- $this->wpdb->query($this->wpdb->prepare("DELETE FROM $table WHERE `post_id` = $new_id AND `meta_key` = %s", $meta_key));
1102
- $meta_value = addslashes($meta_info->meta_value);
1103
- $sql_query_sel[]= "SELECT $new_id, '$meta_key', '$meta_value'";
 
1104
  }
1105
  }
1106
- $sql_query.= implode(" UNION ALL ", $sql_query_sel);
1107
- $this->wpdb->query($sql_query);
 
 
1108
  }
 
1109
  }
1110
 
1111
  function pmwi_buf_prices($pid){
@@ -1151,23 +1309,17 @@ class PMWI_Import_Record extends PMWI_Model_Record {
1151
  $attribute_name = ( isset( $attr_name ) ) ? wc_sanitize_taxonomy_name( stripslashes( (string) $attr_name ) ) : '';
1152
  $attribute_label = ucwords( stripslashes( (string) $attr_name ));
1153
  $attribute_type = 'select';
1154
- $attribute_orderby = 'menu_order';
1155
 
1156
- $reserved_terms = array(
1157
- 'attachment', 'attachment_id', 'author', 'author_name', 'calendar', 'cat', 'category', 'category__and',
1158
- 'category__in', 'category__not_in', 'category_name', 'comments_per_page', 'comments_popup', 'cpage', 'day',
1159
- 'debug', 'error', 'exact', 'feed', 'hour', 'link_category', 'm', 'minute', 'monthnum', 'more', 'name',
1160
- 'nav_menu', 'nopaging', 'offset', 'order', 'orderby', 'p', 'page', 'page_id', 'paged', 'pagename', 'pb', 'perm',
1161
- 'post', 'post__in', 'post__not_in', 'post_format', 'post_mime_type', 'post_status', 'post_tag', 'post_type',
1162
- 'posts', 'posts_per_archive_page', 'posts_per_page', 'preview', 'robots', 's', 'search', 'second', 'sentence',
1163
- 'showposts', 'static', 'subpost', 'subpost_id', 'tag', 'tag__and', 'tag__in', 'tag__not_in', 'tag_id',
1164
- 'tag_slug__and', 'tag_slug__in', 'taxonomy', 'tb', 'term', 'type', 'w', 'withcomments', 'withoutcomments', 'year',
1165
- );
1166
 
1167
- if ( in_array( $attribute_name, $reserved_terms ) ) {
1168
  $logger and call_user_func($logger, sprintf(__('- <b>WARNING</b>: Slug “%s” is not allowed because it is a reserved term. Change it, please.', 'pmxi_plugin'), wc_attribute_taxonomy_name( $attribute_name )));
1169
  }
1170
- else{
 
1171
  // Register the taxonomy now so that the import works!
1172
  $domain = wc_attribute_taxonomy_name( $attr_name );
1173
  if (strlen($domain) <= 32){
@@ -1202,10 +1354,8 @@ class PMWI_Import_Record extends PMWI_Model_Record {
1202
  }
1203
  else{
1204
  $logger and call_user_func($logger, sprintf(__('- <b>WARNING</b>: Taxonomy “%s” name is more than 32 characters. Change it, please.', 'pmxi_plugin'), $attr_name));
1205
- }
1206
-
1207
  }
1208
-
1209
  }
1210
  }
1211
 
@@ -1258,6 +1408,17 @@ class PMWI_Import_Record extends PMWI_Model_Record {
1258
 
1259
  if ( ! empty( $child->variation_id ) ) {
1260
  $available_variations[] = $child->get_variation_attributes();
 
 
 
 
 
 
 
 
 
 
 
1261
  }
1262
  }
1263
 
@@ -1281,14 +1442,19 @@ class PMWI_Import_Record extends PMWI_Model_Record {
1281
  if ( in_array( $variation, $available_variations ) )
1282
  continue;
1283
 
1284
- $variation_id = (!empty($options['is_fast_mode'])) ? pmxi_insert_post($variation_post_data) : wp_insert_post( $variation_post_data );
1285
 
1286
  update_post_meta( $variation_id, '_regular_price', get_post_meta( $post_id, '_regular_price', true ) );
1287
  update_post_meta( $variation_id, '_sale_price', get_post_meta( $post_id, '_sale_price', true ) );
1288
  if ( class_exists('woocommerce_wholesale_pricing') ) update_post_meta( $variation_id, 'pmxi_wholesale_price', get_post_meta( $post_id, 'pmxi_wholesale_price', true ) );
1289
  update_post_meta( $variation_id, '_sale_price_dates_from', get_post_meta( $post_id, '_sale_price_dates_from', true ) );
1290
  update_post_meta( $variation_id, '_sale_price_dates_to', get_post_meta( $post_id, '_sale_price_dates_to', true ) );
1291
- update_post_meta( $variation_id, '_price', get_post_meta( $post_id, '_price', true ) );
 
 
 
 
 
1292
 
1293
  $variation_ids[] = $variation_id;
1294
 
16
  public $post_meta_to_insert;
17
  public $existing_meta_keys;
18
  public $articleData;
19
+
20
+ public $reserved_terms = array(
21
+ 'attachment', 'attachment_id', 'author', 'author_name', 'calendar', 'cat', 'category', 'category__and',
22
+ 'category__in', 'category__not_in', 'category_name', 'comments_per_page', 'comments_popup', 'cpage', 'day',
23
+ 'debug', 'error', 'exact', 'feed', 'hour', 'link_category', 'm', 'minute', 'monthnum', 'more', 'name',
24
+ 'nav_menu', 'nopaging', 'offset', 'order', 'orderby', 'p', 'page', 'page_id', 'paged', 'pagename', 'pb', 'perm',
25
+ 'post', 'post__in', 'post__not_in', 'post_format', 'post_mime_type', 'post_status', 'post_tag', 'post_type',
26
+ 'posts', 'posts_per_archive_page', 'posts_per_page', 'preview', 'robots', 's', 'search', 'second', 'sentence',
27
+ 'showposts', 'static', 'subpost', 'subpost_id', 'tag', 'tag__and', 'tag__in', 'tag__not_in', 'tag_id',
28
+ 'tag_slug__and', 'tag_slug__in', 'taxonomy', 'tb', 'term', 'type', 'w', 'withcomments', 'withoutcomments', 'year',
29
+ );
30
 
31
  /**
32
  * Initialize model instance
46
  */
47
  public function parse($parsing_data = array()) { //$import, $count, $xml, $logger = NULL, $chunk = false, $xpath_prefix = ""
48
 
49
+ extract($parsing_data);
 
 
50
 
51
  add_filter('user_has_cap', array($this, '_filter_has_cap_unfiltered_html')); kses_init(); // do not perform special filtering for imported content
52
 
62
 
63
  // Composing product types
64
  if ($import->options['is_multiple_product_type'] != 'yes' and "" != $import->options['single_product_type']){
65
+ $this->data['product_types'] = XmlImportParser::factory($xml, $cxpath, $import->options['single_product_type'], $file)->parse($records); $tmp_files[] = $file;
66
  }
67
  else{
68
  $count and $this->data['product_types'] = array_fill(0, $count, $import->options['multiple_product_type']);
237
  elseif($import->options['product_stock_status'] == 'auto'){
238
  $count and $this->data['product_stock_status'] = array_fill(0, $count, $import->options['product_stock_status']);
239
  foreach ($this->data['product_stock_qty'] as $key => $value) {
240
+ if ($this->data['product_manage_stock'][$key] == 'yes'){
241
+ $this->data['product_stock_status'][$key] = (( (int) $value === 0 or (int) $value < 0 ) and $value != "") ? 'outofstock' : 'instock';
242
+ }
243
+ else{
244
+ $this->data['product_stock_status'][$key] = 'instock';
245
+ }
246
  }
247
  }
248
  else{
390
  $count and $this->data['single_product_id_first_is_variation'] = array_fill(0, $count, "");
391
  }
392
 
393
+ // Composing product is Manage stock
394
+ if ($import->options['is_variation_product_manage_stock'] == 'xpath' and "" != $import->options['single_variation_product_manage_stock']){
395
+
396
+ $this->data['v_product_manage_stock'] = XmlImportParser::factory($xml, $cxpath, $import->options['single_variation_product_manage_stock'], $file)->parse($records); $tmp_files[] = $file;
397
+
398
+ }
399
+ else{
400
+ $count and $this->data['v_product_manage_stock'] = array_fill(0, $count, $import->options['is_variation_product_manage_stock']);
401
+ }
402
+
403
+ // Stock Qty
404
+ if ($import->options['variation_stock'] != ""){
405
+
406
+ $this->data['v_stock'] = XmlImportParser::factory($xml, $cxpath, $import->options['variation_stock'], $file)->parse($records); $tmp_files[] = $file;
407
+
408
+ }
409
+ else{
410
+ $count and $this->data['v_stock'] = array_fill(0, $count, '');
411
+ }
412
+
413
+ // Stock Status
414
+ if ($import->options['variation_stock_status'] == 'xpath' and "" != $import->options['single_variation_stock_status']){
415
+ $this->data['v_stock_status'] = XmlImportParser::factory($xml, $cxpath, $import->options['single_variation_stock_status'], $file)->parse($records); $tmp_files[] = $file;
416
+ }
417
+ elseif($import->options['variation_stock_status'] == 'auto'){
418
+ $count and $this->data['v_stock_status'] = array_fill(0, $count, $import->options['variation_stock_status']);
419
+ foreach ($this->data['v_stock'] as $key => $value) {
420
+ if ($this->data['v_product_manage_stock'][$key] == 'yes'){
421
+ $this->data['v_stock_status'][$key] = ( ( (int) $value === 0 or (int) $value < 0 ) and $value != "") ? 'outofstock' : 'instock';
422
+ }
423
+ else{
424
+ $this->data['v_stock_status'][$key] = 'instock';
425
+ }
426
+ }
427
+ }
428
+ else{
429
+ $count and $this->data['v_stock_status'] = array_fill(0, $count, $import->options['variation_stock_status']);
430
+ }
431
+
432
  if ($import->options['matching_parent'] != "auto") {
433
  switch ($import->options['matching_parent']) {
434
  case 'first_is_parent_id':
468
  $attribute_create_taxonomy_terms = array();
469
 
470
  if (!empty($import->options['attribute_name'][0])){
471
+ foreach ($import->options['attribute_name'] as $j => $attribute_name) { if ($attribute_name == "") continue;
472
+ $attribute_keys[$j] = XmlImportParser::factory($xml, $cxpath, $attribute_name, $file)->parse($records); $tmp_files[] = $file;
473
  $attribute_values[$j] = XmlImportParser::factory($xml, $cxpath, $import->options['attribute_value'][$j], $file)->parse($records); $tmp_files[] = $file;
474
  $attribute_in_variation[$j] = XmlImportParser::factory($xml, $cxpath, $import->options['in_variations'][$j], $file)->parse($records); $tmp_files[] = $file;
475
  $attribute_is_visible[$j] = XmlImportParser::factory($xml, $cxpath, $import->options['is_visible'][$j], $file)->parse($records); $tmp_files[] = $file;
501
  unlink($file);
502
  }
503
 
504
+ if ($import->options['put_variation_image_to_gallery']){
505
+ add_action('pmxi_gallery_image', array($this, 'wpai_gallery_image'), 10, 3);
506
+ }
507
+
508
  return $this->data;
509
  }
510
 
516
 
517
  extract($importData);
518
 
519
+ if ( ! in_array($importData['post_type'], array('product', 'product_variation'))) return;
520
 
521
  $cxpath = $xpath_prefix . $import->xpath;
522
 
529
  // Get types
530
  $product_type = empty( $product_types[$i] ) ? 'simple' : sanitize_title( stripslashes( $product_types[$i] ) );
531
 
532
+ if ($this->options['update_all_data'] == 'no' and ! $this->options['is_update_product_type'] and ! $is_new_product ){
533
  $product = get_product($pid);
534
  $product_type = $product->product_type;
535
+ }
536
 
537
  $this->existing_meta_keys = array();
538
  foreach (get_post_meta($pid, '') as $cur_meta_key => $cur_meta_val) $this->existing_meta_keys[] = $cur_meta_key;
547
  $is_featured = $product_featured[$i];
548
 
549
  // Product type + Downloadable/Virtual
550
+ if ($is_new_product or $this->options['update_all_data'] == 'no' and $this->options['is_update_product_type']){
551
+ //wp_set_object_terms( $pid, $product_type, 'product_type' );
552
+ $product_type_term = term_exists($product_type, 'product_type', 0);
553
+ if ( ! empty($product_type_term) and ! is_wp_error($product_type_term) ){
554
+ $this->associate_terms( $pid, array( (int) $product_type_term['term_taxonomy_id'] ), 'product_type' );
555
+ }
556
+ }
557
 
558
  $this->pushmeta($pid, '_downloadable', ($is_downloadable == "yes") ? 'yes' : 'no' );
559
  $this->pushmeta($pid, '_virtual', ($is_virtual == "yes") ? 'yes' : 'no' );
560
 
561
  // Update post meta
562
+ $this->pushmeta($pid, '_regular_price', ($product_regular_price[$i] == "") ? '' : stripslashes( $product_regular_price[$i] ) );
563
+ $this->pushmeta($pid, '_sale_price', ($product_sale_price[$i] == "") ? '' : stripslashes( $product_sale_price[$i] ) );
564
  $this->pushmeta($pid, '_tax_status', stripslashes( $product_tax_status[$i] ) );
565
  $this->pushmeta($pid, '_tax_class', stripslashes( $product_tax_class[$i] ) );
566
  $this->pushmeta($pid, '_visibility', stripslashes( $product_visibility[$i] ) );
586
 
587
  // Save shipping class
588
  if ( pmwi_is_update_taxonomy($articleData, $this->options, 'product_shipping_class') ){
589
+
590
+ if (ctype_digit($product_shipping_class[$i])){
591
+
592
+ $p_shipping_class = $product_shipping_class[$i] > 0 && $product_type != 'external' ? absint( $product_shipping_class[$i] ) : '';
593
+
594
+ $t_shipping_class = get_term_by('slug', $p_shipping_class, 'product_shipping_class');
595
+
596
+ if ( ! empty($t_shipping_class) and ! is_wp_error($t_shipping_class) ) {
597
+
598
+ $p_shipping_class = (int) $t_shipping_class->term_taxonomy_id;
599
+
600
+ }
601
+ else{
602
+
603
+ $t_shipping_class = term_exists( (int) $product_shipping_class[$i], 'product_shipping_class', 0);
604
+
605
+ if ( ! is_wp_error($t_shipping_class) )
606
+ $p_shipping_class = (int) $t_shipping_class['term_taxonomy_id'];
607
+ }
608
+ }
609
+ else{
610
+
611
+ $t_shipping_class = term_exists($product_shipping_class[$i], 'product_shipping_class', 0);
612
+ if ( empty($t_shipping_class) and !is_wp_error($t_shipping_class) ){
613
+ $t_shipping_class = term_exists(htmlspecialchars(strtolower($product_shipping_class[$i])), 'product_shipping_class', 0);
614
+ }
615
+ if ( ! is_wp_error($t_shipping_class) )
616
+ $p_shipping_class = (int) $t_shipping_class['term_taxonomy_id'];
617
+ }
618
+
619
+ $this->associate_terms( $pid, array( $p_shipping_class ), 'product_shipping_class' );
620
+
621
+ //wp_set_object_terms( $pid, $p_shipping_class, 'product_shipping_class');
622
+
623
  }
624
 
625
  // Unique SKU
626
  $sku = ($is_new_product) ? '' : get_post_meta($pid, '_sku', true);
627
+ $new_sku = wc_clean( trim( stripslashes( $product_sku[$i] ) ) );
628
 
629
  if ( $new_sku == '' and $this->options['disable_auto_sku_generation'] ) {
630
  $this->pushmeta($pid, '_sku', '' );
665
 
666
  $is_variation_attributes_defined = false;
667
 
668
+ if ( $this->options['update_all_data'] == "yes" or ( $this->options['update_all_data'] == "no" and $this->options['is_update_attributes']) or $is_new_product){ // Update Product Attributes
669
 
670
  $is_update_attributes = true;
671
 
675
 
676
  $attr_names = array();
677
 
678
+ foreach ($serialized_attributes as $anum => $attr_data) { $attr_name = $attr_data['names'][$i];
679
+
680
+ // if ( in_array( $attr_name, $this->reserved_terms ) ) {
681
+ // $attr_name .= 's';
682
+ // }
683
 
684
  if (empty($attr_name) or in_array($attr_name, $attr_names)) continue;
685
 
686
+ $attr_names[] = $attr_name;
687
 
688
  $is_visible = intval( $attr_data['is_visible'][$i] );
689
  $is_variation = intval( $attr_data['in_variation'][$i] );
690
  $is_taxonomy = intval( $attr_data['in_taxonomy'][$i] );
691
 
692
+ if ( $is_variation and $attr_data['value'][$i] != "" ) {
693
+ $is_variation_attributes_defined = true;
694
+ }
695
+
696
  // Update only these Attributes, leave the rest alone
697
+ if ($this->options['update_all_data'] == "no" and $this->options['is_update_attributes'] and $this->options['update_attributes_logic'] == 'only'){
698
  if ( ! empty($this->options['attributes_list']) and is_array($this->options['attributes_list'])) {
699
  if ( ! in_array( ( ($is_taxonomy) ? wc_attribute_taxonomy_name( $attr_name ) : $attr_name ) , array_filter($this->options['attributes_list'], 'trim'))){
700
  $attribute_position++;
708
  }
709
 
710
  // Leave these attributes alone, update all other Attributes
711
+ if ($this->options['update_all_data'] == "no" and $this->options['is_update_attributes'] and $this->options['update_attributes_logic'] == 'all_except'){
712
  if ( ! empty($this->options['attributes_list']) and is_array($this->options['attributes_list'])) {
713
  if ( in_array( ( ($is_taxonomy) ? wc_attribute_taxonomy_name( $attr_name ) : $attr_name ) , array_filter($this->options['attributes_list'], 'trim'))){
714
  $attribute_position++;
779
 
780
  } else {
781
 
782
+ if ( taxonomy_exists( wc_attribute_taxonomy_name( $attr_name ) )){
783
+ //wp_set_object_terms( $pid, NULL, wc_attribute_taxonomy_name( $attr_name ) );
784
+ $this->associate_terms( $pid, NULL, wc_attribute_taxonomy_name( $attr_name ) );
785
+ }
786
 
787
  if (!empty($attr_data['value'][$i])){
788
 
797
  );
798
  }
799
 
800
+ }
 
 
 
 
801
 
802
  $attribute_position++;
803
  }
804
  }
805
 
806
+ if ($is_new_product or $is_update_attributes) {
807
 
808
  $current_product_attributes = get_post_meta($pid, '_product_attributes', true);
809
 
810
+ update_post_meta($pid, '_product_attributes', ( ! empty($current_product_attributes)) ? array_merge($current_product_attributes, $attributes) : $attributes );
811
  }
812
 
813
+ }else{
814
+
815
+ $is_variation_attributes_defined = true;
816
+
817
+ } // is update attributes
818
 
819
  // Sales and prices
820
  if ( ! in_array( $product_type, array( 'grouped' ) ) ) {
843
 
844
  // Update price if on sale
845
  if ( $product_sale_price[$i] != '' && $date_to == '' && $date_from == '' ){
846
+ $this->pushmeta($pid, '_price', (empty($product_sale_price[$i])) ? '' : stripslashes( $product_sale_price[$i] ));
847
  }
848
  else{
849
+ $this->pushmeta($pid, '_price', ($product_regular_price[$i] == "") ? '' : stripslashes( $product_regular_price[$i] ));
850
  }
851
 
852
  if ( $product_sale_price[$i] != '' && $date_from && strtotime( $date_from ) < strtotime( 'NOW', current_time( 'timestamp' ) ) ){
853
+ $this->pushmeta($pid, '_price', (empty($product_sale_price[$i])) ? '' : stripslashes( $product_sale_price[$i] ));
854
  }
855
 
856
  if ( $date_to && strtotime( $date_to ) < strtotime( 'NOW', current_time( 'timestamp' ) ) ) {
857
+ $this->pushmeta($pid, '_price', ($product_regular_price[$i] == "") ? '' : stripslashes( $product_regular_price[$i] ));
858
  $this->pushmeta($pid, '_sale_price_dates_from', '');
859
  $this->pushmeta($pid, '_sale_price_dates_to', '');
860
  }
935
  }
936
 
937
  // Stock Data
938
+ if ( 'yes' === get_option( 'woocommerce_manage_stock' ) ) {
939
 
940
+ $manage_stock = 'no';
941
+ $backorders = 'no';
942
+ $stock_status = wc_clean( $product_stock_status[$i] );
943
 
944
+ if ( 'external' === $product_type ) {
 
 
 
 
 
945
 
946
+ $stock_status = 'instock';
 
 
 
 
 
947
 
948
+ } elseif ( 'variable' === $product_type ) {
 
 
 
 
949
 
950
+ // Stock status is always determined by children so sync later
951
+ $stock_status = '';
952
+
953
+ if ( $product_manage_stock[$i] == 'yes' ) {
954
+ $manage_stock = 'yes';
955
+ $backorders = wc_clean( $product_allow_backorders[$i] );
956
  }
957
 
958
+ } elseif ( 'grouped' !== $product_type && $product_manage_stock[$i] == 'yes' ) {
959
+ $manage_stock = 'yes';
960
+ $backorders = wc_clean( $product_allow_backorders[$i] );
961
+ }
962
+
963
+ $this->pushmeta($pid, '_manage_stock', $manage_stock);
964
+ $this->pushmeta($pid, '_backorders', $backorders);
965
 
966
+ if ( $stock_status and $this->is_update_cf('_stock_status') ) {
967
+ update_post_meta( $pid, '_stock_status', $stock_status );
968
+ }
 
 
969
 
970
+ if ( $product_manage_stock[$i] == 'yes' ) {
971
+ $this->is_update_cf('_stock') and update_post_meta( $pid, '_stock', wc_stock_amount( $product_stock_qty[$i] ) );
972
+ } else {
973
+ $this->pushmeta($pid, '_stock', '');
974
  }
975
 
976
  } else {
977
+ update_post_meta( $pid, '_stock_status', wc_clean( $product_stock_status[$i] ) );
978
+ }
 
 
979
 
980
  // Upsells
981
  if ( !empty( $product_up_sells[$i] ) ) {
1066
  if ( isset( $product_download_type[$i] ) )
1067
  $this->pushmeta($pid, '_download_type', esc_attr( $product_download_type ));
1068
 
1069
+ }
1070
+
1071
+
1072
+ }
1073
+
1074
+ public function make_simple_product($post_parent){
1075
+
1076
+ // $children = get_posts( array(
1077
+ // 'post_parent' => $post_parent,
1078
+ // 'posts_per_page'=> -1,
1079
+ // 'post_type' => 'product_variation',
1080
+ // 'fields' => 'ids',
1081
+ // 'orderby' => 'ID',
1082
+ // 'order' => 'ASC',
1083
+ // 'post_status' => array('draft', 'publish', 'trash', 'pending', 'future', 'private')
1084
+ // ) );
1085
+
1086
+ // if (count($children)){
1087
+ // foreach ($children as $child) {
1088
+ // wp_delete_post($child);
1089
+ // }
1090
+ // }
1091
+
1092
+ //wp_set_object_terms( $post_parent, 'simple', 'product_type' );
1093
+
1094
+ $product_type_term = term_exists('simple', 'product_type', 0);
1095
+ if ( ! empty($product_type_term) and ! is_wp_error($product_type_term) ){
1096
+ $this->associate_terms( $post_parent, array( (int) $product_type_term['term_taxonomy_id'] ), 'product_type' );
1097
+ }
1098
+
1099
+ $this->pmwi_update_prices( $post_parent );
1100
+ }
1101
+
1102
+ public function wpai_gallery_image($pid, $attid, $image_filepath){
1103
+
1104
+ $table = $this->wpdb->posts;
1105
+
1106
+ $p = $this->wpdb->get_row($this->wpdb->prepare("SELECT * FROM $table WHERE ID = %d;", $pid));
1107
+
1108
+ if ($p and $p->post_parent){
1109
+
1110
+ $gallery = explode(",", get_post_meta($p->post_parent, '_product_image_gallery', true));
1111
+ if (is_array($gallery)){
1112
+ if ( ! in_array($attid, $gallery) ) $gallery[] = $attid;
1113
+ }
1114
+ else{
1115
+ $gallery = array($attid);
1116
+ }
1117
+
1118
+ update_post_meta($p->post_parent, '_product_image_gallery', implode(',', $gallery));
1119
+
1120
+ }
1121
 
 
 
 
1122
  }
1123
 
1124
  protected function executeSQL(){
1147
 
1148
  //$table = _get_meta_table( 'post' );
1149
 
1150
+ if ( empty($this->articleData['ID']) or $this->is_update_cf($meta_key)){
1151
 
1152
  update_post_meta($pid, $meta_key, $meta_value);
1153
 
1181
  */
1182
  protected function is_update_cf( $meta_key ){
1183
 
1184
+ if ( $this->options['update_all_data'] == 'yes') return true;
1185
 
1186
  if ( ! $this->options['is_update_custom_fields'] ) return false;
1187
 
1188
+ if ( $this->options['update_custom_fields_logic'] == "full_update" ) return true;
1189
+ if ( $this->options['update_custom_fields_logic'] == "only" and ! empty($this->options['custom_fields_list']) and is_array($this->options['custom_fields_list']) and in_array($meta_key, $this->options['custom_fields_list']) ) return true;
1190
+ if ( $this->options['update_custom_fields_logic'] == "all_except" and ( empty($this->options['custom_fields_list']) or ! in_array($meta_key, $this->options['custom_fields_list']) )) return true;
1191
 
1192
  return false;
1193
 
1198
  $terms = wp_get_object_terms( $pid, $tx_name );
1199
  $term_ids = array();
1200
 
1201
+ $assign_taxes = (is_array($assign_taxes)) ? array_filter($assign_taxes) : false;
1202
+
1203
  if ( ! empty($terms) ){
1204
  if ( ! is_wp_error( $terms ) ) {
1205
  foreach ($terms as $term_info) {
1211
  }
1212
  }
1213
 
1214
+ if (empty($assign_taxes)){
1215
+ //_wc_term_recount($terms, $tx_name, true, false);
1216
+ return;
1217
+ }
1218
 
1219
+ foreach ($assign_taxes as $tt) {
1220
  $this->wpdb->insert( $this->wpdb->term_relationships, array( 'object_id' => $pid, 'term_taxonomy_id' => $tt ) );
1221
  $this->wpdb->query( "UPDATE {$this->wpdb->term_taxonomy} SET count = count + 1 WHERE term_taxonomy_id = $tt" );
1222
+ delete_transient( 'wc_ln_count_' . md5( sanitize_key( $tx_name ) . sanitize_key( $tt ) ) );
1223
  }
1224
 
1225
  $values = array();
1226
  $term_order = 0;
1227
+ foreach ( $assign_taxes as $tt ){
1228
  $values[] = $this->wpdb->prepare( "(%d, %d, %d)", $pid, $tt, ++$term_order);
1229
+ }
1230
 
1231
 
1232
+ if ( $values ){
1233
  if ( false === $this->wpdb->query( "INSERT INTO {$this->wpdb->term_relationships} (object_id, term_taxonomy_id, term_order) VALUES " . join( ',', $values ) . " ON DUPLICATE KEY UPDATE term_order = VALUES(term_order)" ) ){
1234
+ $logger and call_user_func($logger, __('<b>ERROR</b> Could not insert term relationship into the database', 'pmxi_plugin') . ': '. $this->wpdb->last_error);
 
1235
  }
1236
+ }
1237
 
1238
  wp_cache_delete( $pid, $tx_name . '_relationships' );
1239
+
1240
+ //_wc_term_recount( $assign_taxes, $tx_name );
1241
  }
1242
 
1243
  protected function duplicate_post_meta( $new_id, $id ) {
1251
  $sql_query = "INSERT INTO $table (post_id, meta_key, meta_value) ";
1252
  foreach ($post_meta_infos as $meta_info) {
1253
  if ($this->is_update_cf($meta_info->meta_key)){
1254
+ update_post_meta($new_id, $meta_info->meta_key, $meta_info->meta_value);
1255
+ //$meta_key = $meta_info->meta_key;
1256
+ // $this->wpdb->query($this->wpdb->prepare("DELETE FROM $table WHERE `post_id` = $new_id AND `meta_key` = %s", $meta_key));
1257
+ // $meta_value = addslashes($meta_info->meta_value);
1258
+ // $sql_query_sel[]= "SELECT $new_id, '$meta_key', '$meta_value'";
1259
  }
1260
  }
1261
+ // if ( ! empty($sql_query_sel) ){
1262
+ // $sql_query.= implode(" UNION ALL ", $sql_query_sel);
1263
+ // $this->wpdb->query($sql_query);
1264
+ // }
1265
  }
1266
+
1267
  }
1268
 
1269
  function pmwi_buf_prices($pid){
1309
  $attribute_name = ( isset( $attr_name ) ) ? wc_sanitize_taxonomy_name( stripslashes( (string) $attr_name ) ) : '';
1310
  $attribute_label = ucwords( stripslashes( (string) $attr_name ));
1311
  $attribute_type = 'select';
1312
+ $attribute_orderby = 'menu_order';
1313
 
1314
+ // if ( in_array( $attribute_name, $this->reserved_terms ) ) {
1315
+ // $attribute_name .= 's';
1316
+ // }
 
 
 
 
 
 
 
1317
 
1318
+ if ( in_array( $attribute_name, $this->reserved_terms ) ) {
1319
  $logger and call_user_func($logger, sprintf(__('- <b>WARNING</b>: Slug “%s” is not allowed because it is a reserved term. Change it, please.', 'pmxi_plugin'), wc_attribute_taxonomy_name( $attribute_name )));
1320
  }
1321
+ else{
1322
+
1323
  // Register the taxonomy now so that the import works!
1324
  $domain = wc_attribute_taxonomy_name( $attr_name );
1325
  if (strlen($domain) <= 32){
1354
  }
1355
  else{
1356
  $logger and call_user_func($logger, sprintf(__('- <b>WARNING</b>: Taxonomy “%s” name is more than 32 characters. Change it, please.', 'pmxi_plugin'), $attr_name));
1357
+ }
 
1358
  }
 
1359
  }
1360
  }
1361
 
1408
 
1409
  if ( ! empty( $child->variation_id ) ) {
1410
  $available_variations[] = $child->get_variation_attributes();
1411
+
1412
+ update_post_meta( $child->variation_id, '_regular_price', get_post_meta( $post_id, '_regular_price', true ) );
1413
+ update_post_meta( $child->variation_id, '_sale_price', get_post_meta( $post_id, '_sale_price', true ) );
1414
+ if ( class_exists('woocommerce_wholesale_pricing') ) update_post_meta( $child->variation_id, 'pmxi_wholesale_price', get_post_meta( $post_id, 'pmxi_wholesale_price', true ) );
1415
+ update_post_meta( $child->variation_id, '_sale_price_dates_from', get_post_meta( $post_id, '_sale_price_dates_from', true ) );
1416
+ update_post_meta( $child->variation_id, '_sale_price_dates_to', get_post_meta( $post_id, '_sale_price_dates_to', true ) );
1417
+ update_post_meta( $child->variation_id, '_price', get_post_meta( $post_id, '_price', true ) );
1418
+ update_post_meta( $child->variation_id, '_stock', get_post_meta( $post_id, '_stock', true ) );
1419
+ update_post_meta( $child->variation_id, '_stock_status', get_post_meta( $post_id, '_stock_status', true ) );
1420
+ update_post_meta( $child->variation_id, '_manage_stock', get_post_meta( $post_id, '_manage_stock', true ) );
1421
+ update_post_meta( $child->variation_id, '_backorders', get_post_meta( $post_id, '_backorders', true ) );
1422
  }
1423
  }
1424
 
1442
  if ( in_array( $variation, $available_variations ) )
1443
  continue;
1444
 
1445
+ $variation_id = wp_insert_post( $variation_post_data );
1446
 
1447
  update_post_meta( $variation_id, '_regular_price', get_post_meta( $post_id, '_regular_price', true ) );
1448
  update_post_meta( $variation_id, '_sale_price', get_post_meta( $post_id, '_sale_price', true ) );
1449
  if ( class_exists('woocommerce_wholesale_pricing') ) update_post_meta( $variation_id, 'pmxi_wholesale_price', get_post_meta( $post_id, 'pmxi_wholesale_price', true ) );
1450
  update_post_meta( $variation_id, '_sale_price_dates_from', get_post_meta( $post_id, '_sale_price_dates_from', true ) );
1451
  update_post_meta( $variation_id, '_sale_price_dates_to', get_post_meta( $post_id, '_sale_price_dates_to', true ) );
1452
+ update_post_meta( $variation_id, '_price', get_post_meta( $post_id, '_price', true ) );
1453
+ update_post_meta( $variation_id, '_stock', get_post_meta( $post_id, '_stock', true ) );
1454
+ update_post_meta( $variation_id, '_stock_status', get_post_meta( $post_id, '_stock_status', true ) );
1455
+ update_post_meta( $variation_id, '_manage_stock', get_post_meta( $post_id, '_manage_stock', true ) );
1456
+ update_post_meta( $variation_id, '_backorders', get_post_meta( $post_id, '_backorders', true ) );
1457
+
1458
 
1459
  $variation_ids[] = $variation_id;
1460
 
plugin.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: WP All Import - WooCommerce Add-On
4
  Plugin URI: http://www.wpallimport.com/
5
  Description: An extremely easy, drag & drop importer to import WooCommerce simple products. A paid upgrade is available for premium support and support for Variable, Grouped, and External/Affiliate products
6
- Version: 1.2.1
7
  Author: Soflyy
8
  */
9
  /**
@@ -24,7 +24,7 @@ define('PMWI_ROOT_URL', rtrim(plugin_dir_url(__FILE__), '/'));
24
  */
25
  define('PMWI_PREFIX', 'pmwi_');
26
 
27
- define('PMWI_FREE_VERSION', '1.2.1');
28
 
29
  define('PMWI_EDITION', 'free');
30
 
@@ -273,33 +273,43 @@ final class PMWI_Plugin {
273
  $controllerName = preg_replace('%(^' . preg_quote(self::PREFIX, '%') . '|_).%e', 'strtoupper("$0")', str_replace('-', '_', $page)); // capitalize prefix and first letters of class name parts
274
  $actionName = str_replace('-', '_', $action);
275
  if (method_exists($controllerName, $actionName)) {
276
- $this->_admin_current_screen = (object)array(
277
- 'id' => $controllerName,
278
- 'base' => $controllerName,
279
- 'action' => $actionName,
280
- 'is_ajax' => isset($_SERVER['HTTP_X_REQUESTED_WITH']) and strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest',
281
- 'is_network' => is_network_admin(),
282
- 'is_user' => is_user_admin(),
283
- );
284
- add_filter('current_screen', array($this, 'getAdminCurrentScreen'));
285
- add_filter('admin_body_class', create_function('', 'return "' . PMWI_Plugin::PREFIX . 'plugin";'));
286
-
287
- $controller = new $controllerName();
288
- if ( ! $controller instanceof PMWI_Controller_Admin) {
289
- throw new Exception("Administration page `$page` matches to a wrong controller type.");
290
- }
291
 
292
- if ($this->_admin_current_screen->is_ajax) { // ajax request
293
- $controller->$action();
294
- do_action('PMWI_action_after');
295
- die(); // stop processing since we want to output only what controller is randered, nothing in addition
296
- } elseif ( ! $controller->isInline) {
297
- ob_start();
298
- $controller->$action();
299
- $buffer = ob_get_clean();
300
  } else {
301
- $buffer_callback = array($controller, $action);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
302
  }
 
303
  } else { // redirect to dashboard if requested page and/or action don't exist
304
  wp_redirect(admin_url()); die();
305
  }
@@ -554,6 +564,7 @@ final class PMWI_Plugin {
554
  'variable_whosale_price_use_parent' => 0,
555
  'disable_auto_sku_generation' => 0,
556
  'is_default_attributes' => 0,
 
557
  'disable_sku_matching' => 1,
558
  'disable_prepare_price' => 1,
559
  'prepare_price_to_woo_format' => 0,
@@ -573,7 +584,14 @@ final class PMWI_Plugin {
573
  'update_attributes_logic' => 'full_update',
574
  'attributes_list' => array(),
575
  'attributes_only_list' => array(),
576
- 'attributes_except_list' => array()
 
 
 
 
 
 
 
577
  );
578
  }
579
  }
3
  Plugin Name: WP All Import - WooCommerce Add-On
4
  Plugin URI: http://www.wpallimport.com/
5
  Description: An extremely easy, drag & drop importer to import WooCommerce simple products. A paid upgrade is available for premium support and support for Variable, Grouped, and External/Affiliate products
6
+ Version: 1.2.2
7
  Author: Soflyy
8
  */
9
  /**
24
  */
25
  define('PMWI_PREFIX', 'pmwi_');
26
 
27
+ define('PMWI_FREE_VERSION', '1.2.2');
28
 
29
  define('PMWI_EDITION', 'free');
30
 
273
  $controllerName = preg_replace('%(^' . preg_quote(self::PREFIX, '%') . '|_).%e', 'strtoupper("$0")', str_replace('-', '_', $page)); // capitalize prefix and first letters of class name parts
274
  $actionName = str_replace('-', '_', $action);
275
  if (method_exists($controllerName, $actionName)) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
276
 
277
+ if ( ! get_current_user_id() or ! current_user_can('manage_options')) {
278
+ // This nonce is not valid.
279
+ die( 'Security check' );
280
+
 
 
 
 
281
  } else {
282
+
283
+ $this->_admin_current_screen = (object)array(
284
+ 'id' => $controllerName,
285
+ 'base' => $controllerName,
286
+ 'action' => $actionName,
287
+ 'is_ajax' => isset($_SERVER['HTTP_X_REQUESTED_WITH']) and strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest',
288
+ 'is_network' => is_network_admin(),
289
+ 'is_user' => is_user_admin(),
290
+ );
291
+ add_filter('current_screen', array($this, 'getAdminCurrentScreen'));
292
+ add_filter('admin_body_class', create_function('', 'return "' . PMWI_Plugin::PREFIX . 'plugin";'));
293
+
294
+ $controller = new $controllerName();
295
+ if ( ! $controller instanceof PMWI_Controller_Admin) {
296
+ throw new Exception("Administration page `$page` matches to a wrong controller type.");
297
+ }
298
+
299
+ if ($this->_admin_current_screen->is_ajax) { // ajax request
300
+ $controller->$action();
301
+ do_action('PMWI_action_after');
302
+ die(); // stop processing since we want to output only what controller is randered, nothing in addition
303
+ } elseif ( ! $controller->isInline) {
304
+ ob_start();
305
+ $controller->$action();
306
+ $buffer = ob_get_clean();
307
+ } else {
308
+ $buffer_callback = array($controller, $action);
309
+ }
310
+
311
  }
312
+
313
  } else { // redirect to dashboard if requested page and/or action don't exist
314
  wp_redirect(admin_url()); die();
315
  }
564
  'variable_whosale_price_use_parent' => 0,
565
  'disable_auto_sku_generation' => 0,
566
  'is_default_attributes' => 0,
567
+ 'default_attributes_type' => 'first',
568
  'disable_sku_matching' => 1,
569
  'disable_prepare_price' => 1,
570
  'prepare_price_to_woo_format' => 0,
584
  'update_attributes_logic' => 'full_update',
585
  'attributes_list' => array(),
586
  'attributes_only_list' => array(),
587
+ 'attributes_except_list' => array(),
588
+
589
+ 'is_variation_product_manage_stock' => 'no',
590
+ 'single_variation_product_manage_stock' => '',
591
+ 'variation_stock' => '',
592
+ 'variation_stock_status' => 'auto',
593
+ 'put_variation_image_to_gallery' => 0,
594
+ 'single_variation_stock_status' => ''
595
  );
596
  }
597
  }
readme.txt CHANGED
@@ -1,8 +1,8 @@
1
  === Import Products from any XML or CSV to WooCommerce ===
2
  Contributors: soflyy, wpallimport
3
  Requires at least: 3.5
4
- Tested up to: 4.1
5
- Stable tag: 1.2.1
6
  License: GPLv2 or later
7
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
8
  Tags: woocommerce xml import, woocommerce csv import, woocommerce, import, xml, csv, wp all import, csv import, import csv, xml import, import xml, woocommerce csv importer, woocommerce xml importer, csv importer, csv import suite
@@ -83,6 +83,10 @@ The WooCommerce add-on will appear in the Step 4 of WP All Import.
83
 
84
  == Changelog ==
85
 
 
 
 
 
86
  = 1.2.1 =
87
  * fixed css styles
88
  * added compatibility with woocommerce 2.3
1
  === Import Products from any XML or CSV to WooCommerce ===
2
  Contributors: soflyy, wpallimport
3
  Requires at least: 3.5
4
+ Tested up to: 4.2.2
5
+ Stable tag: 1.2.2
6
  License: GPLv2 or later
7
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
8
  Tags: woocommerce xml import, woocommerce csv import, woocommerce, import, xml, csv, wp all import, csv import, import csv, xml import, import xml, woocommerce csv importer, woocommerce xml importer, csv importer, csv import suite
83
 
84
  == Changelog ==
85
 
86
+ = 1.2.2 =
87
+ * fixed import stock status for negative qty
88
+ * fixed import shipping class when their slugs presented as numeric values
89
+
90
  = 1.2.1 =
91
  * fixed css styles
92
  * added compatibility with woocommerce 2.3
views/admin/import/_tabs/_attributes.php CHANGED
@@ -116,7 +116,7 @@
116
  </table>
117
  </div>
118
  <div class="options_group show_if_variable">
119
- <p class="form-field wpallimport-radio-field" style="padding-left: 0 !important;">
120
  <input type="hidden" name="link_all_variations" value="0" />
121
  <input type="checkbox" id="link_all_variations" name="link_all_variations" value="1" <?php echo $post['link_all_variations'] ? 'checked="checked"' : '' ?>/>
122
  <label style="width: 100px;" for="link_all_variations"><?php _e('Link all variations', 'pmxi_plugin') ?></label>
116
  </table>
117
  </div>
118
  <div class="options_group show_if_variable">
119
+ <p class="form-field wpallimport-radio-field" style="padding-left: 10px !important;">
120
  <input type="hidden" name="link_all_variations" value="0" />
121
  <input type="checkbox" id="link_all_variations" name="link_all_variations" value="1" <?php echo $post['link_all_variations'] ? 'checked="checked"' : '' ?>/>
122
  <label style="width: 100px;" for="link_all_variations"><?php _e('Link all variations', 'pmxi_plugin') ?></label>
views/admin/import/_tabs/_shipping.php CHANGED
@@ -24,15 +24,14 @@
24
  <div class="switcher-target-multiple_product_shipping_class_yes set_with_xpath">
25
  <span class="wpallimport-slide-content" style="padding-left:0;">
26
  <?php
27
- $classes = get_the_terms( 0, 'product_shipping_class' );
28
-
29
  $args = array(
30
  'taxonomy' => 'product_shipping_class',
31
  'hide_empty' => 0,
32
  'show_option_none' => __( 'No shipping class', 'woocommerce' ),
33
  'name' => 'multiple_product_shipping_class',
34
  'id' => 'multiple_product_shipping_class',
35
- 'selected' => ( ! empty($post['multiple_product_shipping_class']) ) ? $post['multiple_product_shipping_class'] : '',
36
  'class' => 'select short'
37
  );
38
 
24
  <div class="switcher-target-multiple_product_shipping_class_yes set_with_xpath">
25
  <span class="wpallimport-slide-content" style="padding-left:0;">
26
  <?php
27
+
 
28
  $args = array(
29
  'taxonomy' => 'product_shipping_class',
30
  'hide_empty' => 0,
31
  'show_option_none' => __( 'No shipping class', 'woocommerce' ),
32
  'name' => 'multiple_product_shipping_class',
33
  'id' => 'multiple_product_shipping_class',
34
+ 'selected' => ( ! empty($post['multiple_product_shipping_class']) and $post['multiple_product_shipping_class'] > 0 ) ? $post['multiple_product_shipping_class'] : '',
35
  'class' => 'select short'
36
  );
37