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

Version Description

  • fixed import total_sales
Download this release

Release Info

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

Code changes from version 1.2.2 to 1.2.3

Files changed (3) hide show
  1. models/import/record.php +51 -228
  2. plugin.php +2 -2
  3. readme.txt +6 -3
models/import/record.php CHANGED
@@ -527,7 +527,7 @@ class PMWI_Import_Record extends PMWI_Model_Record {
527
  $is_new_product = empty($articleData['ID']);
528
 
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);
@@ -540,7 +540,10 @@ class PMWI_Import_Record extends PMWI_Model_Record {
540
  $this->post_meta_to_update = array(); // for bulk UPDATE SQL query
541
  $this->post_meta_to_insert = array(); // for bulk INSERT SQL query
542
  $this->articleData = $articleData;
543
- $this->pushmeta($pid, 'total_sales', '0');
 
 
 
544
 
545
  $is_downloadable = $product_downloadable[$i];
546
  $is_virtual = $product_virtual[$i];
@@ -683,7 +686,7 @@ class PMWI_Import_Record extends PMWI_Model_Record {
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] );
@@ -732,20 +735,28 @@ class PMWI_Import_Record extends PMWI_Model_Record {
732
 
733
  $attr_values = array();
734
 
735
- foreach ($values as $key => $value) {
736
-
737
- $term = term_exists($value, wc_attribute_taxonomy_name( $attr_name ), 0);
738
-
739
- if ( empty($term) and !is_wp_error($term) ){
740
- $term = term_exists(htmlspecialchars($value), wc_attribute_taxonomy_name( $attr_name ), 0);
741
- if ( empty($term) and !is_wp_error($term) and intval($attr_data['is_create_taxonomy_terms'][$i])){
742
-
743
- $term = wp_insert_term(
744
- $value, // the term
745
- wc_attribute_taxonomy_name( $attr_name ) // the taxonomy
746
- );
 
 
 
 
 
 
 
747
  }
748
  }
 
749
  if ( ! is_wp_error($term) )
750
  $attr_values[] = (int) $term['term_taxonomy_id'];
751
 
@@ -842,10 +853,24 @@ class PMWI_Import_Record extends PMWI_Model_Record {
842
  }
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
 
@@ -889,43 +914,7 @@ class PMWI_Import_Record extends PMWI_Model_Record {
889
  $this->wpdb->update( $this->wpdb->posts, array('post_parent' => absint( $product_grouping_parent[$i] ) ), array('ID' => $pid));
890
 
891
  }
892
- }
893
-
894
- // Update parent if grouped so price sorting works and stays in sync with the cheapest child
895
- if ( $product_type == 'grouped' || ( "" != $product_grouping_parent[$i] and absint($product_grouping_parent[$i]) > 0)) {
896
-
897
- $clear_parent_ids = array();
898
-
899
- if ( $product_type == 'grouped' )
900
- $clear_parent_ids[] = $pid;
901
-
902
- if ( "" != $product_grouping_parent[$i] and absint($product_grouping_parent[$i]) > 0 )
903
- $clear_parent_ids[] = absint( $product_grouping_parent[$i] );
904
-
905
- if ( $clear_parent_ids ) {
906
- foreach( $clear_parent_ids as $clear_id ) {
907
-
908
- $children_by_price = get_posts( array(
909
- 'post_parent' => $clear_id,
910
- 'orderby' => 'meta_value_num',
911
- 'order' => 'asc',
912
- 'meta_key' => '_price',
913
- 'posts_per_page'=> 1,
914
- 'post_type' => 'product',
915
- 'fields' => 'ids'
916
- ) );
917
- if ( $children_by_price ) {
918
- foreach ( $children_by_price as $child ) {
919
- $child_price = get_post_meta( $child, '_price', true );
920
- update_post_meta( $clear_id, '_price', $child_price );
921
- }
922
- }
923
-
924
- // Clear cache/transients
925
- //wc_delete_product_transients( $clear_id );
926
- }
927
- }
928
- }
929
 
930
  // Sold Individuall
931
  if ( "yes" == $product_sold_individually[$i] ) {
@@ -1066,9 +1055,13 @@ class PMWI_Import_Record extends PMWI_Model_Record {
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){
@@ -1229,7 +1222,7 @@ class PMWI_Import_Record extends PMWI_Model_Record {
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
  }
@@ -1357,177 +1350,7 @@ class PMWI_Import_Record extends PMWI_Model_Record {
1357
  }
1358
  }
1359
  }
1360
- }
1361
-
1362
- function pmwi_link_all_variations($product_id, $options = array()) {
1363
-
1364
- global $woocommerce;
1365
-
1366
- @set_time_limit(0);
1367
-
1368
- $post_id = intval( $product_id );
1369
-
1370
- if ( ! $post_id ) return 0;
1371
-
1372
- $variations = array();
1373
-
1374
- $_product = get_product( $post_id, array( 'product_type' => 'variable' ) );
1375
-
1376
- $v = $_product->get_attributes();
1377
-
1378
- // Put variation attributes into an array
1379
- foreach ( $_product->get_attributes() as $attribute ) {
1380
-
1381
- if ( ! $attribute['is_variation'] ) continue;
1382
-
1383
- $attribute_field_name = 'attribute_' . sanitize_title( $attribute['name'] );
1384
-
1385
- if ( $attribute['is_taxonomy'] ) {
1386
- $post_terms = wp_get_post_terms( $post_id, $attribute['name'] );
1387
- $options = array();
1388
- foreach ( $post_terms as $term ) {
1389
- $options[] = $term->slug;
1390
- }
1391
- } else {
1392
- $options = explode( '|', $attribute['value'] );
1393
- }
1394
-
1395
- $options = array_map( 'sanitize_title', array_map( 'trim', $options ) );
1396
-
1397
- $variations[ $attribute_field_name ] = $options;
1398
- }
1399
-
1400
- // Quit out if none were found
1401
- if ( sizeof( $variations ) == 0 ) return 0;
1402
-
1403
- // Get existing variations so we don't create duplicates
1404
- $available_variations = array();
1405
-
1406
- foreach( $_product->get_children() as $child_id ) {
1407
- $child = $_product->get_child( $child_id );
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
-
1425
- // Created posts will all have the following data
1426
- $variation_post_data = array(
1427
- 'post_title' => 'Product #' . $post_id . ' Variation',
1428
- 'post_content' => '',
1429
- 'post_status' => 'publish',
1430
- 'post_author' => get_current_user_id(),
1431
- 'post_parent' => $post_id,
1432
- 'post_type' => 'product_variation'
1433
- );
1434
-
1435
- $variation_ids = array();
1436
- $added = 0;
1437
- $possible_variations = $this->array_cartesian( $variations );
1438
-
1439
- foreach ( $possible_variations as $variation ) {
1440
-
1441
- // Check if variation already exists
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
-
1461
- foreach ( $variation as $key => $value ) {
1462
- update_post_meta( $variation_id, $key, $value );
1463
- }
1464
-
1465
- $added++;
1466
-
1467
- //do_action( 'product_variation_linked', $variation_id );
1468
-
1469
- }
1470
-
1471
- wc_delete_product_transients( $post_id );
1472
-
1473
- return $added;
1474
- }
1475
-
1476
-
1477
- function array_cartesian( $input ) {
1478
-
1479
- $result = array();
1480
-
1481
- while ( list( $key, $values ) = each( $input ) ) {
1482
- // If a sub-array is empty, it doesn't affect the cartesian product
1483
- if ( empty( $values ) ) {
1484
- continue;
1485
- }
1486
-
1487
- // Special case: seeding the product array with the values from the first sub-array
1488
- if ( empty( $result ) ) {
1489
- foreach ( $values as $value ) {
1490
- $result[] = array( $key => $value );
1491
- }
1492
- }
1493
- else {
1494
- // Second and subsequent input sub-arrays work like this:
1495
- // 1. In each existing array inside $product, add an item with
1496
- // key == $key and value == first item in input sub-array
1497
- // 2. Then, for each remaining item in current input sub-array,
1498
- // add a copy of each existing array inside $product with
1499
- // key == $key and value == first item in current input sub-array
1500
-
1501
- // Store all items to be added to $product here; adding them on the spot
1502
- // inside the foreach will result in an infinite loop
1503
- $append = array();
1504
- foreach( $result as &$product ) {
1505
- // Do step 1 above. array_shift is not the most efficient, but it
1506
- // allows us to iterate over the rest of the items with a simple
1507
- // foreach, making the code short and familiar.
1508
- $product[ $key ] = array_shift( $values );
1509
-
1510
- // $product is by reference (that's why the key we added above
1511
- // will appear in the end result), so make a copy of it here
1512
- $copy = $product;
1513
-
1514
- // Do step 2 above.
1515
- foreach( $values as $item ) {
1516
- $copy[ $key ] = $item;
1517
- $append[] = $copy;
1518
- }
1519
-
1520
- // Undo the side effecst of array_shift
1521
- array_unshift( $values, $product[ $key ] );
1522
- }
1523
-
1524
- // Out of the foreach, we can add to $results now
1525
- $result = array_merge( $result, $append );
1526
- }
1527
- }
1528
-
1529
- return $result;
1530
- }
1531
 
1532
  public function _filter_has_cap_unfiltered_html($caps)
1533
  {
527
  $is_new_product = empty($articleData['ID']);
528
 
529
  // Get types
530
+ $product_type = 'simple';
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);
540
  $this->post_meta_to_update = array(); // for bulk UPDATE SQL query
541
  $this->post_meta_to_insert = array(); // for bulk INSERT SQL query
542
  $this->articleData = $articleData;
543
+
544
+ $total_sales = get_post_meta($pid, 'total_sales', true);
545
+
546
+ if ( empty($total_sales)) update_post_meta($pid, 'total_sales', '0');
547
 
548
  $is_downloadable = $product_downloadable[$i];
549
  $is_virtual = $product_virtual[$i];
686
 
687
  if (empty($attr_name) or in_array($attr_name, $attr_names)) continue;
688
 
689
+ $attr_names[] = $attr_name;
690
 
691
  $is_visible = intval( $attr_data['is_visible'][$i] );
692
  $is_variation = intval( $attr_data['in_variation'][$i] );
735
 
736
  $attr_values = array();
737
 
738
+ foreach ($values as $key => $val) {
739
+
740
+ $value = substr($val, 0, 199);
741
+
742
+ $term = get_term_by('name', $value, wc_attribute_taxonomy_name( $attr_name ), ARRAY_A);
743
+
744
+ if ( empty($term) and !is_wp_error($term) ){
745
+
746
+ $term = term_exists($value, wc_attribute_taxonomy_name( $attr_name ));
747
+
748
+ if ( empty($term) and !is_wp_error($term) ){
749
+ $term = term_exists(htmlspecialchars($value), wc_attribute_taxonomy_name( $attr_name ));
750
+ if ( empty($term) and !is_wp_error($term) and intval($attr_data['is_create_taxonomy_terms'][$i])){
751
+
752
+ $term = wp_insert_term(
753
+ $value, // the term
754
+ wc_attribute_taxonomy_name( $attr_name ) // the taxonomy
755
+ );
756
+ }
757
  }
758
  }
759
+
760
  if ( ! is_wp_error($term) )
761
  $attr_values[] = (int) $term['term_taxonomy_id'];
762
 
853
  }
854
 
855
  // Update price if on sale
856
+
857
+ if ( $product_sale_price[$i] == '' ){
858
+
859
+ if ( ! empty($this->articleData['ID']) and ! $this->is_update_cf('_sale_price') )
860
+ {
861
+ $product_sale_price[$i] = get_post_meta($pid, '_sale_price', true);
862
+
863
+ }
864
+
865
+ }
866
+
867
+ if ( $product_sale_price[$i] != '' && $date_to == '' && $date_from == '' ){
868
+
869
  $this->pushmeta($pid, '_price', (empty($product_sale_price[$i])) ? '' : stripslashes( $product_sale_price[$i] ));
870
+
871
  }
872
+ else{
873
+
874
  $this->pushmeta($pid, '_price', ($product_regular_price[$i] == "") ? '' : stripslashes( $product_regular_price[$i] ));
875
  }
876
 
914
  $this->wpdb->update( $this->wpdb->posts, array('post_parent' => absint( $product_grouping_parent[$i] ) ), array('ID' => $pid));
915
 
916
  }
917
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
918
 
919
  // Sold Individuall
920
  if ( "yes" == $product_sold_individually[$i] ) {
1055
  if ( isset( $product_download_type[$i] ) )
1056
  $this->pushmeta($pid, '_download_type', esc_attr( $product_download_type ));
1057
 
1058
+ }
1059
 
1060
+ // prepare bulk SQL query
1061
+ //$this->executeSQL();
1062
+
1063
+ wc_delete_product_transients($pid);
1064
+
1065
  }
1066
 
1067
  public function make_simple_product($post_parent){
1222
  }
1223
 
1224
 
1225
+ if ( $values ){
1226
  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)" ) ){
1227
  $logger and call_user_func($logger, __('<b>ERROR</b> Could not insert term relationship into the database', 'pmxi_plugin') . ': '. $this->wpdb->last_error);
1228
  }
1350
  }
1351
  }
1352
  }
1353
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1354
 
1355
  public function _filter_has_cap_unfiltered_html($caps)
1356
  {
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.2
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.2');
28
 
29
  define('PMWI_EDITION', 'free');
30
 
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.3
7
  Author: Soflyy
8
  */
9
  /**
24
  */
25
  define('PMWI_PREFIX', 'pmwi_');
26
 
27
+ define('PMWI_FREE_VERSION', '1.2.3');
28
 
29
  define('PMWI_EDITION', 'free');
30
 
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.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,6 +83,9 @@ The WooCommerce add-on will appear in the Step 4 of WP All Import.
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
1
  === Import Products from any XML or CSV to WooCommerce ===
2
  Contributors: soflyy, wpallimport
3
+ Requires at least: 4.1
4
+ Tested up to: 4.3
5
+ Stable tag: 1.2.3
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.3 =
87
+ * fixed import total_sales
88
+
89
  = 1.2.2 =
90
  * fixed import stock status for negative qty
91
  * fixed import shipping class when their slugs presented as numeric values