Product Import Export for WooCommerce - Version 1.2.2

Version Description

  • Minor content change.
Download this release

Release Info

Developer hikeforce
Plugin Icon 128x128 Product Import Export for WooCommerce
Version 1.2.2
Comparing to
See all releases

Code changes from version 1.2.1 to 1.2.2

Files changed (31) hide show
  1. images/Import-Export-for-WooCommerce-Product-Image.png +0 -0
  2. images/wf-ajax-loader.gif +0 -0
  3. images/wf-failed.png +0 -0
  4. images/wf-import.png +0 -0
  5. images/wf-notice.png +0 -0
  6. images/wf-success.png +0 -0
  7. includes/class-wf-prodimpexpcsv-admin-screen.php +80 -80
  8. includes/class-wf-prodimpexpcsv-ajax-handler.php +68 -68
  9. includes/class-wf-prodimpexpcsv-system-status-tools.php +102 -102
  10. includes/exporter/class-wf-prodimpexpcsv-exporter.php +527 -527
  11. includes/exporter/data/data-wf-hidden-meta-columns.php +19 -19
  12. includes/exporter/data/data-wf-post-columns.php +50 -50
  13. includes/importer/class-wf-csv-parser.php +848 -848
  14. includes/importer/class-wf-prodimpexpcsv-importer.php +40 -40
  15. includes/importer/class-wf-prodimpexpcsv-product-import.php +1476 -1476
  16. includes/importer/data/data-wf-post-defaults.php +21 -21
  17. includes/importer/data/data-wf-postmeta-allowed.php +15 -15
  18. includes/importer/data/data-wf-postmeta-defaults.php +43 -43
  19. includes/importer/data/data-wf-reserved-fields-pair.php +51 -51
  20. includes/importer/data/data-wf-reserved-fields.php +59 -59
  21. includes/importer/views/html-wf-import-greeting.php +54 -54
  22. includes/importer/views/html-wf-import-options.php +114 -114
  23. includes/settings/class-wf-prodimpexpcsv-settings.php +20 -20
  24. includes/views/export/html-wf-export-products.php +73 -73
  25. includes/views/html-wf-admin-screen.php +18 -16
  26. includes/views/import/html-wf-import-products.php +22 -54
  27. includes/views/market.php +95 -0
  28. license.txt +707 -707
  29. product-csv-import-export.php +130 -130
  30. readme.txt +185 -180
  31. styles/wf-style.css +112 -112
images/Import-Export-for-WooCommerce-Product-Image.png ADDED
Binary file
images/wf-ajax-loader.gif CHANGED
File without changes
images/wf-failed.png CHANGED
File without changes
images/wf-import.png CHANGED
File without changes
images/wf-notice.png CHANGED
File without changes
images/wf-success.png CHANGED
File without changes
includes/class-wf-prodimpexpcsv-admin-screen.php CHANGED
@@ -1,81 +1,81 @@
1
- <?php
2
- if ( ! defined( 'ABSPATH' ) ) {
3
- exit;
4
- }
5
-
6
- class WF_ProdImpExpCsv_Admin_Screen {
7
-
8
- /**
9
- * Constructor
10
- */
11
- public function __construct() {
12
- add_action( 'admin_menu', array( $this, 'admin_menu' ) );
13
- add_action( 'admin_print_styles', array( $this, 'admin_scripts' ) );
14
- add_action( 'admin_notices', array( $this, 'admin_notices' ) );
15
- }
16
-
17
- /**
18
- * Notices in admin
19
- */
20
- public function admin_notices() {
21
- if ( ! function_exists( 'mb_detect_encoding' ) ) {
22
- echo '<div class="error"><p>' . __( 'Product CSV Import Export requires the function <code>mb_detect_encoding</code> to import and export CSV files. Please ask your hosting provider to enable this function.', 'wf_csv_import_export' ) . '</p></div>';
23
- }
24
- }
25
-
26
- /**
27
- * Admin Menu
28
- */
29
- public function admin_menu() {
30
- $page = add_submenu_page( 'woocommerce', __( 'Product Im-Ex', 'wf_csv_import_export' ), __( 'Product Im-Ex', 'wf_csv_import_export' ), apply_filters( 'woocommerce_csv_product_role', 'manage_woocommerce' ), 'wf_woocommerce_csv_im_ex', array( $this, 'output' ) );
31
- }
32
-
33
- /**
34
- * Admin Scripts
35
- */
36
- public function admin_scripts() {
37
- wp_enqueue_style( 'woocommerce_admin_styles', WC()->plugin_url() . '/assets/css/admin.css' );
38
- wp_enqueue_style( 'woocommerce-product-csv-importer', plugins_url( basename( plugin_dir_path( WF_ProdImpExpCsv_FILE ) ) . '/styles/wf-style.css', basename( __FILE__ ) ), '', '1.0.0', 'screen' );
39
- }
40
-
41
- /**
42
- * Admin Screen output
43
- */
44
- public function output() {
45
- $tab = 'import';
46
- if( ! empty( $_GET['tab'] ) ) {
47
- if( $_GET['tab'] == 'export' ) {
48
- $tab = 'export';
49
- }
50
- else if ( $_GET['tab'] == 'settings' ) {
51
- $tab = 'settings';
52
- }
53
- }
54
- include( 'views/html-wf-admin-screen.php' );
55
- }
56
-
57
- /**
58
- * Admin page for importing
59
- */
60
- public function admin_import_page() {
61
- include( 'views/import/html-wf-import-products.php' );
62
- $post_columns = include( 'exporter/data/data-wf-post-columns.php' );
63
- include( 'views/export/html-wf-export-products.php' );
64
- }
65
-
66
- /**
67
- * Admin Page for exporting
68
- */
69
- public function admin_export_page() {
70
- $post_columns = include( 'exporter/data/data-wf-post-columns.php' );
71
- include( 'views/export/html-wf-export-products.php' );
72
- }
73
-
74
- /**
75
- * Admin Page for settings
76
- */
77
- public function admin_settings_page() {
78
- }
79
- }
80
-
81
  new WF_ProdImpExpCsv_Admin_Screen();
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ class WF_ProdImpExpCsv_Admin_Screen {
7
+
8
+ /**
9
+ * Constructor
10
+ */
11
+ public function __construct() {
12
+ add_action( 'admin_menu', array( $this, 'admin_menu' ) );
13
+ add_action( 'admin_print_styles', array( $this, 'admin_scripts' ) );
14
+ add_action( 'admin_notices', array( $this, 'admin_notices' ) );
15
+ }
16
+
17
+ /**
18
+ * Notices in admin
19
+ */
20
+ public function admin_notices() {
21
+ if ( ! function_exists( 'mb_detect_encoding' ) ) {
22
+ echo '<div class="error"><p>' . __( 'Product CSV Import Export requires the function <code>mb_detect_encoding</code> to import and export CSV files. Please ask your hosting provider to enable this function.', 'wf_csv_import_export' ) . '</p></div>';
23
+ }
24
+ }
25
+
26
+ /**
27
+ * Admin Menu
28
+ */
29
+ public function admin_menu() {
30
+ $page = add_submenu_page( 'woocommerce', __( 'Product Im-Ex', 'wf_csv_import_export' ), __( 'Product Im-Ex', 'wf_csv_import_export' ), apply_filters( 'woocommerce_csv_product_role', 'manage_woocommerce' ), 'wf_woocommerce_csv_im_ex', array( $this, 'output' ) );
31
+ }
32
+
33
+ /**
34
+ * Admin Scripts
35
+ */
36
+ public function admin_scripts() {
37
+ wp_enqueue_style( 'woocommerce_admin_styles', WC()->plugin_url() . '/assets/css/admin.css' );
38
+ wp_enqueue_style( 'woocommerce-product-csv-importer', plugins_url( basename( plugin_dir_path( WF_ProdImpExpCsv_FILE ) ) . '/styles/wf-style.css', basename( __FILE__ ) ), '', '1.0.0', 'screen' );
39
+ }
40
+
41
+ /**
42
+ * Admin Screen output
43
+ */
44
+ public function output() {
45
+ $tab = 'import';
46
+ if( ! empty( $_GET['tab'] ) ) {
47
+ if( $_GET['tab'] == 'export' ) {
48
+ $tab = 'export';
49
+ }
50
+ else if ( $_GET['tab'] == 'settings' ) {
51
+ $tab = 'settings';
52
+ }
53
+ }
54
+ include( 'views/html-wf-admin-screen.php' );
55
+ }
56
+
57
+ /**
58
+ * Admin page for importing
59
+ */
60
+ public function admin_import_page() {
61
+ include( 'views/import/html-wf-import-products.php' );
62
+ $post_columns = include( 'exporter/data/data-wf-post-columns.php' );
63
+ include( 'views/export/html-wf-export-products.php' );
64
+ }
65
+
66
+ /**
67
+ * Admin Page for exporting
68
+ */
69
+ public function admin_export_page() {
70
+ $post_columns = include( 'exporter/data/data-wf-post-columns.php' );
71
+ include( 'views/export/html-wf-export-products.php' );
72
+ }
73
+
74
+ /**
75
+ * Admin Page for settings
76
+ */
77
+ public function admin_settings_page() {
78
+ }
79
+ }
80
+
81
  new WF_ProdImpExpCsv_Admin_Screen();
includes/class-wf-prodimpexpcsv-ajax-handler.php CHANGED
@@ -1,69 +1,69 @@
1
- <?php
2
- if ( ! defined( 'ABSPATH' ) ) {
3
- exit;
4
- }
5
-
6
- class WF_ProdImpExpCsv_AJAX_Handler {
7
-
8
- /**
9
- * Constructor
10
- */
11
- public function __construct() {
12
- add_action( 'wp_ajax_woocommerce_csv_import_request', array( $this, 'csv_import_request' ) );
13
- add_action( 'wp_ajax_woocommerce_csv_import_regenerate_thumbnail', array( $this, 'regenerate_thumbnail' ) );
14
- }
15
-
16
- /**
17
- * Ajax event for importing a CSV
18
- */
19
- public function csv_import_request() {
20
- define( 'WP_LOAD_IMPORTERS', true );
21
- WF_ProdImpExpCsv_Importer::product_importer();
22
- }
23
-
24
- /**
25
- * From regenerate thumbnails plugin
26
- */
27
- public function regenerate_thumbnail() {
28
- @error_reporting( 0 ); // Don't break the JSON result
29
-
30
- header( 'Content-type: application/json' );
31
-
32
- $id = (int) $_REQUEST['id'];
33
- $image = get_post( $id );
34
-
35
- if ( ! $image || 'attachment' != $image->post_type || 'image/' != substr( $image->post_mime_type, 0, 6 ) )
36
- die( json_encode( array( 'error' => sprintf( __( 'Failed resize: %s is an invalid image ID.', 'wf_csv_import_export' ), esc_html( $_REQUEST['id'] ) ) ) ) );
37
-
38
- if ( ! current_user_can( 'manage_woocommerce' ) )
39
- $this->die_json_error_msg( $image->ID, __( "Your user account doesn't have permission to resize images", 'wf_csv_import_export' ) );
40
-
41
- $fullsizepath = get_attached_file( $image->ID );
42
-
43
- if ( false === $fullsizepath || ! file_exists( $fullsizepath ) )
44
- $this->die_json_error_msg( $image->ID, sprintf( __( 'The originally uploaded image file cannot be found at %s', 'wf_csv_import_export' ), '<code>' . esc_html( $fullsizepath ) . '</code>' ) );
45
-
46
- @set_time_limit( 900 ); // 5 minutes per image should be PLENTY
47
-
48
- $metadata = wp_generate_attachment_metadata( $image->ID, $fullsizepath );
49
-
50
- if ( is_wp_error( $metadata ) )
51
- $this->die_json_error_msg( $image->ID, $metadata->get_error_message() );
52
- if ( empty( $metadata ) )
53
- $this->die_json_error_msg( $image->ID, __( 'Unknown failure reason.', 'wf_csv_import_export' ) );
54
-
55
- // If this fails, then it just means that nothing was changed (old value == new value)
56
- wp_update_attachment_metadata( $image->ID, $metadata );
57
-
58
- die( json_encode( array( 'success' => sprintf( __( '&quot;%1$s&quot; (ID %2$s) was successfully resized in %3$s seconds.', 'wf_csv_import_export' ), esc_html( get_the_title( $image->ID ) ), $image->ID, timer_stop() ) ) ) );
59
- }
60
-
61
- /**
62
- * Die with a JSON formatted error message
63
- */
64
- public function die_json_error_msg( $id, $message ) {
65
- die( json_encode( array( 'error' => sprintf( __( '&quot;%1$s&quot; (ID %2$s) failed to resize. The error message was: %3$s', 'regenerate-thumbnails' ), esc_html( get_the_title( $id ) ), $id, $message ) ) ) );
66
- }
67
- }
68
-
69
  new WF_ProdImpExpCsv_AJAX_Handler();
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ class WF_ProdImpExpCsv_AJAX_Handler {
7
+
8
+ /**
9
+ * Constructor
10
+ */
11
+ public function __construct() {
12
+ add_action( 'wp_ajax_woocommerce_csv_import_request', array( $this, 'csv_import_request' ) );
13
+ add_action( 'wp_ajax_woocommerce_csv_import_regenerate_thumbnail', array( $this, 'regenerate_thumbnail' ) );
14
+ }
15
+
16
+ /**
17
+ * Ajax event for importing a CSV
18
+ */
19
+ public function csv_import_request() {
20
+ define( 'WP_LOAD_IMPORTERS', true );
21
+ WF_ProdImpExpCsv_Importer::product_importer();
22
+ }
23
+
24
+ /**
25
+ * From regenerate thumbnails plugin
26
+ */
27
+ public function regenerate_thumbnail() {
28
+ @error_reporting( 0 ); // Don't break the JSON result
29
+
30
+ header( 'Content-type: application/json' );
31
+
32
+ $id = (int) $_REQUEST['id'];
33
+ $image = get_post( $id );
34
+
35
+ if ( ! $image || 'attachment' != $image->post_type || 'image/' != substr( $image->post_mime_type, 0, 6 ) )
36
+ die( json_encode( array( 'error' => sprintf( __( 'Failed resize: %s is an invalid image ID.', 'wf_csv_import_export' ), esc_html( $_REQUEST['id'] ) ) ) ) );
37
+
38
+ if ( ! current_user_can( 'manage_woocommerce' ) )
39
+ $this->die_json_error_msg( $image->ID, __( "Your user account doesn't have permission to resize images", 'wf_csv_import_export' ) );
40
+
41
+ $fullsizepath = get_attached_file( $image->ID );
42
+
43
+ if ( false === $fullsizepath || ! file_exists( $fullsizepath ) )
44
+ $this->die_json_error_msg( $image->ID, sprintf( __( 'The originally uploaded image file cannot be found at %s', 'wf_csv_import_export' ), '<code>' . esc_html( $fullsizepath ) . '</code>' ) );
45
+
46
+ @set_time_limit( 900 ); // 5 minutes per image should be PLENTY
47
+
48
+ $metadata = wp_generate_attachment_metadata( $image->ID, $fullsizepath );
49
+
50
+ if ( is_wp_error( $metadata ) )
51
+ $this->die_json_error_msg( $image->ID, $metadata->get_error_message() );
52
+ if ( empty( $metadata ) )
53
+ $this->die_json_error_msg( $image->ID, __( 'Unknown failure reason.', 'wf_csv_import_export' ) );
54
+
55
+ // If this fails, then it just means that nothing was changed (old value == new value)
56
+ wp_update_attachment_metadata( $image->ID, $metadata );
57
+
58
+ die( json_encode( array( 'success' => sprintf( __( '&quot;%1$s&quot; (ID %2$s) was successfully resized in %3$s seconds.', 'wf_csv_import_export' ), esc_html( get_the_title( $image->ID ) ), $image->ID, timer_stop() ) ) ) );
59
+ }
60
+
61
+ /**
62
+ * Die with a JSON formatted error message
63
+ */
64
+ public function die_json_error_msg( $id, $message ) {
65
+ die( json_encode( array( 'error' => sprintf( __( '&quot;%1$s&quot; (ID %2$s) failed to resize. The error message was: %3$s', 'regenerate-thumbnails' ), esc_html( get_the_title( $id ) ), $id, $message ) ) ) );
66
+ }
67
+ }
68
+
69
  new WF_ProdImpExpCsv_AJAX_Handler();
includes/class-wf-prodimpexpcsv-system-status-tools.php CHANGED
@@ -1,103 +1,103 @@
1
- <?php
2
- if ( ! defined( 'ABSPATH' ) ) {
3
- exit;
4
- }
5
-
6
- class WF_ProdImpExpCsv_System_Status_Tools {
7
-
8
- /**
9
- * Constructor
10
- */
11
- public function __construct() {
12
- add_filter( 'woocommerce_debug_tools', array( $this, 'tools' ) );
13
- }
14
-
15
- /**
16
- * Tools we add to WC
17
- * @param array $tools
18
- * @return array
19
- */
20
- public function tools( $tools ) {
21
- $tools['delete_products'] = array(
22
- 'name' => __( 'Delete Products','wf_csv_import_export'),
23
- 'button' => __( 'Delete ALL products','wf_csv_import_export' ),
24
- 'desc' => __( 'This tool will delete all products allowing you to start fresh.', 'wf_csv_import_export' ),
25
- 'callback' => array( $this, 'delete_products' )
26
- );
27
- $tools['delete_variations'] = array(
28
- 'name' => __( 'Delete Variations','wf_csv_import_export'),
29
- 'button' => __( 'Delete ALL variations','wf_csv_import_export' ),
30
- 'desc' => __( 'This tool will delete all variations allowing you to start fresh.', 'wf_csv_import_export' ),
31
- 'callback' => array( $this, 'delete_variations' )
32
- );
33
- $tools['delete_orphaned_variations'] = array(
34
- 'name' => __( 'Delete Orphans','wf_csv_import_export'),
35
- 'button' => __( 'Delete orphaned variations','wf_csv_import_export' ),
36
- 'desc' => __( 'This tool will delete variations which have no parent.', 'wf_csv_import_export' ),
37
- 'callback' => array( $this, 'delete_orphaned_variations' )
38
- );
39
- return $tools;
40
- }
41
-
42
- /**
43
- * Delete products
44
- */
45
- public function delete_products() {
46
- global $wpdb;
47
-
48
- // Delete products
49
- $result = absint( $wpdb->delete( $wpdb->posts, array( 'post_type' => 'product' ) ) );
50
- $result2 = absint( $wpdb->delete( $wpdb->posts, array( 'post_type' => 'product_variation' ) ) );
51
-
52
- // Delete meta and term relationships with no post
53
- $wpdb->query( "DELETE pm
54
- FROM {$wpdb->postmeta} pm
55
- LEFT JOIN {$wpdb->posts} wp ON wp.ID = pm.post_id
56
- WHERE wp.ID IS NULL" );
57
- $wpdb->query( "DELETE tr
58
- FROM {$wpdb->term_relationships} tr
59
- LEFT JOIN {$wpdb->posts} wp ON wp.ID = tr.object_id
60
- WHERE wp.ID IS NULL" );
61
-
62
- echo '<div class="updated"><p>' . sprintf( __( '%d Products Deleted', 'wf_csv_import_export' ), ( $result + $result2 ) ) . '</p></div>';
63
- }
64
-
65
- /**
66
- * Delete variations
67
- */
68
- public function delete_variations() {
69
- global $wpdb;
70
-
71
- // Delete products
72
- $result = absint( $wpdb->delete( $wpdb->posts, array( 'post_type' => 'product_variation' ) ) );
73
-
74
- // Delete meta and term relationships with no post
75
- $wpdb->query( "DELETE pm
76
- FROM {$wpdb->postmeta} pm
77
- LEFT JOIN {$wpdb->posts} wp ON wp.ID = pm.post_id
78
- WHERE wp.ID IS NULL" );
79
- $wpdb->query( "DELETE tr
80
- FROM {$wpdb->term_relationships} tr
81
- LEFT JOIN {$wpdb->posts} wp ON wp.ID = tr.object_id
82
- WHERE wp.ID IS NULL" );
83
-
84
- echo '<div class="updated"><p>' . sprintf( __( '%d Variations Deleted', 'wf_csv_import_export' ), $result ) . '</p></div>';
85
- }
86
-
87
- /**
88
- * Delete orphans
89
- */
90
- public function delete_orphaned_variations() {
91
- global $wpdb;
92
-
93
- // Delete meta and term relationships with no post
94
- $result = absint( $wpdb->query( "DELETE products
95
- FROM {$wpdb->posts} products
96
- LEFT JOIN {$wpdb->posts} wp ON wp.ID = products.post_parent
97
- WHERE wp.ID IS NULL AND products.post_type = 'product_variation';" ) );
98
-
99
- echo '<div class="updated"><p>' . sprintf( __( '%d Variations Deleted', 'wf_csv_import_export' ), $result ) . '</p></div>';
100
- }
101
- }
102
-
103
  new WF_ProdImpExpCsv_System_Status_Tools();
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ class WF_ProdImpExpCsv_System_Status_Tools {
7
+
8
+ /**
9
+ * Constructor
10
+ */
11
+ public function __construct() {
12
+ add_filter( 'woocommerce_debug_tools', array( $this, 'tools' ) );
13
+ }
14
+
15
+ /**
16
+ * Tools we add to WC
17
+ * @param array $tools
18
+ * @return array
19
+ */
20
+ public function tools( $tools ) {
21
+ $tools['delete_products'] = array(
22
+ 'name' => __( 'Delete Products','wf_csv_import_export'),
23
+ 'button' => __( 'Delete ALL products','wf_csv_import_export' ),
24
+ 'desc' => __( 'This tool will delete all products allowing you to start fresh.', 'wf_csv_import_export' ),
25
+ 'callback' => array( $this, 'delete_products' )
26
+ );
27
+ $tools['delete_variations'] = array(
28
+ 'name' => __( 'Delete Variations','wf_csv_import_export'),
29
+ 'button' => __( 'Delete ALL variations','wf_csv_import_export' ),
30
+ 'desc' => __( 'This tool will delete all variations allowing you to start fresh.', 'wf_csv_import_export' ),
31
+ 'callback' => array( $this, 'delete_variations' )
32
+ );
33
+ $tools['delete_orphaned_variations'] = array(
34
+ 'name' => __( 'Delete Orphans','wf_csv_import_export'),
35
+ 'button' => __( 'Delete orphaned variations','wf_csv_import_export' ),
36
+ 'desc' => __( 'This tool will delete variations which have no parent.', 'wf_csv_import_export' ),
37
+ 'callback' => array( $this, 'delete_orphaned_variations' )
38
+ );
39
+ return $tools;
40
+ }
41
+
42
+ /**
43
+ * Delete products
44
+ */
45
+ public function delete_products() {
46
+ global $wpdb;
47
+
48
+ // Delete products
49
+ $result = absint( $wpdb->delete( $wpdb->posts, array( 'post_type' => 'product' ) ) );
50
+ $result2 = absint( $wpdb->delete( $wpdb->posts, array( 'post_type' => 'product_variation' ) ) );
51
+
52
+ // Delete meta and term relationships with no post
53
+ $wpdb->query( "DELETE pm
54
+ FROM {$wpdb->postmeta} pm
55
+ LEFT JOIN {$wpdb->posts} wp ON wp.ID = pm.post_id
56
+ WHERE wp.ID IS NULL" );
57
+ $wpdb->query( "DELETE tr
58
+ FROM {$wpdb->term_relationships} tr
59
+ LEFT JOIN {$wpdb->posts} wp ON wp.ID = tr.object_id
60
+ WHERE wp.ID IS NULL" );
61
+
62
+ echo '<div class="updated"><p>' . sprintf( __( '%d Products Deleted', 'wf_csv_import_export' ), ( $result + $result2 ) ) . '</p></div>';
63
+ }
64
+
65
+ /**
66
+ * Delete variations
67
+ */
68
+ public function delete_variations() {
69
+ global $wpdb;
70
+
71
+ // Delete products
72
+ $result = absint( $wpdb->delete( $wpdb->posts, array( 'post_type' => 'product_variation' ) ) );
73
+
74
+ // Delete meta and term relationships with no post
75
+ $wpdb->query( "DELETE pm
76
+ FROM {$wpdb->postmeta} pm
77
+ LEFT JOIN {$wpdb->posts} wp ON wp.ID = pm.post_id
78
+ WHERE wp.ID IS NULL" );
79
+ $wpdb->query( "DELETE tr
80
+ FROM {$wpdb->term_relationships} tr
81
+ LEFT JOIN {$wpdb->posts} wp ON wp.ID = tr.object_id
82
+ WHERE wp.ID IS NULL" );
83
+
84
+ echo '<div class="updated"><p>' . sprintf( __( '%d Variations Deleted', 'wf_csv_import_export' ), $result ) . '</p></div>';
85
+ }
86
+
87
+ /**
88
+ * Delete orphans
89
+ */
90
+ public function delete_orphaned_variations() {
91
+ global $wpdb;
92
+
93
+ // Delete meta and term relationships with no post
94
+ $result = absint( $wpdb->query( "DELETE products
95
+ FROM {$wpdb->posts} products
96
+ LEFT JOIN {$wpdb->posts} wp ON wp.ID = products.post_parent
97
+ WHERE wp.ID IS NULL AND products.post_type = 'product_variation';" ) );
98
+
99
+ echo '<div class="updated"><p>' . sprintf( __( '%d Variations Deleted', 'wf_csv_import_export' ), $result ) . '</p></div>';
100
+ }
101
+ }
102
+
103
  new WF_ProdImpExpCsv_System_Status_Tools();
includes/exporter/class-wf-prodimpexpcsv-exporter.php CHANGED
@@ -1,527 +1,527 @@
1
- <?php
2
- if ( ! defined( 'ABSPATH' ) ) {
3
- exit;
4
- }
5
-
6
- class WF_ProdImpExpCsv_Exporter {
7
-
8
- /**
9
- * Product Exporter Tool
10
- */
11
- public static function do_export( $post_type = 'product' ) {
12
- global $wpdb;
13
-
14
- $export_limit = ! empty( $_POST['limit'] ) ? intval( $_POST['limit'] ) : 999999999;
15
- $export_count = 0;
16
- $limit = 100;
17
- $current_offset = ! empty( $_POST['offset'] ) ? intval( $_POST['offset'] ) : 0;
18
- $csv_columns = include( 'data/data-wf-post-columns.php' );
19
- $user_columns_name = ! empty( $_POST['columns_name'] ) ? $_POST['columns_name'] : $csv_columns;
20
- $product_taxonomies = get_object_taxonomies( 'product', 'name' );
21
- $export_columns = ! empty( $_POST['columns'] ) ? $_POST['columns'] : '';
22
- $include_hidden_meta = ! empty( $_POST['include_hidden_meta'] ) ? true : false;
23
- $product_limit = ! empty( $_POST['product_limit'] ) ? sanitize_text_field( $_POST['product_limit'] ) : '';
24
- $exclude_hidden_meta_columns = include( 'data/data-wf-hidden-meta-columns.php' );
25
-
26
- if ( $limit > $export_limit )
27
- $limit = $export_limit;
28
-
29
- $wpdb->hide_errors();
30
- @set_time_limit(0);
31
- if ( function_exists( 'apache_setenv' ) )
32
- @apache_setenv( 'no-gzip', 1 );
33
- @ini_set('zlib.output_compression', 0);
34
- @ob_clean();
35
-
36
-
37
- header( 'Content-Type: text/csv; charset=UTF-8' );
38
- header( 'Content-Disposition: attachment; filename=woocommerce-product-export.csv' );
39
- header( 'Pragma: no-cache' );
40
- header( 'Expires: 0' );
41
-
42
- $fp = fopen('php://output', 'w');
43
-
44
-
45
- // Headers
46
- $all_meta_keys = self::get_all_metakeys( 'product' );
47
- $found_attributes = self::get_all_product_attributes( 'product' );
48
-
49
- // Loop products and load meta data
50
- $found_product_meta = array();
51
- // Some of the values may not be usable (e.g. arrays of arrays) but the worse
52
- // that can happen is we get an empty column.
53
- foreach ( $all_meta_keys as $meta ) {
54
- if ( ! $meta ) continue;
55
- if ( ! $include_hidden_meta && ! in_array( $meta, array_keys( $csv_columns ) ) && substr( (string)$meta, 0, 1 ) == '_' )
56
- continue;
57
- if ( $include_hidden_meta && ( in_array( $meta, $exclude_hidden_meta_columns ) || in_array( $meta, array_keys( $csv_columns ) ) ) )
58
- continue;
59
- $found_product_meta[] = $meta;
60
- }
61
-
62
- $found_product_meta = array_diff( $found_product_meta, array_keys( $csv_columns ) );
63
-
64
- // Variable to hold the CSV data we're exporting
65
- $row = array();
66
-
67
- // Export header rows
68
- foreach ( $csv_columns as $column => $value ) {
69
-
70
- $temp_head = esc_attr( $user_columns_name[$column] );
71
- if (strpos($temp_head, 'yoast') === false) {
72
- $temp_head = ltrim($temp_head, '_');
73
- }
74
- if ( ! $export_columns || in_array( $column, $export_columns ) ) $row[] = $temp_head;
75
- }
76
-
77
- // Handle special fields like taxonomies
78
- if ( ! $export_columns || in_array( 'images', $export_columns ) ) {
79
- $row[] = 'images';
80
- }
81
-
82
- if ( ! $export_columns || in_array( 'file_paths', $export_columns ) ) {
83
- if ( function_exists( 'wc_get_filename_from_url' ) ) {
84
- $row[] = 'downloadable_files';
85
- } else {
86
- $row[] = 'file_paths';
87
- }
88
- }
89
-
90
- if ( ! $export_columns || in_array( 'taxonomies', $export_columns ) ) {
91
- foreach ( $product_taxonomies as $taxonomy ) {
92
- if ( strstr( $taxonomy->name, 'pa_' ) ) continue; // Skip attributes
93
-
94
- $row[] = 'tax:' . self::format_data( $taxonomy->name );
95
- }
96
- }
97
-
98
- if ( ! $export_columns || in_array( 'meta', $export_columns ) ) {
99
- foreach ( $found_product_meta as $product_meta ) {
100
- $row[] = 'meta:' . self::format_data( $product_meta );
101
- }
102
- }
103
-
104
- if ( ! $export_columns || in_array( 'attributes', $export_columns ) ) {
105
- foreach ( $found_attributes as $attribute ) {
106
- $row[] = 'attribute:' . self::format_data( $attribute );
107
- $row[] = 'attribute_data:' . self::format_data( $attribute );
108
- $row[] = 'attribute_default:' . self::format_data( $attribute );
109
- }
110
- }
111
-
112
-
113
-
114
- // WF: Adding product permalink.
115
- if ( ! $export_columns || in_array( 'product_page_url', $export_columns ) ) {
116
- $row[] = 'Product Page URL';
117
- }
118
-
119
- $row = array_map( 'WF_ProdImpExpCsv_Exporter::wrap_column', $row );
120
- fwrite( $fp, implode( ',', $row ) . "\n" );
121
- unset( $row );
122
-
123
- while ( $export_count < $export_limit ) {
124
-
125
- $product_args = apply_filters( 'woocommerce_csv_product_export_args', array(
126
- 'numberposts' => $limit,
127
- 'post_status' => array( 'publish', 'pending', 'private', 'draft' ),
128
- 'post_type' => array('product'),
129
- 'orderby' => 'ID',
130
- 'suppress_filters' => false,
131
- 'order' => 'ASC',
132
- 'offset' => $current_offset
133
- ) );
134
-
135
-
136
- if ( $product_limit ) {
137
- $parent_ids = array_map( 'intval', explode( ',', $product_limit ) );
138
- $child_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_parent IN (" . implode( ',', $parent_ids ) . ");" );
139
- $product_args['post__in'] = $child_ids;
140
- }
141
-
142
- $products = get_posts( $product_args );
143
- if ( ! $products || is_wp_error( $products ) )
144
- break;
145
-
146
- // Loop products
147
- foreach ( $products as $product ) {
148
- if($product->post_parent == 0) $product->post_parent = '';
149
- $row = array();
150
-
151
- // Pre-process data
152
- $meta_data = get_post_custom( $product->ID );
153
-
154
- $product->meta = new stdClass;
155
- $product->attributes = new stdClass;
156
-
157
- // Meta data
158
- foreach ( $meta_data as $meta => $value ) {
159
- if ( ! $meta ) {
160
- continue;
161
- }
162
- if ( ! $include_hidden_meta && ! in_array( $meta, array_keys( $csv_columns ) ) && substr( $meta, 0, 1 ) == '_' ) {
163
- continue;
164
- }
165
- if ( $include_hidden_meta && in_array( $meta, $exclude_hidden_meta_columns ) ) {
166
- continue;
167
- }
168
-
169
- $meta_value = maybe_unserialize( maybe_unserialize( $value[0] ) );
170
-
171
- if ( is_array( $meta_value ) ) {
172
- $meta_value = json_encode( $meta_value );
173
- }
174
-
175
- $product->meta->$meta = self::format_export_meta( $meta_value, $meta );
176
- }
177
-
178
- // Product attributes
179
- if ( isset( $meta_data['_product_attributes'][0] ) ) {
180
-
181
- $attributes = maybe_unserialize( maybe_unserialize( $meta_data['_product_attributes'][0] ) );
182
-
183
- if ( ! empty( $attributes ) && is_array( $attributes ) ) {
184
- foreach ( $attributes as $key => $attribute ) {
185
- if ( ! $key ) {
186
- continue;
187
- }
188
-
189
- if ( $attribute['is_taxonomy'] == 1 ) {
190
- $terms = wp_get_post_terms( $product->ID, $key, array("fields" => "names") );
191
- if ( ! is_wp_error( $terms ) ) {
192
- $attribute_value = implode( '|', $terms );
193
- } else {
194
- $attribute_value = '';
195
- }
196
- } else {
197
- if ( empty( $attribute['name'] ) ) {
198
- continue;
199
- }
200
- $key = $attribute['name'];
201
- $attribute_value = $attribute['value'];
202
- }
203
-
204
- if ( ! isset( $attribute['position'] ) ) {
205
- $attribute['position'] = 0;
206
- }
207
- if ( ! isset( $attribute['is_visible'] ) ) {
208
- $attribute['is_visible'] = 0;
209
- }
210
- if ( ! isset( $attribute['is_variation'] ) ) {
211
- $attribute['is_variation'] = 0;
212
- }
213
-
214
- $attribute_data = $attribute['position'] . '|' . $attribute['is_visible'] . '|' . $attribute['is_variation'];
215
- $_default_attributes = isset( $meta_data['_default_attributes'][0] ) ? maybe_unserialize( maybe_unserialize( $meta_data['_default_attributes'][0] ) ) : '';
216
-
217
- if ( is_array( $_default_attributes ) ) {
218
- $_default_attribute = isset( $_default_attributes[ $key ] ) ? $_default_attributes[ $key ] : '';
219
- } else {
220
- $_default_attribute = '';
221
- }
222
-
223
- $product->attributes->$key = array(
224
- 'value' => $attribute_value,
225
- 'data' => $attribute_data,
226
- 'default' => $_default_attribute
227
- );
228
- }
229
- }
230
- }
231
-
232
- // GPF
233
- if ( isset( $meta_data['_woocommerce_gpf_data'][0] ) ) {
234
- $product->gpf_data = $meta_data['_woocommerce_gpf_data'][0];
235
- }
236
-
237
- // Get column values
238
- foreach ( $csv_columns as $column => $value ) {
239
- if ( ! $export_columns || in_array( $column, $export_columns ) ) {
240
-
241
- if ($column == '_regular_price' && empty( $product->meta->$column ) ) {
242
- $column = '_price';
243
- }
244
-
245
- if ( isset( $product->meta->$column ) ) {
246
- $row[] = self::format_data( $product->meta->$column );
247
- } elseif ( isset( $product->$column ) && ! is_array( $product->$column ) ) {
248
- if ( $column === 'post_title' ) {
249
- $row[] = sanitize_text_field( $product->$column );
250
- } else {
251
- $row[] = self::format_data( $product->$column );
252
- }
253
- } else {
254
- $row[] = '';
255
- }
256
- }
257
- }
258
-
259
- // Export images/gallery
260
- if ( ! $export_columns || in_array( 'images', $export_columns ) ) {
261
-
262
- $image_file_names = array();
263
-
264
- // Featured image
265
- if ( ( $featured_image_id = get_post_thumbnail_id( $product->ID ) ) && ( $image = wp_get_attachment_image_src( $featured_image_id, 'full' ) ) ) {
266
- $image_file_names[] = current( $image );
267
- }
268
-
269
- // Images
270
- $images = isset( $meta_data['_product_image_gallery'][0] ) ? explode( ',', maybe_unserialize( maybe_unserialize( $meta_data['_product_image_gallery'][0] ) ) ) : false;
271
- $results = array();
272
-
273
- if ( $images ) {
274
- foreach ( $images as $image_id ) {
275
- if ( $featured_image_id == $image_id ) {
276
- continue;
277
- }
278
- $image = wp_get_attachment_image_src( $image_id, 'full' );
279
- if ( $image ) {
280
- $image_file_names[] = current( $image );
281
- }
282
- }
283
- }
284
-
285
- $row[] = implode( ' | ', $image_file_names );
286
-
287
- }
288
-
289
- // Downloadable files
290
- if ( ! $export_columns || in_array( 'file_paths', $export_columns ) ) {
291
- if ( ! function_exists( 'wc_get_filename_from_url' ) ) {
292
- $file_paths = maybe_unserialize( maybe_unserialize( $meta_data['_file_paths'][0] ) );
293
- $file_paths_to_export = array();
294
-
295
- if ( $file_paths ) {
296
- foreach ( $file_paths as $file_path ) {
297
- $file_paths_to_export[] = $file_path;
298
- }
299
- }
300
-
301
- $file_paths_to_export = implode( ' | ', $file_paths_to_export );
302
- $row[] = self::format_data( $file_paths_to_export );
303
- } elseif ( isset( $meta_data['_downloadable_files'][0] ) ) {
304
- $file_paths = maybe_unserialize( maybe_unserialize( $meta_data['_downloadable_files'][0] ) );
305
- $file_paths_to_export = array();
306
-
307
- if ( $file_paths ) {
308
- foreach ( $file_paths as $file_path ) {
309
- $file_paths_to_export[] = ( ! empty( $file_path['name'] ) ? $file_path['name'] : wc_get_filename_from_url( $file_path['file'] ) ) . '::' . $file_path['file'];
310
- }
311
- }
312
- $file_paths_to_export = implode( ' | ', $file_paths_to_export );
313
- $row[] = self::format_data( $file_paths_to_export );
314
- } else {
315
- $row[] = '';
316
- }
317
- }
318
-
319
- // Export taxonomies
320
- if ( ! $export_columns || in_array( 'taxonomies', $export_columns ) ) {
321
- foreach ( $product_taxonomies as $taxonomy ) {
322
- if ( strstr( $taxonomy->name, 'pa_' ) ) continue; // Skip attributes
323
-
324
- if ( is_taxonomy_hierarchical( $taxonomy->name ) ) {
325
- $terms = wp_get_post_terms( $product->ID, $taxonomy->name, array( "fields" => "all" ) );
326
- $formatted_terms = array();
327
-
328
- foreach ( $terms as $term ) {
329
- $ancestors = array_reverse( get_ancestors( $term->term_id, $taxonomy->name ) );
330
- $formatted_term = array();
331
-
332
- foreach ( $ancestors as $ancestor )
333
- $formatted_term[] = get_term( $ancestor, $taxonomy->name )->name;
334
-
335
- $formatted_term[] = $term->name;
336
-
337
- $formatted_terms[] = implode( ' > ', $formatted_term );
338
- }
339
-
340
- $row[] = self::format_data( implode( '|', $formatted_terms ) );
341
- } else {
342
- $terms = wp_get_post_terms( $product->ID, $taxonomy->name, array( "fields" => "names" ) );
343
-
344
- $row[] = self::format_data( implode( '|', $terms ) );
345
- }
346
- }
347
- }
348
-
349
- // Export meta data
350
- if ( ! $export_columns || in_array( 'meta', $export_columns ) ) {
351
- foreach ( $found_product_meta as $product_meta ) {
352
- if ( isset( $product->meta->$product_meta ) ) {
353
- $row[] = self::format_data( $product->meta->$product_meta );
354
- } else {
355
- $row[] = '';
356
- }
357
- }
358
- }
359
-
360
- // Find and export attributes
361
- if ( ! $export_columns || in_array( 'attributes', $export_columns ) ) {
362
- foreach ( $found_attributes as $attribute ) {
363
- if ( isset( $product->attributes ) && isset( $product->attributes->$attribute ) ) {
364
- $values = $product->attributes->$attribute;
365
- $row[] = self::format_data( $values['value'] );
366
- $row[] = self::format_data( $values['data'] );
367
- $row[] = self::format_data( $values['default'] );
368
- } else {
369
- $row[] = '';
370
- $row[] = '';
371
- $row[] = '';
372
- }
373
- }
374
- }
375
-
376
- // Export GPF
377
- if ( function_exists( 'woocommerce_gpf_install' ) && ( ! $export_columns || in_array( 'gpf', $export_columns ) ) ) {
378
-
379
- $gpf_data = empty( $product->gpf_data ) ? '' : maybe_unserialize( $product->gpf_data );
380
-
381
- $row[] = empty( $gpf_data['availability'] ) ? '' : $gpf_data['availability'];
382
- $row[] = empty( $gpf_data['condition'] ) ? '' : $gpf_data['condition'];
383
- $row[] = empty( $gpf_data['brand'] ) ? '' : $gpf_data['brand'];
384
- $row[] = empty( $gpf_data['product_type'] ) ? '' : $gpf_data['product_type'];
385
- $row[] = empty( $gpf_data['google_product_category'] ) ? '' : $gpf_data['google_product_category'];
386
- $row[] = empty( $gpf_data['gtin'] ) ? '' : $gpf_data['gtin'];
387
- $row[] = empty( $gpf_data['mpn'] ) ? '' : $gpf_data['mpn'];
388
- $row[] = empty( $gpf_data['gender'] ) ? '' : $gpf_data['gender'];
389
- $row[] = empty( $gpf_data['age_group'] ) ? '' : $gpf_data['age_group'];
390
- $row[] = empty( $gpf_data['color'] ) ? '' : $gpf_data['color'];
391
- $row[] = empty( $gpf_data['size'] ) ? '' : $gpf_data['size'];
392
- $row[] = empty( $gpf_data['adwords_grouping'] ) ? '' : $gpf_data['adwords_grouping'];
393
- $row[] = empty( $gpf_data['adwords_labels'] ) ? '' : $gpf_data['adwords_labels'];
394
- }
395
-
396
- // WF: Adding product permalink.
397
- if ( ! $export_columns || in_array( 'product_page_url', $export_columns ) ) {
398
- $product_page_url = '';
399
- if ( $product->ID ) {
400
- $product_page_url = get_permalink( $product->ID );
401
- }
402
- if ( $product->post_parent ) {
403
- $product_page_url = get_permalink( $product->post_parent );
404
- }
405
-
406
- $row[] = $product_page_url;
407
- }
408
-
409
- // Add to csv
410
- $row = array_map( 'WF_ProdImpExpCsv_Exporter::wrap_column', $row );
411
- fwrite( $fp, implode( ',', $row ) . "\n" );
412
- unset( $row );
413
-
414
- }
415
- $current_offset += $limit+1;
416
- $export_count += $limit;
417
- unset( $products );
418
- }
419
-
420
- fclose( $fp );
421
- exit;
422
- }
423
-
424
- /**
425
- * Format the data if required
426
- * @param string $meta_value
427
- * @param string $meta name of meta key
428
- * @return string
429
- */
430
- public static function format_export_meta( $meta_value, $meta ) {
431
- switch ( $meta ) {
432
- case '_sale_price_dates_from' :
433
- case '_sale_price_dates_to' :
434
- return $meta_value ? date( 'Y-m-d', $meta_value ) : '';
435
- break;
436
- case '_upsell_ids' :
437
- case '_crosssell_ids' :
438
- return implode( '|', array_filter( (array) json_decode( $meta_value ) ) );
439
- break;
440
- default :
441
- return $meta_value;
442
- break;
443
- }
444
- }
445
-
446
- public static function format_data( $data ) {
447
- $enc = mb_detect_encoding( $data, 'UTF-8, ISO-8859-1', true );
448
- $data = ( $enc == 'UTF-8' ) ? $data : utf8_encode( $data );
449
- return $data;
450
- }
451
-
452
- /**
453
- * Wrap a column in quotes for the CSV
454
- * @param string data to wrap
455
- * @return string wrapped data
456
- */
457
- public static function wrap_column( $data ) {
458
- return '"' . str_replace( '"', '""', $data ) . '"';
459
- }
460
-
461
- /**
462
- * Get a list of all the meta keys for a post type. This includes all public, private,
463
- * used, no-longer used etc. They will be sorted once fetched.
464
- */
465
- public static function get_all_metakeys( $post_type = 'product' ) {
466
- global $wpdb;
467
-
468
- $meta = $wpdb->get_col( $wpdb->prepare(
469
- "SELECT DISTINCT pm.meta_key
470
- FROM {$wpdb->postmeta} AS pm
471
- LEFT JOIN {$wpdb->posts} AS p ON p.ID = pm.post_id
472
- WHERE p.post_type = %s
473
- AND p.post_status IN ( 'publish', 'pending', 'private', 'draft' )",
474
- $post_type
475
- ) );
476
-
477
- sort( $meta );
478
-
479
- return $meta;
480
- }
481
-
482
- /**
483
- * Get a list of all the product attributes for a post type.
484
- * These require a bit more digging into the values.
485
- */
486
- public static function get_all_product_attributes( $post_type = 'product' ) {
487
- global $wpdb;
488
-
489
- $results = $wpdb->get_col( $wpdb->prepare(
490
- "SELECT DISTINCT pm.meta_value
491
- FROM {$wpdb->postmeta} AS pm
492
- LEFT JOIN {$wpdb->posts} AS p ON p.ID = pm.post_id
493
- WHERE p.post_type = %s
494
- AND p.post_status IN ( 'publish', 'pending', 'private', 'draft' )
495
- AND pm.meta_key = '_product_attributes'",
496
- $post_type
497
- ) );
498
-
499
- // Go through each result, and look at the attribute keys within them.
500
- $result = array();
501
-
502
- if ( ! empty( $results ) ) {
503
- foreach( $results as $_product_attributes ) {
504
- $attributes = maybe_unserialize( maybe_unserialize( $_product_attributes ) );
505
- if ( ! empty( $attributes ) && is_array( $attributes ) ) {
506
- foreach( $attributes as $key => $attribute ) {
507
- if ( ! $key ) {
508
- continue;
509
- }
510
- if ( ! strstr( $key, 'pa_' ) ) {
511
- if ( empty( $attribute['name'] ) ) {
512
- continue;
513
- }
514
- $key = $attribute['name'];
515
- }
516
-
517
- $result[ $key ] = $key;
518
- }
519
- }
520
- }
521
- }
522
-
523
- sort( $result );
524
-
525
- return $result;
526
- }
527
- }
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ class WF_ProdImpExpCsv_Exporter {
7
+
8
+ /**
9
+ * Product Exporter Tool
10
+ */
11
+ public static function do_export( $post_type = 'product' ) {
12
+ global $wpdb;
13
+
14
+ $export_limit = ! empty( $_POST['limit'] ) ? intval( $_POST['limit'] ) : 999999999;
15
+ $export_count = 0;
16
+ $limit = 100;
17
+ $current_offset = ! empty( $_POST['offset'] ) ? intval( $_POST['offset'] ) : 0;
18
+ $csv_columns = include( 'data/data-wf-post-columns.php' );
19
+ $user_columns_name = ! empty( $_POST['columns_name'] ) ? $_POST['columns_name'] : $csv_columns;
20
+ $product_taxonomies = get_object_taxonomies( 'product', 'name' );
21
+ $export_columns = ! empty( $_POST['columns'] ) ? $_POST['columns'] : '';
22
+ $include_hidden_meta = ! empty( $_POST['include_hidden_meta'] ) ? true : false;
23
+ $product_limit = ! empty( $_POST['product_limit'] ) ? sanitize_text_field( $_POST['product_limit'] ) : '';
24
+ $exclude_hidden_meta_columns = include( 'data/data-wf-hidden-meta-columns.php' );
25
+
26
+ if ( $limit > $export_limit )
27
+ $limit = $export_limit;
28
+
29
+ $wpdb->hide_errors();
30
+ @set_time_limit(0);
31
+ if ( function_exists( 'apache_setenv' ) )
32
+ @apache_setenv( 'no-gzip', 1 );
33
+ @ini_set('zlib.output_compression', 0);
34
+ @ob_clean();
35
+
36
+
37
+ header( 'Content-Type: text/csv; charset=UTF-8' );
38
+ header( 'Content-Disposition: attachment; filename=woocommerce-product-export.csv' );
39
+ header( 'Pragma: no-cache' );
40
+ header( 'Expires: 0' );
41
+
42
+ $fp = fopen('php://output', 'w');
43
+
44
+
45
+ // Headers
46
+ $all_meta_keys = self::get_all_metakeys( 'product' );
47
+ $found_attributes = self::get_all_product_attributes( 'product' );
48
+
49
+ // Loop products and load meta data
50
+ $found_product_meta = array();
51
+ // Some of the values may not be usable (e.g. arrays of arrays) but the worse
52
+ // that can happen is we get an empty column.
53
+ foreach ( $all_meta_keys as $meta ) {
54
+ if ( ! $meta ) continue;
55
+ if ( ! $include_hidden_meta && ! in_array( $meta, array_keys( $csv_columns ) ) && substr( (string)$meta, 0, 1 ) == '_' )
56
+ continue;
57
+ if ( $include_hidden_meta && ( in_array( $meta, $exclude_hidden_meta_columns ) || in_array( $meta, array_keys( $csv_columns ) ) ) )
58
+ continue;
59
+ $found_product_meta[] = $meta;
60
+ }
61
+
62
+ $found_product_meta = array_diff( $found_product_meta, array_keys( $csv_columns ) );
63
+
64
+ // Variable to hold the CSV data we're exporting
65
+ $row = array();
66
+
67
+ // Export header rows
68
+ foreach ( $csv_columns as $column => $value ) {
69
+
70
+ $temp_head = esc_attr( $user_columns_name[$column] );
71
+ if (strpos($temp_head, 'yoast') === false) {
72
+ $temp_head = ltrim($temp_head, '_');
73
+ }
74
+ if ( ! $export_columns || in_array( $column, $export_columns ) ) $row[] = $temp_head;
75
+ }
76
+
77
+ // Handle special fields like taxonomies
78
+ if ( ! $export_columns || in_array( 'images', $export_columns ) ) {
79
+ $row[] = 'images';
80
+ }
81
+
82
+ if ( ! $export_columns || in_array( 'file_paths', $export_columns ) ) {
83
+ if ( function_exists( 'wc_get_filename_from_url' ) ) {
84
+ $row[] = 'downloadable_files';
85
+ } else {
86
+ $row[] = 'file_paths';
87
+ }
88
+ }
89
+
90
+ if ( ! $export_columns || in_array( 'taxonomies', $export_columns ) ) {
91
+ foreach ( $product_taxonomies as $taxonomy ) {
92
+ if ( strstr( $taxonomy->name, 'pa_' ) ) continue; // Skip attributes
93
+
94
+ $row[] = 'tax:' . self::format_data( $taxonomy->name );
95
+ }
96
+ }
97
+
98
+ if ( ! $export_columns || in_array( 'meta', $export_columns ) ) {
99
+ foreach ( $found_product_meta as $product_meta ) {
100
+ $row[] = 'meta:' . self::format_data( $product_meta );
101
+ }
102
+ }
103
+
104
+ if ( ! $export_columns || in_array( 'attributes', $export_columns ) ) {
105
+ foreach ( $found_attributes as $attribute ) {
106
+ $row[] = 'attribute:' . self::format_data( $attribute );
107
+ $row[] = 'attribute_data:' . self::format_data( $attribute );
108
+ $row[] = 'attribute_default:' . self::format_data( $attribute );
109
+ }
110
+ }
111
+
112
+
113
+
114
+ // WF: Adding product permalink.
115
+ if ( ! $export_columns || in_array( 'product_page_url', $export_columns ) ) {
116
+ $row[] = 'Product Page URL';
117
+ }
118
+
119
+ $row = array_map( 'WF_ProdImpExpCsv_Exporter::wrap_column', $row );
120
+ fwrite( $fp, implode( ',', $row ) . "\n" );
121
+ unset( $row );
122
+
123
+ while ( $export_count < $export_limit ) {
124
+
125
+ $product_args = apply_filters( 'woocommerce_csv_product_export_args', array(
126
+ 'numberposts' => $limit,
127
+ 'post_status' => array( 'publish', 'pending', 'private', 'draft' ),
128
+ 'post_type' => array('product'),
129
+ 'orderby' => 'ID',
130
+ 'suppress_filters' => false,
131
+ 'order' => 'ASC',
132
+ 'offset' => $current_offset
133
+ ) );
134
+
135
+
136
+ if ( $product_limit ) {
137
+ $parent_ids = array_map( 'intval', explode( ',', $product_limit ) );
138
+ $child_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_parent IN (" . implode( ',', $parent_ids ) . ");" );
139
+ $product_args['post__in'] = $child_ids;
140
+ }
141
+
142
+ $products = get_posts( $product_args );
143
+ if ( ! $products || is_wp_error( $products ) )
144
+ break;
145
+
146
+ // Loop products
147
+ foreach ( $products as $product ) {
148
+ if($product->post_parent == 0) $product->post_parent = '';
149
+ $row = array();
150
+
151
+ // Pre-process data
152
+ $meta_data = get_post_custom( $product->ID );
153
+
154
+ $product->meta = new stdClass;
155
+ $product->attributes = new stdClass;
156
+
157
+ // Meta data
158
+ foreach ( $meta_data as $meta => $value ) {
159
+ if ( ! $meta ) {
160
+ continue;
161
+ }
162
+ if ( ! $include_hidden_meta && ! in_array( $meta, array_keys( $csv_columns ) ) && substr( $meta, 0, 1 ) == '_' ) {
163
+ continue;
164
+ }
165
+ if ( $include_hidden_meta && in_array( $meta, $exclude_hidden_meta_columns ) ) {
166
+ continue;
167
+ }
168
+
169
+ $meta_value = maybe_unserialize( maybe_unserialize( $value[0] ) );
170
+
171
+ if ( is_array( $meta_value ) ) {
172
+ $meta_value = json_encode( $meta_value );
173
+ }
174
+
175
+ $product->meta->$meta = self::format_export_meta( $meta_value, $meta );
176
+ }
177
+
178
+ // Product attributes
179
+ if ( isset( $meta_data['_product_attributes'][0] ) ) {
180
+
181
+ $attributes = maybe_unserialize( maybe_unserialize( $meta_data['_product_attributes'][0] ) );
182
+
183
+ if ( ! empty( $attributes ) && is_array( $attributes ) ) {
184
+ foreach ( $attributes as $key => $attribute ) {
185
+ if ( ! $key ) {
186
+ continue;
187
+ }
188
+
189
+ if ( $attribute['is_taxonomy'] == 1 ) {
190
+ $terms = wp_get_post_terms( $product->ID, $key, array("fields" => "names") );
191
+ if ( ! is_wp_error( $terms ) ) {
192
+ $attribute_value = implode( '|', $terms );
193
+ } else {
194
+ $attribute_value = '';
195
+ }
196
+ } else {
197
+ if ( empty( $attribute['name'] ) ) {
198
+ continue;
199
+ }
200
+ $key = $attribute['name'];
201
+ $attribute_value = $attribute['value'];
202
+ }
203
+
204
+ if ( ! isset( $attribute['position'] ) ) {
205
+ $attribute['position'] = 0;
206
+ }
207
+ if ( ! isset( $attribute['is_visible'] ) ) {
208
+ $attribute['is_visible'] = 0;
209
+ }
210
+ if ( ! isset( $attribute['is_variation'] ) ) {
211
+ $attribute['is_variation'] = 0;
212
+ }
213
+
214
+ $attribute_data = $attribute['position'] . '|' . $attribute['is_visible'] . '|' . $attribute['is_variation'];
215
+ $_default_attributes = isset( $meta_data['_default_attributes'][0] ) ? maybe_unserialize( maybe_unserialize( $meta_data['_default_attributes'][0] ) ) : '';
216
+
217
+ if ( is_array( $_default_attributes ) ) {
218
+ $_default_attribute = isset( $_default_attributes[ $key ] ) ? $_default_attributes[ $key ] : '';
219
+ } else {
220
+ $_default_attribute = '';
221
+ }
222
+
223
+ $product->attributes->$key = array(
224
+ 'value' => $attribute_value,
225
+ 'data' => $attribute_data,
226
+ 'default' => $_default_attribute
227
+ );
228
+ }
229
+ }
230
+ }
231
+
232
+ // GPF
233
+ if ( isset( $meta_data['_woocommerce_gpf_data'][0] ) ) {
234
+ $product->gpf_data = $meta_data['_woocommerce_gpf_data'][0];
235
+ }
236
+
237
+ // Get column values
238
+ foreach ( $csv_columns as $column => $value ) {
239
+ if ( ! $export_columns || in_array( $column, $export_columns ) ) {
240
+
241
+ if ($column == '_regular_price' && empty( $product->meta->$column ) ) {
242
+ $column = '_price';
243
+ }
244
+
245
+ if ( isset( $product->meta->$column ) ) {
246
+ $row[] = self::format_data( $product->meta->$column );
247
+ } elseif ( isset( $product->$column ) && ! is_array( $product->$column ) ) {
248
+ if ( $column === 'post_title' ) {
249
+ $row[] = sanitize_text_field( $product->$column );
250
+ } else {
251
+ $row[] = self::format_data( $product->$column );
252
+ }
253
+ } else {
254
+ $row[] = '';
255
+ }
256
+ }
257
+ }
258
+
259
+ // Export images/gallery
260
+ if ( ! $export_columns || in_array( 'images', $export_columns ) ) {
261
+
262
+ $image_file_names = array();
263
+
264
+ // Featured image
265
+ if ( ( $featured_image_id = get_post_thumbnail_id( $product->ID ) ) && ( $image = wp_get_attachment_image_src( $featured_image_id, 'full' ) ) ) {
266
+ $image_file_names[] = current( $image );
267
+ }
268
+
269
+ // Images
270
+ $images = isset( $meta_data['_product_image_gallery'][0] ) ? explode( ',', maybe_unserialize( maybe_unserialize( $meta_data['_product_image_gallery'][0] ) ) ) : false;
271
+ $results = array();
272
+
273
+ if ( $images ) {
274
+ foreach ( $images as $image_id ) {
275
+ if ( $featured_image_id == $image_id ) {
276
+ continue;
277
+ }
278
+ $image = wp_get_attachment_image_src( $image_id, 'full' );
279
+ if ( $image ) {
280
+ $image_file_names[] = current( $image );
281
+ }
282
+ }
283
+ }
284
+
285
+ $row[] = implode( ' | ', $image_file_names );
286
+
287
+ }
288
+
289
+ // Downloadable files
290
+ if ( ! $export_columns || in_array( 'file_paths', $export_columns ) ) {
291
+ if ( ! function_exists( 'wc_get_filename_from_url' ) ) {
292
+ $file_paths = maybe_unserialize( maybe_unserialize( $meta_data['_file_paths'][0] ) );
293
+ $file_paths_to_export = array();
294
+
295
+ if ( $file_paths ) {
296
+ foreach ( $file_paths as $file_path ) {
297
+ $file_paths_to_export[] = $file_path;
298
+ }
299
+ }
300
+
301
+ $file_paths_to_export = implode( ' | ', $file_paths_to_export );
302
+ $row[] = self::format_data( $file_paths_to_export );
303
+ } elseif ( isset( $meta_data['_downloadable_files'][0] ) ) {
304
+ $file_paths = maybe_unserialize( maybe_unserialize( $meta_data['_downloadable_files'][0] ) );
305
+ $file_paths_to_export = array();
306
+
307
+ if ( $file_paths ) {
308
+ foreach ( $file_paths as $file_path ) {
309
+ $file_paths_to_export[] = ( ! empty( $file_path['name'] ) ? $file_path['name'] : wc_get_filename_from_url( $file_path['file'] ) ) . '::' . $file_path['file'];
310
+ }
311
+ }
312
+ $file_paths_to_export = implode( ' | ', $file_paths_to_export );
313
+ $row[] = self::format_data( $file_paths_to_export );
314
+ } else {
315
+ $row[] = '';
316
+ }
317
+ }
318
+
319
+ // Export taxonomies
320
+ if ( ! $export_columns || in_array( 'taxonomies', $export_columns ) ) {
321
+ foreach ( $product_taxonomies as $taxonomy ) {
322
+ if ( strstr( $taxonomy->name, 'pa_' ) ) continue; // Skip attributes
323
+
324
+ if ( is_taxonomy_hierarchical( $taxonomy->name ) ) {
325
+ $terms = wp_get_post_terms( $product->ID, $taxonomy->name, array( "fields" => "all" ) );
326
+ $formatted_terms = array();
327
+
328
+ foreach ( $terms as $term ) {
329
+ $ancestors = array_reverse( get_ancestors( $term->term_id, $taxonomy->name ) );
330
+ $formatted_term = array();
331
+
332
+ foreach ( $ancestors as $ancestor )
333
+ $formatted_term[] = get_term( $ancestor, $taxonomy->name )->name;
334
+
335
+ $formatted_term[] = $term->name;
336
+
337
+ $formatted_terms[] = implode( ' > ', $formatted_term );
338
+ }
339
+
340
+ $row[] = self::format_data( implode( '|', $formatted_terms ) );
341
+ } else {
342
+ $terms = wp_get_post_terms( $product->ID, $taxonomy->name, array( "fields" => "names" ) );
343
+
344
+ $row[] = self::format_data( implode( '|', $terms ) );
345
+ }
346
+ }
347
+ }
348
+
349
+ // Export meta data
350
+ if ( ! $export_columns || in_array( 'meta', $export_columns ) ) {
351
+ foreach ( $found_product_meta as $product_meta ) {
352
+ if ( isset( $product->meta->$product_meta ) ) {
353
+ $row[] = self::format_data( $product->meta->$product_meta );
354
+ } else {
355
+ $row[] = '';
356
+ }
357
+ }
358
+ }
359
+
360
+ // Find and export attributes
361
+ if ( ! $export_columns || in_array( 'attributes', $export_columns ) ) {
362
+ foreach ( $found_attributes as $attribute ) {
363
+ if ( isset( $product->attributes ) && isset( $product->attributes->$attribute ) ) {
364
+ $values = $product->attributes->$attribute;
365
+ $row[] = self::format_data( $values['value'] );
366
+ $row[] = self::format_data( $values['data'] );
367
+ $row[] = self::format_data( $values['default'] );
368
+ } else {
369
+ $row[] = '';
370
+ $row[] = '';
371
+ $row[] = '';
372
+ }
373
+ }
374
+ }
375
+
376
+ // Export GPF
377
+ if ( function_exists( 'woocommerce_gpf_install' ) && ( ! $export_columns || in_array( 'gpf', $export_columns ) ) ) {
378
+
379
+ $gpf_data = empty( $product->gpf_data ) ? '' : maybe_unserialize( $product->gpf_data );
380
+
381
+ $row[] = empty( $gpf_data['availability'] ) ? '' : $gpf_data['availability'];
382
+ $row[] = empty( $gpf_data['condition'] ) ? '' : $gpf_data['condition'];
383
+ $row[] = empty( $gpf_data['brand'] ) ? '' : $gpf_data['brand'];
384
+ $row[] = empty( $gpf_data['product_type'] ) ? '' : $gpf_data['product_type'];
385
+ $row[] = empty( $gpf_data['google_product_category'] ) ? '' : $gpf_data['google_product_category'];
386
+ $row[] = empty( $gpf_data['gtin'] ) ? '' : $gpf_data['gtin'];
387
+ $row[] = empty( $gpf_data['mpn'] ) ? '' : $gpf_data['mpn'];
388
+ $row[] = empty( $gpf_data['gender'] ) ? '' : $gpf_data['gender'];
389
+ $row[] = empty( $gpf_data['age_group'] ) ? '' : $gpf_data['age_group'];
390
+ $row[] = empty( $gpf_data['color'] ) ? '' : $gpf_data['color'];
391
+ $row[] = empty( $gpf_data['size'] ) ? '' : $gpf_data['size'];
392
+ $row[] = empty( $gpf_data['adwords_grouping'] ) ? '' : $gpf_data['adwords_grouping'];
393
+ $row[] = empty( $gpf_data['adwords_labels'] ) ? '' : $gpf_data['adwords_labels'];
394
+ }
395
+
396
+ // WF: Adding product permalink.
397
+ if ( ! $export_columns || in_array( 'product_page_url', $export_columns ) ) {
398
+ $product_page_url = '';
399
+ if ( $product->ID ) {
400
+ $product_page_url = get_permalink( $product->ID );
401
+ }
402
+ if ( $product->post_parent ) {
403
+ $product_page_url = get_permalink( $product->post_parent );
404
+ }
405
+
406
+ $row[] = $product_page_url;
407
+ }
408
+
409
+ // Add to csv
410
+ $row = array_map( 'WF_ProdImpExpCsv_Exporter::wrap_column', $row );
411
+ fwrite( $fp, implode( ',', $row ) . "\n" );
412
+ unset( $row );
413
+
414
+ }
415
+ $current_offset += $limit+1;
416
+ $export_count += $limit;
417
+ unset( $products );
418
+ }
419
+
420
+ fclose( $fp );
421
+ exit;
422
+ }
423
+
424
+ /**
425
+ * Format the data if required
426
+ * @param string $meta_value
427
+ * @param string $meta name of meta key
428
+ * @return string
429
+ */
430
+ public static function format_export_meta( $meta_value, $meta ) {
431
+ switch ( $meta ) {
432
+ case '_sale_price_dates_from' :
433
+ case '_sale_price_dates_to' :
434
+ return $meta_value ? date( 'Y-m-d', $meta_value ) : '';
435
+ break;
436
+ case '_upsell_ids' :
437
+ case '_crosssell_ids' :
438
+ return implode( '|', array_filter( (array) json_decode( $meta_value ) ) );
439
+ break;
440
+ default :
441
+ return $meta_value;
442
+ break;
443
+ }
444
+ }
445
+
446
+ public static function format_data( $data ) {
447
+ $enc = mb_detect_encoding( $data, 'UTF-8, ISO-8859-1', true );
448
+ $data = ( $enc == 'UTF-8' ) ? $data : utf8_encode( $data );
449
+ return $data;
450
+ }
451
+
452
+ /**
453
+ * Wrap a column in quotes for the CSV
454
+ * @param string data to wrap
455
+ * @return string wrapped data
456
+ */
457
+ public static function wrap_column( $data ) {
458
+ return '"' . str_replace( '"', '""', $data ) . '"';
459
+ }
460
+
461
+ /**
462
+ * Get a list of all the meta keys for a post type. This includes all public, private,
463
+ * used, no-longer used etc. They will be sorted once fetched.
464
+ */
465
+ public static function get_all_metakeys( $post_type = 'product' ) {
466
+ global $wpdb;
467
+
468
+ $meta = $wpdb->get_col( $wpdb->prepare(
469
+ "SELECT DISTINCT pm.meta_key
470
+ FROM {$wpdb->postmeta} AS pm
471
+ LEFT JOIN {$wpdb->posts} AS p ON p.ID = pm.post_id
472
+ WHERE p.post_type = %s
473
+ AND p.post_status IN ( 'publish', 'pending', 'private', 'draft' )",
474
+ $post_type
475
+ ) );
476
+
477
+ sort( $meta );
478
+
479
+ return $meta;
480
+ }
481
+
482
+ /**
483
+ * Get a list of all the product attributes for a post type.
484
+ * These require a bit more digging into the values.
485
+ */
486
+ public static function get_all_product_attributes( $post_type = 'product' ) {
487
+ global $wpdb;
488
+
489
+ $results = $wpdb->get_col( $wpdb->prepare(
490
+ "SELECT DISTINCT pm.meta_value
491
+ FROM {$wpdb->postmeta} AS pm
492
+ LEFT JOIN {$wpdb->posts} AS p ON p.ID = pm.post_id
493
+ WHERE p.post_type = %s
494
+ AND p.post_status IN ( 'publish', 'pending', 'private', 'draft' )
495
+ AND pm.meta_key = '_product_attributes'",
496
+ $post_type
497
+ ) );
498
+
499
+ // Go through each result, and look at the attribute keys within them.
500
+ $result = array();
501
+
502
+ if ( ! empty( $results ) ) {
503
+ foreach( $results as $_product_attributes ) {
504
+ $attributes = maybe_unserialize( maybe_unserialize( $_product_attributes ) );
505
+ if ( ! empty( $attributes ) && is_array( $attributes ) ) {
506
+ foreach( $attributes as $key => $attribute ) {
507
+ if ( ! $key ) {
508
+ continue;
509
+ }
510
+ if ( ! strstr( $key, 'pa_' ) ) {
511
+ if ( empty( $attribute['name'] ) ) {
512
+ continue;
513
+ }
514
+ $key = $attribute['name'];
515
+ }
516
+
517
+ $result[ $key ] = $key;
518
+ }
519
+ }
520
+ }
521
+ }
522
+
523
+ sort( $result );
524
+
525
+ return $result;
526
+ }
527
+ }
includes/exporter/data/data-wf-hidden-meta-columns.php CHANGED
@@ -1,20 +1,20 @@
1
- <?php
2
-
3
- // Exclude columns handled specifically
4
- return array(
5
- '_product_attributes',
6
- '_file_paths',
7
- '_woocommerce_gpf_data',
8
- '_price',
9
- '_default_attributes',
10
- '_edit_last',
11
- '_edit_lock',
12
- '_wp_old_slug',
13
- '_product_image_gallery',
14
- '_max_variation_price',
15
- '_max_variation_regular_price',
16
- '_max_variation_sale_price',
17
- '_min_variation_price',
18
- '_min_variation_regular_price',
19
- '_min_variation_sale_price',
20
  );
1
+ <?php
2
+
3
+ // Exclude columns handled specifically
4
+ return array(
5
+ '_product_attributes',
6
+ '_file_paths',
7
+ '_woocommerce_gpf_data',
8
+ '_price',
9
+ '_default_attributes',
10
+ '_edit_last',
11
+ '_edit_lock',
12
+ '_wp_old_slug',
13
+ '_product_image_gallery',
14
+ '_max_variation_price',
15
+ '_max_variation_regular_price',
16
+ '_max_variation_sale_price',
17
+ '_min_variation_price',
18
+ '_min_variation_regular_price',
19
+ '_min_variation_sale_price',
20
  );
includes/exporter/data/data-wf-post-columns.php CHANGED
@@ -1,51 +1,51 @@
1
- <?php
2
- if ( ! defined( 'ABSPATH' ) ) {
3
- exit;
4
- }
5
-
6
- return apply_filters('woocommerce_csv_product_post_columns', array(
7
- 'post_title' => 'post_title',
8
- 'post_name' => 'post_name',
9
- 'ID' => 'ID',
10
- 'post_excerpt' => 'post_excerpt',
11
- 'post_content' => 'post_content',
12
- 'post_status' => 'post_status',
13
- 'menu_order' => 'menu_order',
14
- 'post_date' => 'post_date',
15
- 'post_author' => 'post_author',
16
- 'comment_status' => 'comment_status',
17
-
18
- // Meta
19
- '_sku' => 'sku',
20
- '_downloadable' => 'downloadable',
21
- '_virtual' => 'virtual',
22
- '_stock' => 'stock',
23
- '_regular_price' => 'regular_price',
24
- '_sale_price' => 'sale_price',
25
- '_weight' => 'weight',
26
- '_length' => 'length',
27
- '_width' => 'width',
28
- '_height' => 'height',
29
- '_tax_class' => 'tax_class',
30
-
31
- '_visibility' => 'visibility',
32
- '_stock_status' => 'stock_status',
33
- '_backorders' => 'backorders',
34
- '_manage_stock' => 'manage_stock',
35
- '_tax_status' => 'tax_status',
36
- '_upsell_ids' => 'upsell_ids',
37
- '_crosssell_ids' => 'crosssell_ids',
38
- '_featured' => 'featured',
39
-
40
- '_sale_price_dates_from' => 'sale_price_dates_from',
41
- '_sale_price_dates_to' => 'sale_price_dates_to',
42
-
43
- // Downloadable products
44
- '_download_limit' => 'download_limit',
45
- '_download_expiry' => 'download_expiry',
46
-
47
- // Virtual products
48
- '_product_url' => 'product_url',
49
- '_button_text' => 'button_text',
50
-
51
  ) );
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ return apply_filters('woocommerce_csv_product_post_columns', array(
7
+ 'post_title' => 'post_title',
8
+ 'post_name' => 'post_name',
9
+ 'ID' => 'ID',
10
+ 'post_excerpt' => 'post_excerpt',
11
+ 'post_content' => 'post_content',
12
+ 'post_status' => 'post_status',
13
+ 'menu_order' => 'menu_order',
14
+ 'post_date' => 'post_date',
15
+ 'post_author' => 'post_author',
16
+ 'comment_status' => 'comment_status',
17
+
18
+ // Meta
19
+ '_sku' => 'sku',
20
+ '_downloadable' => 'downloadable',
21
+ '_virtual' => 'virtual',
22
+ '_stock' => 'stock',
23
+ '_regular_price' => 'regular_price',
24
+ '_sale_price' => 'sale_price',
25
+ '_weight' => 'weight',
26
+ '_length' => 'length',
27
+ '_width' => 'width',
28
+ '_height' => 'height',
29
+ '_tax_class' => 'tax_class',
30
+
31
+ '_visibility' => 'visibility',
32
+ '_stock_status' => 'stock_status',
33
+ '_backorders' => 'backorders',
34
+ '_manage_stock' => 'manage_stock',
35
+ '_tax_status' => 'tax_status',
36
+ '_upsell_ids' => 'upsell_ids',
37
+ '_crosssell_ids' => 'crosssell_ids',
38
+ '_featured' => 'featured',
39
+
40
+ '_sale_price_dates_from' => 'sale_price_dates_from',
41
+ '_sale_price_dates_to' => 'sale_price_dates_to',
42
+
43
+ // Downloadable products
44
+ '_download_limit' => 'download_limit',
45
+ '_download_expiry' => 'download_expiry',
46
+
47
+ // Virtual products
48
+ '_product_url' => 'product_url',
49
+ '_button_text' => 'button_text',
50
+
51
  ) );
includes/importer/class-wf-csv-parser.php CHANGED
@@ -1,848 +1,848 @@
1
- <?php
2
- /**
3
- * WooCommerce CSV Importer class for managing parsing of CSV files.
4
- */
5
- class WF_CSV_Parser {
6
-
7
- var $row;
8
- var $post_type;
9
- var $reserved_fields; // Fields we map/handle (not custom fields)
10
- var $post_defaults; // Default post data
11
- var $postmeta_defaults; // default post meta
12
- var $postmeta_allowed; // post meta validation
13
- var $allowed_product_types; // Allowed product types
14
-
15
- /**
16
- * Constructor
17
- */
18
- public function __construct( $post_type = 'product' ) {
19
- $this->post_type = $post_type;
20
- $this->reserved_fields = include( 'data/data-wf-reserved-fields.php' );
21
- $this->post_defaults = include( 'data/data-wf-post-defaults.php' );
22
- $this->postmeta_defaults = include( 'data/data-wf-postmeta-defaults.php' );
23
- $this->postmeta_allowed = include( 'data/data-wf-postmeta-allowed.php' );
24
-
25
- $simple_term = get_term_by( 'slug', 'simple', 'product_type' );
26
- $variable_term = get_term_by( 'slug', 'variable', 'product_type' );
27
- $grouped_term = get_term_by( 'slug', 'grouped', 'product_type' );
28
- $external_term = get_term_by( 'slug', 'external', 'product_type' );
29
-
30
- $this->allowed_product_types = array(
31
- 'simple' => $simple_term->term_id,
32
- 'variable' => $variable_term->term_id,
33
- 'grouped' => $grouped_term->term_id,
34
- 'external' => $external_term->term_id
35
- );
36
-
37
- }
38
-
39
- /**
40
- * Format data from the csv file
41
- * @param string $data
42
- * @param string $enc
43
- * @return string
44
- */
45
- public function format_data_from_csv( $data, $enc ) {
46
- return ( $enc == 'UTF-8' ) ? $data : utf8_encode( $data );
47
- }
48
-
49
- /**
50
- * Parse the data
51
- * @param string $file [description]
52
- * @param string $delimiter [description]
53
- * @param array $mapping [description]
54
- * @param integer $start_pos [description]
55
- * @param integer $end_pos [description]
56
- * @return array
57
- */
58
- public function parse_data( $file, $delimiter, $mapping, $start_pos = 0, $end_pos = null, $eval_field ) {
59
- // Set locale
60
- $enc = mb_detect_encoding( $file, 'UTF-8, ISO-8859-1', true );
61
- if ( $enc )
62
- setlocale( LC_ALL, 'en_US.' . $enc );
63
- @ini_set( 'auto_detect_line_endings', true );
64
-
65
- $parsed_data = array();
66
- $raw_headers = array();
67
-
68
- // Put all CSV data into an associative array
69
- if ( ( $handle = fopen( $file, "r" ) ) !== FALSE ) {
70
-
71
- $header = fgetcsv( $handle, 0, $delimiter );
72
- if ( $start_pos != 0 )
73
- fseek( $handle, $start_pos );
74
-
75
- while ( ( $postmeta = fgetcsv( $handle, 0, $delimiter ) ) !== FALSE ) {
76
- $row = array();
77
-
78
- foreach ( $header as $key => $heading ) {
79
- // Heading is the lowercase version of the column name
80
- $s_heading = strtolower( $heading );
81
-
82
- // Check if this heading is being mapped to a different field
83
- if ( isset( $mapping[$s_heading] ) ) {
84
- if ( $mapping[$s_heading] == 'import_as_meta' ) {
85
-
86
- $s_heading = 'meta:' . $s_heading;
87
-
88
- } elseif ( $mapping[$s_heading] == 'import_as_images' ) {
89
-
90
- $s_heading = 'images';
91
-
92
- } else {
93
- $s_heading = esc_attr( $mapping[$s_heading] );
94
- }
95
- }
96
- foreach ($mapping as $mkey => $mvalue) {
97
- if(trim($mvalue) === trim($heading)){
98
- $s_heading = $mkey;
99
- }
100
- }
101
-
102
- if ( $s_heading == '' )
103
- continue;
104
-
105
- // Add the heading to the parsed data
106
- $row[$s_heading] = ( isset( $postmeta[$key] ) ) ? $this->format_data_from_csv( $postmeta[$key], $enc ) : '';
107
-
108
- $row[$s_heading] = $this->evaluate_field($row[$s_heading], $eval_field[strtolower( $heading )]);
109
-
110
- // Raw Headers stores the actual column name in the CSV
111
- $raw_headers[ $s_heading ] = $heading;
112
- }
113
- $parsed_data[] = $row;
114
-
115
- unset( $postmeta, $row );
116
-
117
- $position = ftell( $handle );
118
-
119
- if ( $end_pos && $position >= $end_pos )
120
- break;
121
- }
122
- fclose( $handle );
123
- }
124
- return array( $parsed_data, $raw_headers, $position );
125
- }
126
-
127
- private function evaluate_field($value, $evaluation_field){
128
- //echo "value:$value, $evaluation_field </br>";
129
- $processed_value = $value;
130
- if(!empty($evaluation_field)){
131
- $operator = substr($evaluation_field, 0, 1);
132
- if(in_array($operator, array('=', '+', '-', '*', '/', '&'))){
133
- $eval_val = substr($evaluation_field, 1);
134
- //echo "operator:$operator";
135
- switch($operator){
136
- case '=':
137
- $processed_value = trim($eval_val);
138
- break;
139
- case '+':
140
- $processed_value = $value + $eval_val;
141
- break;
142
- case '-':
143
- $processed_value = $value - $eval_val;
144
- break;
145
- case '*':
146
- $processed_value = $value * $eval_val;
147
- break;
148
- case '/':
149
- $processed_value = $value / $eval_val;
150
- break;
151
- case '&':
152
- if (strpos($eval_val, '[VAL]') !== false) {
153
- $processed_value = str_replace('[VAL]',$value,$eval_val);
154
- }
155
- else{
156
- $processed_value = $value . $eval_val;
157
- }
158
- break;
159
- }
160
- }
161
- }
162
- return $processed_value;
163
- }
164
-
165
- /**
166
- * Parse product
167
- * @param array $item
168
- * @param integer $merge_empty_cells
169
- * @return array
170
- */
171
- public function parse_product( $item, $merge_empty_cells = 0 ) {
172
- global $WF_CSV_Product_Import, $wpdb;
173
- $this->row++;
174
-
175
- $terms_array = $postmeta = $product = array();
176
- $attributes = $default_attributes = $gpf_data = null;
177
-
178
- // Merging
179
- $merging = ( ! empty( $_GET['merge'] ) && $_GET['merge'] ) ? true : false;
180
- //if($item['post_parent']!== '' && $item['parent_sku'] !== ''){
181
-
182
- $this->post_defaults['post_type'] = 'product';
183
- $this->post_type = 'product';
184
- // Post ID field mapping
185
- $post_id = ( ! empty( $item['id'] ) ) ? $item['id'] : 0;
186
- $post_id = ( ! empty( $item['post_id'] ) ) ? $item['post_id'] : $post_id;
187
- if ( $merging ) {
188
-
189
- $product['merging'] = true;
190
-
191
- $WF_CSV_Product_Import->log->add( 'csv-import', sprintf( __('> Row %s - preparing for merge.', 'wf_csv_import_export'), $this->row ) );
192
-
193
- // Required fields
194
- if ( ! $post_id && empty( $item['sku'] ) ) {
195
-
196
- $WF_CSV_Product_Import->log->add( 'csv-import', __( '> > Cannot merge without id or sku. Importing instead.', 'wf_csv_import_export') );
197
-
198
- $merging = false;
199
- } else {
200
-
201
- // Check product exists
202
- if ( ! $post_id ) {
203
- // Check product to merge exists
204
- $db_query = $wpdb->prepare("
205
- SELECT $wpdb->posts.ID
206
- FROM $wpdb->posts
207
- LEFT JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id)
208
- WHERE $wpdb->posts.post_type = 'product'
209
- AND $wpdb->posts.post_status IN ( 'publish', 'private', 'draft', 'pending', 'future' )
210
- AND $wpdb->postmeta.meta_key = '_sku' AND $wpdb->postmeta.meta_value = '%s'
211
- ", $item['sku']);
212
- $found_product_id = $wpdb->get_var($db_query);
213
- if ( ! $found_product_id ) {
214
- $WF_CSV_Product_Import->log->add( 'csv-import', sprintf(__( '> > Skipped. Cannot find product with sku %s. Importing instead.', 'wf_csv_import_export'), $item['sku']) );
215
- $merging = false;
216
-
217
- } else {
218
-
219
- $post_id = $found_product_id;
220
-
221
- $WF_CSV_Product_Import->log->add( 'csv-import', sprintf(__( '> > Found product with ID %s.', 'wf_csv_import_export'), $post_id) );
222
-
223
- }
224
- }
225
- $product['merging'] = true;
226
- }
227
- }
228
-
229
- if ( ! $merging ) {
230
-
231
- $product['merging'] = false;
232
- $WF_CSV_Product_Import->log->add( 'csv-import', sprintf( __('> Row %s - preparing for import.', 'wf_csv_import_export'), $this->row ) );
233
-
234
- // Required fields
235
- if ( $item['post_parent']=== '' && $item['post_title']=== '') {
236
- $WF_CSV_Product_Import->log->add( 'csv-import', __( '> > Skipped. No post_title set for new product.', 'wf_csv_import_export') );
237
- return new WP_Error( 'parse-error', __( 'No post_title set for new product.', 'wf_csv_import_export' ) );
238
- }
239
- if ( $item['post_parent']!== '' && $item['post_parent']!== null && $item['parent_sku'] === '' ) {
240
- $WF_CSV_Product_Import->log->add( 'csv-import', __( '> > Skipped. No parent set for new variation product.', 'wf_csv_import_export') );
241
- //return new WP_Error( 'parse-error', __( 'No post_title set for new product.', 'wf_csv_import_export' ) );
242
- return new WP_Error( 'parse-error', __( 'No parent set for new variation product.', 'wf_csv_import_export' ) );
243
- }
244
-
245
- }
246
-
247
- $product['post_id'] = $post_id;
248
-
249
-
250
- // Get post fields
251
- foreach ( $this->post_defaults as $column => $default ) {
252
- if ( isset( $item[ $column ] ) ) $product[ $column ] = $item[ $column ];
253
- }
254
-
255
- // Get custom fields
256
- foreach ( $this->postmeta_defaults as $column => $default ) {
257
- if ( isset( $item[$column] ) )
258
- $postmeta[$column] = (string) $item[$column];
259
- elseif ( isset( $item['_' . $column] ) )
260
- $postmeta[$column] = (string) $item['_' . $column];
261
-
262
- // Check custom fields are valid
263
- if ( isset( $postmeta[$column] ) && isset( $this->postmeta_allowed[$column] ) && ! in_array( $postmeta[$column], $this->postmeta_allowed[$column] ) ) {
264
- $postmeta[$column] = $this->postmeta_defaults[$column];
265
- }
266
- }
267
-
268
- if ( ! $merging ) {
269
- // Merge post meta with defaults
270
- $product = wp_parse_args( $product, $this->post_defaults );
271
- $postmeta = wp_parse_args( $postmeta, $this->postmeta_defaults );
272
- }
273
-
274
- // Handle special meta fields
275
- if ( isset($item['post_parent']) ) {
276
-
277
- // price
278
- if ( $merging ) {
279
- if ( ! isset( $postmeta['regular_price'] ) )
280
- $postmeta['regular_price'] = get_post_meta( $post_id, '_regular_price', true );
281
- $postmeta['regular_price'] = $this->hf_currency_formatter($postmeta['regular_price']);
282
- if ( ! isset( $postmeta['sale_price'] ) )
283
- $postmeta['sale_price'] = get_post_meta( $post_id, '_sale_price', true );
284
- $postmeta['sale_price'] = $this->hf_currency_formatter($postmeta['sale_price']);
285
- }
286
-
287
- if ( isset( $postmeta['regular_price'] ) && isset( $postmeta['sale_price'] ) && $postmeta['sale_price'] !== '' ) {
288
- $postmeta['sale_price'] = $this->hf_currency_formatter($postmeta['sale_price']);
289
- $postmeta['regular_price'] = $this->hf_currency_formatter($postmeta['regular_price']);
290
- $price = min( $postmeta['sale_price'], $postmeta['regular_price']);
291
- $postmeta['price'] = $price;
292
- } elseif ( isset( $postmeta['regular_price'] ) ) {
293
- $postmeta['price'] = $this->hf_currency_formatter($postmeta['regular_price']);
294
- }
295
-
296
- } else {
297
-
298
- // price
299
- if ( $merging ) {
300
- if ( ! isset( $postmeta['regular_price'] ) )
301
- $postmeta['regular_price'] = get_post_meta( $post_id, '_regular_price', true );
302
- $postmeta['regular_price'] = $this->hf_currency_formatter($postmeta['regular_price']);
303
- if ( ! isset( $postmeta['sale_price'] ) )
304
- $postmeta['sale_price'] = get_post_meta( $post_id, '_sale_price', true );
305
- $postmeta['sale_price'] = $this->hf_currency_formatter($postmeta['sale_price']);
306
- }
307
-
308
- if ( isset( $postmeta['regular_price'] ) && isset( $postmeta['sale_price'] ) && $postmeta['sale_price'] !== '' ) {
309
- $postmeta['sale_price'] = $this->hf_currency_formatter($postmeta['sale_price']);
310
- $postmeta['regular_price'] = $this->hf_currency_formatter($postmeta['regular_price']);
311
- $price = min( $postmeta['sale_price'], $postmeta['regular_price']);
312
- $postmeta['price'] = $price;
313
- } elseif ( isset( $postmeta['regular_price'] ) ) {
314
- $postmeta['price'] = $this->hf_currency_formatter($postmeta['regular_price']);
315
- }
316
-
317
- // Reset dynamically generated meta
318
- $postmeta['min_variation_price'] = $postmeta['max_variation_price'] = $postmeta['min_variation_regular_price'] =$postmeta['max_variation_regular_price'] = $postmeta['min_variation_sale_price'] = $postmeta['max_variation_sale_price'] = '';
319
- }
320
-
321
- // upsells
322
- if ( isset( $postmeta['upsell_ids'] ) && ! is_array( $postmeta['upsell_ids'] ) ) {
323
- $ids = array_filter( array_map( 'trim', explode( '|', $postmeta['upsell_ids'] ) ) );
324
- $postmeta['upsell_ids'] = $ids;
325
- }
326
-
327
- // crosssells
328
- if ( isset( $postmeta['crosssell_ids'] ) && ! is_array( $postmeta['crosssell_ids'] ) ) {
329
- $ids = array_filter( array_map( 'trim', explode( '|', $postmeta['crosssell_ids'] ) ) );
330
- $postmeta['crosssell_ids'] = $ids;
331
- }
332
-
333
- // Sale dates
334
- if ( isset( $postmeta['sale_price_dates_from'] ) ) {
335
- $postmeta['sale_price_dates_from'] = empty( $postmeta['sale_price_dates_from'] ) ? '' : strtotime( $postmeta['sale_price_dates_from'] );
336
- }
337
-
338
- if ( isset( $postmeta['sale_price_dates_to'] ) ) {
339
- $postmeta['sale_price_dates_to'] = empty( $postmeta['sale_price_dates_to'] ) ? '' : strtotime( $postmeta['sale_price_dates_to'] );
340
- }
341
-
342
- // Relative stock updates
343
- if ( $merging ) {
344
- if ( isset( $postmeta['stock'] ) ) {
345
-
346
- $postmeta['stock'] = trim( $postmeta['stock'] );
347
-
348
- $mode = substr( $postmeta['stock'], 0, 3 );
349
-
350
- if ( $mode == '(+)' ) {
351
- $old_stock = absint( get_post_meta( $post_id, '_stock', true ) );
352
- $amount = absint( substr( $postmeta['stock'], 3 ) );
353
- $new_stock = $old_stock + $amount;
354
- $postmeta['stock'] = $new_stock;
355
- }
356
-
357
- if ( $mode == '(-)' ) {
358
- $old_stock = absint( get_post_meta( $post_id, '_stock', true ) );
359
- $amount = absint( substr( $postmeta['stock'], 3 ) );
360
- $new_stock = $old_stock - $amount;
361
- $postmeta['stock'] = $new_stock;
362
- }
363
- }
364
- }
365
-
366
- // Format post status
367
- if ( ! empty( $product['post_status'] ) ) {
368
- $product['post_status'] = strtolower( $product['post_status'] );
369
-
370
- if ( empty($item['post_parent']) ) {
371
- if ( ! in_array( $product['post_status'], array( 'publish', 'private', 'draft', 'pending', 'future', 'inherit', 'trash' ) ) ) {
372
- $product['post_status'] = 'publish';
373
- }
374
- } else {
375
- if ( ! in_array( $product['post_status'], array( 'private', 'publish' ) ) ) {
376
- $product['post_status'] = 'publish';
377
- }
378
- }
379
- }
380
-
381
- // Put set core product postmeta into product array
382
- foreach ( $postmeta as $key => $value ) {
383
- $product['postmeta'][] = array( 'key' => '_' . esc_attr($key), 'value' => $value );
384
- }
385
-
386
- /**
387
- * Handle other columns
388
- */
389
- foreach ( $item as $key => $value ) {
390
-
391
- if ( empty($item['post_parent']) && ! $merge_empty_cells && $value == "" )
392
- continue;
393
-
394
- /**
395
- * File path handling
396
- */
397
- if ( $key == 'file_paths' || $key == 'downloadable_files' ) {
398
-
399
- $file_paths = explode( '|', $value );
400
- $_file_paths = array();
401
- foreach ( $file_paths as $file_path ) {
402
- // 2.1
403
- if ( function_exists( 'wc_get_filename_from_url' ) ) {
404
- $file_path = array_map( 'trim', explode( '::', $file_path ) );
405
- if ( sizeof( $file_path ) === 2 ) {
406
- $file_name = $file_path[0];
407
- $file_path = $file_path[1];
408
- } else {
409
- $file_name = wc_get_filename_from_url( $file_path[0] );
410
- $file_path = $file_path[0];
411
- }
412
- $_file_paths[ md5( $file_path ) ] = array(
413
- 'name' => $file_name,
414
- 'file' => $file_path
415
- );
416
- } else {
417
- $file_path = trim( $file_path );
418
- $_file_paths[ md5( $file_path ) ] = $file_path;
419
- }
420
- }
421
- $value = $_file_paths;
422
-
423
- $product['postmeta'][] = array( 'key' => '_' . esc_attr( $key ), 'value' => $value );
424
- }
425
-
426
- elseif ( strstr( $key, 'tax:' ) ) {
427
-
428
- // Get taxonomy
429
- $taxonomy = trim( str_replace( 'tax:', '', $key ) );
430
-
431
- // Exists?
432
- if ( ! taxonomy_exists( $taxonomy ) ) {
433
- $WF_CSV_Product_Import->log->add( 'csv-import', sprintf( __('> > Skipping taxonomy "%s" - it does not exist.', 'wf_csv_import_export'), $taxonomy ) );
434
- continue;
435
- }
436
-
437
- // Product type check
438
- if ( $taxonomy == 'product_type' ) {
439
- $term = strtolower( $value );
440
-
441
- if ( ! array_key_exists( $term, $this->allowed_product_types ) ) {
442
- $WF_CSV_Product_Import->log->add( 'csv-import', sprintf( __('> > > Product type "%s" not allowed - using simple.', 'wf_csv_import_export'), $term ) );
443
- $term_id = $this->allowed_product_types['simple'];
444
- } else {
445
- $term_id = $this->allowed_product_types[ $term ];
446
- }
447
-
448
- // Add to array
449
- $terms_array[] = array(
450
- 'taxonomy' => $taxonomy,
451
- 'terms' => array( $term_id )
452
- );
453
-
454
- continue;
455
- }
456
-
457
- // Get terms - ID => parent
458
- $terms = array();
459
- $raw_terms = explode( '|', $value );
460
- $raw_terms = array_map( 'trim', $raw_terms );
461
-
462
- // Handle term hierachy (>)
463
- foreach ( $raw_terms as $raw_term ) {
464
-
465
- if ( strstr( $raw_term, '>' ) ) {
466
-
467
- $raw_term = explode( '>', $raw_term );
468
- $raw_term = array_map( 'trim', $raw_term );
469
- $raw_term = array_map( 'wp_specialchars', $raw_term );
470
- $raw_term = array_filter( $raw_term );
471
-
472
- $parent = 0;
473
- $loop = 0;
474
-
475
- foreach ( $raw_term as $term ) {
476
- $loop ++;
477
- $term_id = '';
478
-
479
- if ( isset( $this->inserted_terms[ $taxonomy ][ $parent ][ $term ] ) ) {
480
- $term_id = $this->inserted_terms[ $taxonomy ][ $parent ][ $term ];
481
- } elseif ( $term ) {
482
-
483
- /**
484
- * Check term existance
485
- */
486
- $term_may_exist = term_exists( $term, $taxonomy, absint( $parent ) );
487
-
488
- $WF_CSV_Product_Import->log->add( 'CSV-Import', sprintf( __( '> > (' . __LINE__ . ') Term %s (%s) exists? %s', 'wf_csv_import_export' ), sanitize_text_field( $term ), esc_html( $taxonomy ), $term_may_exist ? print_r( $term_may_exist, true ) : '-' ) );
489
-
490
- if ( is_array( $term_may_exist ) ) {
491
- $possible_term = get_term( $term_may_exist['term_id'], 'product_cat' );
492
-
493
- if ( $possible_term->parent == $parent ) {
494
- $term_id = $term_may_exist['term_id'];
495
- }
496
- }
497
-
498
- if ( ! $term_id ) {
499
-
500
- // Create appropriate slug
501
- $slug = array();
502
-
503
- for ( $i = 0; $i < $loop; $i ++ )
504
- $slug[] = $raw_term[ $i ];
505
-
506
- $slug = sanitize_title( implode( '-', $slug ) );
507
-
508
- $t = wp_insert_term( $term, $taxonomy, array( 'parent' => $parent, 'slug' => $slug ) );
509
-
510
- if ( ! is_wp_error( $t ) ) {
511
- $term_id = $t['term_id'];
512
- } else {
513
- $WF_CSV_Product_Import->log->add( 'CSV-Import', sprintf( __( '> > (' . __LINE__ . ') Failed to import term %s, parent %s - %s', 'wf_csv_import_export' ), sanitize_text_field( $term ), sanitize_text_field( $parent ), sanitize_text_field( $taxonomy ) ) );
514
- break;
515
- }
516
- }
517
-
518
- $this->inserted_terms[$taxonomy][$parent][$term] = $term_id;
519
-
520
- }
521
-
522
- if ( ! $term_id )
523
- break;
524
-
525
- // Add to product terms, ready to set if this is the final term
526
- if ( sizeof( $raw_term ) == $loop )
527
- $terms[] = $term_id;
528
-
529
- $parent = $term_id;
530
- }
531
-
532
- } else {
533
-
534
- $term_id = '';
535
- $raw_term = wp_specialchars( $raw_term );
536
-
537
- if ( isset( $this->inserted_terms[$taxonomy][0][$raw_term] ) ) {
538
-
539
- $term_id = $this->inserted_terms[$taxonomy][0][$raw_term];
540
-
541
- } elseif ( $raw_term ) {
542
-
543
- // Check term existance
544
- $term_exists = term_exists( $raw_term, $taxonomy, 0 );
545
- $term_id = is_array( $term_exists ) ? $term_exists['term_id'] : 0;
546
-
547
- if ( ! $term_id ) {
548
- $t = wp_insert_term( trim( $raw_term ), $taxonomy, array( 'parent' => 0 ) );
549
-
550
- if ( ! is_wp_error( $t ) ) {
551
- $term_id = $t['term_id'];
552
- } else {
553
- $WF_CSV_Product_Import->log->add( 'csv-import', sprintf( __( '> > Failed to import term %s %s', 'wf_csv_import_export' ), esc_html($raw_term), esc_html($taxonomy) ) );
554
- break;
555
- }
556
- }
557
-
558
- $this->inserted_terms[$taxonomy][0][$raw_term] = $term_id;
559
-
560
- }
561
-
562
- // Store terms for later insertion
563
- if ( $term_id )
564
- $terms[] = $term_id;
565
-
566
- }
567
-
568
- }
569
-
570
- // Any defined?
571
- if ( sizeof( $terms ) == 0 )
572
- continue;
573
-
574
- // Add to array
575
- $terms_array[] = array(
576
- 'taxonomy' => $taxonomy,
577
- 'terms' => $terms
578
- );
579
- }
580
-
581
- /**
582
- * Handle Attributes
583
- */
584
- elseif ( strstr( $key, 'attribute:' ) ) {
585
-
586
- $attribute_key = sanitize_title( trim( str_replace( 'attribute:', '', $key ) ) );
587
- $attribute_name = str_replace( 'attribute:', '', $WF_CSV_Product_Import->raw_headers[ $key ] );
588
-
589
- if ( ! $attribute_key )
590
- continue;
591
-
592
- // Taxonomy
593
- if ( substr( $attribute_key, 0, 3 ) == 'pa_' ) {
594
-
595
- $taxonomy = $attribute_key;
596
-
597
- // Exists?
598
- if ( ! taxonomy_exists( $taxonomy ) ) {
599
-
600
- $nicename = strtolower( sanitize_title( str_replace( 'pa_', '', $taxonomy ) ) );
601
-
602
- $WF_CSV_Product_Import->log->add( 'csv-import', sprintf( __('> > Attribute taxonomy "%s" does not exist. Adding it. Nicename: %s', 'wf_csv_import_export'), $taxonomy, $nicename ) );
603
-
604
- $exists_in_db = $wpdb->get_var( "SELECT attribute_id FROM " . $wpdb->prefix . "woocommerce_attribute_taxonomies WHERE attribute_name = '" . $nicename . "';" );
605
-
606
- if ( ! $exists_in_db ) {
607
- // Create the taxonomy
608
- $wpdb->insert( $wpdb->prefix . "woocommerce_attribute_taxonomies", array( 'attribute_name' => $nicename, 'attribute_label' => $nicename, 'attribute_type' => 'select', 'attribute_orderby' => 'menu_order' ) );
609
- } else {
610
- $WF_CSV_Product_Import->log->add( 'csv-import', sprintf( __('> > Attribute taxonomy %s already exists in DB.', 'wf_csv_import_export'), $taxonomy ) );
611
- }
612
-
613
- // Register the taxonomy now so that the import works!
614
- register_taxonomy( $taxonomy,
615
- array( 'product', 'product_variation' ),
616
- array(
617
- 'hierarchical' => true,
618
- 'show_ui' => false,
619
- 'query_var' => true,
620
- 'rewrite' => false,
621
- )
622
- );
623
- }
624
-
625
- // Get terms
626
- $terms = array();
627
- $raw_terms = explode( '|', $value );
628
- $raw_terms = array_map( 'wp_specialchars', $raw_terms );
629
- $raw_terms = array_map( 'trim', $raw_terms );
630
-
631
- if ( sizeof( $raw_terms ) > 0 ) {
632
-
633
- foreach ( $raw_terms as $raw_term ) {
634
-
635
- if ( empty( $raw_term ) && 0 != $raw_term ) {
636
- continue;
637
- }
638
-
639
- // Check term existance
640
- $term_exists = term_exists( $raw_term, $taxonomy, 0 );
641
- $term_id = is_array( $term_exists ) ? $term_exists['term_id'] : 0;
642
-
643
- if ( ! $term_id ) {
644
- $t = wp_insert_term( trim( $raw_term ), $taxonomy );
645
-
646
- if ( ! is_wp_error( $t ) ) {
647
- $term_id = $t['term_id'];
648
-
649
- $WF_CSV_Product_Import->log->add( 'csv-import', sprintf( __( '> > Inserted Raw Term %s ID = %s', 'wf_csv_import_export' ), esc_html( $raw_term ), $term_id ) );
650
- } else {
651
- $WF_CSV_Product_Import->log->add( 'csv-import', sprintf( __( '> > Failed to import term %s %s', 'wf_csv_import_export' ), esc_html($raw_term), esc_html($taxonomy) ) );
652
- break;
653
- }
654
- } else {
655
- $WF_CSV_Product_Import->log->add( 'csv-import', sprintf( __( '> > Raw Term %s ID = %s', 'wf_csv_import_export' ), esc_html( $raw_term ), $term_id ) );
656
- }
657
-
658
- if ( $term_id ) {
659
- $terms[] = $term_id;
660
- }
661
- }
662
-
663
- }
664
-
665
- // Add to array
666
- $terms_array[] = array(
667
- 'taxonomy' => $taxonomy,
668
- 'terms' => $terms
669
- );
670
-
671
- // Ensure we have original attributes
672
- if ( is_null( $attributes ) && $merging ) {
673
- $attributes = array_filter( (array) maybe_unserialize( get_post_meta( $post_id, '_product_attributes', true ) ) );
674
- } elseif ( is_null( $attributes ) ) {
675
- $attributes = array();
676
- }
677
-
678
- // Set attribute
679
- if ( ! isset( $attributes[$taxonomy] ) )
680
- $attributes[$taxonomy] = array();
681
-
682
- $attributes[$taxonomy]['name'] = $taxonomy;
683
- $attributes[$taxonomy]['value'] = null;
684
- $attributes[$taxonomy]['is_taxonomy'] = 1;
685
-
686
- if ( ! isset( $attributes[$taxonomy]['position'] ) )
687
- $attributes[$taxonomy]['position'] = 0;
688
- if ( ! isset( $attributes[$taxonomy]['is_visible'] ) )
689
- $attributes[$taxonomy]['is_visible'] = 1;
690
- if ( ! isset( $attributes[$taxonomy]['is_variation'] ) )
691
- $attributes[$taxonomy]['is_variation'] = 0;
692
-
693
- } else {
694
-
695
- if ( ! $value || ! $attribute_key ) continue;
696
-
697
- // Set attribute
698
- if ( ! isset( $attributes[$attribute_key] ) )
699
- $attributes[$attribute_key] = array();
700
-
701
- $attributes[$attribute_key]['name'] = $attribute_name;
702
- $attributes[$attribute_key]['value'] = $value;
703
- $attributes[$attribute_key]['is_taxonomy'] = 0;
704
-
705
- if ( ! isset( $attributes[$attribute_key]['position'] ) )
706
- $attributes[$attribute_key]['position'] = 0;
707
- if ( ! isset( $attributes[$attribute_key]['is_visible'] ) )
708
- $attributes[$attribute_key]['is_visible'] = 1;
709
- if ( ! isset( $attributes[$attribute_key]['is_variation'] ) )
710
- $attributes[$attribute_key]['is_variation'] = 0;
711
- }
712
-
713
- }
714
-
715
- /**
716
- * Handle Attributes Data - position|is_visible|is_variation
717
- */
718
- elseif ( strstr( $key, 'attribute_data:' ) ) {
719
-
720
- $attribute_key = sanitize_title( trim( str_replace( 'attribute_data:', '', $key ) ) );
721
-
722
- if ( ! $attribute_key ) {
723
- continue;
724
- }
725
-
726
- $values = explode( '|', $value );
727
- $position = isset( $values[0] ) ? (int) $values[0] : 0;
728
- $visible = isset( $values[1] ) ? (int) $values[1] : 1;
729
- $variation = isset( $values[2] ) ? (int) $values[2] : 0;
730
-
731
- // Ensure we have original attributes
732
- if ( ! isset( $attributes[ $attribute_key ] ) ) {
733
- if ( $merging ) {
734
- $existing_attributes = array_filter( (array) maybe_unserialize( get_post_meta( $post_id, '_product_attributes', true ) ) );
735
- $attributes[ $attribute_key ] = isset( $existing_attributes[ $attribute_key ] ) ? $existing_attributes[ $attribute_key ] : array();
736
- } else {
737
- $attributes[ $attribute_key ] = array();
738
- }
739
- }
740
-
741
- $attributes[ $attribute_key ]['position'] = $position;
742
- $attributes[ $attribute_key ]['is_visible'] = $visible;
743
- $attributes[ $attribute_key ]['is_variation'] = $variation;
744
- }
745
-
746
- /**
747
- * Handle Attributes Default Values
748
- */
749
- elseif ( strstr( $key, 'attribute_default:' ) ) {
750
-
751
- $attribute_key = sanitize_title( trim( str_replace( 'attribute_default:', '', $key ) ) );
752
-
753
- if ( ! $attribute_key ) continue;
754
-
755
- // Ensure we have original attributes
756
- if ( is_null( $default_attributes ) && $merging ) {
757
- $default_attributes = array_filter( (array) maybe_unserialize( get_post_meta( $post_id, '_default_attributes', true ) ) );
758
- } elseif ( is_null( $default_attributes ) ) {
759
- $default_attributes = array();
760
- }
761
-
762
- $default_attributes[ $attribute_key ] = $value;
763
- }
764
-
765
- /**
766
- * Handle gpf: google product feed columns
767
- */
768
- elseif ( strstr( $key, 'gpf:' ) ) {
769
-
770
- $gpf_key = trim( str_replace( 'gpf:', '', $key ) );
771
-
772
- // Get original values
773
- if ( is_null( $gpf_data ) && $merging ) {
774
- $gpf_data = array_filter( (array) maybe_unserialize( get_post_meta( $post_id, '_woocommerce_gpf_data', true ) ) );
775
- } elseif ( is_null( $gpf_data ) ) {
776
- $gpf_data = array(
777
- 'availability' => '',
778
- 'condition' => '',
779
- 'brand' => '',
780
- 'product_type' => '',
781
- 'google_product_category' => '',
782
- 'gtin' => '',
783
- 'mpn' => '',
784
- 'gender' => '',
785
- 'age_group' => '',
786
- 'color' => '',
787
- 'size' => ''
788
- );
789
- }
790
-
791
- $gpf_data[$gpf_key] = $value;
792
-
793
- }
794
-
795
- /**
796
- * Handle upsell SKUs which we cannot assign until we get IDs later on
797
- */
798
- elseif ( strstr( $key, 'upsell_skus' ) ) {
799
- if ( $value ) {
800
- $skus = array_filter( array_map( 'trim', explode( '|', $value ) ) );
801
- $product['upsell_skus'] = $skus;
802
- }
803
- }
804
-
805
- /**
806
- * Handle crosssells SKUs which we cannot assign until we get IDs later on
807
- */
808
- elseif ( strstr( $key, 'crosssell_skus' ) ) {
809
- if ( $value ) {
810
- $skus = array_filter( array_map( 'trim', explode( '|', $value ) ) );
811
- $product['crosssell_skus'] = $skus;
812
- }
813
- }
814
-
815
- }
816
-
817
- // Remove empty attribues
818
- if(!empty($attributes))
819
- foreach ( $attributes as $key => $value ) {
820
- if ( ! isset($value['name']) ) unset( $attributes[$key] );
821
- }
822
-
823
- /**
824
- * Handle images
825
- */
826
- if ( ! empty( $item['images'] ) ) {
827
- $images = array_map( 'trim', explode( '|', $item['images'] ) );
828
- } else {
829
- $images = '';
830
- }
831
-
832
- $product['postmeta'][] = array( 'key' => '_default_attributes', 'value' => $default_attributes );
833
- $product['attributes'] = $attributes;
834
- $product['gpf_data'] = $gpf_data;
835
- $product['images'] = $images;
836
- $product['terms'] = $terms_array;
837
- $product['sku'] = ( ! empty( $item['sku'] ) ) ? $item['sku'] : '';
838
- $product['post_title'] = ( ! empty( $item['post_title'] ) ) ? $item['post_title'] : '';
839
- $product['post_type'] = $this->post_type;
840
- unset( $item, $terms_array, $postmeta, $attributes, $gpf_data, $images );
841
- return $product;
842
- }
843
- function hf_currency_formatter($price){
844
- $decimal_seperator = wc_get_price_decimal_separator();
845
- //return ereg_replace("[^0-9\\'.$decimal_seperator.']", "", $price);
846
- return preg_replace("[^0-9\\'.$decimal_seperator.']", "", $price);
847
- }
848
- }
1
+ <?php
2
+ /**
3
+ * WooCommerce CSV Importer class for managing parsing of CSV files.
4
+ */
5
+ class WF_CSV_Parser {
6
+
7
+ var $row;
8
+ var $post_type;
9
+ var $reserved_fields; // Fields we map/handle (not custom fields)
10
+ var $post_defaults; // Default post data
11
+ var $postmeta_defaults; // default post meta
12
+ var $postmeta_allowed; // post meta validation
13
+ var $allowed_product_types; // Allowed product types
14
+
15
+ /**
16
+ * Constructor
17
+ */
18
+ public function __construct( $post_type = 'product' ) {
19
+ $this->post_type = $post_type;
20
+ $this->reserved_fields = include( 'data/data-wf-reserved-fields.php' );
21
+ $this->post_defaults = include( 'data/data-wf-post-defaults.php' );
22
+ $this->postmeta_defaults = include( 'data/data-wf-postmeta-defaults.php' );
23
+ $this->postmeta_allowed = include( 'data/data-wf-postmeta-allowed.php' );
24
+
25
+ $simple_term = get_term_by( 'slug', 'simple', 'product_type' );
26
+ $variable_term = get_term_by( 'slug', 'variable', 'product_type' );
27
+ $grouped_term = get_term_by( 'slug', 'grouped', 'product_type' );
28
+ $external_term = get_term_by( 'slug', 'external', 'product_type' );
29
+
30
+ $this->allowed_product_types = array(
31
+ 'simple' => $simple_term->term_id,
32
+ 'variable' => $variable_term->term_id,
33
+ 'grouped' => $grouped_term->term_id,
34
+ 'external' => $external_term->term_id
35
+ );
36
+
37
+ }
38
+
39
+ /**
40
+ * Format data from the csv file
41
+ * @param string $data
42
+ * @param string $enc
43
+ * @return string
44
+ */
45
+ public function format_data_from_csv( $data, $enc ) {
46
+ return ( $enc == 'UTF-8' ) ? $data : utf8_encode( $data );
47
+ }
48
+
49
+ /**
50
+ * Parse the data
51
+ * @param string $file [description]
52
+ * @param string $delimiter [description]
53
+ * @param array $mapping [description]
54
+ * @param integer $start_pos [description]
55
+ * @param integer $end_pos [description]
56
+ * @return array
57
+ */
58
+ public function parse_data( $file, $delimiter, $mapping, $start_pos = 0, $end_pos = null, $eval_field ) {
59
+ // Set locale
60
+ $enc = mb_detect_encoding( $file, 'UTF-8, ISO-8859-1', true );
61
+ if ( $enc )
62
+ setlocale( LC_ALL, 'en_US.' . $enc );
63
+ @ini_set( 'auto_detect_line_endings', true );
64
+
65
+ $parsed_data = array();
66
+ $raw_headers = array();
67
+
68
+ // Put all CSV data into an associative array
69
+ if ( ( $handle = fopen( $file, "r" ) ) !== FALSE ) {
70
+
71
+ $header = fgetcsv( $handle, 0, $delimiter );
72
+ if ( $start_pos != 0 )
73
+ fseek( $handle, $start_pos );
74
+
75
+ while ( ( $postmeta = fgetcsv( $handle, 0, $delimiter ) ) !== FALSE ) {
76
+ $row = array();
77
+
78
+ foreach ( $header as $key => $heading ) {
79
+ // Heading is the lowercase version of the column name
80
+ $s_heading = strtolower( $heading );
81
+
82
+ // Check if this heading is being mapped to a different field
83
+ if ( isset( $mapping[$s_heading] ) ) {
84
+ if ( $mapping[$s_heading] == 'import_as_meta' ) {
85
+
86
+ $s_heading = 'meta:' . $s_heading;
87
+
88
+ } elseif ( $mapping[$s_heading] == 'import_as_images' ) {
89
+
90
+ $s_heading = 'images';
91
+
92
+ } else {
93
+ $s_heading = esc_attr( $mapping[$s_heading] );
94
+ }
95
+ }
96
+ foreach ($mapping as $mkey => $mvalue) {
97
+ if(trim($mvalue) === trim($heading)){
98
+ $s_heading = $mkey;
99
+ }
100
+ }
101
+
102
+ if ( $s_heading == '' )
103
+ continue;
104
+
105
+ // Add the heading to the parsed data
106
+ $row[$s_heading] = ( isset( $postmeta[$key] ) ) ? $this->format_data_from_csv( $postmeta[$key], $enc ) : '';
107
+
108
+ $row[$s_heading] = $this->evaluate_field($row[$s_heading], $eval_field[strtolower( $heading )]);
109
+
110
+ // Raw Headers stores the actual column name in the CSV
111
+ $raw_headers[ $s_heading ] = $heading;
112
+ }
113
+ $parsed_data[] = $row;
114
+
115
+ unset( $postmeta, $row );
116
+
117
+ $position = ftell( $handle );
118
+
119
+ if ( $end_pos && $position >= $end_pos )
120
+ break;
121
+ }
122
+ fclose( $handle );
123
+ }
124
+ return array( $parsed_data, $raw_headers, $position );
125
+ }
126
+
127
+ private function evaluate_field($value, $evaluation_field){
128
+ //echo "value:$value, $evaluation_field </br>";
129
+ $processed_value = $value;
130
+ if(!empty($evaluation_field)){
131
+ $operator = substr($evaluation_field, 0, 1);
132
+ if(in_array($operator, array('=', '+', '-', '*', '/', '&'))){
133
+ $eval_val = substr($evaluation_field, 1);
134
+ //echo "operator:$operator";
135
+ switch($operator){
136
+ case '=':
137
+ $processed_value = trim($eval_val);
138
+ break;
139
+ case '+':
140
+ $processed_value = $value + $eval_val;
141
+ break;
142
+ case '-':
143
+ $processed_value = $value - $eval_val;
144
+ break;
145
+ case '*':
146
+ $processed_value = $value * $eval_val;
147
+ break;
148
+ case '/':
149
+ $processed_value = $value / $eval_val;
150
+ break;
151
+ case '&':
152
+ if (strpos($eval_val, '[VAL]') !== false) {
153
+ $processed_value = str_replace('[VAL]',$value,$eval_val);
154
+ }
155
+ else{
156
+ $processed_value = $value . $eval_val;
157
+ }
158
+ break;
159
+ }
160
+ }
161
+ }
162
+ return $processed_value;
163
+ }
164
+
165
+ /**
166
+ * Parse product
167
+ * @param array $item
168
+ * @param integer $merge_empty_cells
169
+ * @return array
170
+ */
171
+ public function parse_product( $item, $merge_empty_cells = 0 ) {
172
+ global $WF_CSV_Product_Import, $wpdb;
173
+ $this->row++;
174
+
175
+ $terms_array = $postmeta = $product = array();
176
+ $attributes = $default_attributes = $gpf_data = null;
177
+
178
+ // Merging
179
+ $merging = ( ! empty( $_GET['merge'] ) && $_GET['merge'] ) ? true : false;
180
+ //if($item['post_parent']!== '' && $item['parent_sku'] !== ''){
181
+
182
+ $this->post_defaults['post_type'] = 'product';
183
+ $this->post_type = 'product';
184
+ // Post ID field mapping
185
+ $post_id = ( ! empty( $item['id'] ) ) ? $item['id'] : 0;
186
+ $post_id = ( ! empty( $item['post_id'] ) ) ? $item['post_id'] : $post_id;
187
+ if ( $merging ) {
188
+
189
+ $product['merging'] = true;
190
+
191
+ $WF_CSV_Product_Import->log->add( 'csv-import', sprintf( __('> Row %s - preparing for merge.', 'wf_csv_import_export'), $this->row ) );
192
+
193
+ // Required fields
194
+ if ( ! $post_id && empty( $item['sku'] ) ) {
195
+
196
+ $WF_CSV_Product_Import->log->add( 'csv-import', __( '> > Cannot merge without id or sku. Importing instead.', 'wf_csv_import_export') );
197
+
198
+ $merging = false;
199
+ } else {
200
+
201
+ // Check product exists
202
+ if ( ! $post_id ) {
203
+ // Check product to merge exists
204
+ $db_query = $wpdb->prepare("
205
+ SELECT $wpdb->posts.ID
206
+ FROM $wpdb->posts
207
+ LEFT JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id)
208
+ WHERE $wpdb->posts.post_type = 'product'
209
+ AND $wpdb->posts.post_status IN ( 'publish', 'private', 'draft', 'pending', 'future' )
210
+ AND $wpdb->postmeta.meta_key = '_sku' AND $wpdb->postmeta.meta_value = '%s'
211
+ ", $item['sku']);
212
+ $found_product_id = $wpdb->get_var($db_query);
213
+ if ( ! $found_product_id ) {
214
+ $WF_CSV_Product_Import->log->add( 'csv-import', sprintf(__( '> > Skipped. Cannot find product with sku %s. Importing instead.', 'wf_csv_import_export'), $item['sku']) );
215
+ $merging = false;
216
+
217
+ } else {
218
+
219
+ $post_id = $found_product_id;
220
+
221
+ $WF_CSV_Product_Import->log->add( 'csv-import', sprintf(__( '> > Found product with ID %s.', 'wf_csv_import_export'), $post_id) );
222
+
223
+ }
224
+ }
225
+ $product['merging'] = true;
226
+ }
227
+ }
228
+
229
+ if ( ! $merging ) {
230
+
231
+ $product['merging'] = false;
232
+ $WF_CSV_Product_Import->log->add( 'csv-import', sprintf( __('> Row %s - preparing for import.', 'wf_csv_import_export'), $this->row ) );
233
+
234
+ // Required fields
235
+ if ( $item['post_parent']=== '' && $item['post_title']=== '') {
236
+ $WF_CSV_Product_Import->log->add( 'csv-import', __( '> > Skipped. No post_title set for new product.', 'wf_csv_import_export') );
237
+ return new WP_Error( 'parse-error', __( 'No post_title set for new product.', 'wf_csv_import_export' ) );
238
+ }
239
+ if ( $item['post_parent']!== '' && $item['post_parent']!== null && $item['parent_sku'] === '' ) {
240
+ $WF_CSV_Product_Import->log->add( 'csv-import', __( '> > Skipped. No parent set for new variation product.', 'wf_csv_import_export') );
241
+ //return new WP_Error( 'parse-error', __( 'No post_title set for new product.', 'wf_csv_import_export' ) );
242
+ return new WP_Error( 'parse-error', __( 'No parent set for new variation product.', 'wf_csv_import_export' ) );
243
+ }
244
+
245
+ }
246
+
247
+ $product['post_id'] = $post_id;
248
+
249
+
250
+ // Get post fields
251
+ foreach ( $this->post_defaults as $column => $default ) {
252
+ if ( isset( $item[ $column ] ) ) $product[ $column ] = $item[ $column ];
253
+ }
254
+
255
+ // Get custom fields
256
+ foreach ( $this->postmeta_defaults as $column => $default ) {
257
+ if ( isset( $item[$column] ) )
258
+ $postmeta[$column] = (string) $item[$column];
259
+ elseif ( isset( $item['_' . $column] ) )
260
+ $postmeta[$column] = (string) $item['_' . $column];
261
+
262
+ // Check custom fields are valid
263
+ if ( isset( $postmeta[$column] ) && isset( $this->postmeta_allowed[$column] ) && ! in_array( $postmeta[$column], $this->postmeta_allowed[$column] ) ) {
264
+ $postmeta[$column] = $this->postmeta_defaults[$column];
265
+ }
266
+ }
267
+
268
+ if ( ! $merging ) {
269
+ // Merge post meta with defaults
270
+ $product = wp_parse_args( $product, $this->post_defaults );
271
+ $postmeta = wp_parse_args( $postmeta, $this->postmeta_defaults );
272
+ }
273
+
274
+ // Handle special meta fields
275
+ if ( isset($item['post_parent']) ) {
276
+
277
+ // price
278
+ if ( $merging ) {
279
+ if ( ! isset( $postmeta['regular_price'] ) )
280
+ $postmeta['regular_price'] = get_post_meta( $post_id, '_regular_price', true );
281
+ $postmeta['regular_price'] = $this->hf_currency_formatter($postmeta['regular_price']);
282
+ if ( ! isset( $postmeta['sale_price'] ) )
283
+ $postmeta['sale_price'] = get_post_meta( $post_id, '_sale_price', true );
284
+ $postmeta['sale_price'] = $this->hf_currency_formatter($postmeta['sale_price']);
285
+ }
286
+
287
+ if ( isset( $postmeta['regular_price'] ) && isset( $postmeta['sale_price'] ) && $postmeta['sale_price'] !== '' ) {
288
+ $postmeta['sale_price'] = $this->hf_currency_formatter($postmeta['sale_price']);
289
+ $postmeta['regular_price'] = $this->hf_currency_formatter($postmeta['regular_price']);
290
+ $price = min( $postmeta['sale_price'], $postmeta['regular_price']);
291
+ $postmeta['price'] = $price;
292
+ } elseif ( isset( $postmeta['regular_price'] ) ) {
293
+ $postmeta['price'] = $this->hf_currency_formatter($postmeta['regular_price']);
294
+ }
295
+
296
+ } else {
297
+
298
+ // price
299
+ if ( $merging ) {
300
+ if ( ! isset( $postmeta['regular_price'] ) )
301
+ $postmeta['regular_price'] = get_post_meta( $post_id, '_regular_price', true );
302
+ $postmeta['regular_price'] = $this->hf_currency_formatter($postmeta['regular_price']);
303
+ if ( ! isset( $postmeta['sale_price'] ) )
304
+ $postmeta['sale_price'] = get_post_meta( $post_id, '_sale_price', true );
305
+ $postmeta['sale_price'] = $this->hf_currency_formatter($postmeta['sale_price']);
306
+ }
307
+
308
+ if ( isset( $postmeta['regular_price'] ) && isset( $postmeta['sale_price'] ) && $postmeta['sale_price'] !== '' ) {
309
+ $postmeta['sale_price'] = $this->hf_currency_formatter($postmeta['sale_price']);
310
+ $postmeta['regular_price'] = $this->hf_currency_formatter($postmeta['regular_price']);
311
+ $price = min( $postmeta['sale_price'], $postmeta['regular_price']);
312
+ $postmeta['price'] = $price;
313
+ } elseif ( isset( $postmeta['regular_price'] ) ) {
314
+ $postmeta['price'] = $this->hf_currency_formatter($postmeta['regular_price']);
315
+ }
316
+
317
+ // Reset dynamically generated meta
318
+ $postmeta['min_variation_price'] = $postmeta['max_variation_price'] = $postmeta['min_variation_regular_price'] =$postmeta['max_variation_regular_price'] = $postmeta['min_variation_sale_price'] = $postmeta['max_variation_sale_price'] = '';
319
+ }
320
+
321
+ // upsells
322
+ if ( isset( $postmeta['upsell_ids'] ) && ! is_array( $postmeta['upsell_ids'] ) ) {
323
+ $ids = array_filter( array_map( 'trim', explode( '|', $postmeta['upsell_ids'] ) ) );
324
+ $postmeta['upsell_ids'] = $ids;
325
+ }
326
+
327
+ // crosssells
328
+ if ( isset( $postmeta['crosssell_ids'] ) && ! is_array( $postmeta['crosssell_ids'] ) ) {
329
+ $ids = array_filter( array_map( 'trim', explode( '|', $postmeta['crosssell_ids'] ) ) );
330
+ $postmeta['crosssell_ids'] = $ids;
331
+ }
332
+
333
+ // Sale dates
334
+ if ( isset( $postmeta['sale_price_dates_from'] ) ) {
335
+ $postmeta['sale_price_dates_from'] = empty( $postmeta['sale_price_dates_from'] ) ? '' : strtotime( $postmeta['sale_price_dates_from'] );
336
+ }
337
+
338
+ if ( isset( $postmeta['sale_price_dates_to'] ) ) {
339
+ $postmeta['sale_price_dates_to'] = empty( $postmeta['sale_price_dates_to'] ) ? '' : strtotime( $postmeta['sale_price_dates_to'] );
340
+ }
341
+
342
+ // Relative stock updates
343
+ if ( $merging ) {
344
+ if ( isset( $postmeta['stock'] ) ) {
345
+
346
+ $postmeta['stock'] = trim( $postmeta['stock'] );
347
+
348
+ $mode = substr( $postmeta['stock'], 0, 3 );
349
+
350
+ if ( $mode == '(+)' ) {
351
+ $old_stock = absint( get_post_meta( $post_id, '_stock', true ) );
352
+ $amount = absint( substr( $postmeta['stock'], 3 ) );
353
+ $new_stock = $old_stock + $amount;
354
+ $postmeta['stock'] = $new_stock;
355
+ }
356
+
357
+ if ( $mode == '(-)' ) {
358
+ $old_stock = absint( get_post_meta( $post_id, '_stock', true ) );
359
+ $amount = absint( substr( $postmeta['stock'], 3 ) );
360
+ $new_stock = $old_stock - $amount;
361
+ $postmeta['stock'] = $new_stock;
362
+ }
363
+ }
364
+ }
365
+
366
+ // Format post status
367
+ if ( ! empty( $product['post_status'] ) ) {
368
+ $product['post_status'] = strtolower( $product['post_status'] );
369
+
370
+ if ( empty($item['post_parent']) ) {
371
+ if ( ! in_array( $product['post_status'], array( 'publish', 'private', 'draft', 'pending', 'future', 'inherit', 'trash' ) ) ) {
372
+ $product['post_status'] = 'publish';
373
+ }
374
+ } else {
375
+ if ( ! in_array( $product['post_status'], array( 'private', 'publish' ) ) ) {
376
+ $product['post_status'] = 'publish';
377
+ }
378
+ }
379
+ }
380
+
381
+ // Put set core product postmeta into product array
382
+ foreach ( $postmeta as $key => $value ) {
383
+ $product['postmeta'][] = array( 'key' => '_' . esc_attr($key), 'value' => $value );
384
+ }
385
+
386
+ /**
387
+ * Handle other columns
388
+ */
389
+ foreach ( $item as $key => $value ) {
390
+
391
+ if ( empty($item['post_parent']) && ! $merge_empty_cells && $value == "" )
392
+ continue;
393
+
394
+ /**
395
+ * File path handling
396
+ */
397
+ if ( $key == 'file_paths' || $key == 'downloadable_files' ) {
398
+
399
+ $file_paths = explode( '|', $value );
400
+ $_file_paths = array();
401
+ foreach ( $file_paths as $file_path ) {
402
+ // 2.1
403
+ if ( function_exists( 'wc_get_filename_from_url' ) ) {
404
+ $file_path = array_map( 'trim', explode( '::', $file_path ) );
405
+ if ( sizeof( $file_path ) === 2 ) {
406
+ $file_name = $file_path[0];
407
+ $file_path = $file_path[1];
408
+ } else {
409
+ $file_name = wc_get_filename_from_url( $file_path[0] );
410
+ $file_path = $file_path[0];
411
+ }
412
+ $_file_paths[ md5( $file_path ) ] = array(
413
+ 'name' => $file_name,
414
+ 'file' => $file_path
415
+ );
416
+ } else {
417
+ $file_path = trim( $file_path );
418
+ $_file_paths[ md5( $file_path ) ] = $file_path;
419
+ }
420
+ }
421
+ $value = $_file_paths;
422
+
423
+ $product['postmeta'][] = array( 'key' => '_' . esc_attr( $key ), 'value' => $value );
424
+ }
425
+
426
+ elseif ( strstr( $key, 'tax:' ) ) {
427
+
428
+ // Get taxonomy
429
+ $taxonomy = trim( str_replace( 'tax:', '', $key ) );
430
+
431
+ // Exists?
432
+ if ( ! taxonomy_exists( $taxonomy ) ) {
433
+ $WF_CSV_Product_Import->log->add( 'csv-import', sprintf( __('> > Skipping taxonomy "%s" - it does not exist.', 'wf_csv_import_export'), $taxonomy ) );
434
+ continue;
435
+ }
436
+
437
+ // Product type check
438
+ if ( $taxonomy == 'product_type' ) {
439
+ $term = strtolower( $value );
440
+
441
+ if ( ! array_key_exists( $term, $this->allowed_product_types ) ) {
442
+ $WF_CSV_Product_Import->log->add( 'csv-import', sprintf( __('> > > Product type "%s" not allowed - using simple.', 'wf_csv_import_export'), $term ) );
443
+ $term_id = $this->allowed_product_types['simple'];
444
+ } else {
445
+ $term_id = $this->allowed_product_types[ $term ];
446
+ }
447
+
448
+ // Add to array
449
+ $terms_array[] = array(
450
+ 'taxonomy' => $taxonomy,
451
+ 'terms' => array( $term_id )
452
+ );
453
+
454
+ continue;
455
+ }
456
+
457
+ // Get terms - ID => parent
458
+ $terms = array();
459
+ $raw_terms = explode( '|', $value );
460
+ $raw_terms = array_map( 'trim', $raw_terms );
461
+
462
+ // Handle term hierachy (>)
463
+ foreach ( $raw_terms as $raw_term ) {
464
+
465
+ if ( strstr( $raw_term, '>' ) ) {
466
+
467
+ $raw_term = explode( '>', $raw_term );
468
+ $raw_term = array_map( 'trim', $raw_term );
469
+ $raw_term = array_map( 'wp_specialchars', $raw_term );
470
+ $raw_term = array_filter( $raw_term );
471
+
472
+ $parent = 0;
473
+ $loop = 0;
474
+
475
+ foreach ( $raw_term as $term ) {
476
+ $loop ++;
477
+ $term_id = '';
478
+
479
+ if ( isset( $this->inserted_terms[ $taxonomy ][ $parent ][ $term ] ) ) {
480
+ $term_id = $this->inserted_terms[ $taxonomy ][ $parent ][ $term ];
481
+ } elseif ( $term ) {
482
+
483
+ /**
484
+ * Check term existance
485
+ */
486
+ $term_may_exist = term_exists( $term, $taxonomy, absint( $parent ) );
487
+
488
+ $WF_CSV_Product_Import->log->add( 'CSV-Import', sprintf( __( '> > (' . __LINE__ . ') Term %s (%s) exists? %s', 'wf_csv_import_export' ), sanitize_text_field( $term ), esc_html( $taxonomy ), $term_may_exist ? print_r( $term_may_exist, true ) : '-' ) );
489
+
490
+ if ( is_array( $term_may_exist ) ) {
491
+ $possible_term = get_term( $term_may_exist['term_id'], 'product_cat' );
492
+
493
+ if ( $possible_term->parent == $parent ) {
494
+ $term_id = $term_may_exist['term_id'];
495
+ }
496
+ }
497
+
498
+ if ( ! $term_id ) {
499
+
500
+ // Create appropriate slug
501
+ $slug = array();
502
+
503
+ for ( $i = 0; $i < $loop; $i ++ )
504
+ $slug[] = $raw_term[ $i ];
505
+
506
+ $slug = sanitize_title( implode( '-', $slug ) );
507
+
508
+ $t = wp_insert_term( $term, $taxonomy, array( 'parent' => $parent, 'slug' => $slug ) );
509
+
510
+ if ( ! is_wp_error( $t ) ) {
511
+ $term_id = $t['term_id'];
512
+ } else {
513
+ $WF_CSV_Product_Import->log->add( 'CSV-Import', sprintf( __( '> > (' . __LINE__ . ') Failed to import term %s, parent %s - %s', 'wf_csv_import_export' ), sanitize_text_field( $term ), sanitize_text_field( $parent ), sanitize_text_field( $taxonomy ) ) );
514
+ break;
515
+ }
516
+ }
517
+
518
+ $this->inserted_terms[$taxonomy][$parent][$term] = $term_id;
519
+
520
+ }
521
+
522
+ if ( ! $term_id )
523
+ break;
524
+
525
+ // Add to product terms, ready to set if this is the final term
526
+ if ( sizeof( $raw_term ) == $loop )
527
+ $terms[] = $term_id;
528
+
529
+ $parent = $term_id;
530
+ }
531
+
532
+ } else {
533
+
534
+ $term_id = '';
535
+ $raw_term = wp_specialchars( $raw_term );
536
+
537
+ if ( isset( $this->inserted_terms[$taxonomy][0][$raw_term] ) ) {
538
+
539
+ $term_id = $this->inserted_terms[$taxonomy][0][$raw_term];
540
+
541
+ } elseif ( $raw_term ) {
542
+
543
+ // Check term existance
544
+ $term_exists = term_exists( $raw_term, $taxonomy, 0 );
545
+ $term_id = is_array( $term_exists ) ? $term_exists['term_id'] : 0;
546
+
547
+ if ( ! $term_id ) {
548
+ $t = wp_insert_term( trim( $raw_term ), $taxonomy, array( 'parent' => 0 ) );
549
+
550
+ if ( ! is_wp_error( $t ) ) {
551
+ $term_id = $t['term_id'];
552
+ } else {
553
+ $WF_CSV_Product_Import->log->add( 'csv-import', sprintf( __( '> > Failed to import term %s %s', 'wf_csv_import_export' ), esc_html($raw_term), esc_html($taxonomy) ) );
554
+ break;
555
+ }
556
+ }
557
+
558
+ $this->inserted_terms[$taxonomy][0][$raw_term] = $term_id;
559
+
560
+ }
561
+
562
+ // Store terms for later insertion
563
+ if ( $term_id )
564
+ $terms[] = $term_id;
565
+
566
+ }
567
+
568
+ }
569
+
570
+ // Any defined?
571
+ if ( sizeof( $terms ) == 0 )
572
+ continue;
573
+
574
+ // Add to array
575
+ $terms_array[] = array(
576
+ 'taxonomy' => $taxonomy,
577
+ 'terms' => $terms
578
+ );
579
+ }
580
+
581
+ /**
582
+ * Handle Attributes
583
+ */
584
+ elseif ( strstr( $key, 'attribute:' ) ) {
585
+
586
+ $attribute_key = sanitize_title( trim( str_replace( 'attribute:', '', $key ) ) );
587
+ $attribute_name = str_replace( 'attribute:', '', $WF_CSV_Product_Import->raw_headers[ $key ] );
588
+
589
+ if ( ! $attribute_key )
590
+ continue;
591
+
592
+ // Taxonomy
593
+ if ( substr( $attribute_key, 0, 3 ) == 'pa_' ) {
594
+
595
+ $taxonomy = $attribute_key;
596
+
597
+ // Exists?
598
+ if ( ! taxonomy_exists( $taxonomy ) ) {
599
+
600
+ $nicename = strtolower( sanitize_title( str_replace( 'pa_', '', $taxonomy ) ) );
601
+
602
+ $WF_CSV_Product_Import->log->add( 'csv-import', sprintf( __('> > Attribute taxonomy "%s" does not exist. Adding it. Nicename: %s', 'wf_csv_import_export'), $taxonomy, $nicename ) );
603
+
604
+ $exists_in_db = $wpdb->get_var( "SELECT attribute_id FROM " . $wpdb->prefix . "woocommerce_attribute_taxonomies WHERE attribute_name = '" . $nicename . "';" );
605
+
606
+ if ( ! $exists_in_db ) {
607
+ // Create the taxonomy
608
+ $wpdb->insert( $wpdb->prefix . "woocommerce_attribute_taxonomies", array( 'attribute_name' => $nicename, 'attribute_label' => $nicename, 'attribute_type' => 'select', 'attribute_orderby' => 'menu_order' ) );
609
+ } else {
610
+ $WF_CSV_Product_Import->log->add( 'csv-import', sprintf( __('> > Attribute taxonomy %s already exists in DB.', 'wf_csv_import_export'), $taxonomy ) );
611
+ }
612
+
613
+ // Register the taxonomy now so that the import works!
614
+ register_taxonomy( $taxonomy,
615
+ array( 'product', 'product_variation' ),
616
+ array(
617
+ 'hierarchical' => true,
618
+ 'show_ui' => false,
619
+ 'query_var' => true,
620
+ 'rewrite' => false,
621
+ )
622
+ );
623
+ }
624
+
625
+ // Get terms
626
+ $terms = array();
627
+ $raw_terms = explode( '|', $value );
628
+ $raw_terms = array_map( 'wp_specialchars', $raw_terms );
629
+ $raw_terms = array_map( 'trim', $raw_terms );
630
+
631
+ if ( sizeof( $raw_terms ) > 0 ) {
632
+
633
+ foreach ( $raw_terms as $raw_term ) {
634
+
635
+ if ( empty( $raw_term ) && 0 != $raw_term ) {
636
+ continue;
637
+ }
638
+
639
+ // Check term existance
640
+ $term_exists = term_exists( $raw_term, $taxonomy, 0 );
641
+ $term_id = is_array( $term_exists ) ? $term_exists['term_id'] : 0;
642
+
643
+ if ( ! $term_id ) {
644
+ $t = wp_insert_term( trim( $raw_term ), $taxonomy );
645
+
646
+ if ( ! is_wp_error( $t ) ) {
647
+ $term_id = $t['term_id'];
648
+
649
+ $WF_CSV_Product_Import->log->add( 'csv-import', sprintf( __( '> > Inserted Raw Term %s ID = %s', 'wf_csv_import_export' ), esc_html( $raw_term ), $term_id ) );
650
+ } else {
651
+ $WF_CSV_Product_Import->log->add( 'csv-import', sprintf( __( '> > Failed to import term %s %s', 'wf_csv_import_export' ), esc_html($raw_term), esc_html($taxonomy) ) );
652
+ break;
653
+ }
654
+ } else {
655
+ $WF_CSV_Product_Import->log->add( 'csv-import', sprintf( __( '> > Raw Term %s ID = %s', 'wf_csv_import_export' ), esc_html( $raw_term ), $term_id ) );
656
+ }
657
+
658
+ if ( $term_id ) {
659
+ $terms[] = $term_id;
660
+ }
661
+ }
662
+
663
+ }
664
+
665
+ // Add to array
666
+ $terms_array[] = array(
667
+ 'taxonomy' => $taxonomy,
668
+ 'terms' => $terms
669
+ );
670
+
671
+ // Ensure we have original attributes
672
+ if ( is_null( $attributes ) && $merging ) {
673
+ $attributes = array_filter( (array) maybe_unserialize( get_post_meta( $post_id, '_product_attributes', true ) ) );
674
+ } elseif ( is_null( $attributes ) ) {
675
+ $attributes = array();
676
+ }
677
+
678
+ // Set attribute
679
+ if ( ! isset( $attributes[$taxonomy] ) )
680
+ $attributes[$taxonomy] = array();
681
+
682
+ $attributes[$taxonomy]['name'] = $taxonomy;
683
+ $attributes[$taxonomy]['value'] = null;
684
+ $attributes[$taxonomy]['is_taxonomy'] = 1;
685
+
686
+ if ( ! isset( $attributes[$taxonomy]['position'] ) )
687
+ $attributes[$taxonomy]['position'] = 0;
688
+ if ( ! isset( $attributes[$taxonomy]['is_visible'] ) )
689
+ $attributes[$taxonomy]['is_visible'] = 1;
690
+ if ( ! isset( $attributes[$taxonomy]['is_variation'] ) )
691
+ $attributes[$taxonomy]['is_variation'] = 0;
692
+
693
+ } else {
694
+
695
+ if ( ! $value || ! $attribute_key ) continue;
696
+
697
+ // Set attribute
698
+ if ( ! isset( $attributes[$attribute_key] ) )
699
+ $attributes[$attribute_key] = array();
700
+
701
+ $attributes[$attribute_key]['name'] = $attribute_name;
702
+ $attributes[$attribute_key]['value'] = $value;
703
+ $attributes[$attribute_key]['is_taxonomy'] = 0;
704
+
705
+ if ( ! isset( $attributes[$attribute_key]['position'] ) )
706
+ $attributes[$attribute_key]['position'] = 0;
707
+ if ( ! isset( $attributes[$attribute_key]['is_visible'] ) )
708
+ $attributes[$attribute_key]['is_visible'] = 1;
709
+ if ( ! isset( $attributes[$attribute_key]['is_variation'] ) )
710
+ $attributes[$attribute_key]['is_variation'] = 0;
711
+ }
712
+
713
+ }
714
+
715
+ /**
716
+ * Handle Attributes Data - position|is_visible|is_variation
717
+ */
718
+ elseif ( strstr( $key, 'attribute_data:' ) ) {
719
+
720
+ $attribute_key = sanitize_title( trim( str_replace( 'attribute_data:', '', $key ) ) );
721
+
722
+ if ( ! $attribute_key ) {
723
+ continue;
724
+ }
725
+
726
+ $values = explode( '|', $value );
727
+ $position = isset( $values[0] ) ? (int) $values[0] : 0;
728
+ $visible = isset( $values[1] ) ? (int) $values[1] : 1;
729
+ $variation = isset( $values[2] ) ? (int) $values[2] : 0;
730
+
731
+ // Ensure we have original attributes
732
+ if ( ! isset( $attributes[ $attribute_key ] ) ) {
733
+ if ( $merging ) {
734
+ $existing_attributes = array_filter( (array) maybe_unserialize( get_post_meta( $post_id, '_product_attributes', true ) ) );
735
+ $attributes[ $attribute_key ] = isset( $existing_attributes[ $attribute_key ] ) ? $existing_attributes[ $attribute_key ] : array();
736
+ } else {
737
+ $attributes[ $attribute_key ] = array();
738
+ }
739
+ }
740
+
741
+ $attributes[ $attribute_key ]['position'] = $position;
742
+ $attributes[ $attribute_key ]['is_visible'] = $visible;
743
+ $attributes[ $attribute_key ]['is_variation'] = $variation;
744
+ }
745
+
746
+ /**
747
+ * Handle Attributes Default Values
748
+ */
749
+ elseif ( strstr( $key, 'attribute_default:' ) ) {
750
+
751
+ $attribute_key = sanitize_title( trim( str_replace( 'attribute_default:', '', $key ) ) );
752
+
753
+ if ( ! $attribute_key ) continue;
754
+
755
+ // Ensure we have original attributes
756
+ if ( is_null( $default_attributes ) && $merging ) {
757
+ $default_attributes = array_filter( (array) maybe_unserialize( get_post_meta( $post_id, '_default_attributes', true ) ) );
758
+ } elseif ( is_null( $default_attributes ) ) {
759
+ $default_attributes = array();
760
+ }
761
+
762
+ $default_attributes[ $attribute_key ] = $value;
763
+ }
764
+
765
+ /**
766
+ * Handle gpf: google product feed columns
767
+ */
768
+ elseif ( strstr( $key, 'gpf:' ) ) {
769
+
770
+ $gpf_key = trim( str_replace( 'gpf:', '', $key ) );
771
+
772
+ // Get original values
773
+ if ( is_null( $gpf_data ) && $merging ) {
774
+ $gpf_data = array_filter( (array) maybe_unserialize( get_post_meta( $post_id, '_woocommerce_gpf_data', true ) ) );
775
+ } elseif ( is_null( $gpf_data ) ) {
776
+ $gpf_data = array(
777
+ 'availability' => '',
778
+ 'condition' => '',
779
+ 'brand' => '',
780
+ 'product_type' => '',
781
+ 'google_product_category' => '',
782
+ 'gtin' => '',
783
+ 'mpn' => '',
784
+ 'gender' => '',
785
+ 'age_group' => '',
786
+ 'color' => '',
787
+ 'size' => ''
788
+ );
789
+ }
790
+
791
+ $gpf_data[$gpf_key] = $value;
792
+
793
+ }
794
+
795
+ /**
796
+ * Handle upsell SKUs which we cannot assign until we get IDs later on
797
+ */
798
+ elseif ( strstr( $key, 'upsell_skus' ) ) {
799
+ if ( $value ) {
800
+ $skus = array_filter( array_map( 'trim', explode( '|', $value ) ) );
801
+ $product['upsell_skus'] = $skus;
802
+ }
803
+ }
804
+
805
+ /**
806
+ * Handle crosssells SKUs which we cannot assign until we get IDs later on
807
+ */
808
+ elseif ( strstr( $key, 'crosssell_skus' ) ) {
809
+ if ( $value ) {
810
+ $skus = array_filter( array_map( 'trim', explode( '|', $value ) ) );
811
+ $product['crosssell_skus'] = $skus;
812
+ }
813
+ }
814
+
815
+ }
816
+
817
+ // Remove empty attribues
818
+ if(!empty($attributes))
819
+ foreach ( $attributes as $key => $value ) {
820
+ if ( ! isset($value['name']) ) unset( $attributes[$key] );
821
+ }
822
+
823
+ /**
824
+ * Handle images
825
+ */
826
+ if ( ! empty( $item['images'] ) ) {
827
+ $images = array_map( 'trim', explode( '|', $item['images'] ) );
828
+ } else {
829
+ $images = '';
830
+ }
831
+
832
+ $product['postmeta'][] = array( 'key' => '_default_attributes', 'value' => $default_attributes );
833
+ $product['attributes'] = $attributes;
834
+ $product['gpf_data'] = $gpf_data;
835
+ $product['images'] = $images;
836
+ $product['terms'] = $terms_array;
837
+ $product['sku'] = ( ! empty( $item['sku'] ) ) ? $item['sku'] : '';
838
+ $product['post_title'] = ( ! empty( $item['post_title'] ) ) ? $item['post_title'] : '';
839
+ $product['post_type'] = $this->post_type;
840
+ unset( $item, $terms_array, $postmeta, $attributes, $gpf_data, $images );
841
+ return $product;
842
+ }
843
+ function hf_currency_formatter($price){
844
+ $decimal_seperator = wc_get_price_decimal_separator();
845
+ //return ereg_replace("[^0-9\\'.$decimal_seperator.']", "", $price);
846
+ return preg_replace("[^0-9\\'.$decimal_seperator.']", "", $price);
847
+ }
848
+ }
includes/importer/class-wf-prodimpexpcsv-importer.php CHANGED
@@ -1,41 +1,41 @@
1
- <?php
2
- if ( ! defined( 'ABSPATH' ) ) {
3
- exit;
4
- }
5
-
6
- class WF_ProdImpExpCsv_Importer {
7
-
8
- /**
9
- * Product Exporter Tool
10
- */
11
- public static function load_wp_importer() {
12
- // Load Importer API
13
- require_once ABSPATH . 'wp-admin/includes/import.php';
14
-
15
- if ( ! class_exists( 'WP_Importer' ) ) {
16
- $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
17
- if ( file_exists( $class_wp_importer ) ) {
18
- require $class_wp_importer;
19
- }
20
- }
21
- }
22
-
23
- /**
24
- * Product Importer Tool
25
- */
26
- public static function product_importer() {
27
- if ( ! defined( 'WP_LOAD_IMPORTERS' ) ) {
28
- return;
29
- }
30
-
31
- self::load_wp_importer();
32
-
33
- // includes
34
- require_once 'class-wf-prodimpexpcsv-product-import.php';
35
- require_once 'class-wf-csv-parser.php';
36
-
37
- // Dispatch
38
- $GLOBALS['WF_CSV_Product_Import'] = new WF_ProdImpExpCsv_Product_Import();
39
- $GLOBALS['WF_CSV_Product_Import'] ->dispatch();
40
- }
41
  }
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ class WF_ProdImpExpCsv_Importer {
7
+
8
+ /**
9
+ * Product Exporter Tool
10
+ */
11
+ public static function load_wp_importer() {
12
+ // Load Importer API
13
+ require_once ABSPATH . 'wp-admin/includes/import.php';
14
+
15
+ if ( ! class_exists( 'WP_Importer' ) ) {
16
+ $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
17
+ if ( file_exists( $class_wp_importer ) ) {
18
+ require $class_wp_importer;
19
+ }
20
+ }
21
+ }
22
+
23
+ /**
24
+ * Product Importer Tool
25
+ */
26
+ public static function product_importer() {
27
+ if ( ! defined( 'WP_LOAD_IMPORTERS' ) ) {
28
+ return;
29
+ }
30
+
31
+ self::load_wp_importer();
32
+
33
+ // includes
34
+ require_once 'class-wf-prodimpexpcsv-product-import.php';
35
+ require_once 'class-wf-csv-parser.php';
36
+
37
+ // Dispatch
38
+ $GLOBALS['WF_CSV_Product_Import'] = new WF_ProdImpExpCsv_Product_Import();
39
+ $GLOBALS['WF_CSV_Product_Import'] ->dispatch();
40
+ }
41
  }
includes/importer/class-wf-prodimpexpcsv-product-import.php CHANGED
@@ -1,1477 +1,1477 @@
1
- <?php
2
- /**
3
- * WordPress Importer class for managing the import process of a CSV file
4
- *
5
- * @package WordPress
6
- * @subpackage Importer
7
- */
8
- if ( ! class_exists( 'WP_Importer' ) )
9
- return;
10
-
11
- class WF_ProdImpExpCsv_Product_Import extends WP_Importer {
12
-
13
- var $id;
14
- var $file_url;
15
- var $delimiter;
16
- var $merge_empty_cells;
17
-
18
- // mappings from old information to new
19
- var $processed_terms = array();
20
- var $processed_posts = array();
21
- var $post_orphans = array();
22
- var $attachments = array();
23
- var $upsell_skus = array();
24
- var $crosssell_skus = array();
25
-
26
- // Results
27
- var $import_results = array();
28
-
29
- /**
30
- * Constructor
31
- */
32
- public function __construct() {
33
-
34
- $this->log = new WC_Logger();
35
- $this->import_page = 'woocommerce_csv';
36
- $this->file_url_import_enabled = apply_filters( 'woocommerce_csv_product_file_url_import_enabled', true );
37
- }
38
-
39
- /**
40
- * Registered callback function for the WordPress Importer
41
- *
42
- * Manages the three separate stages of the CSV import process
43
- */
44
- public function dispatch() {
45
- global $woocommerce, $wpdb;
46
-
47
- if ( ! empty( $_POST['delimiter'] ) ) {
48
- $this->delimiter = stripslashes( trim( $_POST['delimiter'] ) );
49
- }else if ( ! empty( $_GET['delimiter'] ) ) {
50
- $this->delimiter = stripslashes( trim( $_GET['delimiter'] ) );
51
- }
52
-
53
- if ( ! $this->delimiter )
54
- $this->delimiter = ',';
55
-
56
- if ( ! empty( $_POST['merge_empty_cells'] ) || ! empty( $_GET['merge_empty_cells'] ) ) {
57
- $this->merge_empty_cells = 1;
58
- } else{
59
- $this->merge_empty_cells = 0;
60
- }
61
-
62
- $step = empty( $_GET['step'] ) ? 0 : (int) $_GET['step'];
63
-
64
- switch ( $step ) {
65
- case 0 :
66
- $this->header();
67
- $this->greet();
68
- break;
69
- case 1 :
70
- $this->header();
71
-
72
- check_admin_referer( 'import-upload' );
73
-
74
- if(!empty($_GET['file_url']))
75
- $this->file_url = esc_attr( $_GET['file_url'] );
76
- if(!empty($_GET['file_id']))
77
- $this->id = $_GET['file_id'] ;
78
-
79
- if ( !empty($_GET['clearmapping']) || $this->handle_upload() )
80
- $this->import_options();
81
- else
82
- _e( 'Error with handle_upload!', 'wf_csv_import_export' );
83
- break;
84
- case 2 :
85
- $this->header();
86
-
87
- check_admin_referer( 'import-woocommerce' );
88
-
89
- $this->id = (int) $_POST['import_id'];
90
-
91
- if ( $this->file_url_import_enabled )
92
- $this->file_url = esc_attr( $_POST['import_url'] );
93
-
94
- if ( $this->id )
95
- $file = get_attached_file( $this->id );
96
- else if ( $this->file_url_import_enabled )
97
- $file = ABSPATH . $this->file_url;
98
-
99
- $file = str_replace( "\\", "/", $file );
100
-
101
- if ( $file ) {
102
- ?>
103
- <table id="import-progress" class="widefat_importer widefat">
104
- <thead>
105
- <tr>
106
- <th class="status">&nbsp;</th>
107
- <th class="row"><?php _e( 'Row', 'wf_csv_import_export' ); ?></th>
108
- <th><?php _e( 'SKU', 'wf_csv_import_export' ); ?></th>
109
- <th><?php _e( 'Product', 'wf_csv_import_export' ); ?></th>
110
- <th class="reason"><?php _e( 'Status Msg', 'wf_csv_import_export' ); ?></th>
111
- </tr>
112
- </thead>
113
- <tfoot>
114
- <tr class="importer-loading">
115
- <td colspan="5"></td>
116
- </tr>
117
- </tfoot>
118
- <tbody></tbody>
119
- </table>
120
- <script type="text/javascript">
121
- jQuery(document).ready(function($) {
122
-
123
- if ( ! window.console ) { window.console = function(){}; }
124
-
125
- var processed_terms = [];
126
- var processed_posts = [];
127
- var post_orphans = [];
128
- var attachments = [];
129
- var upsell_skus = [];
130
- var crosssell_skus = [];
131
- var i = 1;
132
- var done_count = 0;
133
-
134
- function import_rows( start_pos, end_pos ) {
135
-
136
- var data = {
137
- action: 'woocommerce_csv_import_request',
138
- file: '<?php echo addslashes( $file ); ?>',
139
- mapping: '<?php echo json_encode( $_POST['map_from'] ); ?>',
140
- eval_field: '<?php echo stripslashes(json_encode(($_POST['eval_field']),JSON_HEX_APOS)) ?>',
141
- delimiter: '<?php echo $this->delimiter; ?>',
142
- merge_empty_cells: '<?php echo $this->merge_empty_cells; ?>',
143
- start_pos: start_pos,
144
- end_pos: end_pos,
145
- };
146
- data.eval_field = $.parseJSON(data.eval_field);
147
- return $.ajax({
148
- url: '<?php echo add_query_arg( array( 'import_page' => $this->import_page, 'step' => '3', 'merge' => ! empty( $_GET['merge'] ) ? '1' : '0' ), admin_url( 'admin-ajax.php' ) ); ?>',
149
- data: data,
150
- type: 'POST',
151
- success: function( response ) {
152
- console.log( response );
153
- if ( response ) {
154
-
155
- try {
156
- // Get the valid JSON only from the returned string
157
- if ( response.indexOf("<!--WC_START-->") >= 0 )
158
- response = response.split("<!--WC_START-->")[1]; // Strip off before after WC_START
159
-
160
- if ( response.indexOf("<!--WC_END-->") >= 0 )
161
- response = response.split("<!--WC_END-->")[0]; // Strip off anything after WC_END
162
-
163
- // Parse
164
- var results = $.parseJSON( response );
165
-
166
- if ( results.error ) {
167
-
168
- $('#import-progress tbody').append( '<tr id="row-' + i + '" class="error"><td class="status" colspan="5">' + results.error + '</td></tr>' );
169
-
170
- i++;
171
-
172
- } else if ( results.import_results && $( results.import_results ).size() > 0 ) {
173
-
174
- $.each( results.processed_terms, function( index, value ) {
175
- processed_terms.push( value );
176
- });
177
-
178
- $.each( results.processed_posts, function( index, value ) {
179
- processed_posts.push( value );
180
- });
181
-
182
- $.each( results.post_orphans, function( index, value ) {
183
- post_orphans.push( value );
184
- });
185
-
186
- $.each( results.attachments, function( index, value ) {
187
- attachments.push( value );
188
- });
189
-
190
- upsell_skus = jQuery.extend( {}, upsell_skus, results.upsell_skus );
191
- crosssell_skus = jQuery.extend( {}, crosssell_skus, results.crosssell_skus );
192
-
193
- $( results.import_results ).each(function( index, row ) {
194
- $('#import-progress tbody').append( '<tr id="row-' + i + '" class="' + row['status'] + '"><td><mark class="result" title="' + row['status'] + '">' + row['status'] + '</mark></td><td class="row">' + i + '</td><td>' + row['sku'] + '</td><td>' + row['post_id'] + ' - ' + row['post_title'] + '</td><td class="reason">' + row['reason'] + '</td></tr>' );
195
-
196
- i++;
197
- });
198
- }
199
-
200
- } catch(err) {}
201
-
202
- } else {
203
- $('#import-progress tbody').append( '<tr class="error"><td class="status" colspan="5">' + '<?php _e( 'AJAX Error', 'wf_csv_import_export' ); ?>' + '</td></tr>' );
204
- }
205
-
206
- var w = $(window);
207
- var row = $( "#row-" + ( i - 1 ) );
208
-
209
- if ( row.length ) {
210
- w.scrollTop( row.offset().top - (w.height()/2) );
211
- }
212
-
213
- done_count++;
214
-
215
- $('body').trigger( 'woocommerce_csv_import_request_complete' );
216
- }
217
- });
218
- }
219
-
220
- var rows = [];
221
-
222
- <?php
223
- $limit = apply_filters( 'woocommerce_csv_import_limit_per_request', 10 );
224
- $enc = mb_detect_encoding( $file, 'UTF-8, ISO-8859-1', true );
225
- if ( $enc )
226
- setlocale( LC_ALL, 'en_US.' . $enc );
227
- @ini_set( 'auto_detect_line_endings', true );
228
-
229
- $count = 0;
230
- $previous_position = 0;
231
- $position = 0;
232
- $import_count = 0;
233
-
234
- // Get CSV positions
235
- if ( ( $handle = fopen( $file, "r" ) ) !== FALSE ) {
236
-
237
- while ( ( $postmeta = fgetcsv( $handle, 0, $this->delimiter ) ) !== FALSE ) {
238
- $count++;
239
-
240
- if ( $count >= $limit ) {
241
- $previous_position = $position;
242
- $position = ftell( $handle );
243
- $count = 0;
244
- $import_count ++;
245
-
246
- // Import rows between $previous_position $position
247
- ?>rows.push( [ <?php echo $previous_position; ?>, <?php echo $position; ?> ] ); <?php
248
- }
249
- }
250
-
251
- // Remainder
252
- if ( $count > 0 ) {
253
- ?>rows.push( [ <?php echo $position; ?>, '' ] ); <?php
254
- $import_count ++;
255
- }
256
-
257
- fclose( $handle );
258
- }
259
- ?>
260
-
261
- var data = rows.shift();
262
- var regen_count = 0;
263
- import_rows( data[0], data[1] );
264
-
265
- $('body').on( 'woocommerce_csv_import_request_complete', function() {
266
- if ( done_count == <?php echo $import_count; ?> ) {
267
-
268
- if ( attachments.length ) {
269
-
270
- $('#import-progress tbody').append( '<tr class="regenerating"><td colspan="5"><div class="progress"></div></td></tr>' );
271
-
272
- index = 0;
273
-
274
- $.each( attachments, function( i, value ) {
275
- regenerate_thumbnail( value );
276
- index ++;
277
- if ( index == attachments.length ) {
278
- import_done();
279
- }
280
- });
281
-
282
- } else {
283
- import_done();
284
- }
285
-
286
- } else {
287
- // Call next request
288
- data = rows.shift();
289
- import_rows( data[0], data[1] );
290
- }
291
- } );
292
-
293
- // Regenerate a specified image via AJAX
294
- function regenerate_thumbnail( id ) {
295
- $.ajax({
296
- type: 'POST',
297
- url: ajaxurl,
298
- data: { action: "woocommerce_csv_import_regenerate_thumbnail", id: id },
299
- success: function( response ) {
300
- if ( response !== Object( response ) || ( typeof response.success === "undefined" && typeof response.error === "undefined" ) ) {
301
- response = new Object;
302
- response.success = false;
303
- response.error = "<?php printf( esc_js( __( 'The resize request was abnormally terminated (ID %s). This is likely due to the image exceeding available memory or some other type of fatal error.', 'wf_csv_import_export' ) ), '" + id + "' ); ?>";
304
- }
305
-
306
- regen_count ++;
307
-
308
- $('#import-progress tbody .regenerating .progress').css( 'width', ( ( regen_count / attachments.length ) * 100 ) + '%' ).html( regen_count + ' / ' + attachments.length + ' <?php echo esc_js( __( 'thumbnails regenerated', 'wf_csv_import_export' ) ); ?>' );
309
-
310
- if ( ! response.success ) {
311
- $('#import-progress tbody').append( '<tr><td colspan="5">' + response.error + '</td></tr>' );
312
- }
313
- },
314
- error: function( response ) {
315
- $('#import-progress tbody').append( '<tr><td colspan="5">' + response.error + '</td></tr>' );
316
- }
317
- });
318
- }
319
-
320
- function import_done() {
321
- var data = {
322
- action: 'woocommerce_csv_import_request',
323
- file: '<?php echo $file; ?>',
324
- processed_terms: processed_terms,
325
- processed_posts: processed_posts,
326
- post_orphans: post_orphans,
327
- upsell_skus: upsell_skus,
328
- crosssell_skus: crosssell_skus
329
- };
330
-
331
- $.ajax({
332
- url: '<?php echo add_query_arg( array( 'import_page' => $this->import_page, 'step' => '4', 'merge' => ! empty( $_GET['merge'] ) ? 1 : 0 ), admin_url( 'admin-ajax.php' ) ); ?>',
333
- data: data,
334
- type: 'POST',
335
- success: function( response ) {
336
- console.log( response );
337
- $('#import-progress tbody').append( '<tr class="complete"><td colspan="5">' + response + '</td></tr>' );
338
- $('.importer-loading').hide();
339
- }
340
- });
341
- }
342
- });
343
- </script>
344
- <?php
345
- } else {
346
- echo '<p class="error">' . __( 'Error finding uploaded file!', 'wf_csv_import_export' ) . '</p>';
347
- }
348
- break;
349
- case 3 :
350
- // Check access - cannot use nonce here as it will expire after multiple requests
351
- if ( ! current_user_can( 'manage_woocommerce' ) )
352
- die();
353
-
354
- add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) );
355
-
356
- if ( function_exists( 'gc_enable' ) )
357
- gc_enable();
358
-
359
- @set_time_limit(0);
360
- @ob_flush();
361
- @flush();
362
- $wpdb->hide_errors();
363
-
364
- $file = stripslashes( $_POST['file'] );
365
- $mapping = json_decode( stripslashes( $_POST['mapping'] ), true );
366
- $eval_field = $_POST['eval_field'];
367
- $start_pos = isset( $_POST['start_pos'] ) ? absint( $_POST['start_pos'] ) : 0;
368
- $end_pos = isset( $_POST['end_pos'] ) ? absint( $_POST['end_pos'] ) : '';
369
-
370
- update_option( 'wf_prod_csv_imp_exp_mapping', array($mapping,$eval_field ));
371
-
372
- $position = $this->import_start( $file, $mapping, $start_pos, $end_pos, $eval_field );
373
- $this->import();
374
- $this->import_end();
375
-
376
- $results = array();
377
- $results['import_results'] = $this->import_results;
378
- $results['processed_terms'] = $this->processed_terms;
379
- $results['processed_posts'] = $this->processed_posts;
380
- $results['post_orphans'] = $this->post_orphans;
381
- $results['attachments'] = $this->attachments;
382
- $results['upsell_skus'] = $this->upsell_skus;
383
- $results['crosssell_skus'] = $this->crosssell_skus;
384
-
385
- echo "<!--WC_START-->";
386
- echo json_encode( $results );
387
- echo "<!--WC_END-->";
388
- exit;
389
- break;
390
- case 4 :
391
- // Check access - cannot use nonce here as it will expire after multiple requests
392
- if ( ! current_user_can( 'manage_woocommerce' ) )
393
- die();
394
-
395
- add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) );
396
-
397
- if ( function_exists( 'gc_enable' ) )
398
- gc_enable();
399
-
400
- @set_time_limit(0);
401
- @ob_flush();
402
- @flush();
403
- $wpdb->hide_errors();
404
-
405
- $this->processed_terms = isset( $_POST['processed_terms'] ) ? $_POST['processed_terms'] : array();
406
- $this->processed_posts = isset( $_POST['processed_posts']) ? $_POST['processed_posts'] : array();
407
- $this->post_orphans = isset( $_POST['post_orphans']) ? $_POST['post_orphans'] : array();
408
- $this->crosssell_skus = isset( $_POST['crosssell_skus']) ? array_filter( (array) $_POST['crosssell_skus'] ) : array();
409
- $this->upsell_skus = isset( $_POST['upsell_skus']) ? array_filter( (array) $_POST['upsell_skus'] ) : array();
410
-
411
- _e( 'Step 1...', 'wf_csv_import_export' ) . ' ';
412
-
413
- wp_defer_term_counting( true );
414
- wp_defer_comment_counting( true );
415
-
416
- _e( 'Step 2...', 'wf_csv_import_export' ) . ' ';
417
-
418
- echo 'Step 3...' . ' '; // Easter egg
419
-
420
- // reset transients for products
421
- if ( function_exists( 'wc_delete_product_transients' ) ) {
422
- wc_delete_product_transients();
423
- } else {
424
- $woocommerce->clear_product_transients();
425
- }
426
-
427
- delete_transient( 'wc_attribute_taxonomies' );
428
-
429
- $wpdb->query("DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_wc_product_type_%')");
430
-
431
- _e( 'Finalizing...', 'wf_csv_import_export' ) . ' ';
432
-
433
- $this->backfill_parents();
434
-
435
- if ( ! empty( $this->upsell_skus ) ) {
436
-
437
- _e( 'Linking upsells...', 'wf_csv_import_export' ) . ' ';
438
-
439
- foreach ( $this->upsell_skus as $post_id => $skus ) {
440
- $this->link_product_skus( 'upsell', $post_id, $skus );
441
- }
442
- }
443
-
444
- if ( ! empty( $this->crosssell_skus ) ) {
445
-
446
- _e( 'Linking crosssells...', 'wf_csv_import_export' ) . ' ';
447
-
448
- foreach ( $this->crosssell_skus as $post_id => $skus ) {
449
- $this->link_product_skus( 'crosssell', $post_id, $skus );
450
- }
451
- }
452
- // SUCCESS
453
- _e( 'Finished. Import complete.', 'wf_csv_import_export' );
454
-
455
- $this->import_end();
456
- exit;
457
- break;
458
- }
459
-
460
- $this->footer();
461
- }
462
-
463
- /**
464
- * format_data_from_csv
465
- */
466
- public function format_data_from_csv( $data, $enc ) {
467
- return ( $enc == 'UTF-8' ) ? $data : utf8_encode( $data );
468
- }
469
-
470
- /**
471
- * Display pre-import options
472
- */
473
- public function import_options() {
474
- $j = 0;
475
-
476
- if ( $this->id )
477
- $file = get_attached_file( $this->id );
478
- else if ( $this->file_url_import_enabled )
479
- $file = ABSPATH . $this->file_url;
480
- else
481
- return;
482
-
483
- // Set locale
484
- $enc = mb_detect_encoding( $file, 'UTF-8, ISO-8859-1', true );
485
- if ( $enc ) setlocale( LC_ALL, 'en_US.' . $enc );
486
- @ini_set( 'auto_detect_line_endings', true );
487
-
488
- // Get headers
489
- if ( ( $handle = fopen( $file, "r" ) ) !== FALSE ) {
490
-
491
- $row = $raw_headers = array();
492
- $header = fgetcsv( $handle, 0, $this->delimiter );
493
-
494
- while ( ( $postmeta = fgetcsv( $handle, 0, $this->delimiter ) ) !== FALSE ) {
495
- foreach ( $header as $key => $heading ) {
496
- if ( ! $heading ) continue;
497
- $s_heading = strtolower( $heading );
498
- $row[$s_heading] = ( isset( $postmeta[$key] ) ) ? $this->format_data_from_csv( $postmeta[$key], $enc ) : '';
499
- $raw_headers[ $s_heading ] = $heading;
500
- }
501
- break;
502
- }
503
- fclose( $handle );
504
- }
505
-
506
- $mapping_from_db = get_option( 'wf_prod_csv_imp_exp_mapping');
507
- $saved_mapping = null;
508
- $saved_evaluation = null;
509
- if($mapping_from_db && is_array($mapping_from_db) && count($mapping_from_db) == 2 && empty($_GET['clearmapping'])){
510
- //if(count(array_intersect_key ( $mapping_from_db[0] , $row)) == count($mapping_from_db[0])){
511
- $reset_action = 'admin.php?clearmapping=1&amp;import=' . $this->import_page . '&amp;step=1&amp;merge=' . ( ! empty( $_GET['merge'] ) ? 1 : 0 ) . '&amp;file_url=' . $this->file_url . '&amp;delimiter=' . $this->delimiter . '&amp;merge_empty_cells=' . $this->merge_empty_cells . '&amp;file_id=' . $this->id . '';
512
- $reset_action = esc_attr(wp_nonce_url($reset_action, 'import-upload'));
513
- echo '<h3>' . __( 'Map to fields are pre-selected based on your last import. <a href="'.$reset_action.'">Click here</a> to clear saved mapping.', 'wf_csv_import_export' ) . '</h3>';
514
- $saved_mapping = $mapping_from_db[0];
515
- $saved_evaluation = $mapping_from_db[1];
516
- //}
517
- }
518
-
519
- $merge = (!empty($_GET['merge']) && $_GET['merge']) ? 1 : 0;
520
-
521
- $attrs = self::get_all_product_attributes();
522
- $attr_keys = array_values($attrs);
523
-
524
- $attributes = array();
525
- if(!empty($attr_keys) && !empty($attrs))
526
- $attributes = array_combine($attr_keys , $attrs);
527
-
528
- $product_ptaxonomies = get_object_taxonomies( 'product', 'name' );
529
- $product_vtaxonomies = get_object_taxonomies( 'product_variation', 'name' );
530
- $product_taxonomies = array_merge($product_ptaxonomies, $product_vtaxonomies);
531
- $taxonomies = array_keys($product_taxonomies);
532
- $new_keys = array_values($taxonomies);
533
- $taxonomies = array_combine($new_keys , $taxonomies);
534
- include( 'views/html-wf-import-options.php' );
535
- }
536
-
537
- /**
538
- * The main controller for the actual import stage.
539
- */
540
- public function import() {
541
- global $woocommerce, $wpdb;
542
-
543
- wp_suspend_cache_invalidation( true );
544
-
545
- $this->log->add( 'csv-import', '---' );
546
- $this->log->add( 'csv-import', __( 'Processing products.', 'wf_csv_import_export' ) );
547
- foreach ( $this->parsed_data as $key => &$item ) {
548
-
549
- $product = $this->parser->parse_product( $item, $this->merge_empty_cells );
550
- if ( ! is_wp_error( $product ) )
551
- $this->process_product( $product );
552
- else
553
- $this->add_import_result( 'failed', $product->get_error_message(), 'Not parsed', json_encode( $item ), '-' );
554
-
555
- unset( $item, $product );
556
- $i++;
557
- }
558
- $this->log->add( 'csv-import', __( 'Finished processing products.', 'wf_csv_import_export' ) );
559
- wp_suspend_cache_invalidation( false );
560
- }
561
-
562
- /**
563
- * Parses the CSV file and prepares us for the task of processing parsed data
564
- *
565
- * @param string $file Path to the CSV file for importing
566
- */
567
- public function import_start( $file, $mapping, $start_pos, $end_pos, $eval_field ) {
568
-
569
- $memory = size_format( woocommerce_let_to_num( ini_get( 'memory_limit' ) ) );
570
- $wp_memory = size_format( woocommerce_let_to_num( WP_MEMORY_LIMIT ) );
571
-
572
- $this->log->add( 'csv-import', '---[ New Import ] PHP Memory: ' . $memory . ', WP Memory: ' . $wp_memory );
573
- $this->log->add( 'csv-import', __( 'Parsing products CSV.', 'wf_csv_import_export' ) );
574
-
575
- $this->parser = new WF_CSV_Parser( 'product' );
576
-
577
- list( $this->parsed_data, $this->raw_headers, $position ) = $this->parser->parse_data( $file, $this->delimiter, $mapping, $start_pos, $end_pos, $eval_field );
578
-
579
- $this->log->add( 'csv-import', __( 'Finished parsing products CSV.', 'wf_csv_import_export' ) );
580
-
581
- unset( $import_data );
582
-
583
- wp_defer_term_counting( true );
584
- wp_defer_comment_counting( true );
585
-
586
- return $position;
587
- }
588
-
589
- /**
590
- * Performs post-import cleanup of files and the cache
591
- */
592
- public function import_end() {
593
-
594
- //wp_cache_flush(); Stops output in some hosting environments
595
- foreach ( get_taxonomies() as $tax ) {
596
- delete_option( "{$tax}_children" );
597
- _get_term_hierarchy( $tax );
598
- }
599
-
600
- wp_defer_term_counting( false );
601
- wp_defer_comment_counting( false );
602
-
603
- do_action( 'import_end' );
604
- }
605
-
606
- /**
607
- * Handles the CSV upload and initial parsing of the file to prepare for
608
- * displaying author import options
609
- *
610
- * @return bool False if error uploading or invalid file, true otherwise
611
- */
612
- public function handle_upload() {
613
- if($this->handle_ftp()){
614
- return true;
615
- }
616
- if ( empty( $_POST['file_url'] ) ) {
617
-
618
- $file = wp_import_handle_upload();
619
-
620
- if ( isset( $file['error'] ) ) {
621
- echo '<p><strong>' . __( 'Sorry, there has been an error.', 'wf_csv_import_export' ) . '</strong><br />';
622
- echo esc_html( $file['error'] ) . '</p>';
623
- return false;
624
- }
625
-
626
- $this->id = (int) $file['id'];
627
- return true;
628
-
629
- } else {
630
-
631
- if ( file_exists( ABSPATH . $_POST['file_url'] ) ) {
632
-
633
- $this->file_url = esc_attr( $_POST['file_url'] );
634
- return true;
635
-
636
- } else {
637
-
638
- echo '<p><strong>' . __( 'Sorry, there has been an error.', 'wf_csv_import_export' ) . '</strong></p>';
639
- return false;
640
-
641
- }
642
-
643
- }
644
-
645
- return false;
646
- }
647
-
648
- public function product_exists( $title, $sku = '', $post_name = '' ) {
649
- global $wpdb;
650
-
651
- // Post Title Check
652
- $post_title = stripslashes( sanitize_post_field( 'post_title', $title, 0, 'db' ) );
653
-
654
- $query = "SELECT ID FROM $wpdb->posts WHERE post_type = 'product' AND post_status IN ( 'publish', 'private', 'draft', 'pending', 'future' )";
655
- $args = array();
656
-
657
- /*
658
- * removed title check
659
- if ( ! empty ( $title ) ) {
660
- $query .= ' AND post_title = %s';
661
- $args[] = $post_title;
662
- }
663
- */
664
-
665
- if ( ! empty ( $post_name ) ) {
666
- $query .= ' AND post_name = %s';
667
- $args[] = $post_name;
668
- }
669
-
670
- if ( ! empty ( $args ) ) {
671
- $posts_that_exist = $wpdb->get_col( $wpdb->prepare( $query, $args ) );
672
-
673
- if ( $posts_that_exist ) {
674
-
675
- foreach( $posts_that_exist as $post_exists ) {
676
-
677
- // Check unique SKU
678
- $post_exists_sku = get_post_meta( $post_exists, '_sku', true );
679
-
680
- if ( $sku == $post_exists_sku ) {
681
- return true;
682
- }
683
-
684
- }
685
-
686
- }
687
- }
688
-
689
- // Sku Check
690
- if ( $sku ) {
691
-
692
- $post_exists_sku = $wpdb->get_var( $wpdb->prepare( "
693
- SELECT $wpdb->posts.ID
694
- FROM $wpdb->posts
695
- LEFT JOIN $wpdb->postmeta ON ( $wpdb->posts.ID = $wpdb->postmeta.post_id )
696
- WHERE $wpdb->posts.post_status IN ( 'publish', 'private', 'draft', 'pending', 'future' )
697
- AND $wpdb->postmeta.meta_key = '_sku' AND $wpdb->postmeta.meta_value = '%s'
698
- ", $sku ) );
699
-
700
- if ( $post_exists_sku ) {
701
- return true;
702
- }
703
- }
704
-
705
- return false;
706
- }
707
-
708
- /**
709
- * Create new posts based on import information
710
- */
711
- public function process_product( $post ) {
712
-
713
- $processing_product_id = absint( $post['post_id'] );
714
- $processing_product = get_post( $processing_product_id );
715
- $processing_product_title = $processing_product ? $processing_product->post_title : '';
716
- $processing_product_sku = $processing_product ? $processing_product->sku : '';
717
- $merging = ! empty( $post['merging'] );
718
-
719
- if ( ! empty( $post['post_title'] ) ) {
720
- $processing_product_title = $post['post_title'];
721
- }
722
-
723
- if ( ! empty( $post['sku'] ) ) {
724
- $processing_product_sku = $post['sku'];
725
- }
726
-
727
- if ( ! empty( $processing_product_id ) && isset( $this->processed_posts[ $processing_product_id ] ) ) {
728
- $this->add_import_result( 'skipped', __( 'Product already processed', 'wf_csv_import_export' ), $processing_product_id, $processing_product_title, $processing_product_sku );
729
- $this->log->add( 'csv-import', __('> Post ID already processed. Skipping.', 'wf_csv_import_export'), true );
730
- unset( $post );
731
- return;
732
- }
733
-
734
- if ( ! empty ( $post['post_status'] ) && $post['post_status'] == 'auto-draft' ) {
735
- $this->add_import_result( 'skipped', __( 'Skipping auto-draft', 'wf_csv_import_export' ), $processing_product_id, $processing_product_title, $processing_product_sku );
736
- $this->log->add( 'csv-import', __('> Skipping auto-draft.', 'wf_csv_import_export'), true );
737
- unset( $post );
738
- return;
739
- }
740
- // Check if post exists when importing
741
- if ( ! $merging ) {
742
- if ( $this->product_exists( $processing_product_title, $processing_product_sku, $post['post_name'] ) ) {
743
- if(!$processing_product_id && empty($processing_product_sku)) {
744
- // if no sku , no id and no merge + is product in db with same title -> just give message
745
- $usr_msg = 'Product with same title already exist.';
746
- }else{
747
- $usr_msg = 'Product already exists.';
748
- }
749
- $this->add_import_result( 'skipped', __( $usr_msg, 'wf_csv_import_export' ), $processing_product_id, $processing_product_title, $processing_product_sku );
750
- $this->log->add( 'csv-import', sprintf( __('> &#8220;%s&#8221;'.$usr_msg, 'wf_csv_import_export'), esc_html($processing_product_title) ), true );
751
- unset( $post );
752
- return;
753
- }
754
-
755
- if ( $processing_product_id && is_string( get_post_status( $processing_product_id ) ) ) {
756
- $this->add_import_result( 'skipped', __( 'Importing post ID conflicts with an existing post ID', 'wf_csv_import_export' ), $processing_product_id, get_the_title( $processing_product_id ), '' );
757
- $this->log->add( 'csv-import', sprintf( __('> &#8220;%s&#8221; ID already exists.', 'wf_csv_import_export'), esc_html( $processing_product_id ) ), true );
758
- unset( $post );
759
- return;
760
- }
761
- }
762
- // Check post type to avoid conflicts with IDs
763
- $is_post_exist_in_db = get_post_type( $processing_product_id );
764
- if ( $merging && $processing_product_id && !empty($is_post_exist_in_db) && (get_post_type( $processing_product_id ) !== $post['post_type'] )) {
765
- $this->add_import_result( 'skipped', __( 'Post is not a product', 'wf_csv_import_export' ), $processing_product_id, $processing_product_title, $processing_product_sku );
766
- $this->log->add( 'csv-import', sprintf( __('> &#8220;%s&#8221; is not a product.', 'wf_csv_import_export'), esc_html($processing_product_id) ), true );
767
- unset( $post );
768
- return;
769
- }
770
-
771
- if ( $merging && !empty($is_post_exist_in_db) ) {
772
-
773
- // Only merge fields which are set
774
- $post_id = $processing_product_id;
775
-
776
- $this->log->add( 'csv-import', sprintf( __('> Merging post ID %s.', 'wf_csv_import_export'), $post_id ), true );
777
-
778
- $postdata = array(
779
- 'ID' => $post_id
780
- );
781
-
782
- if ( $this->merge_empty_cells ) {
783
- if ( isset( $post['post_content'] ) ) {
784
- $postdata['post_content'] = $post['post_content'];
785
- }
786
- if ( isset( $post['post_excerpt'] ) ) {
787
- $postdata['post_excerpt'] = $post['post_excerpt'];
788
- }
789
- if ( isset( $post['post_password'] ) ) {
790
- $postdata['post_password'] = $post['post_password'];
791
- }
792
- if ( isset( $post['post_parent'] ) ) {
793
- $postdata['post_parent'] = $post['post_parent'];
794
- }
795
- } else {
796
- if ( ! empty( $post['post_content'] ) ) {
797
- $postdata['post_content'] = $post['post_content'];
798
- }
799
- if ( ! empty( $post['post_excerpt'] ) ) {
800
- $postdata['post_excerpt'] = $post['post_excerpt'];
801
- }
802
- if ( ! empty( $post['post_password'] ) ) {
803
- $postdata['post_password'] = $post['post_password'];
804
- }
805
- if ( isset( $post['post_parent'] ) && $post['post_parent'] !== '' ) {
806
- $postdata['post_parent'] = $post['post_parent'];
807
- }
808
- }
809
-
810
- if ( ! empty( $post['post_title'] ) ) {
811
- $postdata['post_title'] = $post['post_title'];
812
- }
813
-
814
- if ( ! empty( $post['post_author'] ) ) {
815
- $postdata['post_author'] = absint( $post['post_author'] );
816
- }
817
- if ( ! empty( $post['post_date'] ) ) {
818
- $postdata['post_date'] = date("Y-m-d H:i:s", strtotime( $post['post_date'] ) );
819
- }
820
- if ( ! empty( $post['post_date_gmt'] ) ) {
821
- $postdata['post_date_gmt'] = date("Y-m-d H:i:s", strtotime( $post['post_date_gmt'] ) );
822
- }
823
- if ( ! empty( $post['post_name'] ) ) {
824
- $postdata['post_name'] = $post['post_name'];
825
- }
826
- if ( ! empty( $post['post_status'] ) ) {
827
- $postdata['post_status'] = $post['post_status'];
828
- }
829
- if ( ! empty( $post['menu_order'] ) ) {
830
- $postdata['menu_order'] = $post['menu_order'];
831
- }
832
- if ( ! empty( $post['comment_status'] ) ) {
833
- $postdata['comment_status'] = $post['comment_status'];
834
- }
835
- if ( sizeof( $postdata ) > 1 ) {
836
- $result = wp_update_post( $postdata );
837
-
838
- if ( ! $result ) {
839
- $this->add_import_result( 'failed', __( 'Failed to update product', 'wf_csv_import_export' ), $post_id, $processing_product_title, $processing_product_sku );
840
- $this->log->add( 'csv-import', sprintf( __('> Failed to update product %s', 'wf_csv_import_export'), $post_id ), true );
841
- unset( $post );
842
- return;
843
- } else {
844
- $this->log->add( 'csv-import', __( '> Merged post data: ', 'wf_csv_import_export' ) . print_r( $postdata, true ) );
845
- }
846
- }
847
-
848
- } else {
849
- $merging = FALSE;
850
- // Get parent
851
- $post_parent = $post['post_parent'];
852
-
853
- if ( $post_parent !== "" ) {
854
- $post_parent = absint( $post_parent );
855
-
856
- if ( $post_parent > 0 ) {
857
- // if we already know the parent, map it to the new local ID
858
- if ( isset( $this->processed_posts[ $post_parent ] ) ) {
859
- $post_parent = $this->processed_posts[ $post_parent ];
860
-
861
- // otherwise record the parent for later
862
- } else {
863
-
864
- $this->post_orphans[ intval( $processing_product_id ) ] = $post_parent;
865
- //$post_parent = 0;
866
-
867
- }
868
-
869
- }
870
- }
871
-
872
- // Insert product
873
- $this->log->add( 'csv-import', sprintf( __('> Inserting %s', 'wf_csv_import_export'), esc_html( $processing_product_title ) ), true );
874
-
875
- $postdata = array(
876
- 'import_id' => $processing_product_id,
877
- 'post_author' => $post['post_author'] ? absint( $post['post_author'] ) : get_current_user_id(),
878
- 'post_date' => ( $post['post_date'] ) ? date( 'Y-m-d H:i:s', strtotime( $post['post_date'] )) : '',
879
- 'post_date_gmt' => ( $post['post_date_gmt'] ) ? date( 'Y-m-d H:i:s', strtotime( $post['post_date_gmt'] )) : '',
880
- 'post_content' => $post['post_content'],
881
- 'post_excerpt' => $post['post_excerpt'],
882
- 'post_title' => $processing_product_title,
883
- 'post_name' => ( $post['post_name'] ) ? $post['post_name'] : sanitize_title( $processing_product_title ),
884
- 'post_status' => ( $post['post_status'] ) ? $post['post_status'] : 'publish',
885
- 'post_parent' => $post_parent,
886
- 'menu_order' => $post['menu_order'],
887
- 'post_type' => $post['post_type'],
888
- 'post_password' => $post['post_password'],
889
- 'comment_status' => $post['comment_status'],
890
- );
891
- $post_id = wp_insert_post( $postdata, true );
892
-
893
- if ( is_wp_error( $post_id ) ) {
894
-
895
- $this->add_import_result( 'failed', __( 'Failed to import product', 'wf_csv_import_export' ), $processing_product_id, $processing_product_title, $processing_product_sku );
896
- $this->log->add( 'csv-import', sprintf( __( 'Failed to import product &#8220;%s&#8221;', 'wf_csv_import_export' ), esc_html($processing_product_title) ) );
897
- unset( $post );
898
- return;
899
-
900
- } else {
901
-
902
- $this->log->add( 'csv-import', sprintf( __('> Inserted - post ID is %s.', 'wf_csv_import_export'), $post_id ) );
903
-
904
- }
905
- }
906
-
907
- unset( $postdata );
908
-
909
- // map pre-import ID to local ID
910
- if ( empty( $processing_product_id ) ) {
911
- $processing_product_id = (int) $post_id;
912
- }
913
-
914
- $this->processed_posts[ intval( $processing_product_id ) ] = (int) $post_id;
915
-
916
- // add categories, tags and other terms
917
- if ( ! empty( $post['terms'] ) && is_array( $post['terms'] ) ) {
918
-
919
- $terms_to_set = array();
920
-
921
- foreach ( $post['terms'] as $term_group ) {
922
-
923
- $taxonomy = $term_group['taxonomy'];
924
- $terms = $term_group['terms'];
925
-
926
- if ( ! $taxonomy || ! taxonomy_exists( $taxonomy ) ) {
927
- continue;
928
- }
929
-
930
- if ( ! is_array( $terms ) ) {
931
- $terms = array( $terms );
932
- }
933
-
934
- $terms_to_set[ $taxonomy ] = array();
935
-
936
- foreach ( $terms as $term_id ) {
937
-
938
- if ( ! $term_id ) continue;
939
-
940
- $terms_to_set[ $taxonomy ][] = intval( $term_id );
941
- }
942
-
943
- }
944
-
945
- foreach ( $terms_to_set as $tax => $ids ) {
946
- $tt_ids = wp_set_post_terms( $post_id, $ids, $tax, false );
947
- }
948
-
949
- unset( $post['terms'], $terms_to_set );
950
- }
951
-
952
- // add/update post meta
953
- if ( ! empty( $post['postmeta'] ) && is_array( $post['postmeta'] ) ) {
954
- foreach ( $post['postmeta'] as $meta ) {
955
- $key = apply_filters( 'import_post_meta_key', $meta['key'] );
956
-
957
- if ( $key ) {
958
- update_post_meta( $post_id, $key, maybe_unserialize( $meta['value'] ) );
959
- }
960
-
961
- if ( $key == '_file_paths' ) {
962
- do_action( 'woocommerce_process_product_file_download_paths', $post_id, 0, maybe_unserialize( $meta['value'] ) );
963
- }
964
-
965
- }
966
-
967
- unset( $post['postmeta'] );
968
- }
969
-
970
- // Import images and add to post
971
- if ( ! empty( $post['images'] ) && is_array($post['images']) ) {
972
-
973
- $featured = true;
974
- $gallery_ids = array();
975
-
976
- if ($merging) {
977
-
978
- // Get basenames
979
- $image_basenames = array();
980
-
981
- foreach( $post['images'] as $image )
982
- $image_basenames[] = basename( $image );
983
-
984
- // Loop attachments already attached to the product
985
- $attachments = get_posts( 'post_parent=' . $post_id . '&post_type=attachment&fields=ids&post_mime_type=image&numberposts=-1' );
986
-
987
- foreach ( $attachments as $attachment_key => $attachment ) {
988
-
989
- $attachment_url = wp_get_attachment_url( $attachment );
990
- $attachment_basename = basename( $attachment_url );
991
-
992
- // Don't import existing images
993
- if ( in_array( $attachment_url, $post['images'] ) || in_array( $attachment_basename, $image_basenames ) ) {
994
-
995
- foreach( $post['images'] as $key => $image ) {
996
-
997
- if ( $image == $attachment_url || basename( $image ) == $attachment_basename ) {
998
- unset( $post['images'][ $key ] );
999
-
1000
- $this->log->add( 'csv-import', sprintf( __( '> > Image exists - skipping %s', 'wf_csv_import_export' ), basename( $image ) ) );
1001
-
1002
- if ( $key == 0 ) {
1003
- update_post_meta( $post_id, '_thumbnail_id', $attachment );
1004
- $featured = false;
1005
- } else {
1006
- $gallery_ids[ $key ] = $attachment;
1007
- }
1008
- }
1009
-
1010
- }
1011
-
1012
- } else {
1013
-
1014
- // Detach image which is not being merged
1015
- $attachment_post = array();
1016
- $attachment_post['ID'] = $attachment;
1017
- $attachment_post['post_parent'] = '';
1018
- wp_update_post( $attachment_post );
1019
- unset( $attachment_post );
1020
-
1021
- }
1022
-
1023
- }
1024
-
1025
- unset( $attachments );
1026
- }
1027
-
1028
- if ( $post['images'] ) foreach ( $post['images'] as $image_key => $image ) {
1029
-
1030
- $this->log->add( 'csv-import', sprintf( __( '> > Importing image "%s"', 'wf_csv_import_export' ), $image ) );
1031
-
1032
- $filename = basename( $image );
1033
-
1034
- $attachment = array(
1035
- 'post_title' => preg_replace( '/\.[^.]+$/', '', $processing_product_title . ' ' . ( $image_key + 1 ) ),
1036
- 'post_content' => '',
1037
- 'post_status' => 'inherit',
1038
- 'post_parent' => $post_id
1039
- );
1040
-
1041
- $attachment_id = $this->process_attachment( $attachment, $image, $post_id );
1042
-
1043
- if ( ! is_wp_error( $attachment_id ) && $attachment_id ) {
1044
-
1045
- $this->log->add( 'csv-import', sprintf( __( '> > Imported image "%s"', 'wf_csv_import_export' ), $image ) );
1046
-
1047
- // Set alt
1048
- update_post_meta( $attachment_id, '_wp_attachment_image_alt', $processing_product_title );
1049
-
1050
- if ( $featured ) {
1051
- update_post_meta( $post_id, '_thumbnail_id', $attachment_id );
1052
- } else {
1053
- $gallery_ids[ $image_key ] = $attachment_id;
1054
- }
1055
-
1056
- update_post_meta( $attachment_id, '_woocommerce_exclude_image', 0 );
1057
-
1058
- $featured = false;
1059
- } else {
1060
- $this->log->add( 'csv-import', sprintf( __( '> > Error importing image "%s"', 'wf_csv_import_export' ), $image ) );
1061
- $this->log->add( 'csv-import', '> > ' . $attachment_id->get_error_message() );
1062
- }
1063
-
1064
- unset( $attachment, $attachment_id );
1065
- }
1066
-
1067
- $this->log->add( 'csv-import', __( '> > Images set', 'wf_csv_import_export' ) );
1068
-
1069
- ksort( $gallery_ids );
1070
-
1071
- update_post_meta( $post_id, '_product_image_gallery', implode( ',', $gallery_ids ) );
1072
-
1073
- unset( $post['images'], $featured, $gallery_ids );
1074
- }
1075
-
1076
- // Import attributes
1077
- if ( ! empty( $post['attributes'] ) && is_array($post['attributes']) ) {
1078
-
1079
- if ($merging) {
1080
- $attributes = array_filter( (array) maybe_unserialize( get_post_meta( $post_id, '_product_attributes', true ) ) );
1081
- $attributes = array_merge( $attributes, $post['attributes'] );
1082
- } else {
1083
- $attributes = $post['attributes'];
1084
- }
1085
-
1086
- // Sort attribute positions
1087
- if ( ! function_exists( 'attributes_cmp' ) ) {
1088
- function attributes_cmp( $a, $b ) {
1089
- if ( $a['position'] == $b['position'] ) return 0;
1090
- return ( $a['position'] < $b['position'] ) ? -1 : 1;
1091
- }
1092
- }
1093
- uasort( $attributes, 'attributes_cmp' );
1094
-
1095
- update_post_meta( $post_id, '_product_attributes', $attributes );
1096
-
1097
- unset( $post['attributes'], $attributes );
1098
- }
1099
-
1100
- // Import GPF
1101
- if ( ! empty( $post['gpf_data'] ) && is_array( $post['gpf_data'] ) ) {
1102
-
1103
- update_post_meta( $post_id, '_woocommerce_gpf_data', $post['gpf_data'] );
1104
-
1105
- unset( $post['gpf_data'] );
1106
- }
1107
-
1108
- if ( ! empty( $post['upsell_skus'] ) && is_array( $post['upsell_skus'] ) ) {
1109
- $this->upsell_skus[ $post_id ] = $post['upsell_skus'];
1110
- }
1111
-
1112
- if ( ! empty( $post['crosssell_skus'] ) && is_array( $post['crosssell_skus'] ) ) {
1113
- $this->crosssell_skus[ $post_id ] = $post['crosssell_skus'];
1114
- }
1115
-
1116
- add_post_meta( $post_id, 'total_sales', 0 );
1117
-
1118
- if ( $merging ) {
1119
- $this->add_import_result( 'merged', 'Merge successful', $post_id, $processing_product_title, $processing_product_sku );
1120
- $this->log->add( 'csv-import', sprintf( __('> Finished merging post ID %s.', 'wf_csv_import_export'), $post_id ) );
1121
- } else {
1122
- $this->add_import_result( 'imported', 'Import successful', $post_id, $processing_product_title, $processing_product_sku );
1123
- $this->log->add( 'csv-import', sprintf( __('> Finished importing post ID %s.', 'wf_csv_import_export'), $post_id ) );
1124
- }
1125
-
1126
- unset( $post );
1127
- }
1128
-
1129
- /**
1130
- * Log a row's import status
1131
- */
1132
- protected function add_import_result( $status, $reason, $post_id = '', $post_title = '', $sku = '' ) {
1133
- $this->import_results[] = array(
1134
- 'post_title' => $post_title,
1135
- 'post_id' => $post_id,
1136
- 'sku' => $sku,
1137
- 'status' => $status,
1138
- 'reason' => $reason
1139
- );
1140
- }
1141
-
1142
- /**
1143
- * If fetching attachments is enabled then attempt to create a new attachment
1144
- *
1145
- * @param array $post Attachment post details from WXR
1146
- * @param string $url URL to fetch attachment from
1147
- * @return int|WP_Error Post ID on success, WP_Error otherwise
1148
- */
1149
- public function process_attachment( $post, $url, $post_id ) {
1150
-
1151
- $attachment_id = '';
1152
- $attachment_url = '';
1153
- $attachment_file = '';
1154
- $upload_dir = wp_upload_dir();
1155
-
1156
- // If same server, make it a path and move to upload directory
1157
- /*if ( strstr( $url, $upload_dir['baseurl'] ) ) {
1158
-
1159
- $url = str_replace( $upload_dir['baseurl'], $upload_dir['basedir'], $url );
1160
-
1161
- } else*/
1162
- if ( strstr( $url, site_url() ) ) {
1163
- $abs_url = str_replace( trailingslashit( site_url() ), trailingslashit( ABSPATH ), urldecode($url) );
1164
- $new_name = wp_unique_filename( $upload_dir['path'], basename( urldecode($url) ) );
1165
- $new_url = trailingslashit( $upload_dir['path'] ) . $new_name;
1166
-
1167
- if ( copy( $abs_url, $new_url ) ) {
1168
- $url = basename( $new_url );
1169
- }
1170
- }
1171
-
1172
- if ( ! strstr( $url, 'http' ) ) {
1173
-
1174
- // Local file
1175
- $attachment_file = trailingslashit( $upload_dir['basedir'] ) . 'product_images/' . $url;
1176
-
1177
- // We have the path, check it exists
1178
- if ( ! file_exists( $attachment_file ) )
1179
- $attachment_file = trailingslashit( $upload_dir['path'] ) . $url;
1180
-
1181
- // We have the path, check it exists
1182
- if ( file_exists( $attachment_file ) ) {
1183
-
1184
- $attachment_url = str_replace( trailingslashit( ABSPATH ), trailingslashit( site_url() ), $attachment_file );
1185
-
1186
- if ( $info = wp_check_filetype( $attachment_file ) )
1187
- $post['post_mime_type'] = $info['type'];
1188
- else
1189
- return new WP_Error( 'attachment_processing_error', __('Invalid file type', 'wordpress-importer') );
1190
-
1191
- $post['guid'] = $attachment_url;
1192
-
1193
- $attachment_id = wp_insert_attachment( $post, $attachment_file, $post_id );
1194
-
1195
- } else {
1196
- return new WP_Error( 'attachment_processing_error', __('Local image did not exist!', 'wordpress-importer') );
1197
- }
1198
-
1199
- } else {
1200
-
1201
- // if the URL is absolute, but does not contain address, then upload it assuming base_site_url
1202
- if ( preg_match( '|^/[\w\W]+$|', $url ) )
1203
- $url = rtrim( site_url(), '/' ) . $url;
1204
-
1205
- $upload = $this->fetch_remote_file( $url, $post );
1206
-
1207
- if ( is_wp_error( $upload ) )
1208
- return $upload;
1209
-
1210
- if ( $info = wp_check_filetype( $upload['file'] ) )
1211
- $post['post_mime_type'] = $info['type'];
1212
- else
1213
- return new WP_Error( 'attachment_processing_error', __('Invalid file type', 'wordpress-importer') );
1214
-
1215
- $post['guid'] = $upload['url'];
1216
- $attachment_file = $upload['file'];
1217
- $attachment_url = $upload['url'];
1218
-
1219
- // as per wp-admin/includes/upload.php
1220
- $attachment_id = wp_insert_attachment( $post, $upload['file'], $post_id );
1221
-
1222
- unset( $upload );
1223
- }
1224
-
1225
- if ( ! is_wp_error( $attachment_id ) && $attachment_id > 0 ) {
1226
- $this->log->add( 'csv-import', sprintf( __( '> > Inserted image attachment "%s"', 'wf_csv_import_export' ), $url ) );
1227
-
1228
- $this->attachments[] = $attachment_id;
1229
- }
1230
-
1231
- return $attachment_id;
1232
- }
1233
-
1234
- /**
1235
- * Attempt to download a remote file attachment
1236
- */
1237
- public function fetch_remote_file( $url, $post ) {
1238
-
1239
- // extract the file name and extension from the url
1240
- $file_name = basename( current( explode( '?', $url ) ) );
1241
- $wp_filetype = wp_check_filetype( $file_name, null );
1242
- $parsed_url = @parse_url( $url );
1243
-
1244
- // Check parsed URL
1245
- if ( ! $parsed_url || ! is_array( $parsed_url ) )
1246
- return new WP_Error( 'import_file_error', 'Invalid URL' );
1247
-
1248
- // Ensure url is valid
1249
- $url = str_replace( " ", '%20', $url );
1250
-
1251
- // Get the file
1252
- $response = wp_remote_get( $url, array(
1253
- 'timeout' => 10
1254
- ) );
1255
-
1256
- if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) !== 200 )
1257
- return new WP_Error( 'import_file_error', 'Error getting remote image' );
1258
-
1259
- // Ensure we have a file name and type
1260
- if ( ! $wp_filetype['type'] ) {
1261
-
1262
- $headers = wp_remote_retrieve_headers( $response );
1263
-
1264
- if ( isset( $headers['content-disposition'] ) && strstr( $headers['content-disposition'], 'filename=' ) ) {
1265
-
1266
- $disposition = end( explode( 'filename=', $headers['content-disposition'] ) );
1267
- $disposition = sanitize_file_name( $disposition );
1268
- $file_name = $disposition;
1269
-
1270
- } elseif ( isset( $headers['content-type'] ) && strstr( $headers['content-type'], 'image/' ) ) {
1271
-
1272
- $file_name = 'image.' . str_replace( 'image/', '', $headers['content-type'] );
1273
-
1274
- }
1275
-
1276
- unset( $headers );
1277
- }
1278
-
1279
- // Upload the file
1280
- $upload = wp_upload_bits( $file_name, '', wp_remote_retrieve_body( $response ) );
1281
-
1282
- if ( $upload['error'] )
1283
- return new WP_Error( 'upload_dir_error', $upload['error'] );
1284
-
1285
- // Get filesize
1286
- $filesize = filesize( $upload['file'] );
1287
-
1288
- if ( 0 == $filesize ) {
1289
- @unlink( $upload['file'] );
1290
- unset( $upload );
1291
- return new WP_Error( 'import_file_error', __('Zero size file downloaded', 'wf_csv_import_export') );
1292
- }
1293
-
1294
- unset( $response );
1295
-
1296
- return $upload;
1297
- }
1298
-
1299
- /**
1300
- * Decide what the maximum file size for downloaded attachments is.
1301
- * Default is 0 (unlimited), can be filtered via import_attachment_size_limit
1302
- *
1303
- * @return int Maximum attachment file size to import
1304
- */
1305
- public function max_attachment_size() {
1306
- return apply_filters( 'import_attachment_size_limit', 0 );
1307
- }
1308
-
1309
- /**
1310
- * Attempt to associate posts and menu items with previously missing parents
1311
- */
1312
- public function backfill_parents() {
1313
- global $wpdb;
1314
-
1315
- // find parents for post orphans
1316
- if ( ! empty( $this->post_orphans ) && is_array( $this->post_orphans ) )
1317
- foreach ( $this->post_orphans as $child_id => $parent_id ) {
1318
- $local_child_id = $local_parent_id = false;
1319
- if ( isset( $this->processed_posts[$child_id] ) )
1320
- $local_child_id = $this->processed_posts[$child_id];
1321
- if ( isset( $this->processed_posts[$parent_id] ) )
1322
- $local_parent_id = $this->processed_posts[$parent_id];
1323
-
1324
- if ( $local_child_id && $local_parent_id )
1325
- $wpdb->update( $wpdb->posts, array( 'post_parent' => $local_parent_id ), array( 'ID' => $local_child_id ), '%d', '%d' );
1326
- }
1327
- }
1328
-
1329
- /**
1330
- * Attempt to associate posts and menu items with previously missing parents
1331
- */
1332
- public function link_product_skus( $type, $product_id, $skus ) {
1333
- global $wpdb;
1334
-
1335
- $ids = array();
1336
-
1337
- foreach ( $skus as $sku ) {
1338
- $ids[] = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_sku' AND meta_value = %s;", $sku ) );
1339
- }
1340
-
1341
- $ids = array_filter( $ids );
1342
-
1343
- update_post_meta( $product_id, "_{$type}_ids", $ids );
1344
- }
1345
-
1346
- private function handle_ftp(){
1347
- $enable_ftp_ie = !empty( $_POST['enable_ftp_ie'] ) ? true : false;
1348
- if($enable_ftp_ie == false) return false;
1349
-
1350
- $ftp_server = ! empty( $_POST['ftp_server'] ) ? $_POST['ftp_server'] : '';
1351
- $ftp_server_path = ! empty( $_POST['ftp_server_path'] ) ? $_POST['ftp_server_path'] : '';
1352
- $ftp_user = ! empty( $_POST['ftp_user'] ) ? $_POST['ftp_user'] : '';
1353
- $ftp_password = ! empty( $_POST['ftp_password'] ) ? $_POST['ftp_password'] : '';
1354
- $use_ftps = ! empty( $_POST['use_ftps'] ) ? true : false;
1355
-
1356
-
1357
- $settings = array();
1358
- $settings[ 'ftp_server' ] = $ftp_server;
1359
- $settings[ 'ftp_user' ] = $ftp_user;
1360
- $settings[ 'ftp_password' ] = $ftp_password;
1361
- $settings[ 'use_ftps' ] = $use_ftps;
1362
- $settings[ 'enable_ftp_ie' ] = $enable_ftp_ie;
1363
- $settings[ 'ftp_server_path' ] = $ftp_server_path;
1364
-
1365
-
1366
- $local_file = 'wp-content/plugins/product-csv-import-export-for-woocommerce/temp-import.csv';
1367
- $server_file = $ftp_server_path;
1368
-
1369
- update_option( 'wf_shipment_tracking_importer_ftp', $settings );
1370
-
1371
- $ftp_conn = $use_ftps ? ftp_ssl_connect($ftp_server) : ftp_connect($ftp_server);
1372
- $error_message = "";
1373
- $success = false;
1374
- if($ftp_conn == false){
1375
- $error_message = "There is connection problem\n";
1376
- }
1377
-
1378
- if(empty($error_message)){
1379
- if(ftp_login($ftp_conn, $ftp_user, $ftp_password) == false){
1380
- $error_message = "Not able to login \n";
1381
- }
1382
- }
1383
- if(empty($error_message)){
1384
-
1385
- if (ftp_get($ftp_conn, ABSPATH.$local_file, $server_file, FTP_BINARY)) {
1386
- $error_message = "";
1387
- $success = true;
1388
- } else {
1389
- $error_message = "There was a problem\n";
1390
- }
1391
- }
1392
-
1393
- ftp_close($ftp_conn);
1394
- if($success){
1395
- $this->file_url = $local_file;
1396
- }else{
1397
- die($error_message);
1398
- }
1399
- return true;
1400
- }
1401
-
1402
- // Display import page title
1403
- public function header() {
1404
- echo '<div class="wrap"><div class="icon32" id="icon-woocommerce-importer"><br></div>';
1405
- echo '<h2>' . ( empty( $_GET['merge'] ) ? __( 'Import', 'wf_csv_import_export' ) : __( 'Merge Products', 'wf_csv_import_export' ) ) . '</h2>';
1406
- }
1407
-
1408
- // Close div.wrap
1409
- public function footer() {
1410
- echo '</div>';
1411
- }
1412
-
1413
- /**
1414
- * Display introductory text and file upload form
1415
- */
1416
- public function greet() {
1417
- $action = 'admin.php?import=woocommerce_csv&amp;step=1&amp;merge=' . ( ! empty( $_GET['merge'] ) ? 1 : 0 );
1418
- $bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() );
1419
- $size = size_format( $bytes );
1420
- $upload_dir = wp_upload_dir();
1421
-
1422
- include( 'views/html-wf-import-greeting.php' );
1423
- }
1424
-
1425
- /**
1426
- * Added to http_request_timeout filter to force timeout at 60 seconds during import
1427
- * @return int 60
1428
- */
1429
- public function bump_request_timeout( $val ) {
1430
- return 60;
1431
- }
1432
- /**
1433
- * Get a list of all the product attributes for a post type.
1434
- * These require a bit more digging into the values.
1435
- */
1436
- public static function get_all_product_attributes( $post_type = 'product' ) {
1437
- global $wpdb;
1438
-
1439
- $results = $wpdb->get_col( $wpdb->prepare(
1440
- "SELECT DISTINCT pm.meta_value
1441
- FROM {$wpdb->postmeta} AS pm
1442
- LEFT JOIN {$wpdb->posts} AS p ON p.ID = pm.post_id
1443
- WHERE p.post_type = %s
1444
- AND p.post_status IN ( 'publish', 'pending', 'private', 'draft' )
1445
- AND pm.meta_key = '_product_attributes'",
1446
- $post_type
1447
- ) );
1448
-
1449
- // Go through each result, and look at the attribute keys within them.
1450
- $result = array();
1451
-
1452
- if ( ! empty( $results ) ) {
1453
- foreach( $results as $_product_attributes ) {
1454
- $attributes = maybe_unserialize( maybe_unserialize( $_product_attributes ) );
1455
- if ( ! empty( $attributes ) && is_array( $attributes ) ) {
1456
- foreach( $attributes as $key => $attribute ) {
1457
- if ( ! $key ) {
1458
- continue;
1459
- }
1460
- if ( ! strstr( $key, 'pa_' ) ) {
1461
- if ( empty( $attribute['name'] ) ) {
1462
- continue;
1463
- }
1464
- $key = $attribute['name'];
1465
- }
1466
-
1467
- $result[ $key ] = $key;
1468
- }
1469
- }
1470
- }
1471
- }
1472
-
1473
- sort( $result );
1474
-
1475
- return $result;
1476
- }
1477
  }
1
+ <?php
2
+ /**
3
+ * WordPress Importer class for managing the import process of a CSV file
4
+ *
5
+ * @package WordPress
6
+ * @subpackage Importer
7
+ */
8
+ if ( ! class_exists( 'WP_Importer' ) )
9
+ return;
10
+
11
+ class WF_ProdImpExpCsv_Product_Import extends WP_Importer {
12
+
13
+ var $id;
14
+ var $file_url;
15
+ var $delimiter;
16
+ var $merge_empty_cells;
17
+
18
+ // mappings from old information to new
19
+ var $processed_terms = array();
20
+ var $processed_posts = array();
21
+ var $post_orphans = array();
22
+ var $attachments = array();
23
+ var $upsell_skus = array();
24
+ var $crosssell_skus = array();
25
+
26
+ // Results
27
+ var $import_results = array();
28
+
29
+ /**
30
+ * Constructor
31
+ */
32
+ public function __construct() {
33
+
34
+ $this->log = new WC_Logger();
35
+ $this->import_page = 'woocommerce_csv';
36
+ $this->file_url_import_enabled = apply_filters( 'woocommerce_csv_product_file_url_import_enabled', true );
37
+ }
38
+
39
+ /**
40
+ * Registered callback function for the WordPress Importer
41
+ *
42
+ * Manages the three separate stages of the CSV import process
43
+ */
44
+ public function dispatch() {
45
+ global $woocommerce, $wpdb;
46
+
47
+ if ( ! empty( $_POST['delimiter'] ) ) {
48
+ $this->delimiter = stripslashes( trim( $_POST['delimiter'] ) );
49
+ }else if ( ! empty( $_GET['delimiter'] ) ) {
50
+ $this->delimiter = stripslashes( trim( $_GET['delimiter'] ) );
51
+ }
52
+
53
+ if ( ! $this->delimiter )
54
+ $this->delimiter = ',';
55
+
56
+ if ( ! empty( $_POST['merge_empty_cells'] ) || ! empty( $_GET['merge_empty_cells'] ) ) {
57
+ $this->merge_empty_cells = 1;
58
+ } else{
59
+ $this->merge_empty_cells = 0;
60
+ }
61
+
62
+ $step = empty( $_GET['step'] ) ? 0 : (int) $_GET['step'];
63
+
64
+ switch ( $step ) {
65
+ case 0 :
66
+ $this->header();
67
+ $this->greet();
68
+ break;
69
+ case 1 :
70
+ $this->header();
71
+
72
+ check_admin_referer( 'import-upload' );
73
+
74
+ if(!empty($_GET['file_url']))
75
+ $this->file_url = esc_attr( $_GET['file_url'] );
76
+ if(!empty($_GET['file_id']))
77
+ $this->id = $_GET['file_id'] ;
78
+
79
+ if ( !empty($_GET['clearmapping']) || $this->handle_upload() )
80
+ $this->import_options();
81
+ else
82
+ _e( 'Error with handle_upload!', 'wf_csv_import_export' );
83
+ break;
84
+ case 2 :
85
+ $this->header();
86
+
87
+ check_admin_referer( 'import-woocommerce' );
88
+
89
+ $this->id = (int) $_POST['import_id'];
90
+
91
+ if ( $this->file_url_import_enabled )
92
+ $this->file_url = esc_attr( $_POST['import_url'] );
93
+
94
+ if ( $this->id )
95
+ $file = get_attached_file( $this->id );
96
+ else if ( $this->file_url_import_enabled )
97
+ $file = ABSPATH . $this->file_url;
98
+
99
+ $file = str_replace( "\\", "/", $file );
100
+
101
+ if ( $file ) {
102
+ ?>
103
+ <table id="import-progress" class="widefat_importer widefat">
104
+ <thead>
105
+ <tr>
106
+ <th class="status">&nbsp;</th>
107
+ <th class="row"><?php _e( 'Row', 'wf_csv_import_export' ); ?></th>
108
+ <th><?php _e( 'SKU', 'wf_csv_import_export' ); ?></th>
109
+ <th><?php _e( 'Product', 'wf_csv_import_export' ); ?></th>
110
+ <th class="reason"><?php _e( 'Status Msg', 'wf_csv_import_export' ); ?></th>
111
+ </tr>
112
+ </thead>
113
+ <tfoot>
114
+ <tr class="importer-loading">
115
+ <td colspan="5"></td>
116
+ </tr>
117
+ </tfoot>
118
+ <tbody></tbody>
119
+ </table>
120
+ <script type="text/javascript">
121
+ jQuery(document).ready(function($) {
122
+
123
+ if ( ! window.console ) { window.console = function(){}; }
124
+
125
+ var processed_terms = [];
126
+ var processed_posts = [];
127
+ var post_orphans = [];
128
+ var attachments = [];
129
+ var upsell_skus = [];
130
+ var crosssell_skus = [];
131
+ var i = 1;
132
+ var done_count = 0;
133
+
134
+ function import_rows( start_pos, end_pos ) {
135
+
136
+ var data = {
137
+ action: 'woocommerce_csv_import_request',
138
+ file: '<?php echo addslashes( $file ); ?>',
139
+ mapping: '<?php echo json_encode( $_POST['map_from'] ); ?>',
140
+ eval_field: '<?php echo stripslashes(json_encode(($_POST['eval_field']),JSON_HEX_APOS)) ?>',
141
+ delimiter: '<?php echo $this->delimiter; ?>',
142
+ merge_empty_cells: '<?php echo $this->merge_empty_cells; ?>',
143
+ start_pos: start_pos,
144
+ end_pos: end_pos,
145
+ };
146
+ data.eval_field = $.parseJSON(data.eval_field);
147
+ return $.ajax({
148
+ url: '<?php echo add_query_arg( array( 'import_page' => $this->import_page, 'step' => '3', 'merge' => ! empty( $_GET['merge'] ) ? '1' : '0' ), admin_url( 'admin-ajax.php' ) ); ?>',
149
+ data: data,
150
+ type: 'POST',
151
+ success: function( response ) {
152
+ console.log( response );
153
+ if ( response ) {
154
+
155
+ try {
156
+ // Get the valid JSON only from the returned string
157
+ if ( response.indexOf("<!--WC_START-->") >= 0 )
158
+ response = response.split("<!--WC_START-->")[1]; // Strip off before after WC_START
159
+
160
+ if ( response.indexOf("<!--WC_END-->") >= 0 )
161
+ response = response.split("<!--WC_END-->")[0]; // Strip off anything after WC_END
162
+
163
+ // Parse
164
+ var results = $.parseJSON( response );
165
+
166
+ if ( results.error ) {
167
+
168
+ $('#import-progress tbody').append( '<tr id="row-' + i + '" class="error"><td class="status" colspan="5">' + results.error + '</td></tr>' );
169
+
170
+ i++;
171
+
172
+ } else if ( results.import_results && $( results.import_results ).size() > 0 ) {
173
+
174
+ $.each( results.processed_terms, function( index, value ) {
175
+ processed_terms.push( value );
176
+ });
177
+
178
+ $.each( results.processed_posts, function( index, value ) {
179
+ processed_posts.push( value );
180
+ });
181
+
182
+ $.each( results.post_orphans, function( index, value ) {
183
+ post_orphans.push( value );
184
+ });
185
+
186
+ $.each( results.attachments, function( index, value ) {
187
+ attachments.push( value );
188
+ });
189
+
190
+ upsell_skus = jQuery.extend( {}, upsell_skus, results.upsell_skus );
191
+ crosssell_skus = jQuery.extend( {}, crosssell_skus, results.crosssell_skus );
192
+
193
+ $( results.import_results ).each(function( index, row ) {
194
+ $('#import-progress tbody').append( '<tr id="row-' + i + '" class="' + row['status'] + '"><td><mark class="result" title="' + row['status'] + '">' + row['status'] + '</mark></td><td class="row">' + i + '</td><td>' + row['sku'] + '</td><td>' + row['post_id'] + ' - ' + row['post_title'] + '</td><td class="reason">' + row['reason'] + '</td></tr>' );
195
+
196
+ i++;
197
+ });
198
+ }
199
+
200
+ } catch(err) {}
201
+
202
+ } else {
203
+ $('#import-progress tbody').append( '<tr class="error"><td class="status" colspan="5">' + '<?php _e( 'AJAX Error', 'wf_csv_import_export' ); ?>' + '</td></tr>' );
204
+ }
205
+
206
+ var w = $(window);
207
+ var row = $( "#row-" + ( i - 1 ) );
208
+
209
+ if ( row.length ) {
210
+ w.scrollTop( row.offset().top - (w.height()/2) );
211
+ }
212
+
213
+ done_count++;
214
+
215
+ $('body').trigger( 'woocommerce_csv_import_request_complete' );
216
+ }
217
+ });
218
+ }
219
+
220
+ var rows = [];
221
+
222
+ <?php
223
+ $limit = apply_filters( 'woocommerce_csv_import_limit_per_request', 10 );
224
+ $enc = mb_detect_encoding( $file, 'UTF-8, ISO-8859-1', true );
225
+ if ( $enc )
226
+ setlocale( LC_ALL, 'en_US.' . $enc );
227
+ @ini_set( 'auto_detect_line_endings', true );
228
+
229
+ $count = 0;
230
+ $previous_position = 0;
231
+ $position = 0;
232
+ $import_count = 0;
233
+
234
+ // Get CSV positions
235
+ if ( ( $handle = fopen( $file, "r" ) ) !== FALSE ) {
236
+
237
+ while ( ( $postmeta = fgetcsv( $handle, 0, $this->delimiter ) ) !== FALSE ) {
238
+ $count++;
239
+
240
+ if ( $count >= $limit ) {
241
+ $previous_position = $position;
242
+ $position = ftell( $handle );
243
+ $count = 0;
244
+ $import_count ++;
245
+
246
+ // Import rows between $previous_position $position
247
+ ?>rows.push( [ <?php echo $previous_position; ?>, <?php echo $position; ?> ] ); <?php
248
+ }
249
+ }
250
+
251
+ // Remainder
252
+ if ( $count > 0 ) {
253
+ ?>rows.push( [ <?php echo $position; ?>, '' ] ); <?php
254
+ $import_count ++;
255
+ }
256
+
257
+ fclose( $handle );
258
+ }
259
+ ?>
260
+
261
+ var data = rows.shift();
262
+ var regen_count = 0;
263
+ import_rows( data[0], data[1] );
264
+
265
+ $('body').on( 'woocommerce_csv_import_request_complete', function() {
266
+ if ( done_count == <?php echo $import_count; ?> ) {
267
+
268
+ if ( attachments.length ) {
269
+
270
+ $('#import-progress tbody').append( '<tr class="regenerating"><td colspan="5"><div class="progress"></div></td></tr>' );
271
+
272
+ index = 0;
273
+
274
+ $.each( attachments, function( i, value ) {
275
+ regenerate_thumbnail( value );
276
+ index ++;
277
+ if ( index == attachments.length ) {
278
+ import_done();
279
+ }
280
+ });
281
+
282
+ } else {
283
+ import_done();
284
+ }
285
+
286
+ } else {
287
+ // Call next request
288
+ data = rows.shift();
289
+ import_rows( data[0], data[1] );
290
+ }
291
+ } );
292
+
293
+ // Regenerate a specified image via AJAX
294
+ function regenerate_thumbnail( id ) {
295
+ $.ajax({
296
+ type: 'POST',
297
+ url: ajaxurl,
298
+ data: { action: "woocommerce_csv_import_regenerate_thumbnail", id: id },
299
+ success: function( response ) {
300
+ if ( response !== Object( response ) || ( typeof response.success === "undefined" && typeof response.error === "undefined" ) ) {
301
+ response = new Object;
302
+ response.success = false;
303
+ response.error = "<?php printf( esc_js( __( 'The resize request was abnormally terminated (ID %s). This is likely due to the image exceeding available memory or some other type of fatal error.', 'wf_csv_import_export' ) ), '" + id + "' ); ?>";
304
+ }
305
+
306
+ regen_count ++;
307
+
308
+ $('#import-progress tbody .regenerating .progress').css( 'width', ( ( regen_count / attachments.length ) * 100 ) + '%' ).html( regen_count + ' / ' + attachments.length + ' <?php echo esc_js( __( 'thumbnails regenerated', 'wf_csv_import_export' ) ); ?>' );
309
+
310
+ if ( ! response.success ) {
311
+ $('#import-progress tbody').append( '<tr><td colspan="5">' + response.error + '</td></tr>' );
312
+ }
313
+ },
314
+ error: function( response ) {
315
+ $('#import-progress tbody').append( '<tr><td colspan="5">' + response.error + '</td></tr>' );
316
+ }
317
+ });
318
+ }
319
+
320
+ function import_done() {
321
+ var data = {
322
+ action: 'woocommerce_csv_import_request',
323
+ file: '<?php echo $file; ?>',
324
+ processed_terms: processed_terms,
325
+ processed_posts: processed_posts,
326
+ post_orphans: post_orphans,
327
+ upsell_skus: upsell_skus,
328
+ crosssell_skus: crosssell_skus
329
+ };
330
+
331
+ $.ajax({
332
+ url: '<?php echo add_query_arg( array( 'import_page' => $this->import_page, 'step' => '4', 'merge' => ! empty( $_GET['merge'] ) ? 1 : 0 ), admin_url( 'admin-ajax.php' ) ); ?>',
333
+ data: data,
334
+ type: 'POST',
335
+ success: function( response ) {
336
+ console.log( response );
337
+ $('#import-progress tbody').append( '<tr class="complete"><td colspan="5">' + response + '</td></tr>' );
338
+ $('.importer-loading').hide();
339
+ }
340
+ });
341
+ }
342
+ });
343
+ </script>
344
+ <?php
345
+ } else {
346
+ echo '<p class="error">' . __( 'Error finding uploaded file!', 'wf_csv_import_export' ) . '</p>';
347
+ }
348
+ break;
349
+ case 3 :
350
+ // Check access - cannot use nonce here as it will expire after multiple requests
351
+ if ( ! current_user_can( 'manage_woocommerce' ) )
352
+ die();
353
+
354
+ add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) );
355
+
356
+ if ( function_exists( 'gc_enable' ) )
357
+ gc_enable();
358
+
359
+ @set_time_limit(0);
360
+ @ob_flush();
361
+ @flush();
362
+ $wpdb->hide_errors();
363
+
364
+ $file = stripslashes( $_POST['file'] );
365
+ $mapping = json_decode( stripslashes( $_POST['mapping'] ), true );
366
+ $eval_field = $_POST['eval_field'];
367
+ $start_pos = isset( $_POST['start_pos'] ) ? absint( $_POST['start_pos'] ) : 0;
368
+ $end_pos = isset( $_POST['end_pos'] ) ? absint( $_POST['end_pos'] ) : '';
369
+
370
+ update_option( 'wf_prod_csv_imp_exp_mapping', array($mapping,$eval_field ));
371
+
372
+ $position = $this->import_start( $file, $mapping, $start_pos, $end_pos, $eval_field );
373
+ $this->import();
374
+ $this->import_end();
375
+
376
+ $results = array();
377
+ $results['import_results'] = $this->import_results;
378
+ $results['processed_terms'] = $this->processed_terms;
379
+ $results['processed_posts'] = $this->processed_posts;
380
+ $results['post_orphans'] = $this->post_orphans;
381
+ $results['attachments'] = $this->attachments;
382
+ $results['upsell_skus'] = $this->upsell_skus;
383
+ $results['crosssell_skus'] = $this->crosssell_skus;
384
+
385
+ echo "<!--WC_START-->";
386
+ echo json_encode( $results );
387
+ echo "<!--WC_END-->";
388
+ exit;
389
+ break;
390
+ case 4 :
391
+ // Check access - cannot use nonce here as it will expire after multiple requests
392
+ if ( ! current_user_can( 'manage_woocommerce' ) )
393
+ die();
394
+
395
+ add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) );
396
+
397
+ if ( function_exists( 'gc_enable' ) )
398
+ gc_enable();
399
+
400
+ @set_time_limit(0);
401
+ @ob_flush();
402
+ @flush();
403
+ $wpdb->hide_errors();
404
+
405
+ $this->processed_terms = isset( $_POST['processed_terms'] ) ? $_POST['processed_terms'] : array();
406
+ $this->processed_posts = isset( $_POST['processed_posts']) ? $_POST['processed_posts'] : array();
407
+ $this->post_orphans = isset( $_POST['post_orphans']) ? $_POST['post_orphans'] : array();
408
+ $this->crosssell_skus = isset( $_POST['crosssell_skus']) ? array_filter( (array) $_POST['crosssell_skus'] ) : array();
409
+ $this->upsell_skus = isset( $_POST['upsell_skus']) ? array_filter( (array) $_POST['upsell_skus'] ) : array();
410
+
411
+ _e( 'Step 1...', 'wf_csv_import_export' ) . ' ';
412
+
413
+ wp_defer_term_counting( true );
414
+ wp_defer_comment_counting( true );
415
+
416
+ _e( 'Step 2...', 'wf_csv_import_export' ) . ' ';
417
+
418
+ echo 'Step 3...' . ' '; // Easter egg
419
+
420
+ // reset transients for products
421
+ if ( function_exists( 'wc_delete_product_transients' ) ) {
422
+ wc_delete_product_transients();
423
+ } else {
424
+ $woocommerce->clear_product_transients();
425
+ }
426
+
427
+ delete_transient( 'wc_attribute_taxonomies' );
428
+
429
+ $wpdb->query("DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_wc_product_type_%')");
430
+
431
+ _e( 'Finalizing...', 'wf_csv_import_export' ) . ' ';
432
+
433
+ $this->backfill_parents();
434
+
435
+ if ( ! empty( $this->upsell_skus ) ) {
436
+
437
+ _e( 'Linking upsells...', 'wf_csv_import_export' ) . ' ';
438
+
439
+ foreach ( $this->upsell_skus as $post_id => $skus ) {
440
+ $this->link_product_skus( 'upsell', $post_id, $skus );
441
+ }
442
+ }
443
+
444
+ if ( ! empty( $this->crosssell_skus ) ) {
445
+
446
+ _e( 'Linking crosssells...', 'wf_csv_import_export' ) . ' ';
447
+
448
+ foreach ( $this->crosssell_skus as $post_id => $skus ) {
449
+ $this->link_product_skus( 'crosssell', $post_id, $skus );
450
+ }
451
+ }
452
+ // SUCCESS
453
+ _e( 'Finished. Import complete.', 'wf_csv_import_export' );
454
+
455
+ $this->import_end();
456
+ exit;
457
+ break;
458
+ }
459
+
460
+ $this->footer();
461
+ }
462
+
463
+ /**
464
+ * format_data_from_csv
465
+ */
466
+ public function format_data_from_csv( $data, $enc ) {
467
+ return ( $enc == 'UTF-8' ) ? $data : utf8_encode( $data );
468
+ }
469
+
470
+ /**
471
+ * Display pre-import options
472
+ */
473
+ public function import_options() {
474
+ $j = 0;
475
+
476
+ if ( $this->id )
477
+ $file = get_attached_file( $this->id );
478
+ else if ( $this->file_url_import_enabled )
479
+ $file = ABSPATH . $this->file_url;
480
+ else
481
+ return;
482
+
483
+ // Set locale
484
+ $enc = mb_detect_encoding( $file, 'UTF-8, ISO-8859-1', true );
485
+ if ( $enc ) setlocale( LC_ALL, 'en_US.' . $enc );
486
+ @ini_set( 'auto_detect_line_endings', true );
487
+
488
+ // Get headers
489
+ if ( ( $handle = fopen( $file, "r" ) ) !== FALSE ) {
490
+
491
+ $row = $raw_headers = array();
492
+ $header = fgetcsv( $handle, 0, $this->delimiter );
493
+
494
+ while ( ( $postmeta = fgetcsv( $handle, 0, $this->delimiter ) ) !== FALSE ) {
495
+ foreach ( $header as $key => $heading ) {
496
+ if ( ! $heading ) continue;
497
+ $s_heading = strtolower( $heading );
498
+ $row[$s_heading] = ( isset( $postmeta[$key] ) ) ? $this->format_data_from_csv( $postmeta[$key], $enc ) : '';
499
+ $raw_headers[ $s_heading ] = $heading;
500
+ }
501
+ break;
502
+ }
503
+ fclose( $handle );
504
+ }
505
+
506
+ $mapping_from_db = get_option( 'wf_prod_csv_imp_exp_mapping');
507
+ $saved_mapping = null;
508
+ $saved_evaluation = null;
509
+ if($mapping_from_db && is_array($mapping_from_db) && count($mapping_from_db) == 2 && empty($_GET['clearmapping'])){
510
+ //if(count(array_intersect_key ( $mapping_from_db[0] , $row)) == count($mapping_from_db[0])){
511
+ $reset_action = 'admin.php?clearmapping=1&amp;import=' . $this->import_page . '&amp;step=1&amp;merge=' . ( ! empty( $_GET['merge'] ) ? 1 : 0 ) . '&amp;file_url=' . $this->file_url . '&amp;delimiter=' . $this->delimiter . '&amp;merge_empty_cells=' . $this->merge_empty_cells . '&amp;file_id=' . $this->id . '';
512
+ $reset_action = esc_attr(wp_nonce_url($reset_action, 'import-upload'));
513
+ echo '<h3>' . __( 'Map to fields are pre-selected based on your last import. <a href="'.$reset_action.'">Click here</a> to clear saved mapping.', 'wf_csv_import_export' ) . '</h3>';
514
+ $saved_mapping = $mapping_from_db[0];
515
+ $saved_evaluation = $mapping_from_db[1];
516
+ //}
517
+ }
518
+
519
+ $merge = (!empty($_GET['merge']) && $_GET['merge']) ? 1 : 0;
520
+
521
+ $attrs = self::get_all_product_attributes();
522
+ $attr_keys = array_values($attrs);
523
+
524
+ $attributes = array();
525
+ if(!empty($attr_keys) && !empty($attrs))
526
+ $attributes = array_combine($attr_keys , $attrs);
527
+
528
+ $product_ptaxonomies = get_object_taxonomies( 'product', 'name' );
529
+ $product_vtaxonomies = get_object_taxonomies( 'product_variation', 'name' );
530
+ $product_taxonomies = array_merge($product_ptaxonomies, $product_vtaxonomies);
531
+ $taxonomies = array_keys($product_taxonomies);
532
+ $new_keys = array_values($taxonomies);
533
+ $taxonomies = array_combine($new_keys , $taxonomies);
534
+ include( 'views/html-wf-import-options.php' );
535
+ }
536
+
537
+ /**
538
+ * The main controller for the actual import stage.
539
+ */
540
+ public function import() {
541
+ global $woocommerce, $wpdb;
542
+
543
+ wp_suspend_cache_invalidation( true );
544
+
545
+ $this->log->add( 'csv-import', '---' );
546
+ $this->log->add( 'csv-import', __( 'Processing products.', 'wf_csv_import_export' ) );
547
+ foreach ( $this->parsed_data as $key => &$item ) {
548
+
549
+ $product = $this->parser->parse_product( $item, $this->merge_empty_cells );
550
+ if ( ! is_wp_error( $product ) )
551
+ $this->process_product( $product );
552
+ else
553
+ $this->add_import_result( 'failed', $product->get_error_message(), 'Not parsed', json_encode( $item ), '-' );
554
+
555
+ unset( $item, $product );
556
+ $i++;
557
+ }
558
+ $this->log->add( 'csv-import', __( 'Finished processing products.', 'wf_csv_import_export' ) );
559
+ wp_suspend_cache_invalidation( false );
560
+ }
561
+
562
+ /**
563
+ * Parses the CSV file and prepares us for the task of processing parsed data
564
+ *
565
+ * @param string $file Path to the CSV file for importing
566
+ */
567
+ public function import_start( $file, $mapping, $start_pos, $end_pos, $eval_field ) {
568
+
569
+ $memory = size_format( woocommerce_let_to_num( ini_get( 'memory_limit' ) ) );
570
+ $wp_memory = size_format( woocommerce_let_to_num( WP_MEMORY_LIMIT ) );
571
+
572
+ $this->log->add( 'csv-import', '---[ New Import ] PHP Memory: ' . $memory . ', WP Memory: ' . $wp_memory );
573
+ $this->log->add( 'csv-import', __( 'Parsing products CSV.', 'wf_csv_import_export' ) );
574
+
575
+ $this->parser = new WF_CSV_Parser( 'product' );
576
+
577
+ list( $this->parsed_data, $this->raw_headers, $position ) = $this->parser->parse_data( $file, $this->delimiter, $mapping, $start_pos, $end_pos, $eval_field );
578
+
579
+ $this->log->add( 'csv-import', __( 'Finished parsing products CSV.', 'wf_csv_import_export' ) );
580
+
581
+ unset( $import_data );
582
+
583
+ wp_defer_term_counting( true );
584
+ wp_defer_comment_counting( true );
585
+
586
+ return $position;
587
+ }
588
+
589
+ /**
590
+ * Performs post-import cleanup of files and the cache
591
+ */
592
+ public function import_end() {
593
+
594
+ //wp_cache_flush(); Stops output in some hosting environments
595
+ foreach ( get_taxonomies() as $tax ) {
596
+ delete_option( "{$tax}_children" );
597
+ _get_term_hierarchy( $tax );
598
+ }
599
+
600
+ wp_defer_term_counting( false );
601
+ wp_defer_comment_counting( false );
602
+
603
+ do_action( 'import_end' );
604
+ }
605
+
606
+ /**
607
+ * Handles the CSV upload and initial parsing of the file to prepare for
608
+ * displaying author import options
609
+ *
610
+ * @return bool False if error uploading or invalid file, true otherwise
611
+ */
612
+ public function handle_upload() {
613
+ if($this->handle_ftp()){
614
+ return true;
615
+ }
616
+ if ( empty( $_POST['file_url'] ) ) {
617
+
618
+ $file = wp_import_handle_upload();
619
+
620
+ if ( isset( $file['error'] ) ) {
621
+ echo '<p><strong>' . __( 'Sorry, there has been an error.', 'wf_csv_import_export' ) . '</strong><br />';
622
+ echo esc_html( $file['error'] ) . '</p>';
623
+ return false;
624
+ }
625
+
626
+ $this->id = (int) $file['id'];
627
+ return true;
628
+
629
+ } else {
630
+
631
+ if ( file_exists( ABSPATH . $_POST['file_url'] ) ) {
632
+
633
+ $this->file_url = esc_attr( $_POST['file_url'] );
634
+ return true;
635
+
636
+ } else {
637
+
638
+ echo '<p><strong>' . __( 'Sorry, there has been an error.', 'wf_csv_import_export' ) . '</strong></p>';
639
+ return false;
640
+
641
+ }
642
+
643
+ }
644
+
645
+ return false;
646
+ }
647
+
648
+ public function product_exists( $title, $sku = '', $post_name = '' ) {
649
+ global $wpdb;
650
+
651
+ // Post Title Check
652
+ $post_title = stripslashes( sanitize_post_field( 'post_title', $title, 0, 'db' ) );
653
+
654
+ $query = "SELECT ID FROM $wpdb->posts WHERE post_type = 'product' AND post_status IN ( 'publish', 'private', 'draft', 'pending', 'future' )";
655
+ $args = array();
656
+
657
+ /*
658
+ * removed title check
659
+ if ( ! empty ( $title ) ) {
660
+ $query .= ' AND post_title = %s';
661
+ $args[] = $post_title;
662
+ }
663
+ */
664
+
665
+ if ( ! empty ( $post_name ) ) {
666
+ $query .= ' AND post_name = %s';
667
+ $args[] = $post_name;
668
+ }
669
+
670
+ if ( ! empty ( $args ) ) {
671
+ $posts_that_exist = $wpdb->get_col( $wpdb->prepare( $query, $args ) );
672
+
673
+ if ( $posts_that_exist ) {
674
+
675
+ foreach( $posts_that_exist as $post_exists ) {
676
+
677
+ // Check unique SKU
678
+ $post_exists_sku = get_post_meta( $post_exists, '_sku', true );
679
+
680
+ if ( $sku == $post_exists_sku ) {
681
+ return true;
682
+ }
683
+
684
+ }
685
+
686
+ }
687
+ }
688
+
689
+ // Sku Check
690
+ if ( $sku ) {
691
+
692
+ $post_exists_sku = $wpdb->get_var( $wpdb->prepare( "
693
+ SELECT $wpdb->posts.ID
694
+ FROM $wpdb->posts
695
+ LEFT JOIN $wpdb->postmeta ON ( $wpdb->posts.ID = $wpdb->postmeta.post_id )
696
+ WHERE $wpdb->posts.post_status IN ( 'publish', 'private', 'draft', 'pending', 'future' )
697
+ AND $wpdb->postmeta.meta_key = '_sku' AND $wpdb->postmeta.meta_value = '%s'
698
+ ", $sku ) );
699
+
700
+ if ( $post_exists_sku ) {
701
+ return true;
702
+ }
703
+ }
704
+
705
+ return false;
706
+ }
707
+
708
+ /**
709
+ * Create new posts based on import information
710
+ */
711
+ public function process_product( $post ) {
712
+
713
+ $processing_product_id = absint( $post['post_id'] );
714
+ $processing_product = get_post( $processing_product_id );
715
+ $processing_product_title = $processing_product ? $processing_product->post_title : '';
716
+ $processing_product_sku = $processing_product ? $processing_product->sku : '';
717
+ $merging = ! empty( $post['merging'] );
718
+
719
+ if ( ! empty( $post['post_title'] ) ) {
720
+ $processing_product_title = $post['post_title'];
721
+ }
722
+
723
+ if ( ! empty( $post['sku'] ) ) {
724
+ $processing_product_sku = $post['sku'];
725
+ }
726
+
727
+ if ( ! empty( $processing_product_id ) && isset( $this->processed_posts[ $processing_product_id ] ) ) {
728
+ $this->add_import_result( 'skipped', __( 'Product already processed', 'wf_csv_import_export' ), $processing_product_id, $processing_product_title, $processing_product_sku );
729
+ $this->log->add( 'csv-import', __('> Post ID already processed. Skipping.', 'wf_csv_import_export'), true );
730
+ unset( $post );
731
+ return;
732
+ }
733
+
734
+ if ( ! empty ( $post['post_status'] ) && $post['post_status'] == 'auto-draft' ) {
735
+ $this->add_import_result( 'skipped', __( 'Skipping auto-draft', 'wf_csv_import_export' ), $processing_product_id, $processing_product_title, $processing_product_sku );
736
+ $this->log->add( 'csv-import', __('> Skipping auto-draft.', 'wf_csv_import_export'), true );
737
+ unset( $post );
738
+ return;
739
+ }
740
+ // Check if post exists when importing
741
+ if ( ! $merging ) {
742
+ if ( $this->product_exists( $processing_product_title, $processing_product_sku, $post['post_name'] ) ) {
743
+ if(!$processing_product_id && empty($processing_product_sku)) {
744
+ // if no sku , no id and no merge + is product in db with same title -> just give message
745
+ $usr_msg = 'Product with same title already exist.';
746
+ }else{
747
+ $usr_msg = 'Product already exists.';
748
+ }
749
+ $this->add_import_result( 'skipped', __( $usr_msg, 'wf_csv_import_export' ), $processing_product_id, $processing_product_title, $processing_product_sku );
750
+ $this->log->add( 'csv-import', sprintf( __('> &#8220;%s&#8221;'.$usr_msg, 'wf_csv_import_export'), esc_html($processing_product_title) ), true );
751
+ unset( $post );
752
+ return;
753
+ }
754
+
755
+ if ( $processing_product_id && is_string( get_post_status( $processing_product_id ) ) ) {
756
+ $this->add_import_result( 'skipped', __( 'Importing post ID conflicts with an existing post ID', 'wf_csv_import_export' ), $processing_product_id, get_the_title( $processing_product_id ), '' );
757
+ $this->log->add( 'csv-import', sprintf( __('> &#8220;%s&#8221; ID already exists.', 'wf_csv_import_export'), esc_html( $processing_product_id ) ), true );
758
+ unset( $post );
759
+ return;
760
+ }
761
+ }
762
+ // Check post type to avoid conflicts with IDs
763
+ $is_post_exist_in_db = get_post_type( $processing_product_id );
764
+ if ( $merging && $processing_product_id && !empty($is_post_exist_in_db) && (get_post_type( $processing_product_id ) !== $post['post_type'] )) {
765
+ $this->add_import_result( 'skipped', __( 'Post is not a product', 'wf_csv_import_export' ), $processing_product_id, $processing_product_title, $processing_product_sku );
766
+ $this->log->add( 'csv-import', sprintf( __('> &#8220;%s&#8221; is not a product.', 'wf_csv_import_export'), esc_html($processing_product_id) ), true );
767
+ unset( $post );
768
+ return;
769
+ }
770
+
771
+ if ( $merging && !empty($is_post_exist_in_db) ) {
772
+
773
+ // Only merge fields which are set
774
+ $post_id = $processing_product_id;
775
+
776
+ $this->log->add( 'csv-import', sprintf( __('> Merging post ID %s.', 'wf_csv_import_export'), $post_id ), true );
777
+
778
+ $postdata = array(
779
+ 'ID' => $post_id
780
+ );
781
+
782
+ if ( $this->merge_empty_cells ) {
783
+ if ( isset( $post['post_content'] ) ) {
784
+ $postdata['post_content'] = $post['post_content'];
785
+ }
786
+ if ( isset( $post['post_excerpt'] ) ) {
787
+ $postdata['post_excerpt'] = $post['post_excerpt'];
788
+ }
789
+ if ( isset( $post['post_password'] ) ) {
790
+ $postdata['post_password'] = $post['post_password'];
791
+ }
792
+ if ( isset( $post['post_parent'] ) ) {
793
+ $postdata['post_parent'] = $post['post_parent'];
794
+ }
795
+ } else {
796
+ if ( ! empty( $post['post_content'] ) ) {
797
+ $postdata['post_content'] = $post['post_content'];
798
+ }
799
+ if ( ! empty( $post['post_excerpt'] ) ) {
800
+ $postdata['post_excerpt'] = $post['post_excerpt'];
801
+ }
802
+ if ( ! empty( $post['post_password'] ) ) {
803
+ $postdata['post_password'] = $post['post_password'];
804
+ }
805
+ if ( isset( $post['post_parent'] ) && $post['post_parent'] !== '' ) {
806
+ $postdata['post_parent'] = $post['post_parent'];
807
+ }
808
+ }
809
+
810
+ if ( ! empty( $post['post_title'] ) ) {
811
+ $postdata['post_title'] = $post['post_title'];
812
+ }
813
+
814
+ if ( ! empty( $post['post_author'] ) ) {
815
+ $postdata['post_author'] = absint( $post['post_author'] );
816
+ }
817
+ if ( ! empty( $post['post_date'] ) ) {
818
+ $postdata['post_date'] = date("Y-m-d H:i:s", strtotime( $post['post_date'] ) );
819
+ }
820
+ if ( ! empty( $post['post_date_gmt'] ) ) {
821
+ $postdata['post_date_gmt'] = date("Y-m-d H:i:s", strtotime( $post['post_date_gmt'] ) );
822
+ }
823
+ if ( ! empty( $post['post_name'] ) ) {
824
+ $postdata['post_name'] = $post['post_name'];
825
+ }
826
+ if ( ! empty( $post['post_status'] ) ) {
827
+ $postdata['post_status'] = $post['post_status'];
828
+ }
829
+ if ( ! empty( $post['menu_order'] ) ) {
830
+ $postdata['menu_order'] = $post['menu_order'];
831
+ }
832
+ if ( ! empty( $post['comment_status'] ) ) {
833
+ $postdata['comment_status'] = $post['comment_status'];
834
+ }
835
+ if ( sizeof( $postdata ) > 1 ) {
836
+ $result = wp_update_post( $postdata );
837
+
838
+ if ( ! $result ) {
839
+ $this->add_import_result( 'failed', __( 'Failed to update product', 'wf_csv_import_export' ), $post_id, $processing_product_title, $processing_product_sku );
840
+ $this->log->add( 'csv-import', sprintf( __('> Failed to update product %s', 'wf_csv_import_export'), $post_id ), true );
841
+ unset( $post );
842
+ return;
843
+ } else {
844
+ $this->log->add( 'csv-import', __( '> Merged post data: ', 'wf_csv_import_export' ) . print_r( $postdata, true ) );
845
+ }
846
+ }
847
+
848
+ } else {
849
+ $merging = FALSE;
850
+ // Get parent
851
+ $post_parent = $post['post_parent'];
852
+
853
+ if ( $post_parent !== "" ) {
854
+ $post_parent = absint( $post_parent );
855
+
856
+ if ( $post_parent > 0 ) {
857
+ // if we already know the parent, map it to the new local ID
858
+ if ( isset( $this->processed_posts[ $post_parent ] ) ) {
859
+ $post_parent = $this->processed_posts[ $post_parent ];
860
+
861
+ // otherwise record the parent for later
862
+ } else {
863
+
864
+ $this->post_orphans[ intval( $processing_product_id ) ] = $post_parent;
865
+ //$post_parent = 0;
866
+
867
+ }
868
+
869
+ }
870
+ }
871
+
872
+ // Insert product
873
+ $this->log->add( 'csv-import', sprintf( __('> Inserting %s', 'wf_csv_import_export'), esc_html( $processing_product_title ) ), true );
874
+
875
+ $postdata = array(
876
+ 'import_id' => $processing_product_id,
877
+ 'post_author' => $post['post_author'] ? absint( $post['post_author'] ) : get_current_user_id(),
878
+ 'post_date' => ( $post['post_date'] ) ? date( 'Y-m-d H:i:s', strtotime( $post['post_date'] )) : '',
879
+ 'post_date_gmt' => ( $post['post_date_gmt'] ) ? date( 'Y-m-d H:i:s', strtotime( $post['post_date_gmt'] )) : '',
880
+ 'post_content' => $post['post_content'],
881
+ 'post_excerpt' => $post['post_excerpt'],
882
+ 'post_title' => $processing_product_title,
883
+ 'post_name' => ( $post['post_name'] ) ? $post['post_name'] : sanitize_title( $processing_product_title ),
884
+ 'post_status' => ( $post['post_status'] ) ? $post['post_status'] : 'publish',
885
+ 'post_parent' => $post_parent,
886
+ 'menu_order' => $post['menu_order'],
887
+ 'post_type' => $post['post_type'],
888
+ 'post_password' => $post['post_password'],
889
+ 'comment_status' => $post['comment_status'],
890
+ );
891
+ $post_id = wp_insert_post( $postdata, true );
892
+
893
+ if ( is_wp_error( $post_id ) ) {
894
+
895
+ $this->add_import_result( 'failed', __( 'Failed to import product', 'wf_csv_import_export' ), $processing_product_id, $processing_product_title, $processing_product_sku );
896
+ $this->log->add( 'csv-import', sprintf( __( 'Failed to import product &#8220;%s&#8221;', 'wf_csv_import_export' ), esc_html($processing_product_title) ) );
897
+ unset( $post );
898
+ return;
899
+
900
+ } else {
901
+
902
+ $this->log->add( 'csv-import', sprintf( __('> Inserted - post ID is %s.', 'wf_csv_import_export'), $post_id ) );
903
+
904
+ }
905
+ }
906
+
907
+ unset( $postdata );
908
+
909
+ // map pre-import ID to local ID
910
+ if ( empty( $processing_product_id ) ) {
911
+ $processing_product_id = (int) $post_id;
912
+ }
913
+
914
+ $this->processed_posts[ intval( $processing_product_id ) ] = (int) $post_id;
915
+
916
+ // add categories, tags and other terms
917
+ if ( ! empty( $post['terms'] ) && is_array( $post['terms'] ) ) {
918
+
919
+ $terms_to_set = array();
920
+
921
+ foreach ( $post['terms'] as $term_group ) {
922
+
923
+ $taxonomy = $term_group['taxonomy'];
924
+ $terms = $term_group['terms'];
925
+
926
+ if ( ! $taxonomy || ! taxonomy_exists( $taxonomy ) ) {
927
+ continue;
928
+ }
929
+
930
+ if ( ! is_array( $terms ) ) {
931
+ $terms = array( $terms );
932
+ }
933
+
934
+ $terms_to_set[ $taxonomy ] = array();
935
+
936
+ foreach ( $terms as $term_id ) {
937
+
938
+ if ( ! $term_id ) continue;
939
+
940
+ $terms_to_set[ $taxonomy ][] = intval( $term_id );
941
+ }
942
+
943
+ }
944
+
945
+ foreach ( $terms_to_set as $tax => $ids ) {
946
+ $tt_ids = wp_set_post_terms( $post_id, $ids, $tax, false );
947
+ }
948
+
949
+ unset( $post['terms'], $terms_to_set );
950
+ }
951
+
952
+ // add/update post meta
953
+ if ( ! empty( $post['postmeta'] ) && is_array( $post['postmeta'] ) ) {
954
+ foreach ( $post['postmeta'] as $meta ) {
955
+ $key = apply_filters( 'import_post_meta_key', $meta['key'] );
956
+
957
+ if ( $key ) {
958
+ update_post_meta( $post_id, $key, maybe_unserialize( $meta['value'] ) );
959
+ }
960
+
961
+ if ( $key == '_file_paths' ) {
962
+ do_action( 'woocommerce_process_product_file_download_paths', $post_id, 0, maybe_unserialize( $meta['value'] ) );
963
+ }
964
+
965
+ }
966
+
967
+ unset( $post['postmeta'] );
968
+ }
969
+
970
+ // Import images and add to post
971
+ if ( ! empty( $post['images'] ) && is_array($post['images']) ) {
972
+
973
+ $featured = true;
974
+ $gallery_ids = array();
975
+
976
+ if ($merging) {
977
+
978
+ // Get basenames
979
+ $image_basenames = array();
980
+
981
+ foreach( $post['images'] as $image )
982
+ $image_basenames[] = basename( $image );
983
+
984
+ // Loop attachments already attached to the product
985
+ $attachments = get_posts( 'post_parent=' . $post_id . '&post_type=attachment&fields=ids&post_mime_type=image&numberposts=-1' );
986
+
987
+ foreach ( $attachments as $attachment_key => $attachment ) {
988
+
989
+ $attachment_url = wp_get_attachment_url( $attachment );
990
+ $attachment_basename = basename( $attachment_url );
991
+
992
+ // Don't import existing images
993
+ if ( in_array( $attachment_url, $post['images'] ) || in_array( $attachment_basename, $image_basenames ) ) {
994
+
995
+ foreach( $post['images'] as $key => $image ) {
996
+
997
+ if ( $image == $attachment_url || basename( $image ) == $attachment_basename ) {
998
+ unset( $post['images'][ $key ] );
999
+
1000
+ $this->log->add( 'csv-import', sprintf( __( '> > Image exists - skipping %s', 'wf_csv_import_export' ), basename( $image ) ) );
1001
+
1002
+ if ( $key == 0 ) {
1003
+ update_post_meta( $post_id, '_thumbnail_id', $attachment );
1004
+ $featured = false;
1005
+ } else {
1006
+ $gallery_ids[ $key ] = $attachment;
1007
+ }
1008
+ }
1009
+
1010
+ }
1011
+
1012
+ } else {
1013
+
1014
+ // Detach image which is not being merged
1015
+ $attachment_post = array();
1016
+ $attachment_post['ID'] = $attachment;
1017
+ $attachment_post['post_parent'] = '';
1018
+ wp_update_post( $attachment_post );
1019
+ unset( $attachment_post );
1020
+
1021
+ }
1022
+
1023
+ }
1024
+
1025
+ unset( $attachments );
1026
+ }
1027
+
1028
+ if ( $post['images'] ) foreach ( $post['images'] as $image_key => $image ) {
1029
+
1030
+ $this->log->add( 'csv-import', sprintf( __( '> > Importing image "%s"', 'wf_csv_import_export' ), $image ) );
1031
+
1032
+ $filename = basename( $image );
1033
+
1034
+ $attachment = array(
1035
+ 'post_title' => preg_replace( '/\.[^.]+$/', '', $processing_product_title . ' ' . ( $image_key + 1 ) ),
1036
+ 'post_content' => '',
1037
+ 'post_status' => 'inherit',
1038
+ 'post_parent' => $post_id
1039
+ );
1040
+
1041
+ $attachment_id = $this->process_attachment( $attachment, $image, $post_id );
1042
+
1043
+ if ( ! is_wp_error( $attachment_id ) && $attachment_id ) {
1044
+
1045
+ $this->log->add( 'csv-import', sprintf( __( '> > Imported image "%s"', 'wf_csv_import_export' ), $image ) );
1046
+
1047
+ // Set alt
1048
+ update_post_meta( $attachment_id, '_wp_attachment_image_alt', $processing_product_title );
1049
+
1050
+ if ( $featured ) {
1051
+ update_post_meta( $post_id, '_thumbnail_id', $attachment_id );
1052
+ } else {
1053
+ $gallery_ids[ $image_key ] = $attachment_id;
1054
+ }
1055
+
1056
+ update_post_meta( $attachment_id, '_woocommerce_exclude_image', 0 );
1057
+
1058
+ $featured = false;
1059
+ } else {
1060
+ $this->log->add( 'csv-import', sprintf( __( '> > Error importing image "%s"', 'wf_csv_import_export' ), $image ) );
1061
+ $this->log->add( 'csv-import', '> > ' . $attachment_id->get_error_message() );
1062
+ }
1063
+
1064
+ unset( $attachment, $attachment_id );
1065
+ }
1066
+
1067
+ $this->log->add( 'csv-import', __( '> > Images set', 'wf_csv_import_export' ) );
1068
+
1069
+ ksort( $gallery_ids );
1070
+
1071
+ update_post_meta( $post_id, '_product_image_gallery', implode( ',', $gallery_ids ) );
1072
+
1073
+ unset( $post['images'], $featured, $gallery_ids );
1074
+ }
1075
+
1076
+ // Import attributes
1077
+ if ( ! empty( $post['attributes'] ) && is_array($post['attributes']) ) {
1078
+
1079
+ if ($merging) {
1080
+ $attributes = array_filter( (array) maybe_unserialize( get_post_meta( $post_id, '_product_attributes', true ) ) );
1081
+ $attributes = array_merge( $attributes, $post['attributes'] );
1082
+ } else {
1083
+ $attributes = $post['attributes'];
1084
+ }
1085
+
1086
+ // Sort attribute positions
1087
+ if ( ! function_exists( 'attributes_cmp' ) ) {
1088
+ function attributes_cmp( $a, $b ) {
1089
+ if ( $a['position'] == $b['position'] ) return 0;
1090
+ return ( $a['position'] < $b['position'] ) ? -1 : 1;
1091
+ }
1092
+ }
1093
+ uasort( $attributes, 'attributes_cmp' );
1094
+
1095
+ update_post_meta( $post_id, '_product_attributes', $attributes );
1096
+
1097
+ unset( $post['attributes'], $attributes );
1098
+ }
1099
+
1100
+ // Import GPF
1101
+ if ( ! empty( $post['gpf_data'] ) && is_array( $post['gpf_data'] ) ) {
1102
+
1103
+ update_post_meta( $post_id, '_woocommerce_gpf_data', $post['gpf_data'] );
1104
+
1105
+ unset( $post['gpf_data'] );
1106
+ }
1107
+
1108
+ if ( ! empty( $post['upsell_skus'] ) && is_array( $post['upsell_skus'] ) ) {
1109
+ $this->upsell_skus[ $post_id ] = $post['upsell_skus'];
1110
+ }
1111
+
1112
+ if ( ! empty( $post['crosssell_skus'] ) && is_array( $post['crosssell_skus'] ) ) {
1113
+ $this->crosssell_skus[ $post_id ] = $post['crosssell_skus'];
1114
+ }
1115
+
1116
+ add_post_meta( $post_id, 'total_sales', 0 );
1117
+
1118
+ if ( $merging ) {
1119
+ $this->add_import_result( 'merged', 'Merge successful', $post_id, $processing_product_title, $processing_product_sku );
1120
+ $this->log->add( 'csv-import', sprintf( __('> Finished merging post ID %s.', 'wf_csv_import_export'), $post_id ) );
1121
+ } else {
1122
+ $this->add_import_result( 'imported', 'Import successful', $post_id, $processing_product_title, $processing_product_sku );
1123
+ $this->log->add( 'csv-import', sprintf( __('> Finished importing post ID %s.', 'wf_csv_import_export'), $post_id ) );
1124
+ }
1125
+
1126
+ unset( $post );
1127
+ }
1128
+
1129
+ /**
1130
+ * Log a row's import status
1131
+ */
1132
+ protected function add_import_result( $status, $reason, $post_id = '', $post_title = '', $sku = '' ) {
1133
+ $this->import_results[] = array(
1134
+ 'post_title' => $post_title,
1135
+ 'post_id' => $post_id,
1136
+ 'sku' => $sku,
1137
+ 'status' => $status,
1138
+ 'reason' => $reason
1139
+ );
1140
+ }
1141
+
1142
+ /**
1143
+ * If fetching attachments is enabled then attempt to create a new attachment
1144
+ *
1145
+ * @param array $post Attachment post details from WXR
1146
+ * @param string $url URL to fetch attachment from
1147
+ * @return int|WP_Error Post ID on success, WP_Error otherwise
1148
+ */
1149
+ public function process_attachment( $post, $url, $post_id ) {
1150
+
1151
+ $attachment_id = '';
1152
+ $attachment_url = '';
1153
+ $attachment_file = '';
1154
+ $upload_dir = wp_upload_dir();
1155
+
1156
+ // If same server, make it a path and move to upload directory
1157
+ /*if ( strstr( $url, $upload_dir['baseurl'] ) ) {
1158
+
1159
+ $url = str_replace( $upload_dir['baseurl'], $upload_dir['basedir'], $url );
1160
+
1161
+ } else*/
1162
+ if ( strstr( $url, site_url() ) ) {
1163
+ $abs_url = str_replace( trailingslashit( site_url() ), trailingslashit( ABSPATH ), urldecode($url) );
1164
+ $new_name = wp_unique_filename( $upload_dir['path'], basename( urldecode($url) ) );
1165
+ $new_url = trailingslashit( $upload_dir['path'] ) . $new_name;
1166
+
1167
+ if ( copy( $abs_url, $new_url ) ) {
1168
+ $url = basename( $new_url );
1169
+ }
1170
+ }
1171
+
1172
+ if ( ! strstr( $url, 'http' ) ) {
1173
+
1174
+ // Local file
1175
+ $attachment_file = trailingslashit( $upload_dir['basedir'] ) . 'product_images/' . $url;
1176
+
1177
+ // We have the path, check it exists
1178
+ if ( ! file_exists( $attachment_file ) )
1179
+ $attachment_file = trailingslashit( $upload_dir['path'] ) . $url;
1180
+
1181
+ // We have the path, check it exists
1182
+ if ( file_exists( $attachment_file ) ) {
1183
+
1184
+ $attachment_url = str_replace( trailingslashit( ABSPATH ), trailingslashit( site_url() ), $attachment_file );
1185
+
1186
+ if ( $info = wp_check_filetype( $attachment_file ) )
1187
+ $post['post_mime_type'] = $info['type'];
1188
+ else
1189
+ return new WP_Error( 'attachment_processing_error', __('Invalid file type', 'wordpress-importer') );
1190
+
1191
+ $post['guid'] = $attachment_url;
1192
+
1193
+ $attachment_id = wp_insert_attachment( $post, $attachment_file, $post_id );
1194
+
1195
+ } else {
1196
+ return new WP_Error( 'attachment_processing_error', __('Local image did not exist!', 'wordpress-importer') );
1197
+ }
1198
+
1199
+ } else {
1200
+
1201
+ // if the URL is absolute, but does not contain address, then upload it assuming base_site_url
1202
+ if ( preg_match( '|^/[\w\W]+$|', $url ) )
1203
+ $url = rtrim( site_url(), '/' ) . $url;
1204
+
1205
+ $upload = $this->fetch_remote_file( $url, $post );
1206
+
1207
+ if ( is_wp_error( $upload ) )
1208
+ return $upload;
1209
+
1210
+ if ( $info = wp_check_filetype( $upload['file'] ) )
1211
+ $post['post_mime_type'] = $info['type'];
1212
+ else
1213
+ return new WP_Error( 'attachment_processing_error', __('Invalid file type', 'wordpress-importer') );
1214
+
1215
+ $post['guid'] = $upload['url'];
1216
+ $attachment_file = $upload['file'];
1217
+ $attachment_url = $upload['url'];
1218
+
1219
+ // as per wp-admin/includes/upload.php
1220
+ $attachment_id = wp_insert_attachment( $post, $upload['file'], $post_id );
1221
+
1222
+ unset( $upload );
1223
+ }
1224
+
1225
+ if ( ! is_wp_error( $attachment_id ) && $attachment_id > 0 ) {
1226
+ $this->log->add( 'csv-import', sprintf( __( '> > Inserted image attachment "%s"', 'wf_csv_import_export' ), $url ) );
1227
+
1228
+ $this->attachments[] = $attachment_id;
1229
+ }
1230
+
1231
+ return $attachment_id;
1232
+ }
1233
+
1234
+ /**
1235
+ * Attempt to download a remote file attachment
1236
+ */
1237
+ public function fetch_remote_file( $url, $post ) {
1238
+
1239
+ // extract the file name and extension from the url
1240
+ $file_name = basename( current( explode( '?', $url ) ) );
1241
+ $wp_filetype = wp_check_filetype( $file_name, null );
1242
+ $parsed_url = @parse_url( $url );
1243
+
1244
+ // Check parsed URL
1245
+ if ( ! $parsed_url || ! is_array( $parsed_url ) )
1246
+ return new WP_Error( 'import_file_error', 'Invalid URL' );
1247
+
1248
+ // Ensure url is valid
1249
+ $url = str_replace( " ", '%20', $url );
1250
+
1251
+ // Get the file
1252
+ $response = wp_remote_get( $url, array(
1253
+ 'timeout' => 10
1254
+ ) );
1255
+
1256
+ if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) !== 200 )
1257
+ return new WP_Error( 'import_file_error', 'Error getting remote image' );
1258
+
1259
+ // Ensure we have a file name and type
1260
+ if ( ! $wp_filetype['type'] ) {
1261
+
1262
+ $headers = wp_remote_retrieve_headers( $response );
1263
+
1264
+ if ( isset( $headers['content-disposition'] ) && strstr( $headers['content-disposition'], 'filename=' ) ) {
1265
+
1266
+ $disposition = end( explode( 'filename=', $headers['content-disposition'] ) );
1267
+ $disposition = sanitize_file_name( $disposition );
1268
+ $file_name = $disposition;
1269
+
1270
+ } elseif ( isset( $headers['content-type'] ) && strstr( $headers['content-type'], 'image/' ) ) {
1271
+
1272
+ $file_name = 'image.' . str_replace( 'image/', '', $headers['content-type'] );
1273
+
1274
+ }
1275
+
1276
+ unset( $headers );
1277
+ }
1278
+
1279
+ // Upload the file
1280
+ $upload = wp_upload_bits( $file_name, '', wp_remote_retrieve_body( $response ) );
1281
+
1282
+ if ( $upload['error'] )
1283
+ return new WP_Error( 'upload_dir_error', $upload['error'] );
1284
+
1285
+ // Get filesize
1286
+ $filesize = filesize( $upload['file'] );
1287
+
1288
+ if ( 0 == $filesize ) {
1289
+ @unlink( $upload['file'] );
1290
+ unset( $upload );
1291
+ return new WP_Error( 'import_file_error', __('Zero size file downloaded', 'wf_csv_import_export') );
1292
+ }
1293
+
1294
+ unset( $response );
1295
+
1296
+ return $upload;
1297
+ }
1298
+
1299
+ /**
1300
+ * Decide what the maximum file size for downloaded attachments is.
1301
+ * Default is 0 (unlimited), can be filtered via import_attachment_size_limit
1302
+ *
1303
+ * @return int Maximum attachment file size to import
1304
+ */
1305
+ public function max_attachment_size() {
1306
+ return apply_filters( 'import_attachment_size_limit', 0 );
1307
+ }
1308
+
1309
+ /**
1310
+ * Attempt to associate posts and menu items with previously missing parents
1311
+ */
1312
+ public function backfill_parents() {
1313
+ global $wpdb;
1314
+
1315
+ // find parents for post orphans
1316
+ if ( ! empty( $this->post_orphans ) && is_array( $this->post_orphans ) )
1317
+ foreach ( $this->post_orphans as $child_id => $parent_id ) {
1318
+ $local_child_id = $local_parent_id = false;
1319
+ if ( isset( $this->processed_posts[$child_id] ) )
1320
+ $local_child_id = $this->processed_posts[$child_id];
1321
+ if ( isset( $this->processed_posts[$parent_id] ) )
1322
+ $local_parent_id = $this->processed_posts[$parent_id];
1323
+
1324
+ if ( $local_child_id && $local_parent_id )
1325
+ $wpdb->update( $wpdb->posts, array( 'post_parent' => $local_parent_id ), array( 'ID' => $local_child_id ), '%d', '%d' );
1326
+ }
1327
+ }
1328
+
1329
+ /**
1330
+ * Attempt to associate posts and menu items with previously missing parents
1331
+ */
1332
+ public function link_product_skus( $type, $product_id, $skus ) {
1333
+ global $wpdb;
1334
+
1335
+ $ids = array();
1336
+
1337
+ foreach ( $skus as $sku ) {
1338
+ $ids[] = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_sku' AND meta_value = %s;", $sku ) );
1339
+ }
1340
+
1341
+ $ids = array_filter( $ids );
1342
+
1343
+ update_post_meta( $product_id, "_{$type}_ids", $ids );
1344
+ }
1345
+
1346
+ private function handle_ftp(){
1347
+ $enable_ftp_ie = !empty( $_POST['enable_ftp_ie'] ) ? true : false;
1348
+ if($enable_ftp_ie == false) return false;
1349
+
1350
+ $ftp_server = ! empty( $_POST['ftp_server'] ) ? $_POST['ftp_server'] : '';
1351
+ $ftp_server_path = ! empty( $_POST['ftp_server_path'] ) ? $_POST['ftp_server_path'] : '';
1352
+ $ftp_user = ! empty( $_POST['ftp_user'] ) ? $_POST['ftp_user'] : '';
1353
+ $ftp_password = ! empty( $_POST['ftp_password'] ) ? $_POST['ftp_password'] : '';
1354
+ $use_ftps = ! empty( $_POST['use_ftps'] ) ? true : false;
1355
+
1356
+
1357
+ $settings = array();
1358
+ $settings[ 'ftp_server' ] = $ftp_server;
1359
+ $settings[ 'ftp_user' ] = $ftp_user;
1360
+ $settings[ 'ftp_password' ] = $ftp_password;
1361
+ $settings[ 'use_ftps' ] = $use_ftps;
1362
+ $settings[ 'enable_ftp_ie' ] = $enable_ftp_ie;
1363
+ $settings[ 'ftp_server_path' ] = $ftp_server_path;
1364
+
1365
+
1366
+ $local_file = 'wp-content/plugins/product-csv-import-export-for-woocommerce/temp-import.csv';
1367
+ $server_file = $ftp_server_path;
1368
+
1369
+ update_option( 'wf_shipment_tracking_importer_ftp', $settings );
1370
+
1371
+ $ftp_conn = $use_ftps ? ftp_ssl_connect($ftp_server) : ftp_connect($ftp_server);
1372
+ $error_message = "";
1373
+ $success = false;
1374
+ if($ftp_conn == false){
1375
+ $error_message = "There is connection problem\n";
1376
+ }
1377
+
1378
+ if(empty($error_message)){
1379
+ if(ftp_login($ftp_conn, $ftp_user, $ftp_password) == false){
1380
+ $error_message = "Not able to login \n";
1381
+ }
1382
+ }
1383
+ if(empty($error_message)){
1384
+
1385
+ if (ftp_get($ftp_conn, ABSPATH.$local_file, $server_file, FTP_BINARY)) {
1386
+ $error_message = "";
1387
+ $success = true;
1388
+ } else {
1389
+ $error_message = "There was a problem\n";
1390
+ }
1391
+ }
1392
+
1393
+ ftp_close($ftp_conn);
1394
+ if($success){
1395
+ $this->file_url = $local_file;
1396
+ }else{
1397
+ die($error_message);
1398
+ }
1399
+ return true;
1400
+ }
1401
+
1402
+ // Display import page title
1403
+ public function header() {
1404
+ echo '<div class="wrap"><div class="icon32" id="icon-woocommerce-importer"><br></div>';
1405
+ echo '<h2>' . ( empty( $_GET['merge'] ) ? __( 'Import', 'wf_csv_import_export' ) : __( 'Merge Products', 'wf_csv_import_export' ) ) . '</h2>';
1406
+ }
1407
+
1408
+ // Close div.wrap
1409
+ public function footer() {
1410
+ echo '</div>';
1411
+ }
1412
+
1413
+ /**
1414
+ * Display introductory text and file upload form
1415
+ */
1416
+ public function greet() {
1417
+ $action = 'admin.php?import=woocommerce_csv&amp;step=1&amp;merge=' . ( ! empty( $_GET['merge'] ) ? 1 : 0 );
1418
+ $bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() );
1419
+ $size = size_format( $bytes );
1420
+ $upload_dir = wp_upload_dir();
1421
+
1422
+ include( 'views/html-wf-import-greeting.php' );
1423
+ }
1424
+
1425
+ /**
1426
+ * Added to http_request_timeout filter to force timeout at 60 seconds during import
1427
+ * @return int 60
1428
+ */
1429
+ public function bump_request_timeout( $val ) {
1430
+ return 60;
1431
+ }
1432
+ /**
1433
+ * Get a list of all the product attributes for a post type.
1434
+ * These require a bit more digging into the values.
1435
+ */
1436
+ public static function get_all_product_attributes( $post_type = 'product' ) {
1437
+ global $wpdb;
1438
+
1439
+ $results = $wpdb->get_col( $wpdb->prepare(
1440
+ "SELECT DISTINCT pm.meta_value
1441
+ FROM {$wpdb->postmeta} AS pm
1442
+ LEFT JOIN {$wpdb->posts} AS p ON p.ID = pm.post_id
1443
+ WHERE p.post_type = %s
1444
+ AND p.post_status IN ( 'publish', 'pending', 'private', 'draft' )
1445
+ AND pm.meta_key = '_product_attributes'",
1446
+ $post_type
1447
+ ) );
1448
+
1449
+ // Go through each result, and look at the attribute keys within them.
1450
+ $result = array();
1451
+
1452
+ if ( ! empty( $results ) ) {
1453
+ foreach( $results as $_product_attributes ) {
1454
+ $attributes = maybe_unserialize( maybe_unserialize( $_product_attributes ) );
1455
+ if ( ! empty( $attributes ) && is_array( $attributes ) ) {
1456
+ foreach( $attributes as $key => $attribute ) {
1457
+ if ( ! $key ) {
1458
+ continue;
1459
+ }
1460
+ if ( ! strstr( $key, 'pa_' ) ) {
1461
+ if ( empty( $attribute['name'] ) ) {
1462
+ continue;
1463
+ }
1464
+ $key = $attribute['name'];
1465
+ }
1466
+
1467
+ $result[ $key ] = $key;
1468
+ }
1469
+ }
1470
+ }
1471
+ }
1472
+
1473
+ sort( $result );
1474
+
1475
+ return $result;
1476
+ }
1477
  }
includes/importer/data/data-wf-post-defaults.php CHANGED
@@ -1,22 +1,22 @@
1
- <?php
2
- if ( ! defined( 'ABSPATH' ) ) {
3
- exit;
4
- }
5
-
6
- // New post defaults
7
- return array(
8
- 'post_type' => $this->post_type,
9
- 'menu_order' => '',
10
- 'postmeta' => array(),
11
- 'post_status' => 'publish',
12
- 'post_title' => '',
13
- 'post_name' => '',
14
- 'post_date' => '',
15
- 'post_date_gmt' => '',
16
- 'post_content' => '',
17
- 'post_excerpt' => '',
18
- 'post_parent' => '',
19
- 'post_password' => '',
20
- 'post_author' => '',
21
- 'comment_status'=> 'open'
22
  );
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ // New post defaults
7
+ return array(
8
+ 'post_type' => $this->post_type,
9
+ 'menu_order' => '',
10
+ 'postmeta' => array(),
11
+ 'post_status' => 'publish',
12
+ 'post_title' => '',
13
+ 'post_name' => '',
14
+ 'post_date' => '',
15
+ 'post_date_gmt' => '',
16
+ 'post_content' => '',
17
+ 'post_excerpt' => '',
18
+ 'post_parent' => '',
19
+ 'post_password' => '',
20
+ 'post_author' => '',
21
+ 'comment_status'=> 'open'
22
  );
includes/importer/data/data-wf-postmeta-allowed.php CHANGED
@@ -1,16 +1,16 @@
1
- <?php
2
- if ( ! defined( 'ABSPATH' ) ) {
3
- exit;
4
- }
5
-
6
- // New postmeta allowed
7
- return array(
8
- 'downloadable' => array( 'yes', 'no' ),
9
- 'virtual' => array( 'yes', 'no' ),
10
- 'visibility' => array( 'visible', 'catalog', 'search', 'hidden' ),
11
- 'stock_status' => array( 'instock', 'outofstock' ),
12
- 'backorders' => array( 'yes', 'no', 'notify' ),
13
- 'manage_stock' => array( 'yes', 'no' ),
14
- 'tax_status' => array( 'taxable', 'shipping', 'none' ),
15
- 'featured' => array( 'yes', 'no' ),
16
  );
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ // New postmeta allowed
7
+ return array(
8
+ 'downloadable' => array( 'yes', 'no' ),
9
+ 'virtual' => array( 'yes', 'no' ),
10
+ 'visibility' => array( 'visible', 'catalog', 'search', 'hidden' ),
11
+ 'stock_status' => array( 'instock', 'outofstock' ),
12
+ 'backorders' => array( 'yes', 'no', 'notify' ),
13
+ 'manage_stock' => array( 'yes', 'no' ),
14
+ 'tax_status' => array( 'taxable', 'shipping', 'none' ),
15
+ 'featured' => array( 'yes', 'no' ),
16
  );
includes/importer/data/data-wf-postmeta-defaults.php CHANGED
@@ -1,44 +1,44 @@
1
- <?php
2
- if ( ! defined( 'ABSPATH' ) ) {
3
- exit;
4
- }
5
-
6
- // New postmeta defaults
7
- return apply_filters( 'woocommerce_csv_product_postmeta_defaults', array(
8
- 'sku' => '',
9
- 'downloadable' => 'no',
10
- 'virtual' => 'no',
11
- 'price' => '',
12
- 'visibility' => 'visible',
13
- 'stock' => 0,
14
- 'stock_status' => 'instock',
15
- 'backorders' => 'no',
16
- 'manage_stock' => 'no',
17
- 'sale_price' => '',
18
- 'regular_price' => '',
19
- 'weight' => '',
20
- 'length' => '',
21
- 'width' => '',
22
- 'height' => '',
23
- 'tax_status' => 'taxable',
24
- 'tax_class' => '',
25
- 'upsell_ids' => array(),
26
- 'crosssell_ids' => array(),
27
- 'upsell_skus' => array(),
28
- 'crosssell_skus' => array(),
29
- 'sale_price_dates_from' => '',
30
- 'sale_price_dates_to' => '',
31
- 'min_variation_price' => '',
32
- 'max_variation_price' => '',
33
- 'min_variation_regular_price' => '',
34
- 'max_variation_regular_price' => '',
35
- 'min_variation_sale_price' => '',
36
- 'max_variation_sale_price' => '',
37
- 'featured' => 'no',
38
- 'file_path' => '',
39
- 'file_paths' => '',
40
- 'download_limit' => '',
41
- 'download_expiry' => '',
42
- 'product_url' => '',
43
- 'button_text' => '',
44
  ) );
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ // New postmeta defaults
7
+ return apply_filters( 'woocommerce_csv_product_postmeta_defaults', array(
8
+ 'sku' => '',
9
+ 'downloadable' => 'no',
10
+ 'virtual' => 'no',
11
+ 'price' => '',
12
+ 'visibility' => 'visible',
13
+ 'stock' => 0,
14
+ 'stock_status' => 'instock',
15
+ 'backorders' => 'no',
16
+ 'manage_stock' => 'no',
17
+ 'sale_price' => '',
18
+ 'regular_price' => '',
19
+ 'weight' => '',
20
+ 'length' => '',
21
+ 'width' => '',
22
+ 'height' => '',
23
+ 'tax_status' => 'taxable',
24
+ 'tax_class' => '',
25
+ 'upsell_ids' => array(),
26
+ 'crosssell_ids' => array(),
27
+ 'upsell_skus' => array(),
28
+ 'crosssell_skus' => array(),
29
+ 'sale_price_dates_from' => '',
30
+ 'sale_price_dates_to' => '',
31
+ 'min_variation_price' => '',
32
+ 'max_variation_price' => '',
33
+ 'min_variation_regular_price' => '',
34
+ 'max_variation_regular_price' => '',
35
+ 'min_variation_sale_price' => '',
36
+ 'max_variation_sale_price' => '',
37
+ 'featured' => 'no',
38
+ 'file_path' => '',
39
+ 'file_paths' => '',
40
+ 'download_limit' => '',
41
+ 'download_expiry' => '',
42
+ 'product_url' => '',
43
+ 'button_text' => '',
44
  ) );
includes/importer/data/data-wf-reserved-fields-pair.php CHANGED
@@ -1,51 +1,51 @@
1
- <?php
2
-
3
- // Reserved column names
4
- return array(
5
- 'id' => 'Product ID | Product ID',
6
- 'post_title' => 'Product Title | Product Title. ie Name of the product ',
7
- 'post_name' => 'Product Name | Unique part of the product link',
8
- 'post_status' => 'Product Status | Product Status ( published , draft ...)',
9
- 'post_content' => 'Product Description | Description about the Product',
10
- 'post_excerpt' => 'Product Short Description | Short description about the Product',
11
- 'post_date' => 'Post Date | Product posted date',
12
- //'post_date_gmt' => 'Post Date GMT | Tooltip data Status',
13
- 'sku' => 'Product SKU | Product SKU - This will unique and Product identifier',
14
- 'post_password' => 'Post Password | To Protect a post with password',
15
- 'post_author' => 'Prodcut Author | Prodcut Author ( 1 - Admin )',
16
- 'menu_order' => 'Menu Order | If menu enabled , menu order',
17
- 'comment_status' => 'Comment Status | Comment Status ( Open or Closed comments for this prodcut)',
18
- 'downloadable' => 'Type: Downloadable | Is Product is downloadable eg:- Book',
19
- 'virtual' => 'Type: Virtual | Is Product is virtual',
20
- 'visibility' => 'Visibility: Visibility | Visibility status ( hidden or visible)',
21
- 'featured' => 'Visibility: Featured | Featured Product',
22
- 'stock' => 'Inventory: Stock | Stock Quantity',
23
- 'stock_status' => 'Inventory: Stock Status | InStock or OutofStock',
24
- 'backorders' => 'Inventory: Backorders | Backorders',
25
- 'manage_stock' => 'Inventory: Manage Stock | 1 to enable 0 to disable',
26
- 'sale_price' => 'Price: Sale Price | Sale Price ',
27
- 'regular_price' => 'Price: Regular Price | Regular Price',
28
- 'sale_price_dates_from' => 'Sale Price Dates: From | Sale Price Dates effect from',
29
- 'sale_price_dates_to' => 'Sale Price Dates: To | Sale Price Dates effect to',
30
- 'weight' => 'Dimensions: Weight | Wight of product in LB , OZ , KG as of your woocommerce Unit',
31
- 'length' => 'Dimensions: length | Length',
32
- 'width' => 'Dimensions: width | Width',
33
- 'height' => 'Dimensions: height | Height',
34
- 'tax_status' => 'Tax: Tax Status | Taxable product or not',
35
- 'tax_class' => 'Tax: Tax Class | Tax class ( eg:- reduced rate)',
36
- 'upsell_ids' => 'Related Products: Upsell IDs | Upsell Product ids',
37
- 'crosssell_ids' => 'Related Products: Crosssell IDs | Crosssell Product ids',
38
- 'file_paths' => 'Downloads: File Paths (WC 2.0.x) | File Paths',
39
- 'downloadable_files' => 'Downloads: Downloadable Files (WC 2.1.x) | Downloadable Files',
40
- 'download_limit' => 'Downloads: Download Limit | Download Limit',
41
- 'download_expiry' => 'Downloads: Download Expiry | Download Expiry ',
42
- 'product_url' => 'External: Product URL | Product URL if the Product is external',
43
- 'button_text' => 'External: Button Text | Buy button text for Product , if the Product is external',
44
- 'images' => 'Images/Gallery | Image URLs seperated with &#124;',
45
- 'tax:product_type' => 'Product Type | ( eg:- simple , variable)',
46
- 'tax:product_cat' => 'Product Categories | Product related categories',
47
- 'tax:product_tag' => 'Product Tags | Product related tags',
48
- 'tax:product_shipping_class' => 'Product Shipping Class | Allow you to group similar products for shipping',
49
-
50
-
51
- );
1
+ <?php
2
+
3
+ // Reserved column names
4
+ return array(
5
+ 'id' => 'Product ID | Product ID',
6
+ 'post_title' => 'Product Title | Product Title. ie Name of the product ',
7
+ 'post_name' => 'Product Name | Unique part of the product link',
8
+ 'post_status' => 'Product Status | Product Status ( published , draft ...)',
9
+ 'post_content' => 'Product Description | Description about the Product',
10
+ 'post_excerpt' => 'Product Short Description | Short description about the Product',
11
+ 'post_date' => 'Post Date | Product posted date',
12
+ //'post_date_gmt' => 'Post Date GMT | Tooltip data Status',
13
+ 'sku' => 'Product SKU | Product SKU - This will unique and Product identifier',
14
+ 'post_password' => 'Post Password | To Protect a post with password',
15
+ 'post_author' => 'Prodcut Author | Prodcut Author ( 1 - Admin )',
16
+ 'menu_order' => 'Menu Order | If menu enabled , menu order',
17
+ 'comment_status' => 'Comment Status | Comment Status ( Open or Closed comments for this prodcut)',
18
+ 'downloadable' => 'Type: Downloadable | Is Product is downloadable eg:- Book',
19
+ 'virtual' => 'Type: Virtual | Is Product is virtual',
20
+ 'visibility' => 'Visibility: Visibility | Visibility status ( hidden or visible)',
21
+ 'featured' => 'Visibility: Featured | Featured Product',
22
+ 'stock' => 'Inventory: Stock | Stock Quantity',
23
+ 'stock_status' => 'Inventory: Stock Status | InStock or OutofStock',
24
+ 'backorders' => 'Inventory: Backorders | Backorders',
25
+ 'manage_stock' => 'Inventory: Manage Stock | 1 to enable 0 to disable',
26
+ 'sale_price' => 'Price: Sale Price | Sale Price ',
27
+ 'regular_price' => 'Price: Regular Price | Regular Price',
28
+ 'sale_price_dates_from' => 'Sale Price Dates: From | Sale Price Dates effect from',
29
+ 'sale_price_dates_to' => 'Sale Price Dates: To | Sale Price Dates effect to',
30
+ 'weight' => 'Dimensions: Weight | Wight of product in LB , OZ , KG as of your woocommerce Unit',
31
+ 'length' => 'Dimensions: length | Length',
32
+ 'width' => 'Dimensions: width | Width',
33
+ 'height' => 'Dimensions: height | Height',
34
+ 'tax_status' => 'Tax: Tax Status | Taxable product or not',
35
+ 'tax_class' => 'Tax: Tax Class | Tax class ( eg:- reduced rate)',
36
+ 'upsell_ids' => 'Related Products: Upsell IDs | Upsell Product ids',
37
+ 'crosssell_ids' => 'Related Products: Crosssell IDs | Crosssell Product ids',
38
+ 'file_paths' => 'Downloads: File Paths (WC 2.0.x) | File Paths',
39
+ 'downloadable_files' => 'Downloads: Downloadable Files (WC 2.1.x) | Downloadable Files',
40
+ 'download_limit' => 'Downloads: Download Limit | Download Limit',
41
+ 'download_expiry' => 'Downloads: Download Expiry | Download Expiry ',
42
+ 'product_url' => 'External: Product URL | Product URL if the Product is external',
43
+ 'button_text' => 'External: Button Text | Buy button text for Product , if the Product is external',
44
+ 'images' => 'Images/Gallery | Image URLs seperated with &#124;',
45
+ 'tax:product_type' => 'Product Type | ( eg:- simple , variable)',
46
+ 'tax:product_cat' => 'Product Categories | Product related categories',
47
+ 'tax:product_tag' => 'Product Tags | Product related tags',
48
+ 'tax:product_shipping_class' => 'Product Shipping Class | Allow you to group similar products for shipping',
49
+
50
+
51
+ );
includes/importer/data/data-wf-reserved-fields.php CHANGED
@@ -1,60 +1,60 @@
1
- <?php
2
-
3
- // Reserved column names
4
- return array(
5
- 'id',
6
- 'product_type',
7
- 'post_id',
8
- 'post_title',
9
- 'post_name',
10
- 'post_status',
11
- 'post_date',
12
- 'post_date_gmt',
13
- 'post_content',
14
- 'post_excerpt',
15
- 'post_parent',
16
- 'post_password',
17
- 'sku',
18
- 'post_type',
19
- 'post_author',
20
- 'menu_order',
21
- 'postmeta',
22
- 'comment_status',
23
- 'downloadable',
24
- 'virtual',
25
- 'visibility',
26
- 'stock',
27
- 'stock_status',
28
- 'backorders',
29
- 'manage_stock',
30
- 'price',
31
- 'sale_price',
32
- 'regular_price',
33
- 'weight',
34
- 'length',
35
- 'width',
36
- 'height',
37
- 'tax_status',
38
- 'tax_class',
39
- 'upsell_ids',
40
- 'crosssell_ids',
41
- 'upsell_skus',
42
- 'crosssell_skus',
43
- 'sale_price_dates_from',
44
- 'sale_price_dates_to',
45
- 'min_variation_price',
46
- 'max_variation_price',
47
- 'min_variation_regular_price',
48
- 'max_variation_regular_price',
49
- 'min_variation_sale_price',
50
- 'max_variation_sale_price',
51
- 'featured',
52
- 'file_path',
53
- 'file_paths',
54
- 'downloadable_files',
55
- 'download_limit',
56
- 'download_expiry',
57
- 'product_url',
58
- 'button_text',
59
- 'default_attributes'
60
  );
1
+ <?php
2
+
3
+ // Reserved column names
4
+ return array(
5
+ 'id',
6
+ 'product_type',
7
+ 'post_id',
8
+ 'post_title',
9
+ 'post_name',
10
+ 'post_status',
11
+ 'post_date',
12
+ 'post_date_gmt',
13
+ 'post_content',
14
+ 'post_excerpt',
15
+ 'post_parent',
16
+ 'post_password',
17
+ 'sku',
18
+ 'post_type',
19
+ 'post_author',
20
+ 'menu_order',
21
+ 'postmeta',
22
+ 'comment_status',
23
+ 'downloadable',
24
+ 'virtual',
25
+ 'visibility',
26
+ 'stock',
27
+ 'stock_status',
28
+ 'backorders',
29
+ 'manage_stock',
30
+ 'price',
31
+ 'sale_price',
32
+ 'regular_price',
33
+ 'weight',
34
+ 'length',
35
+ 'width',
36
+ 'height',
37
+ 'tax_status',
38
+ 'tax_class',
39
+ 'upsell_ids',
40
+ 'crosssell_ids',
41
+ 'upsell_skus',
42
+ 'crosssell_skus',
43
+ 'sale_price_dates_from',
44
+ 'sale_price_dates_to',
45
+ 'min_variation_price',
46
+ 'max_variation_price',
47
+ 'min_variation_regular_price',
48
+ 'max_variation_regular_price',
49
+ 'min_variation_sale_price',
50
+ 'max_variation_sale_price',
51
+ 'featured',
52
+ 'file_path',
53
+ 'file_paths',
54
+ 'downloadable_files',
55
+ 'download_limit',
56
+ 'download_expiry',
57
+ 'product_url',
58
+ 'button_text',
59
+ 'default_attributes'
60
  );
includes/importer/views/html-wf-import-greeting.php CHANGED
@@ -1,55 +1,55 @@
1
- <?php
2
-
3
- $ftp_server = '';
4
- $ftp_user = '';
5
- $ftp_password = '';
6
- $use_ftps = '';
7
- $enable_ftp_ie = '';
8
- $ftp_server_path = '';
9
- if(!empty($ftp_settings)){
10
- $ftp_server = $ftp_settings[ 'ftp_server' ];
11
- $ftp_user = $ftp_settings[ 'ftp_user' ];
12
- $ftp_password = $ftp_settings[ 'ftp_password' ];
13
- $use_ftps = $ftp_settings[ 'use_ftps' ];
14
- $enable_ftp_ie = $ftp_settings[ 'enable_ftp_ie' ];
15
- $ftp_server_path = $ftp_settings[ 'ftp_server_path' ];
16
- }
17
-
18
- ?>
19
- <div>
20
- <p><?php _e( 'You can import products (in CSV format) in to the shop using any of below methods.', 'wf_csv_import_export' ); ?></p>
21
-
22
- <?php if ( ! empty( $upload_dir['error'] ) ) : ?>
23
- <div class="error"><p><?php _e('Before you can upload your import file, you will need to fix the following error:'); ?></p>
24
- <p><strong><?php echo $upload_dir['error']; ?></strong></p></div>
25
- <?php else : ?>
26
- <form enctype="multipart/form-data" id="import-upload-form" method="post" action="<?php echo esc_attr(wp_nonce_url($action, 'import-upload')); ?>">
27
- <table class="form-table">
28
- <tbody>
29
- <tr>
30
- <th>
31
- <label for="upload"><?php _e( 'Method 1: Select a file from your computer' ); ?></label>
32
- </th>
33
- <td>
34
- <input type="file" id="upload" name="import" size="25" />
35
- <input type="hidden" name="action" value="save" />
36
- <input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" />
37
- <small><?php printf( __('Maximum size: %s' ), $size ); ?></small>
38
- </td>
39
- </tr>
40
- <tr>
41
- <th><label><?php _e( 'Delimiter', 'wf_csv_import_export' ); ?></label><br/></th>
42
- <td><input type="text" name="delimiter" placeholder="," size="2" /></td>
43
- </tr>
44
- <tr>
45
- <th><label><?php _e( 'Merge empty cells', 'wf_csv_import_export' ); ?></label><br/></th>
46
- <td><input type="checkbox" name="merge_empty_cells" placeholder="," size="2" /> <span class="description"><?php _e( 'Check this box to merge empty cells - otherwise (when merging) the empty cells will be ignored when importing things such as attributes.', 'wf_csv_import_export' ); ?></span></td>
47
- </tr>
48
- </tbody>
49
- </table>
50
- <p class="submit">
51
- <input type="submit" class="button button-primary" value="<?php esc_attr_e( 'Upload file and import' ); ?>" />
52
- </p>
53
- </form>
54
- <?php endif; ?>
55
  </div>
1
+ <?php
2
+
3
+ $ftp_server = '';
4
+ $ftp_user = '';
5
+ $ftp_password = '';
6
+ $use_ftps = '';
7
+ $enable_ftp_ie = '';
8
+ $ftp_server_path = '';
9
+ if(!empty($ftp_settings)){
10
+ $ftp_server = $ftp_settings[ 'ftp_server' ];
11
+ $ftp_user = $ftp_settings[ 'ftp_user' ];
12
+ $ftp_password = $ftp_settings[ 'ftp_password' ];
13
+ $use_ftps = $ftp_settings[ 'use_ftps' ];
14
+ $enable_ftp_ie = $ftp_settings[ 'enable_ftp_ie' ];
15
+ $ftp_server_path = $ftp_settings[ 'ftp_server_path' ];
16
+ }
17
+
18
+ ?>
19
+ <div>
20
+ <p><?php _e( 'You can import products (in CSV format) in to the shop using any of below methods.', 'wf_csv_import_export' ); ?></p>
21
+
22
+ <?php if ( ! empty( $upload_dir['error'] ) ) : ?>
23
+ <div class="error"><p><?php _e('Before you can upload your import file, you will need to fix the following error:'); ?></p>
24
+ <p><strong><?php echo $upload_dir['error']; ?></strong></p></div>
25
+ <?php else : ?>
26
+ <form enctype="multipart/form-data" id="import-upload-form" method="post" action="<?php echo esc_attr(wp_nonce_url($action, 'import-upload')); ?>">
27
+ <table class="form-table">
28
+ <tbody>
29
+ <tr>
30
+ <th>
31
+ <label for="upload"><?php _e( 'Method 1: Select a file from your computer' ); ?></label>
32
+ </th>
33
+ <td>
34
+ <input type="file" id="upload" name="import" size="25" />
35
+ <input type="hidden" name="action" value="save" />
36
+ <input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" />
37
+ <small><?php printf( __('Maximum size: %s' ), $size ); ?></small>
38
+ </td>
39
+ </tr>
40
+ <tr>
41
+ <th><label><?php _e( 'Delimiter', 'wf_csv_import_export' ); ?></label><br/></th>
42
+ <td><input type="text" name="delimiter" placeholder="," size="2" /></td>
43
+ </tr>
44
+ <tr>
45
+ <th><label><?php _e( 'Merge empty cells', 'wf_csv_import_export' ); ?></label><br/></th>
46
+ <td><input type="checkbox" name="merge_empty_cells" placeholder="," size="2" /> <span class="description"><?php _e( 'Check this box to merge empty cells - otherwise (when merging) the empty cells will be ignored when importing things such as attributes.', 'wf_csv_import_export' ); ?></span></td>
47
+ </tr>
48
+ </tbody>
49
+ </table>
50
+ <p class="submit">
51
+ <input type="submit" class="button button-primary" value="<?php esc_attr_e( 'Upload file and import' ); ?>" />
52
+ </p>
53
+ </form>
54
+ <?php endif; ?>
55
  </div>
includes/importer/views/html-wf-import-options.php CHANGED
@@ -1,115 +1,115 @@
1
- <form action="<?php echo admin_url('admin.php?import=' . $this->import_page . '&step=2&merge=' . $merge); ?>" method="post">
2
- <?php wp_nonce_field('import-woocommerce'); ?>
3
- <input type="hidden" name="import_id" value="<?php echo $this->id; ?>" />
4
- <?php if ($this->file_url_import_enabled) : ?>
5
- <input type="hidden" name="import_url" value="<?php echo $this->file_url; ?>" />
6
- <?php endif; ?>
7
- <h3><?php _e('Map Fields', 'wf_csv_import_export'); ?></h3>
8
- <p><?php _e('Here you can map your imported columns to product data fields.', 'wf_csv_import_export'); ?></p>
9
- <table class="widefat widefat_importer">
10
- <thead>
11
- <tr>
12
- <th><?php _e('Map to', 'wf_csv_import_export'); ?></th>
13
- <th><?php _e('Column Header', 'wf_csv_import_export'); ?></th>
14
- <th><?php _e('Evaluation Field', 'wf_csv_import_export'); ?>
15
- <?php $plugin_url = WC()->plugin_url(); ?>
16
- <img class="help_tip" style="float:none;" data-tip="<?php _e('Assign constant value HikeFoce to post_author:</br>=HikeFoce</br>Add $5 to Price:sale_price:</br>+5</br>Reduce $5 to Price:sale_price:</br>-5</br>Multiple 1.05 to Price:sale_price:</br>*1.05</br>Divide Price:sale_price by 2:</br>/2</br>Append a value By HikeFoce to post_title:</br>&By HikeFoce</br>Prepend a value HikeFoce to post_title:</br>&HikeFoce [VAL].', 'wf_csv_import_export'); ?>" src="<?php echo $plugin_url; ?>/assets/images/help.png" height="20" width="20" />
17
- </th>
18
- </tr>
19
- </thead>
20
- <tbody>
21
- <?php
22
- $wpost_attributes = include( dirname(__FILE__) . '/../data/data-wf-reserved-fields-pair.php' );
23
-
24
- $taxonomy_n_attributes_items = array();
25
- foreach ($taxonomies as $taxonomy) {
26
- if (substr($taxonomy, 0, 3) !== 'pa_')
27
- $taxonomy_n_attributes_items['tax:' . $taxonomy] = 'tax:' . $taxonomy. '| Product Taxonomies';
28
- }
29
- foreach ($taxonomies as $taxonomy) {
30
- if (substr($taxonomy, 0, 3) == 'pa_')
31
- $taxonomy_n_attributes_items['attribute:' . $taxonomy] = 'attribute:' . $taxonomy. '| Taxonomy Attributes';
32
- }
33
- foreach ($attributes as $attr) {
34
- $attr = sanitize_title($attr);
35
- if (substr($attr, 0, 3) !== 'pa_')
36
- $taxonomy_n_attributes_items['attribute:' . $attr] = 'attribute:' . $attr. '| Product Attributes';
37
- $taxonomy_n_attributes_items['attribute_data:' . $attr] = 'attribute_data:' .$attr. '| Product Attributes Data';
38
- $taxonomy_n_attributes_items['attribute_default:' . $attr] = 'attribute_default:' .$attr. '| Product Attributes default';
39
- }
40
-
41
- foreach ($raw_headers as $key => $column) {
42
- if(!empty($taxonomy_n_attributes_items[$key]))
43
- continue;
44
- if (strstr($key, 'tax:')) {
45
- $column = trim(str_replace('tax:', '', $key));
46
- $taxonomy_n_attributes_items['tax:' . $column] = 'tax:' . $column . '| New Taxonomy:' . $column;
47
- } elseif (strstr($key, 'meta:')) {
48
- $column = trim(str_replace('meta:', '', $key));
49
- $taxonomy_n_attributes_items['meta:' . $column] = 'meta:' . $column . '| Custom Field:' . $column;
50
- } elseif (strstr($key, 'attribute:')) {
51
- $column = trim(str_replace('attribute:', '', $key));
52
- $taxonomy_n_attributes_items['attribute:' . $column] = 'attribute:' . $column . '| New Product Attribute:' . $column;
53
- } elseif (strstr($key, 'attribute_data:')) {
54
- $column = trim(str_replace('attribute_data:', '', $key));
55
- $taxonomy_n_attributes_items['attribute_data:' . $column] = 'attribute_data:' . $column . '| New Product Attribute Data:' . $column;
56
- } elseif (strstr($key, 'attribute_default:')) {
57
- $column = trim(str_replace('attribute_default:', '', $key));
58
- $taxonomy_n_attributes_items['attribute_default:' . $column] = 'attribute_default:' . $column . '| New Product Attribute default value:' . $column;
59
- }
60
- }
61
-
62
- foreach ($taxonomy_n_attributes_items as $key => $value) {
63
- if(!empty($wpost_attributes[$key]))
64
- continue;
65
- $wpost_attributes[$key] = $value;
66
- }
67
-
68
- foreach ($wpost_attributes as $key => $value) :
69
- $sel_key = ($saved_mapping && isset($saved_mapping[$key])) ? $saved_mapping[$key] : $key;
70
- $evaluation_value = ($saved_evaluation && isset($saved_evaluation[$key])) ? $saved_evaluation[$key] : '';
71
- $evaluation_value = stripslashes($evaluation_value);
72
- $values = explode('|',$value);
73
- $value = $values[0];
74
- $tool_tip = $values[1];
75
- ?>
76
- <tr>
77
- <td width="25%">
78
- <img class="help_tip" style="float:none;" data-tip="<?php echo $tool_tip; ?>" src="<?php echo $plugin_url; ?>/assets/images/help.png" height="20" width="20" />
79
- <select name="map_to[<?php echo $key; ?>]" disabled="true"
80
- style=" -webkit-appearance: none;
81
- -moz-appearance: none;
82
- text-indent: 1px;
83
- text-overflow: '';
84
- background-color: #f1f1f1;
85
- border: none;
86
- box-shadow: 0 1px 2px rgba(0, 0, 0, 0.07) inset;
87
- color: #32373c;
88
- outline: 0 none;
89
- transition: border-color 50ms ease-in-out 0s;">
90
- <option value="<?php echo $key; ?>" <?php if ($key == $key) echo 'selected="selected"'; ?>><?php echo $value; ?></option>
91
- </select>
92
- </td>
93
- <td width="25%">
94
- <select name="map_from[<?php echo $key; ?>]">
95
- <option value=""><?php _e('Do not import', 'wf_csv_import_export'); ?></option>
96
- <?php
97
- foreach ($row as $hkey => $hdr):
98
- $hdr = strlen($hdr) > 50 ? substr(strip_tags($hdr), 0, 50) . "..." : $hdr;
99
- ?>
100
- <option value="<?php echo $raw_headers[$hkey]; ?>" <?php selected(strtolower($sel_key), $hkey); ?>><?php echo $raw_headers[$hkey] . " &nbsp; : &nbsp; " . $hdr; ?></option>
101
- <?php endforeach; ?>
102
- </select>
103
- <?php do_action('woocommerce_csv_product_data_mapping', $key); ?>
104
- </td>
105
- <td width="10%"><input type="text" name="eval_field[<?php echo $key; ?>]" value="<?php echo $evaluation_value; ?>" /></td>
106
- </tr>
107
- <?php endforeach; ?>
108
- </tbody>
109
- </table>
110
- <p class="submit">
111
- <input type="submit" class="button button-primary" value="<?php esc_attr_e('Submit', 'wf_csv_import_export'); ?>" />
112
- <input type="hidden" name="delimiter" value="<?php echo $this->delimiter ?>" />
113
- <input type="hidden" name="merge_empty_cells" value="<?php echo $this->merge_empty_cells ?>" />
114
- </p>
115
  </form>
1
+ <form action="<?php echo admin_url('admin.php?import=' . $this->import_page . '&step=2&merge=' . $merge); ?>" method="post">
2
+ <?php wp_nonce_field('import-woocommerce'); ?>
3
+ <input type="hidden" name="import_id" value="<?php echo $this->id; ?>" />
4
+ <?php if ($this->file_url_import_enabled) : ?>
5
+ <input type="hidden" name="import_url" value="<?php echo $this->file_url; ?>" />
6
+ <?php endif; ?>
7
+ <h3><?php _e('Map Fields', 'wf_csv_import_export'); ?></h3>
8
+ <p><?php _e('Here you can map your imported columns to product data fields.', 'wf_csv_import_export'); ?></p>
9
+ <table class="widefat widefat_importer">
10
+ <thead>
11
+ <tr>
12
+ <th><?php _e('Map to', 'wf_csv_import_export'); ?></th>
13
+ <th><?php _e('Column Header', 'wf_csv_import_export'); ?></th>
14
+ <th><?php _e('Evaluation Field', 'wf_csv_import_export'); ?>
15
+ <?php $plugin_url = WC()->plugin_url(); ?>
16
+ <img class="help_tip" style="float:none;" data-tip="<?php _e('Assign constant value HikeFoce to post_author:</br>=HikeFoce</br>Add $5 to Price:sale_price:</br>+5</br>Reduce $5 to Price:sale_price:</br>-5</br>Multiple 1.05 to Price:sale_price:</br>*1.05</br>Divide Price:sale_price by 2:</br>/2</br>Append a value By HikeFoce to post_title:</br>&By HikeFoce</br>Prepend a value HikeFoce to post_title:</br>&HikeFoce [VAL].', 'wf_csv_import_export'); ?>" src="<?php echo $plugin_url; ?>/assets/images/help.png" height="20" width="20" />
17
+ </th>
18
+ </tr>
19
+ </thead>
20
+ <tbody>
21
+ <?php
22
+ $wpost_attributes = include( dirname(__FILE__) . '/../data/data-wf-reserved-fields-pair.php' );
23
+
24
+ $taxonomy_n_attributes_items = array();
25
+ foreach ($taxonomies as $taxonomy) {
26
+ if (substr($taxonomy, 0, 3) !== 'pa_')
27
+ $taxonomy_n_attributes_items['tax:' . $taxonomy] = 'tax:' . $taxonomy. '| Product Taxonomies';
28
+ }
29
+ foreach ($taxonomies as $taxonomy) {
30
+ if (substr($taxonomy, 0, 3) == 'pa_')
31
+ $taxonomy_n_attributes_items['attribute:' . $taxonomy] = 'attribute:' . $taxonomy. '| Taxonomy Attributes';
32
+ }
33
+ foreach ($attributes as $attr) {
34
+ $attr = sanitize_title($attr);
35
+ if (substr($attr, 0, 3) !== 'pa_')
36
+ $taxonomy_n_attributes_items['attribute:' . $attr] = 'attribute:' . $attr. '| Product Attributes';
37
+ $taxonomy_n_attributes_items['attribute_data:' . $attr] = 'attribute_data:' .$attr. '| Product Attributes Data';
38
+ $taxonomy_n_attributes_items['attribute_default:' . $attr] = 'attribute_default:' .$attr. '| Product Attributes default';
39
+ }
40
+
41
+ foreach ($raw_headers as $key => $column) {
42
+ if(!empty($taxonomy_n_attributes_items[$key]))
43
+ continue;
44
+ if (strstr($key, 'tax:')) {
45
+ $column = trim(str_replace('tax:', '', $key));
46
+ $taxonomy_n_attributes_items['tax:' . $column] = 'tax:' . $column . '| New Taxonomy:' . $column;
47
+ } elseif (strstr($key, 'meta:')) {
48
+ $column = trim(str_replace('meta:', '', $key));
49
+ $taxonomy_n_attributes_items['meta:' . $column] = 'meta:' . $column . '| Custom Field:' . $column;
50
+ } elseif (strstr($key, 'attribute:')) {
51
+ $column = trim(str_replace('attribute:', '', $key));
52
+ $taxonomy_n_attributes_items['attribute:' . $column] = 'attribute:' . $column . '| New Product Attribute:' . $column;
53
+ } elseif (strstr($key, 'attribute_data:')) {
54
+ $column = trim(str_replace('attribute_data:', '', $key));
55
+ $taxonomy_n_attributes_items['attribute_data:' . $column] = 'attribute_data:' . $column . '| New Product Attribute Data:' . $column;
56
+ } elseif (strstr($key, 'attribute_default:')) {
57
+ $column = trim(str_replace('attribute_default:', '', $key));
58
+ $taxonomy_n_attributes_items['attribute_default:' . $column] = 'attribute_default:' . $column . '| New Product Attribute default value:' . $column;
59
+ }
60
+ }
61
+
62
+ foreach ($taxonomy_n_attributes_items as $key => $value) {
63
+ if(!empty($wpost_attributes[$key]))
64
+ continue;
65
+ $wpost_attributes[$key] = $value;
66
+ }
67
+
68
+ foreach ($wpost_attributes as $key => $value) :
69
+ $sel_key = ($saved_mapping && isset($saved_mapping[$key])) ? $saved_mapping[$key] : $key;
70
+ $evaluation_value = ($saved_evaluation && isset($saved_evaluation[$key])) ? $saved_evaluation[$key] : '';
71
+ $evaluation_value = stripslashes($evaluation_value);
72
+ $values = explode('|',$value);
73
+ $value = $values[0];
74
+ $tool_tip = $values[1];
75
+ ?>
76
+ <tr>
77
+ <td width="25%">
78
+ <img class="help_tip" style="float:none;" data-tip="<?php echo $tool_tip; ?>" src="<?php echo $plugin_url; ?>/assets/images/help.png" height="20" width="20" />
79
+ <select name="map_to[<?php echo $key; ?>]" disabled="true"
80
+ style=" -webkit-appearance: none;
81
+ -moz-appearance: none;
82
+ text-indent: 1px;
83
+ text-overflow: '';
84
+ background-color: #f1f1f1;
85
+ border: none;
86
+ box-shadow: 0 1px 2px rgba(0, 0, 0, 0.07) inset;
87
+ color: #32373c;
88
+ outline: 0 none;
89
+ transition: border-color 50ms ease-in-out 0s;">
90
+ <option value="<?php echo $key; ?>" <?php if ($key == $key) echo 'selected="selected"'; ?>><?php echo $value; ?></option>
91
+ </select>
92
+ </td>
93
+ <td width="25%">
94
+ <select name="map_from[<?php echo $key; ?>]">
95
+ <option value=""><?php _e('Do not import', 'wf_csv_import_export'); ?></option>
96
+ <?php
97
+ foreach ($row as $hkey => $hdr):
98
+ $hdr = strlen($hdr) > 50 ? substr(strip_tags($hdr), 0, 50) . "..." : $hdr;
99
+ ?>
100
+ <option value="<?php echo $raw_headers[$hkey]; ?>" <?php selected(strtolower($sel_key), $hkey); ?>><?php echo $raw_headers[$hkey] . " &nbsp; : &nbsp; " . $hdr; ?></option>
101
+ <?php endforeach; ?>
102
+ </select>
103
+ <?php do_action('woocommerce_csv_product_data_mapping', $key); ?>
104
+ </td>
105
+ <td width="10%"><input type="text" name="eval_field[<?php echo $key; ?>]" value="<?php echo $evaluation_value; ?>" /></td>
106
+ </tr>
107
+ <?php endforeach; ?>
108
+ </tbody>
109
+ </table>
110
+ <p class="submit">
111
+ <input type="submit" class="button button-primary" value="<?php esc_attr_e('Submit', 'wf_csv_import_export'); ?>" />
112
+ <input type="hidden" name="delimiter" value="<?php echo $this->delimiter ?>" />
113
+ <input type="hidden" name="merge_empty_cells" value="<?php echo $this->merge_empty_cells ?>" />
114
+ </p>
115
  </form>
includes/settings/class-wf-prodimpexpcsv-settings.php CHANGED
@@ -1,20 +1,20 @@
1
- <?php
2
- if ( ! defined( 'ABSPATH' ) ) {
3
- exit;
4
- }
5
-
6
- class WF_ProdImpExpCsv_Settings {
7
-
8
- /**
9
- * Product Exporter Tool
10
- */
11
- public static function save_settings( ) {
12
- global $wpdb;
13
-
14
- //update_option( 'woocommerce_'.WF_PROD_IMP_EXP_ID.'_settings', $settings );
15
-
16
- //echo ':'.$ftp_server.':'.$ftp_user.':'.$ftp_password.':'.$use_ftps; die();
17
- //wp_redirect( admin_url( '/admin.php?page='.WF_WOOCOMMERCE_CSV_IM_EX.'&tab=settings' ) );
18
- //exit;
19
- }
20
- }
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+
6
+ class WF_ProdImpExpCsv_Settings {
7
+
8
+ /**
9
+ * Product Exporter Tool
10
+ */
11
+ public static function save_settings( ) {
12
+ global $wpdb;
13
+
14
+ //update_option( 'woocommerce_'.WF_PROD_IMP_EXP_ID.'_settings', $settings );
15
+
16
+ //echo ':'.$ftp_server.':'.$ftp_user.':'.$ftp_password.':'.$use_ftps; die();
17
+ //wp_redirect( admin_url( '/admin.php?page='.WF_WOOCOMMERCE_CSV_IM_EX.'&tab=settings' ) );
18
+ //exit;
19
+ }
20
+ }
includes/views/export/html-wf-export-products.php CHANGED
@@ -1,74 +1,74 @@
1
- <div class="tool-box">
2
- <h3 class="title"><?php _e('Export Product in CSV Format:', 'wf_csv_import_export'); ?></h3>
3
- <p><?php _e('Export and download your products in CSV format. This file can be used to import products back into your Woocommerce shop.', 'wf_csv_import_export'); ?></p>
4
- <form action="<?php echo admin_url('admin.php?page=wf_woocommerce_csv_im_ex&action=export'); ?>" method="post">
5
-
6
- <table class="form-table">
7
- <tr>
8
- <th>
9
- <label for="v_offset"><?php _e('Offset', 'wf_csv_import_export'); ?></label>
10
- </th>
11
- <td>
12
- <input type="text" name="offset" id="v_offset" placeholder="<?php _e('0', 'wf_csv_import_export'); ?>" class="input-text" />
13
- </td>
14
- </tr>
15
- <tr>
16
- <th>
17
- <label for="v_limit"><?php _e('Limit', 'wf_csv_import_export'); ?></label>
18
- </th>
19
- <td>
20
- <input type="text" name="limit" id="v_limit" placeholder="<?php _e('Unlimited', 'wf_csv_import_export'); ?>" class="input-text" />
21
- </td>
22
- </tr>
23
- <tr>
24
- <th>
25
- <label for="v_columns"><?php _e('Columns', 'wf_csv_import_export'); ?></label>
26
- </th>
27
- <table id="datagrid">
28
- <th style="text-align: left;">
29
- <label for="v_columns"><?php _e('Column', 'wf_csv_import_export'); ?></label>
30
- </th>
31
- <th style="text-align: left;">
32
- <label for="v_columns_name"><?php _e('Column Name', 'wf_csv_import_export'); ?></label>
33
- </th>
34
- <?php
35
- $post_columns['images'] = 'Images (featured and gallery)';
36
- $post_columns['file_paths'] = 'Downloadable file paths';
37
- $post_columns['taxonomies'] = 'Taxonomies (cat/tags/shipping-class)';
38
- $post_columns['attributes'] = 'Attributes';
39
- ?>
40
- <?php foreach ($post_columns as $pkey => $pcolumn) {
41
-
42
- ?>
43
- <tr>
44
- <td>
45
- <input name= "columns[<?php echo $pkey; ?>]" type="checkbox" value="<?php echo $pkey; ?>" checked>
46
- <label for="columns[<?php echo $pkey; ?>]"><?php _e($pcolumn, 'wf_csv_import_export'); ?></label>
47
- </td>
48
- <td>
49
- <?php
50
- $tmpkey = $pkey;
51
- if (strpos($pkey, 'yoast') === false) {
52
- $tmpkey = ltrim($pkey, '_');
53
- }
54
- ?>
55
- <input type="text" name="columns_name[<?php echo $pkey; ?>]" value="<?php echo $tmpkey; ?>" class="input-text" />
56
- </td>
57
- </tr>
58
- <?php } ?>
59
-
60
- </table><br/>
61
- </tr>
62
-
63
- <tr>
64
- <th>
65
- <label for="v_include_hidden_meta"><?php _e('Include hidden meta data', 'wf_csv_import_export'); ?></label>
66
- </th>
67
- <td>
68
- <input type="checkbox" name="include_hidden_meta" id="v_include_hidden_meta" class="checkbox" />
69
- </td>
70
- </tr>
71
- </table>
72
- <p class="submit"><input type="submit" class="button button-primary" value="<?php _e('Export Products', 'wf_csv_import_export'); ?>" /></p>
73
- </form>
74
  </div>
1
+ <div class="tool-box">
2
+ <h3 class="title"><?php _e('Export Product in CSV Format:', 'wf_csv_import_export'); ?></h3>
3
+ <p><?php _e('Export and download your products in CSV format. This file can be used to import products back into your Woocommerce shop.', 'wf_csv_import_export'); ?></p>
4
+ <form action="<?php echo admin_url('admin.php?page=wf_woocommerce_csv_im_ex&action=export'); ?>" method="post">
5
+
6
+ <table class="form-table">
7
+ <tr>
8
+ <th>
9
+ <label for="v_offset"><?php _e('Offset', 'wf_csv_import_export'); ?></label>
10
+ </th>
11
+ <td>
12
+ <input type="text" name="offset" id="v_offset" placeholder="<?php _e('0', 'wf_csv_import_export'); ?>" class="input-text" />
13
+ </td>
14
+ </tr>
15
+ <tr>
16
+ <th>
17
+ <label for="v_limit"><?php _e('Limit', 'wf_csv_import_export'); ?></label>
18
+ </th>
19
+ <td>
20
+ <input type="text" name="limit" id="v_limit" placeholder="<?php _e('Unlimited', 'wf_csv_import_export'); ?>" class="input-text" />
21
+ </td>
22
+ </tr>
23
+ <tr>
24
+ <th>
25
+ <label for="v_columns"><?php _e('Columns', 'wf_csv_import_export'); ?></label>
26
+ </th>
27
+ <table id="datagrid">
28
+ <th style="text-align: left;">
29
+ <label for="v_columns"><?php _e('Column', 'wf_csv_import_export'); ?></label>
30
+ </th>
31
+ <th style="text-align: left;">
32
+ <label for="v_columns_name"><?php _e('Column Name', 'wf_csv_import_export'); ?></label>
33
+ </th>
34
+ <?php
35
+ $post_columns['images'] = 'Images (featured and gallery)';
36
+ $post_columns['file_paths'] = 'Downloadable file paths';
37
+ $post_columns['taxonomies'] = 'Taxonomies (cat/tags/shipping-class)';
38
+ $post_columns['attributes'] = 'Attributes';
39
+ ?>
40
+ <?php foreach ($post_columns as $pkey => $pcolumn) {
41
+
42
+ ?>
43
+ <tr>
44
+ <td>
45
+ <input name= "columns[<?php echo $pkey; ?>]" type="checkbox" value="<?php echo $pkey; ?>" checked>
46
+ <label for="columns[<?php echo $pkey; ?>]"><?php _e($pcolumn, 'wf_csv_import_export'); ?></label>
47
+ </td>
48
+ <td>
49
+ <?php
50
+ $tmpkey = $pkey;
51
+ if (strpos($pkey, 'yoast') === false) {
52
+ $tmpkey = ltrim($pkey, '_');
53
+ }
54
+ ?>
55
+ <input type="text" name="columns_name[<?php echo $pkey; ?>]" value="<?php echo $tmpkey; ?>" class="input-text" />
56
+ </td>
57
+ </tr>
58
+ <?php } ?>
59
+
60
+ </table><br/>
61
+ </tr>
62
+
63
+ <tr>
64
+ <th>
65
+ <label for="v_include_hidden_meta"><?php _e('Include hidden meta data', 'wf_csv_import_export'); ?></label>
66
+ </th>
67
+ <td>
68
+ <input type="checkbox" name="include_hidden_meta" id="v_include_hidden_meta" class="checkbox" />
69
+ </td>
70
+ </tr>
71
+ </table>
72
+ <p class="submit"><input type="submit" class="button button-primary" value="<?php _e('Export Products', 'wf_csv_import_export'); ?>" /></p>
73
+ </form>
74
  </div>
includes/views/html-wf-admin-screen.php CHANGED
@@ -1,17 +1,19 @@
1
- <div class="wrap woocommerce">
2
- <div class="icon32" id="icon-woocommerce-importer"><br></div>
3
- <h2 class="nav-tab-wrapper woo-nav-tab-wrapper">
4
- <a href="<?php echo admin_url('admin.php?page=wf_woocommerce_csv_im_ex') ?>" class="nav-tab <?php echo ($tab == 'import') ? 'nav-tab-active' : ''; ?>"><?php _e('Product Import / Export', 'wf_csv_import_export'); ?></a>
5
- </h2>
6
-
7
- <?php
8
- switch ($tab) {
9
- case "export" :
10
- $this->admin_export_page();
11
- break;
12
- default :
13
- $this->admin_import_page();
14
- break;
15
- }
16
- ?>
 
 
17
  </div>
1
+
2
+ <?php include('market.php'); ?>
3
+ <div class="wrap woocommerce">
4
+ <div class="icon32" id="icon-woocommerce-importer"><br></div>
5
+ <h2 class="nav-tab-wrapper woo-nav-tab-wrapper">
6
+ <a href="<?php echo admin_url('admin.php?page=wf_woocommerce_csv_im_ex') ?>" class="nav-tab <?php echo ($tab == 'import') ? 'nav-tab-active' : ''; ?>"><?php _e('Product Import / Export', 'wf_csv_import_export'); ?></a>
7
+ </h2>
8
+
9
+ <?php
10
+ switch ($tab) {
11
+ case "export" :
12
+ $this->admin_export_page();
13
+ break;
14
+ default :
15
+ $this->admin_import_page();
16
+ break;
17
+ }
18
+ ?>
19
  </div>
includes/views/import/html-wf-import-products.php CHANGED
@@ -1,55 +1,23 @@
1
- <div class="wf-banner updated below-h2">
2
- <p class="main">
3
- <ul>
4
- <li style='color:red;'><strong><?php _e('Your Business is precious! Go Premium!', 'wf_csv_import_export'); ?></strong></li>
5
- <strong><?php _e('HikeForce Import Export Plugin Premium version helps you to seamlessly import/export products into your Woocommerce Store.', 'wf_csv_import_export'); ?></strong><br/><br/>
6
- <?php _e('- Export Products (Simple, Group, External and Variations) in to a CSV file <strong>( Basic version supports only Simple Products )</strong>.', 'wf_csv_import_export'); ?><br/>
7
- <?php _e('- Import Products (Simple, Group, External and Variations) in CSV format in to WooComemrce Store.', 'wf_csv_import_export'); ?><br/>
8
- <?php _e('- Export Products by Category.', 'wf_csv_import_export'); ?><br/>
9
- <?php _e('- Various Filter options for exporting Products.', 'wf_csv_import_export'); ?><br/>
10
- <?php _e('- Map and Transform fields while Importing Products.', 'wf_csv_import_export'); ?><br/>
11
- <?php _e('- Change values while improting products using Evaluation Fields.', 'wf_csv_import_export'); ?><br/>
12
- <?php _e('- Choice to Update or Skip existing imported products.', 'wf_csv_import_export'); ?><br/>
13
- <?php _e('- WPML Supported. French and German (Deutschland) language support Out of the Box.', 'wf_csv_import_export'); ?><br/>
14
- <?php _e('- Import/Export file from/to a remote server via FTP.', 'wf_csv_import_export'); ?><br/>
15
- <?php _e('- Excellent Support for setting it up!', 'wf_csv_import_export'); ?><br/>
16
- </ul>
17
- </p>
18
- <p>
19
- <a href="http://www.xadapter.com/product/product-import-export-plugin-for-woocommerce/" target="_blank" class="button button-primary"><?php _e( 'Upgrade to Premium Version', 'wf_csv_import_export'); ?></a>
20
- <a href="http://productimportexport.hikeforce.com/wp-admin/admin.php?page=wf_woocommerce_csv_im_ex" target="_blank" class="button"><?php _e( 'Live Demo', 'wf_csv_import_export'); ?></a>
21
- <a href="http://www.xadapter.com/2016/06/20/setting-up-product-import-export-plugin-for-woocommerce/" target="_blank" class="button"><?php _e( 'Documentation', 'wf_csv_import_export' ); ?></a>
22
- <a href="<?php echo plugins_url( 'Product_Commercial_Sample_CSV.csv', WF_ProdImpExpCsv_FILE ); ?>" target="_blank" class="button"><?php _e('Sample Commercial CSV', 'wf_csv_import_export'); ?></a>
23
- <a href="<?php echo plugins_url( 'Product_WooCommerce_Sample_CSV.csv', WF_ProdImpExpCsv_FILE ); ?>" target="_blank" class="button"><?php _e('Sample WooCommerce CSV', 'wf_csv_import_export'); ?></a>
24
- </p>
25
- </div>
26
- <style>
27
- .wf-banner img {
28
- float: right;
29
- margin-left: 1em;
30
- padding: 15px 0
31
- }
32
- </style>
33
-
34
- <div class="tool-box">
35
- <h3 class="title"><?php _e('Import Products in CSV Format:', 'wf_csv_import_export'); ?></h3>
36
- <p><?php _e('Import products in CSV format ( works for simple products) from different sources', 'wf_csv_import_export'); ?></p>
37
- <p class="submit">
38
- <?php
39
- $merge_url = admin_url('admin.php?import=woocommerce_csv&merge=1');
40
- $import_url = admin_url('admin.php?import=woocommerce_csv');
41
- ?>
42
- <a class="button button-primary" id="mylink" href="<?php echo admin_url('admin.php?import=woocommerce_csv'); ?>"><?php _e('Import Products', 'wf_csv_import_export'); ?></a>
43
- &nbsp;
44
- <input type="checkbox" id="merge" value="0"><?php _e('Merge products if exists', 'wf_csv_import_export'); ?> <br>
45
- </p>
46
- </div>
47
- <script type="text/javascript">
48
- jQuery('#merge').click(function () {
49
- if (this.checked) {
50
- jQuery("#mylink").attr("href", '<?php echo $merge_url ?>');
51
- } else {
52
- jQuery("#mylink").attr("href", '<?php echo $import_url ?>');
53
- }
54
- });
55
  </script>
1
+
2
+ <div class="tool-box">
3
+ <h3 class="title"><?php _e('Import Products in CSV Format:', 'wf_csv_import_export'); ?></h3>
4
+ <p><?php _e('Import products in CSV format ( works for simple products) from different sources', 'wf_csv_import_export'); ?></p>
5
+ <p class="submit">
6
+ <?php
7
+ $merge_url = admin_url('admin.php?import=woocommerce_csv&merge=1');
8
+ $import_url = admin_url('admin.php?import=woocommerce_csv');
9
+ ?>
10
+ <a class="button button-primary" id="mylink" href="<?php echo admin_url('admin.php?import=woocommerce_csv'); ?>"><?php _e('Import Products', 'wf_csv_import_export'); ?></a>
11
+ &nbsp;
12
+ <input type="checkbox" id="merge" value="0"><?php _e('Merge products if exists', 'wf_csv_import_export'); ?> <br>
13
+ </p>
14
+ </div>
15
+ <script type="text/javascript">
16
+ jQuery('#merge').click(function () {
17
+ if (this.checked) {
18
+ jQuery("#mylink").attr("href", '<?php echo $merge_url ?>');
19
+ } else {
20
+ jQuery("#mylink").attr("href", '<?php echo $import_url ?>');
21
+ }
22
+ });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  </script>
includes/views/market.php ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <style>
2
+ .box14{
3
+ width: 30%;
4
+ margin-top:55px;
5
+ min-height: 310px;
6
+ margin-right: 10px;
7
+ padding:10px;
8
+ position:absolute;
9
+ z-index:1;
10
+ right:0px;
11
+ float:right;
12
+ background: -webkit-gradient(linear, 0% 20%, 0% 92%, from(#fff), to(#f3f3f3), color-stop(.1,#fff));
13
+ border: 1px solid #ccc;
14
+ -webkit-border-radius: 60px 5px;
15
+ -webkit-box-shadow: 0px 0px 35px rgba(0, 0, 0, 0.1) inset;
16
+ }
17
+ .box14_ribbon{
18
+ position:absolute;
19
+ top:0; right: 0;
20
+ width: 130px;
21
+ height: 40px;
22
+ background: -webkit-gradient(linear, 555% 20%, 0% 92%, from(rgba(0, 0, 0, 0.1)), to(rgba(0, 0, 0, 0.0)), color-stop(.1,rgba(0, 0, 0, 0.2)));
23
+ border-left: 1px dashed rgba(0, 0, 0, 0.1);
24
+ border-right: 1px dashed rgba(0, 0, 0, 0.1);
25
+ -webkit-box-shadow: 0px 0px 12px rgba(0, 0, 0, 0.2);
26
+ -webkit-transform: rotate(6deg) skew(0,0) translate(-60%,-5px);
27
+ }
28
+ .box14 h3
29
+ {
30
+ text-align:center;
31
+ margin:2px;
32
+ }
33
+ .box14 p
34
+ {
35
+ text-align:center;
36
+ margin:2px;
37
+ border-width:1px;
38
+ border-style:solid;
39
+ padding:5px;
40
+ border-color: rgb(204, 204, 204);
41
+ }
42
+ .box14 span
43
+ {
44
+ background:#fff;
45
+ padding:5px;
46
+ display:block;
47
+ box-shadow:green 0px 3px inset;
48
+ margin-top:10px;
49
+ }
50
+ .box14 img {
51
+ width: 40%;
52
+ padding-left:30%;
53
+ margin-top: 5px;
54
+ }
55
+ .table-box-main {
56
+ box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
57
+ transition: all 0.3s cubic-bezier(.25,.8,.25,1);
58
+ }
59
+
60
+ .table-box-main:hover {
61
+ box-shadow: 0 14px 28px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22);
62
+ }
63
+ </style>
64
+ <div class="box14 table-box-main">
65
+ <h3>
66
+ <center><a href="https://www.xadapter.com/" target="_blank" style="text-decoration: none;color:black;" >XAdapter</a></center></h3>
67
+ <hr>
68
+ <img src= <?php echo plugins_url()."/product-import-export-for-woo/images/Import-Export-for-WooCommerce-Product-Image.png"; ?>>
69
+ <h3>Product/Review Import Export Plugin For WooCommerce<br/></h3>
70
+ <!-- <p style="color:red;">
71
+ <strong>Your Business is precious. Go Premium!</strong>
72
+ </p> -->
73
+ <br/>
74
+ <center><a href="http://www.xadapter.com/product/product-import-export-plugin-for-woocommerce/" target="_blank" class="button button-primary"><?php _e( 'Upgrade to Premium Version', 'wf_csv_import_export'); ?></a></center>
75
+ <span>
76
+ <ul>
77
+ <li>- Export Products (Simple, Group, External and Variations) in to a CSV file <strong>( Basic version supports only Simple Products )</strong>.</li>
78
+ <li>- Import Products (Simple, Group, External and Variations) in CSV format in to WooComemrce Store.</li>
79
+ <li>- Export Products by Category.</li>
80
+ <li>- Various Filter options for exporting Products. </li>
81
+ <li>- Map and Transform fields while Importing Products.</li>
82
+ <li>- Change values while improting products using Evaluation Fields.</li>
83
+ <li>- Choice to Update or Skip existing imported products. </li>
84
+ <li>- WPML Supported. French and German (Deutschland) language support Out of the Box.</li>
85
+ <li>- Import/Export file from/to a remote server via FTP.</li>
86
+ <li>- Supports Product Reviews Export Import.</li>
87
+ <li>- Excellent Support for setting it up!</li>
88
+ </ul>
89
+ </span>
90
+
91
+ <center>
92
+
93
+ <a href="http://productimportexport.hikeforce.com/wp-admin/admin.php?page=wf_woocommerce_csv_im_ex" target="_blank" class="button"><?php _e( 'Live Demo', 'wf_csv_import_export'); ?></a><a href="https://www.xadapter.com/category/product/product-import-export-plugin-for-woocommerce/" target="_blank" class="button"><?php _e( 'Documentation', 'wf_csv_import_export' ); ?></a><a href="<?php echo plugins_url( 'Product_Commercial_Sample_CSV.csv', WF_ProdImpExpCsv_FILE ); ?>" target="_blank" class="button"><?php _e('Sample Commercial CSV', 'wf_csv_import_export'); ?></a>
94
+ <a href="<?php echo plugins_url( 'Product_WooCommerce_Sample_CSV.csv', WF_ProdImpExpCsv_FILE ); ?>" target="_blank" class="button"><?php _e('Sample WooCommerce CSV', 'wf_csv_import_export'); ?></a></center>
95
+ </div>
license.txt CHANGED
@@ -1,708 +1,708 @@
1
- Product CSV Import Export For WooCommerce
2
-
3
- Copyright 2015 by the contributors
4
-
5
- This program is free software; you can redistribute it and/or modify
6
- it under the terms of the GNU General Public License as published by
7
- the Free Software Foundation; either version 3 of the License, or
8
- (at your option) any later version.
9
-
10
- This program is distributed in the hope that it will be useful,
11
- but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- GNU General Public License for more details.
14
-
15
- You should have received a copy of the GNU General Public License
16
- along with this program; if not, write to the Free Software
17
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
-
19
- This program incorporates work covered by the following copyright and
20
- permission notices:
21
-
22
- WooCommerce Product CSV Import Suite
23
- Copyright: 2009-2011 WooThemes.
24
- License: GNU General Public License v3.0
25
- License URI: http://www.gnu.org/licenses/gpl-3.0.html
26
-
27
- and
28
-
29
- HikeForce
30
-
31
- Product CSV Import Export For WooCommerce is released under the GPL
32
-
33
- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
34
-
35
- GNU GENERAL PUBLIC LICENSE
36
- Version 3, 29 June 2007
37
-
38
- Copyright © 2007 Free Software Foundation, Inc. <http://fsf.org/>
39
- Everyone is permitted to copy and distribute verbatim copies
40
- of this license document, but changing it is not allowed.
41
-
42
- Preamble
43
-
44
- The GNU General Public License is a free, copyleft license for
45
- software and other kinds of works.
46
-
47
- The licenses for most software and other practical works are designed
48
- to take away your freedom to share and change the works. By contrast,
49
- the GNU General Public License is intended to guarantee your freedom to
50
- share and change all versions of a program--to make sure it remains free
51
- software for all its users. We, the Free Software Foundation, use the
52
- GNU General Public License for most of our software; it applies also to
53
- any other work released this way by its authors. You can apply it to
54
- your programs, too.
55
-
56
- When we speak of free software, we are referring to freedom, not
57
- price. Our General Public Licenses are designed to make sure that you
58
- have the freedom to distribute copies of free software (and charge for
59
- them if you wish), that you receive source code or can get it if you
60
- want it, that you can change the software or use pieces of it in new
61
- free programs, and that you know you can do these things.
62
-
63
- To protect your rights, we need to prevent others from denying you
64
- these rights or asking you to surrender the rights. Therefore, you have
65
- certain responsibilities if you distribute copies of the software, or if
66
- you modify it: responsibilities to respect the freedom of others.
67
-
68
- For example, if you distribute copies of such a program, whether
69
- gratis or for a fee, you must pass on to the recipients the same
70
- freedoms that you received. You must make sure that they, too, receive
71
- or can get the source code. And you must show them these terms so they
72
- know their rights.
73
-
74
- Developers that use the GNU GPL protect your rights with two steps:
75
- (1) assert copyright on the software, and (2) offer you this License
76
- giving you legal permission to copy, distribute and/or modify it.
77
-
78
- For the developers' and authors' protection, the GPL clearly explains
79
- that there is no warranty for this free software. For both users' and
80
- authors' sake, the GPL requires that modified versions be marked as
81
- changed, so that their problems will not be attributed erroneously to
82
- authors of previous versions.
83
-
84
- Some devices are designed to deny users access to install or run
85
- modified versions of the software inside them, although the manufacturer
86
- can do so. This is fundamentally incompatible with the aim of
87
- protecting users' freedom to change the software. The systematic
88
- pattern of such abuse occurs in the area of products for individuals to
89
- use, which is precisely where it is most unacceptable. Therefore, we
90
- have designed this version of the GPL to prohibit the practice for those
91
- products. If such problems arise substantially in other domains, we
92
- stand ready to extend this provision to those domains in future versions
93
- of the GPL, as needed to protect the freedom of users.
94
-
95
- Finally, every program is threatened constantly by software patents.
96
- States should not allow patents to restrict development and use of
97
- software on general-purpose computers, but in those that do, we wish to
98
- avoid the special danger that patents applied to a free program could
99
- make it effectively proprietary. To prevent this, the GPL assures that
100
- patents cannot be used to render the program non-free.
101
-
102
- The precise terms and conditions for copying, distribution and
103
- modification follow.
104
-
105
- TERMS AND CONDITIONS
106
-
107
- 0. Definitions.
108
-
109
- "This License" refers to version 3 of the GNU General Public License.
110
-
111
- "Copyright" also means copyright-like laws that apply to other kinds of
112
- works, such as semiconductor masks.
113
-
114
- "The Program" refers to any copyrightable work licensed under this
115
- License. Each licensee is addressed as "you". "Licensees" and
116
- "recipients" may be individuals or organizations.
117
-
118
- To "modify" a work means to copy from or adapt all or part of the work
119
- in a fashion requiring copyright permission, other than the making of an
120
- exact copy. The resulting work is called a "modified version" of the
121
- earlier work or a work "based on" the earlier work.
122
-
123
- A "covered work" means either the unmodified Program or a work based
124
- on the Program.
125
-
126
- To "propagate" a work means to do anything with it that, without
127
- permission, would make you directly or secondarily liable for
128
- infringement under applicable copyright law, except executing it on a
129
- computer or modifying a private copy. Propagation includes copying,
130
- distribution (with or without modification), making available to the
131
- public, and in some countries other activities as well.
132
-
133
- To "convey" a work means any kind of propagation that enables other
134
- parties to make or receive copies. Mere interaction with a user through
135
- a computer network, with no transfer of a copy, is not conveying.
136
-
137
- An interactive user interface displays "Appropriate Legal Notices"
138
- to the extent that it includes a convenient and prominently visible
139
- feature that (1) displays an appropriate copyright notice, and (2)
140
- tells the user that there is no warranty for the work (except to the
141
- extent that warranties are provided), that licensees may convey the
142
- work under this License, and how to view a copy of this License. If
143
- the interface presents a list of user commands or options, such as a
144
- menu, a prominent item in the list meets this criterion.
145
-
146
- 1. Source Code.
147
-
148
- The "source code" for a work means the preferred form of the work
149
- for making modifications to it. "Object code" means any non-source
150
- form of a work.
151
-
152
- A "Standard Interface" means an interface that either is an official
153
- standard defined by a recognized standards body, or, in the case of
154
- interfaces specified for a particular programming language, one that
155
- is widely used among developers working in that language.
156
-
157
- The "System Libraries" of an executable work include anything, other
158
- than the work as a whole, that (a) is included in the normal form of
159
- packaging a Major Component, but which is not part of that Major
160
- Component, and (b) serves only to enable use of the work with that
161
- Major Component, or to implement a Standard Interface for which an
162
- implementation is available to the public in source code form. A
163
- "Major Component", in this context, means a major essential component
164
- (kernel, window system, and so on) of the specific operating system
165
- (if any) on which the executable work runs, or a compiler used to
166
- produce the work, or an object code interpreter used to run it.
167
-
168
- The "Corresponding Source" for a work in object code form means all
169
- the source code needed to generate, install, and (for an executable
170
- work) run the object code and to modify the work, including scripts to
171
- control those activities. However, it does not include the work's
172
- System Libraries, or general-purpose tools or generally available free
173
- programs which are used unmodified in performing those activities but
174
- which are not part of the work. For example, Corresponding Source
175
- includes interface definition files associated with source files for
176
- the work, and the source code for shared libraries and dynamically
177
- linked subprograms that the work is specifically designed to require,
178
- such as by intimate data communication or control flow between those
179
- subprograms and other parts of the work.
180
-
181
- The Corresponding Source need not include anything that users
182
- can regenerate automatically from other parts of the Corresponding
183
- Source.
184
-
185
- The Corresponding Source for a work in source code form is that
186
- same work.
187
-
188
- 2. Basic Permissions.
189
-
190
- All rights granted under this License are granted for the term of
191
- copyright on the Program, and are irrevocable provided the stated
192
- conditions are met. This License explicitly affirms your unlimited
193
- permission to run the unmodified Program. The output from running a
194
- covered work is covered by this License only if the output, given its
195
- content, constitutes a covered work. This License acknowledges your
196
- rights of fair use or other equivalent, as provided by copyright law.
197
-
198
- You may make, run and propagate covered works that you do not
199
- convey, without conditions so long as your license otherwise remains
200
- in force. You may convey covered works to others for the sole purpose
201
- of having them make modifications exclusively for you, or provide you
202
- with facilities for running those works, provided that you comply with
203
- the terms of this License in conveying all material for which you do
204
- not control copyright. Those thus making or running the covered works
205
- for you must do so exclusively on your behalf, under your direction
206
- and control, on terms that prohibit them from making any copies of
207
- your copyrighted material outside their relationship with you.
208
-
209
- Conveying under any other circumstances is permitted solely under
210
- the conditions stated below. Sublicensing is not allowed; section 10
211
- makes it unnecessary.
212
-
213
- 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
214
-
215
- No covered work shall be deemed part of an effective technological
216
- measure under any applicable law fulfilling obligations under article
217
- 11 of the WIPO copyright treaty adopted on 20 December 1996, or
218
- similar laws prohibiting or restricting circumvention of such
219
- measures.
220
-
221
- When you convey a covered work, you waive any legal power to forbid
222
- circumvention of technological measures to the extent such circumvention
223
- is effected by exercising rights under this License with respect to
224
- the covered work, and you disclaim any intention to limit operation or
225
- modification of the work as a means of enforcing, against the work's
226
- users, your or third parties' legal rights to forbid circumvention of
227
- technological measures.
228
-
229
- 4. Conveying Verbatim Copies.
230
-
231
- You may convey verbatim copies of the Program's source code as you
232
- receive it, in any medium, provided that you conspicuously and
233
- appropriately publish on each copy an appropriate copyright notice;
234
- keep intact all notices stating that this License and any
235
- non-permissive terms added in accord with section 7 apply to the code;
236
- keep intact all notices of the absence of any warranty; and give all
237
- recipients a copy of this License along with the Program.
238
-
239
- You may charge any price or no price for each copy that you convey,
240
- and you may offer support or warranty protection for a fee.
241
-
242
- 5. Conveying Modified Source Versions.
243
-
244
- You may convey a work based on the Program, or the modifications to
245
- produce it from the Program, in the form of source code under the
246
- terms of section 4, provided that you also meet all of these conditions:
247
-
248
- a) The work must carry prominent notices stating that you modified
249
- it, and giving a relevant date.
250
-
251
- b) The work must carry prominent notices stating that it is
252
- released under this License and any conditions added under section
253
- 7. This requirement modifies the requirement in section 4 to
254
- "keep intact all notices".
255
-
256
- c) You must license the entire work, as a whole, under this
257
- License to anyone who comes into possession of a copy. This
258
- License will therefore apply, along with any applicable section 7
259
- additional terms, to the whole of the work, and all its parts,
260
- regardless of how they are packaged. This License gives no
261
- permission to license the work in any other way, but it does not
262
- invalidate such permission if you have separately received it.
263
-
264
- d) If the work has interactive user interfaces, each must display
265
- Appropriate Legal Notices; however, if the Program has interactive
266
- interfaces that do not display Appropriate Legal Notices, your
267
- work need not make them do so.
268
-
269
- A compilation of a covered work with other separate and independent
270
- works, which are not by their nature extensions of the covered work,
271
- and which are not combined with it such as to form a larger program,
272
- in or on a volume of a storage or distribution medium, is called an
273
- "aggregate" if the compilation and its resulting copyright are not
274
- used to limit the access or legal rights of the compilation's users
275
- beyond what the individual works permit. Inclusion of a covered work
276
- in an aggregate does not cause this License to apply to the other
277
- parts of the aggregate.
278
-
279
- 6. Conveying Non-Source Forms.
280
-
281
- You may convey a covered work in object code form under the terms
282
- of sections 4 and 5, provided that you also convey the
283
- machine-readable Corresponding Source under the terms of this License,
284
- in one of these ways:
285
-
286
- a) Convey the object code in, or embodied in, a physical product
287
- (including a physical distribution medium), accompanied by the
288
- Corresponding Source fixed on a durable physical medium
289
- customarily used for software interchange.
290
-
291
- b) Convey the object code in, or embodied in, a physical product
292
- (including a physical distribution medium), accompanied by a
293
- written offer, valid for at least three years and valid for as
294
- long as you offer spare parts or customer support for that product
295
- model, to give anyone who possesses the object code either (1) a
296
- copy of the Corresponding Source for all the software in the
297
- product that is covered by this License, on a durable physical
298
- medium customarily used for software interchange, for a price no
299
- more than your reasonable cost of physically performing this
300
- conveying of source, or (2) access to copy the
301
- Corresponding Source from a network server at no charge.
302
-
303
- c) Convey individual copies of the object code with a copy of the
304
- written offer to provide the Corresponding Source. This
305
- alternative is allowed only occasionally and noncommercially, and
306
- only if you received the object code with such an offer, in accord
307
- with subsection 6b.
308
-
309
- d) Convey the object code by offering access from a designated
310
- place (gratis or for a charge), and offer equivalent access to the
311
- Corresponding Source in the same way through the same place at no
312
- further charge. You need not require recipients to copy the
313
- Corresponding Source along with the object code. If the place to
314
- copy the object code is a network server, the Corresponding Source
315
- may be on a different server (operated by you or a third party)
316
- that supports equivalent copying facilities, provided you maintain
317
- clear directions next to the object code saying where to find the
318
- Corresponding Source. Regardless of what server hosts the
319
- Corresponding Source, you remain obligated to ensure that it is
320
- available for as long as needed to satisfy these requirements.
321
-
322
- e) Convey the object code using peer-to-peer transmission, provided
323
- you inform other peers where the object code and Corresponding
324
- Source of the work are being offered to the general public at no
325
- charge under subsection 6d.
326
-
327
- A separable portion of the object code, whose source code is excluded
328
- from the Corresponding Source as a System Library, need not be
329
- included in conveying the object code work.
330
-
331
- A "User Product" is either (1) a "consumer product", which means any
332
- tangible personal property which is normally used for personal, family,
333
- or household purposes, or (2) anything designed or sold for incorporation
334
- into a dwelling. In determining whether a product is a consumer product,
335
- doubtful cases shall be resolved in favor of coverage. For a particular
336
- product received by a particular user, "normally used" refers to a
337
- typical or common use of that class of product, regardless of the status
338
- of the particular user or of the way in which the particular user
339
- actually uses, or expects or is expected to use, the product. A product
340
- is a consumer product regardless of whether the product has substantial
341
- commercial, industrial or non-consumer uses, unless such uses represent
342
- the only significant mode of use of the product.
343
-
344
- "Installation Information" for a User Product means any methods,
345
- procedures, authorization keys, or other information required to install
346
- and execute modified versions of a covered work in that User Product from
347
- a modified version of its Corresponding Source. The information must
348
- suffice to ensure that the continued functioning of the modified object
349
- code is in no case prevented or interfered with solely because
350
- modification has been made.
351
-
352
- If you convey an object code work under this section in, or with, or
353
- specifically for use in, a User Product, and the conveying occurs as
354
- part of a transaction in which the right of possession and use of the
355
- User Product is transferred to the recipient in perpetuity or for a
356
- fixed term (regardless of how the transaction is characterized), the
357
- Corresponding Source conveyed under this section must be accompanied
358
- by the Installation Information. But this requirement does not apply
359
- if neither you nor any third party retains the ability to install
360
- modified object code on the User Product (for example, the work has
361
- been installed in ROM).
362
-
363
- The requirement to provide Installation Information does not include a
364
- requirement to continue to provide support service, warranty, or updates
365
- for a work that has been modified or installed by the recipient, or for
366
- the User Product in which it has been modified or installed. Access to a
367
- network may be denied when the modification itself materially and
368
- adversely affects the operation of the network or violates the rules and
369
- protocols for communication across the network.
370
-
371
- Corresponding Source conveyed, and Installation Information provided,
372
- in accord with this section must be in a format that is publicly
373
- documented (and with an implementation available to the public in
374
- source code form), and must require no special password or key for
375
- unpacking, reading or copying.
376
-
377
- 7. Additional Terms.
378
-
379
- "Additional permissions" are terms that supplement the terms of this
380
- License by making exceptions from one or more of its conditions.
381
- Additional permissions that are applicable to the entire Program shall
382
- be treated as though they were included in this License, to the extent
383
- that they are valid under applicable law. If additional permissions
384
- apply only to part of the Program, that part may be used separately
385
- under those permissions, but the entire Program remains governed by
386
- this License without regard to the additional permissions.
387
-
388
- When you convey a copy of a covered work, you may at your option
389
- remove any additional permissions from that copy, or from any part of
390
- it. (Additional permissions may be written to require their own
391
- removal in certain cases when you modify the work.) You may place
392
- additional permissions on material, added by you to a covered work,
393
- for which you have or can give appropriate copyright permission.
394
-
395
- Notwithstanding any other provision of this License, for material you
396
- add to a covered work, you may (if authorized by the copyright holders of
397
- that material) supplement the terms of this License with terms:
398
-
399
- a) Disclaiming warranty or limiting liability differently from the
400
- terms of sections 15 and 16 of this License; or
401
-
402
- b) Requiring preservation of specified reasonable legal notices or
403
- author attributions in that material or in the Appropriate Legal
404
- Notices displayed by works containing it; or
405
-
406
- c) Prohibiting misrepresentation of the origin of that material, or
407
- requiring that modified versions of such material be marked in
408
- reasonable ways as different from the original version; or
409
-
410
- d) Limiting the use for publicity purposes of names of licensors or
411
- authors of the material; or
412
-
413
- e) Declining to grant rights under trademark law for use of some
414
- trade names, trademarks, or service marks; or
415
-
416
- f) Requiring indemnification of licensors and authors of that
417
- material by anyone who conveys the material (or modified versions of
418
- it) with contractual assumptions of liability to the recipient, for
419
- any liability that these contractual assumptions directly impose on
420
- those licensors and authors.
421
-
422
- All other non-permissive additional terms are considered "further
423
- restrictions" within the meaning of section 10. If the Program as you
424
- received it, or any part of it, contains a notice stating that it is
425
- governed by this License along with a term that is a further
426
- restriction, you may remove that term. If a license document contains
427
- a further restriction but permits relicensing or conveying under this
428
- License, you may add to a covered work material governed by the terms
429
- of that license document, provided that the further restriction does
430
- not survive such relicensing or conveying.
431
-
432
- If you add terms to a covered work in accord with this section, you
433
- must place, in the relevant source files, a statement of the
434
- additional terms that apply to those files, or a notice indicating
435
- where to find the applicable terms.
436
-
437
- Additional terms, permissive or non-permissive, may be stated in the
438
- form of a separately written license, or stated as exceptions;
439
- the above requirements apply either way.
440
-
441
- 8. Termination.
442
-
443
- You may not propagate or modify a covered work except as expressly
444
- provided under this License. Any attempt otherwise to propagate or
445
- modify it is void, and will automatically terminate your rights under
446
- this License (including any patent licenses granted under the third
447
- paragraph of section 11).
448
-
449
- However, if you cease all violation of this License, then your
450
- license from a particular copyright holder is reinstated (a)
451
- provisionally, unless and until the copyright holder explicitly and
452
- finally terminates your license, and (b) permanently, if the copyright
453
- holder fails to notify you of the violation by some reasonable means
454
- prior to 60 days after the cessation.
455
-
456
- Moreover, your license from a particular copyright holder is
457
- reinstated permanently if the copyright holder notifies you of the
458
- violation by some reasonable means, this is the first time you have
459
- received notice of violation of this License (for any work) from that
460
- copyright holder, and you cure the violation prior to 30 days after
461
- your receipt of the notice.
462
-
463
- Termination of your rights under this section does not terminate the
464
- licenses of parties who have received copies or rights from you under
465
- this License. If your rights have been terminated and not permanently
466
- reinstated, you do not qualify to receive new licenses for the same
467
- material under section 10.
468
-
469
- 9. Acceptance Not Required for Having Copies.
470
-
471
- You are not required to accept this License in order to receive or
472
- run a copy of the Program. Ancillary propagation of a covered work
473
- occurring solely as a consequence of using peer-to-peer transmission
474
- to receive a copy likewise does not require acceptance. However,
475
- nothing other than this License grants you permission to propagate or
476
- modify any covered work. These actions infringe copyright if you do
477
- not accept this License. Therefore, by modifying or propagating a
478
- covered work, you indicate your acceptance of this License to do so.
479
-
480
- 10. Automatic Licensing of Downstream Recipients.
481
-
482
- Each time you convey a covered work, the recipient automatically
483
- receives a license from the original licensors, to run, modify and
484
- propagate that work, subject to this License. You are not responsible
485
- for enforcing compliance by third parties with this License.
486
-
487
- An "entity transaction" is a transaction transferring control of an
488
- organization, or substantially all assets of one, or subdividing an
489
- organization, or merging organizations. If propagation of a covered
490
- work results from an entity transaction, each party to that
491
- transaction who receives a copy of the work also receives whatever
492
- licenses to the work the party's predecessor in interest had or could
493
- give under the previous paragraph, plus a right to possession of the
494
- Corresponding Source of the work from the predecessor in interest, if
495
- the predecessor has it or can get it with reasonable efforts.
496
-
497
- You may not impose any further restrictions on the exercise of the
498
- rights granted or affirmed under this License. For example, you may
499
- not impose a license fee, royalty, or other charge for exercise of
500
- rights granted under this License, and you may not initiate litigation
501
- (including a cross-claim or counterclaim in a lawsuit) alleging that
502
- any patent claim is infringed by making, using, selling, offering for
503
- sale, or importing the Program or any portion of it.
504
-
505
- 11. Patents.
506
-
507
- A "contributor" is a copyright holder who authorizes use under this
508
- License of the Program or a work on which the Program is based. The
509
- work thus licensed is called the contributor's "contributor version".
510
-
511
- A contributor's "essential patent claims" are all patent claims
512
- owned or controlled by the contributor, whether already acquired or
513
- hereafter acquired, that would be infringed by some manner, permitted
514
- by this License, of making, using, or selling its contributor version,
515
- but do not include claims that would be infringed only as a
516
- consequence of further modification of the contributor version. For
517
- purposes of this definition, "control" includes the right to grant
518
- patent sublicenses in a manner consistent with the requirements of
519
- this License.
520
-
521
- Each contributor grants you a non-exclusive, worldwide, royalty-free
522
- patent license under the contributor's essential patent claims, to
523
- make, use, sell, offer for sale, import and otherwise run, modify and
524
- propagate the contents of its contributor version.
525
-
526
- In the following three paragraphs, a "patent license" is any express
527
- agreement or commitment, however denominated, not to enforce a patent
528
- (such as an express permission to practice a patent or covenant not to
529
- sue for patent infringement). To "grant" such a patent license to a
530
- party means to make such an agreement or commitment not to enforce a
531
- patent against the party.
532
-
533
- If you convey a covered work, knowingly relying on a patent license,
534
- and the Corresponding Source of the work is not available for anyone
535
- to copy, free of charge and under the terms of this License, through a
536
- publicly available network server or other readily accessible means,
537
- then you must either (1) cause the Corresponding Source to be so
538
- available, or (2) arrange to deprive yourself of the benefit of the
539
- patent license for this particular work, or (3) arrange, in a manner
540
- consistent with the requirements of this License, to extend the patent
541
- license to downstream recipients. "Knowingly relying" means you have
542
- actual knowledge that, but for the patent license, your conveying the
543
- covered work in a country, or your recipient's use of the covered work
544
- in a country, would infringe one or more identifiable patents in that
545
- country that you have reason to believe are valid.
546
-
547
- If, pursuant to or in connection with a single transaction or
548
- arrangement, you convey, or propagate by procuring conveyance of, a
549
- covered work, and grant a patent license to some of the parties
550
- receiving the covered work authorizing them to use, propagate, modify
551
- or convey a specific copy of the covered work, then the patent license
552
- you grant is automatically extended to all recipients of the covered
553
- work and works based on it.
554
-
555
- A patent license is "discriminatory" if it does not include within
556
- the scope of its coverage, prohibits the exercise of, or is
557
- conditioned on the non-exercise of one or more of the rights that are
558
- specifically granted under this License. You may not convey a covered
559
- work if you are a party to an arrangement with a third party that is
560
- in the business of distributing software, under which you make payment
561
- to the third party based on the extent of your activity of conveying
562
- the work, and under which the third party grants, to any of the
563
- parties who would receive the covered work from you, a discriminatory
564
- patent license (a) in connection with copies of the covered work
565
- conveyed by you (or copies made from those copies), or (b) primarily
566
- for and in connection with specific products or compilations that
567
- contain the covered work, unless you entered into that arrangement,
568
- or that patent license was granted, prior to 28 March 2007.
569
-
570
- Nothing in this License shall be construed as excluding or limiting
571
- any implied license or other defenses to infringement that may
572
- otherwise be available to you under applicable patent law.
573
-
574
- 12. No Surrender of Others' Freedom.
575
-
576
- If conditions are imposed on you (whether by court order, agreement or
577
- otherwise) that contradict the conditions of this License, they do not
578
- excuse you from the conditions of this License. If you cannot convey a
579
- covered work so as to satisfy simultaneously your obligations under this
580
- License and any other pertinent obligations, then as a consequence you may
581
- not convey it at all. For example, if you agree to terms that obligate you
582
- to collect a royalty for further conveying from those to whom you convey
583
- the Program, the only way you could satisfy both those terms and this
584
- License would be to refrain entirely from conveying the Program.
585
-
586
- 13. Use with the GNU Affero General Public License.
587
-
588
- Notwithstanding any other provision of this License, you have
589
- permission to link or combine any covered work with a work licensed
590
- under version 3 of the GNU Affero General Public License into a single
591
- combined work, and to convey the resulting work. The terms of this
592
- License will continue to apply to the part which is the covered work,
593
- but the special requirements of the GNU Affero General Public License,
594
- section 13, concerning interaction through a network will apply to the
595
- combination as such.
596
-
597
- 14. Revised Versions of this License.
598
-
599
- The Free Software Foundation may publish revised and/or new versions of
600
- the GNU General Public License from time to time. Such new versions will
601
- be similar in spirit to the present version, but may differ in detail to
602
- address new problems or concerns.
603
-
604
- Each version is given a distinguishing version number. If the
605
- Program specifies that a certain numbered version of the GNU General
606
- Public License "or any later version" applies to it, you have the
607
- option of following the terms and conditions either of that numbered
608
- version or of any later version published by the Free Software
609
- Foundation. If the Program does not specify a version number of the
610
- GNU General Public License, you may choose any version ever published
611
- by the Free Software Foundation.
612
-
613
- If the Program specifies that a proxy can decide which future
614
- versions of the GNU General Public License can be used, that proxy's
615
- public statement of acceptance of a version permanently authorizes you
616
- to choose that version for the Program.
617
-
618
- Later license versions may give you additional or different
619
- permissions. However, no additional obligations are imposed on any
620
- author or copyright holder as a result of your choosing to follow a
621
- later version.
622
-
623
- 15. Disclaimer of Warranty.
624
-
625
- THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
626
- APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
627
- HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
628
- OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
629
- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
630
- PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
631
- IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
632
- ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
633
-
634
- 16. Limitation of Liability.
635
-
636
- IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
637
- WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
638
- THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
639
- GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
640
- USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
641
- DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
642
- PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
643
- EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
644
- SUCH DAMAGES.
645
-
646
- 17. Interpretation of Sections 15 and 16.
647
-
648
- If the disclaimer of warranty and limitation of liability provided
649
- above cannot be given local legal effect according to their terms,
650
- reviewing courts shall apply local law that most closely approximates
651
- an absolute waiver of all civil liability in connection with the
652
- Program, unless a warranty or assumption of liability accompanies a
653
- copy of the Program in return for a fee.
654
-
655
- END OF TERMS AND CONDITIONS
656
-
657
- How to Apply These Terms to Your New Programs
658
-
659
- If you develop a new program, and you want it to be of the greatest
660
- possible use to the public, the best way to achieve this is to make it
661
- free software which everyone can redistribute and change under these terms.
662
-
663
- To do so, attach the following notices to the program. It is safest
664
- to attach them to the start of each source file to most effectively
665
- state the exclusion of warranty; and each file should have at least
666
- the "copyright" line and a pointer to where the full notice is found.
667
-
668
- <one line to give the program's name and a brief idea of what it does.>
669
- Copyright © <year> <name of author>
670
-
671
- This program is free software: you can redistribute it and/or modify
672
- it under the terms of the GNU General Public License as published by
673
- the Free Software Foundation, either version 3 of the License, or
674
- (at your option) any later version.
675
-
676
- This program is distributed in the hope that it will be useful,
677
- but WITHOUT ANY WARRANTY; without even the implied warranty of
678
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
679
- GNU General Public License for more details.
680
-
681
- You should have received a copy of the GNU General Public License
682
- along with this program. If not, see <http://www.gnu.org/licenses/>.
683
-
684
- Also add information on how to contact you by electronic and paper mail.
685
-
686
- If the program does terminal interaction, make it output a short
687
- notice like this when it starts in an interactive mode:
688
-
689
- <program> Copyright © <year> <name of author>
690
- This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
691
- This is free software, and you are welcome to redistribute it
692
- under certain conditions; type `show c' for details.
693
-
694
- The hypothetical commands `show w' and `show c' should show the appropriate
695
- parts of the General Public License. Of course, your program's commands
696
- might be different; for a GUI interface, you would use an "about box".
697
-
698
- You should also get your employer (if you work as a programmer) or school,
699
- if any, to sign a "copyright disclaimer" for the program, if necessary.
700
- For more information on this, and how to apply and follow the GNU GPL, see
701
- <http://www.gnu.org/licenses/>.
702
-
703
- The GNU General Public License does not permit incorporating your program
704
- into proprietary programs. If your program is a subroutine library, you
705
- may consider it more useful to permit linking proprietary applications with
706
- the library. If this is what you want to do, use the GNU Lesser General
707
- Public License instead of this License. But first, please read
708
  <http://www.gnu.org/philosophy/why-not-lgpl.html>.
1
+ Product CSV Import Export For WooCommerce
2
+
3
+ Copyright 2015 by the contributors
4
+
5
+ This program is free software; you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation; either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program; if not, write to the Free Software
17
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
+
19
+ This program incorporates work covered by the following copyright and
20
+ permission notices:
21
+
22
+ WooCommerce Product CSV Import Suite
23
+ Copyright: 2009-2011 WooThemes.
24
+ License: GNU General Public License v3.0
25
+ License URI: http://www.gnu.org/licenses/gpl-3.0.html
26
+
27
+ and
28
+
29
+ HikeForce
30
+
31
+ Product CSV Import Export For WooCommerce is released under the GPL
32
+
33
+ =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
34
+
35
+ GNU GENERAL PUBLIC LICENSE
36
+ Version 3, 29 June 2007
37
+
38
+ Copyright © 2007 Free Software Foundation, Inc. <http://fsf.org/>
39
+ Everyone is permitted to copy and distribute verbatim copies
40
+ of this license document, but changing it is not allowed.
41
+
42
+ Preamble
43
+
44
+ The GNU General Public License is a free, copyleft license for
45
+ software and other kinds of works.
46
+
47
+ The licenses for most software and other practical works are designed
48
+ to take away your freedom to share and change the works. By contrast,
49
+ the GNU General Public License is intended to guarantee your freedom to
50
+ share and change all versions of a program--to make sure it remains free
51
+ software for all its users. We, the Free Software Foundation, use the
52
+ GNU General Public License for most of our software; it applies also to
53
+ any other work released this way by its authors. You can apply it to
54
+ your programs, too.
55
+
56
+ When we speak of free software, we are referring to freedom, not
57
+ price. Our General Public Licenses are designed to make sure that you
58
+ have the freedom to distribute copies of free software (and charge for
59
+ them if you wish), that you receive source code or can get it if you
60
+ want it, that you can change the software or use pieces of it in new
61
+ free programs, and that you know you can do these things.
62
+
63
+ To protect your rights, we need to prevent others from denying you
64
+ these rights or asking you to surrender the rights. Therefore, you have
65
+ certain responsibilities if you distribute copies of the software, or if
66
+ you modify it: responsibilities to respect the freedom of others.
67
+
68
+ For example, if you distribute copies of such a program, whether
69
+ gratis or for a fee, you must pass on to the recipients the same
70
+ freedoms that you received. You must make sure that they, too, receive
71
+ or can get the source code. And you must show them these terms so they
72
+ know their rights.
73
+
74
+ Developers that use the GNU GPL protect your rights with two steps:
75
+ (1) assert copyright on the software, and (2) offer you this License
76
+ giving you legal permission to copy, distribute and/or modify it.
77
+
78
+ For the developers' and authors' protection, the GPL clearly explains
79
+ that there is no warranty for this free software. For both users' and
80
+ authors' sake, the GPL requires that modified versions be marked as
81
+ changed, so that their problems will not be attributed erroneously to
82
+ authors of previous versions.
83
+
84
+ Some devices are designed to deny users access to install or run
85
+ modified versions of the software inside them, although the manufacturer
86
+ can do so. This is fundamentally incompatible with the aim of
87
+ protecting users' freedom to change the software. The systematic
88
+ pattern of such abuse occurs in the area of products for individuals to
89
+ use, which is precisely where it is most unacceptable. Therefore, we
90
+ have designed this version of the GPL to prohibit the practice for those
91
+ products. If such problems arise substantially in other domains, we
92
+ stand ready to extend this provision to those domains in future versions
93
+ of the GPL, as needed to protect the freedom of users.
94
+
95
+ Finally, every program is threatened constantly by software patents.
96
+ States should not allow patents to restrict development and use of
97
+ software on general-purpose computers, but in those that do, we wish to
98
+ avoid the special danger that patents applied to a free program could
99
+ make it effectively proprietary. To prevent this, the GPL assures that
100
+ patents cannot be used to render the program non-free.
101
+
102
+ The precise terms and conditions for copying, distribution and
103
+ modification follow.
104
+
105
+ TERMS AND CONDITIONS
106
+
107
+ 0. Definitions.
108
+
109
+ "This License" refers to version 3 of the GNU General Public License.
110
+
111
+ "Copyright" also means copyright-like laws that apply to other kinds of
112
+ works, such as semiconductor masks.
113
+
114
+ "The Program" refers to any copyrightable work licensed under this
115
+ License. Each licensee is addressed as "you". "Licensees" and
116
+ "recipients" may be individuals or organizations.
117
+
118
+ To "modify" a work means to copy from or adapt all or part of the work
119
+ in a fashion requiring copyright permission, other than the making of an
120
+ exact copy. The resulting work is called a "modified version" of the
121
+ earlier work or a work "based on" the earlier work.
122
+
123
+ A "covered work" means either the unmodified Program or a work based
124
+ on the Program.
125
+
126
+ To "propagate" a work means to do anything with it that, without
127
+ permission, would make you directly or secondarily liable for
128
+ infringement under applicable copyright law, except executing it on a
129
+ computer or modifying a private copy. Propagation includes copying,
130
+ distribution (with or without modification), making available to the
131
+ public, and in some countries other activities as well.
132
+
133
+ To "convey" a work means any kind of propagation that enables other
134
+ parties to make or receive copies. Mere interaction with a user through
135
+ a computer network, with no transfer of a copy, is not conveying.
136
+
137
+ An interactive user interface displays "Appropriate Legal Notices"
138
+ to the extent that it includes a convenient and prominently visible
139
+ feature that (1) displays an appropriate copyright notice, and (2)
140
+ tells the user that there is no warranty for the work (except to the
141
+ extent that warranties are provided), that licensees may convey the
142
+ work under this License, and how to view a copy of this License. If
143
+ the interface presents a list of user commands or options, such as a
144
+ menu, a prominent item in the list meets this criterion.
145
+
146
+ 1. Source Code.
147
+
148
+ The "source code" for a work means the preferred form of the work
149
+ for making modifications to it. "Object code" means any non-source
150
+ form of a work.
151
+
152
+ A "Standard Interface" means an interface that either is an official
153
+ standard defined by a recognized standards body, or, in the case of
154
+ interfaces specified for a particular programming language, one that
155
+ is widely used among developers working in that language.
156
+
157
+ The "System Libraries" of an executable work include anything, other
158
+ than the work as a whole, that (a) is included in the normal form of
159
+ packaging a Major Component, but which is not part of that Major
160
+ Component, and (b) serves only to enable use of the work with that
161
+ Major Component, or to implement a Standard Interface for which an
162
+ implementation is available to the public in source code form. A
163
+ "Major Component", in this context, means a major essential component
164
+ (kernel, window system, and so on) of the specific operating system
165
+ (if any) on which the executable work runs, or a compiler used to
166
+ produce the work, or an object code interpreter used to run it.
167
+
168
+ The "Corresponding Source" for a work in object code form means all
169
+ the source code needed to generate, install, and (for an executable
170
+ work) run the object code and to modify the work, including scripts to
171
+ control those activities. However, it does not include the work's
172
+ System Libraries, or general-purpose tools or generally available free
173
+ programs which are used unmodified in performing those activities but
174
+ which are not part of the work. For example, Corresponding Source
175
+ includes interface definition files associated with source files for
176
+ the work, and the source code for shared libraries and dynamically
177
+ linked subprograms that the work is specifically designed to require,
178
+ such as by intimate data communication or control flow between those
179
+ subprograms and other parts of the work.
180
+
181
+ The Corresponding Source need not include anything that users
182
+ can regenerate automatically from other parts of the Corresponding
183
+ Source.
184
+
185
+ The Corresponding Source for a work in source code form is that
186
+ same work.
187
+
188
+ 2. Basic Permissions.
189
+
190
+ All rights granted under this License are granted for the term of
191
+ copyright on the Program, and are irrevocable provided the stated
192
+ conditions are met. This License explicitly affirms your unlimited
193
+ permission to run the unmodified Program. The output from running a
194
+ covered work is covered by this License only if the output, given its
195
+ content, constitutes a covered work. This License acknowledges your
196
+ rights of fair use or other equivalent, as provided by copyright law.
197
+
198
+ You may make, run and propagate covered works that you do not
199
+ convey, without conditions so long as your license otherwise remains
200
+ in force. You may convey covered works to others for the sole purpose
201
+ of having them make modifications exclusively for you, or provide you
202
+ with facilities for running those works, provided that you comply with
203
+ the terms of this License in conveying all material for which you do
204
+ not control copyright. Those thus making or running the covered works
205
+ for you must do so exclusively on your behalf, under your direction
206
+ and control, on terms that prohibit them from making any copies of
207
+ your copyrighted material outside their relationship with you.
208
+
209
+ Conveying under any other circumstances is permitted solely under
210
+ the conditions stated below. Sublicensing is not allowed; section 10
211
+ makes it unnecessary.
212
+
213
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
214
+
215
+ No covered work shall be deemed part of an effective technological
216
+ measure under any applicable law fulfilling obligations under article
217
+ 11 of the WIPO copyright treaty adopted on 20 December 1996, or
218
+ similar laws prohibiting or restricting circumvention of such
219
+ measures.
220
+
221
+ When you convey a covered work, you waive any legal power to forbid
222
+ circumvention of technological measures to the extent such circumvention
223
+ is effected by exercising rights under this License with respect to
224
+ the covered work, and you disclaim any intention to limit operation or
225
+ modification of the work as a means of enforcing, against the work's
226
+ users, your or third parties' legal rights to forbid circumvention of
227
+ technological measures.
228
+
229
+ 4. Conveying Verbatim Copies.
230
+
231
+ You may convey verbatim copies of the Program's source code as you
232
+ receive it, in any medium, provided that you conspicuously and
233
+ appropriately publish on each copy an appropriate copyright notice;
234
+ keep intact all notices stating that this License and any
235
+ non-permissive terms added in accord with section 7 apply to the code;
236
+ keep intact all notices of the absence of any warranty; and give all
237
+ recipients a copy of this License along with the Program.
238
+
239
+ You may charge any price or no price for each copy that you convey,
240
+ and you may offer support or warranty protection for a fee.
241
+
242
+ 5. Conveying Modified Source Versions.
243
+
244
+ You may convey a work based on the Program, or the modifications to
245
+ produce it from the Program, in the form of source code under the
246
+ terms of section 4, provided that you also meet all of these conditions:
247
+
248
+ a) The work must carry prominent notices stating that you modified
249
+ it, and giving a relevant date.
250
+
251
+ b) The work must carry prominent notices stating that it is
252
+ released under this License and any conditions added under section
253
+ 7. This requirement modifies the requirement in section 4 to
254
+ "keep intact all notices".
255
+
256
+ c) You must license the entire work, as a whole, under this
257
+ License to anyone who comes into possession of a copy. This
258
+ License will therefore apply, along with any applicable section 7
259
+ additional terms, to the whole of the work, and all its parts,
260
+ regardless of how they are packaged. This License gives no
261
+ permission to license the work in any other way, but it does not
262
+ invalidate such permission if you have separately received it.
263
+
264
+ d) If the work has interactive user interfaces, each must display
265
+ Appropriate Legal Notices; however, if the Program has interactive
266
+ interfaces that do not display Appropriate Legal Notices, your
267
+ work need not make them do so.
268
+
269
+ A compilation of a covered work with other separate and independent
270
+ works, which are not by their nature extensions of the covered work,
271
+ and which are not combined with it such as to form a larger program,
272
+ in or on a volume of a storage or distribution medium, is called an
273
+ "aggregate" if the compilation and its resulting copyright are not
274
+ used to limit the access or legal rights of the compilation's users
275
+ beyond what the individual works permit. Inclusion of a covered work
276
+ in an aggregate does not cause this License to apply to the other
277
+ parts of the aggregate.
278
+
279
+ 6. Conveying Non-Source Forms.
280
+
281
+ You may convey a covered work in object code form under the terms
282
+ of sections 4 and 5, provided that you also convey the
283
+ machine-readable Corresponding Source under the terms of this License,
284
+ in one of these ways:
285
+
286
+ a) Convey the object code in, or embodied in, a physical product
287
+ (including a physical distribution medium), accompanied by the
288
+ Corresponding Source fixed on a durable physical medium
289
+ customarily used for software interchange.
290
+
291
+ b) Convey the object code in, or embodied in, a physical product
292
+ (including a physical distribution medium), accompanied by a
293
+ written offer, valid for at least three years and valid for as
294
+ long as you offer spare parts or customer support for that product
295
+ model, to give anyone who possesses the object code either (1) a
296
+ copy of the Corresponding Source for all the software in the
297
+ product that is covered by this License, on a durable physical
298
+ medium customarily used for software interchange, for a price no
299
+ more than your reasonable cost of physically performing this
300
+ conveying of source, or (2) access to copy the
301
+ Corresponding Source from a network server at no charge.
302
+
303
+ c) Convey individual copies of the object code with a copy of the
304
+ written offer to provide the Corresponding Source. This
305
+ alternative is allowed only occasionally and noncommercially, and
306
+ only if you received the object code with such an offer, in accord
307
+ with subsection 6b.
308
+
309
+ d) Convey the object code by offering access from a designated
310
+ place (gratis or for a charge), and offer equivalent access to the
311
+ Corresponding Source in the same way through the same place at no
312
+ further charge. You need not require recipients to copy the
313
+ Corresponding Source along with the object code. If the place to
314
+ copy the object code is a network server, the Corresponding Source
315
+ may be on a different server (operated by you or a third party)
316
+ that supports equivalent copying facilities, provided you maintain
317
+ clear directions next to the object code saying where to find the
318
+ Corresponding Source. Regardless of what server hosts the
319
+ Corresponding Source, you remain obligated to ensure that it is
320
+ available for as long as needed to satisfy these requirements.
321
+
322
+ e) Convey the object code using peer-to-peer transmission, provided
323
+ you inform other peers where the object code and Corresponding
324
+ Source of the work are being offered to the general public at no
325
+ charge under subsection 6d.
326
+
327
+ A separable portion of the object code, whose source code is excluded
328
+ from the Corresponding Source as a System Library, need not be
329
+ included in conveying the object code work.
330
+
331
+ A "User Product" is either (1) a "consumer product", which means any
332
+ tangible personal property which is normally used for personal, family,
333
+ or household purposes, or (2) anything designed or sold for incorporation
334
+ into a dwelling. In determining whether a product is a consumer product,
335
+ doubtful cases shall be resolved in favor of coverage. For a particular
336
+ product received by a particular user, "normally used" refers to a
337
+ typical or common use of that class of product, regardless of the status
338
+ of the particular user or of the way in which the particular user
339
+ actually uses, or expects or is expected to use, the product. A product
340
+ is a consumer product regardless of whether the product has substantial
341
+ commercial, industrial or non-consumer uses, unless such uses represent
342
+ the only significant mode of use of the product.
343
+
344
+ "Installation Information" for a User Product means any methods,
345
+ procedures, authorization keys, or other information required to install
346
+ and execute modified versions of a covered work in that User Product from
347
+ a modified version of its Corresponding Source. The information must
348
+ suffice to ensure that the continued functioning of the modified object
349
+ code is in no case prevented or interfered with solely because
350
+ modification has been made.
351
+
352
+ If you convey an object code work under this section in, or with, or
353
+ specifically for use in, a User Product, and the conveying occurs as
354
+ part of a transaction in which the right of possession and use of the
355
+ User Product is transferred to the recipient in perpetuity or for a
356
+ fixed term (regardless of how the transaction is characterized), the
357
+ Corresponding Source conveyed under this section must be accompanied
358
+ by the Installation Information. But this requirement does not apply
359
+ if neither you nor any third party retains the ability to install
360
+ modified object code on the User Product (for example, the work has
361
+ been installed in ROM).
362
+
363
+ The requirement to provide Installation Information does not include a
364
+ requirement to continue to provide support service, warranty, or updates
365
+ for a work that has been modified or installed by the recipient, or for
366
+ the User Product in which it has been modified or installed. Access to a
367
+ network may be denied when the modification itself materially and
368
+ adversely affects the operation of the network or violates the rules and
369
+ protocols for communication across the network.
370
+
371
+ Corresponding Source conveyed, and Installation Information provided,
372
+ in accord with this section must be in a format that is publicly
373
+ documented (and with an implementation available to the public in
374
+ source code form), and must require no special password or key for
375
+ unpacking, reading or copying.
376
+
377
+ 7. Additional Terms.
378
+
379
+ "Additional permissions" are terms that supplement the terms of this
380
+ License by making exceptions from one or more of its conditions.
381
+ Additional permissions that are applicable to the entire Program shall
382
+ be treated as though they were included in this License, to the extent
383
+ that they are valid under applicable law. If additional permissions
384
+ apply only to part of the Program, that part may be used separately
385
+ under those permissions, but the entire Program remains governed by
386
+ this License without regard to the additional permissions.
387
+
388
+ When you convey a copy of a covered work, you may at your option
389
+ remove any additional permissions from that copy, or from any part of
390
+ it. (Additional permissions may be written to require their own
391
+ removal in certain cases when you modify the work.) You may place
392
+ additional permissions on material, added by you to a covered work,
393
+ for which you have or can give appropriate copyright permission.
394
+
395
+ Notwithstanding any other provision of this License, for material you
396
+ add to a covered work, you may (if authorized by the copyright holders of
397
+ that material) supplement the terms of this License with terms:
398
+
399
+ a) Disclaiming warranty or limiting liability differently from the
400
+ terms of sections 15 and 16 of this License; or
401
+
402
+ b) Requiring preservation of specified reasonable legal notices or
403
+ author attributions in that material or in the Appropriate Legal
404
+ Notices displayed by works containing it; or
405
+
406
+ c) Prohibiting misrepresentation of the origin of that material, or
407
+ requiring that modified versions of such material be marked in
408
+ reasonable ways as different from the original version; or
409
+
410
+ d) Limiting the use for publicity purposes of names of licensors or
411
+ authors of the material; or
412
+
413
+ e) Declining to grant rights under trademark law for use of some
414
+ trade names, trademarks, or service marks; or
415
+
416
+ f) Requiring indemnification of licensors and authors of that
417
+ material by anyone who conveys the material (or modified versions of
418
+ it) with contractual assumptions of liability to the recipient, for
419
+ any liability that these contractual assumptions directly impose on
420
+ those licensors and authors.
421
+
422
+ All other non-permissive additional terms are considered "further
423
+ restrictions" within the meaning of section 10. If the Program as you
424
+ received it, or any part of it, contains a notice stating that it is
425
+ governed by this License along with a term that is a further
426
+ restriction, you may remove that term. If a license document contains
427
+ a further restriction but permits relicensing or conveying under this
428
+ License, you may add to a covered work material governed by the terms
429
+ of that license document, provided that the further restriction does
430
+ not survive such relicensing or conveying.
431
+
432
+ If you add terms to a covered work in accord with this section, you
433
+ must place, in the relevant source files, a statement of the
434
+ additional terms that apply to those files, or a notice indicating
435
+ where to find the applicable terms.
436
+
437
+ Additional terms, permissive or non-permissive, may be stated in the
438
+ form of a separately written license, or stated as exceptions;
439
+ the above requirements apply either way.
440
+
441
+ 8. Termination.
442
+
443
+ You may not propagate or modify a covered work except as expressly
444
+ provided under this License. Any attempt otherwise to propagate or
445
+ modify it is void, and will automatically terminate your rights under
446
+ this License (including any patent licenses granted under the third
447
+ paragraph of section 11).
448
+
449
+ However, if you cease all violation of this License, then your
450
+ license from a particular copyright holder is reinstated (a)
451
+ provisionally, unless and until the copyright holder explicitly and
452
+ finally terminates your license, and (b) permanently, if the copyright
453
+ holder fails to notify you of the violation by some reasonable means
454
+ prior to 60 days after the cessation.
455
+
456
+ Moreover, your license from a particular copyright holder is
457
+ reinstated permanently if the copyright holder notifies you of the
458
+ violation by some reasonable means, this is the first time you have
459
+ received notice of violation of this License (for any work) from that
460
+ copyright holder, and you cure the violation prior to 30 days after
461
+ your receipt of the notice.
462
+
463
+ Termination of your rights under this section does not terminate the
464
+ licenses of parties who have received copies or rights from you under
465
+ this License. If your rights have been terminated and not permanently
466
+ reinstated, you do not qualify to receive new licenses for the same
467
+ material under section 10.
468
+
469
+ 9. Acceptance Not Required for Having Copies.
470
+
471
+ You are not required to accept this License in order to receive or
472
+ run a copy of the Program. Ancillary propagation of a covered work
473
+ occurring solely as a consequence of using peer-to-peer transmission
474
+ to receive a copy likewise does not require acceptance. However,
475
+ nothing other than this License grants you permission to propagate or
476
+ modify any covered work. These actions infringe copyright if you do
477
+ not accept this License. Therefore, by modifying or propagating a
478
+ covered work, you indicate your acceptance of this License to do so.
479
+
480
+ 10. Automatic Licensing of Downstream Recipients.
481
+
482
+ Each time you convey a covered work, the recipient automatically
483
+ receives a license from the original licensors, to run, modify and
484
+ propagate that work, subject to this License. You are not responsible
485
+ for enforcing compliance by third parties with this License.
486
+
487
+ An "entity transaction" is a transaction transferring control of an
488
+ organization, or substantially all assets of one, or subdividing an
489
+ organization, or merging organizations. If propagation of a covered
490
+ work results from an entity transaction, each party to that
491
+ transaction who receives a copy of the work also receives whatever
492
+ licenses to the work the party's predecessor in interest had or could
493
+ give under the previous paragraph, plus a right to possession of the
494
+ Corresponding Source of the work from the predecessor in interest, if
495
+ the predecessor has it or can get it with reasonable efforts.
496
+
497
+ You may not impose any further restrictions on the exercise of the
498
+ rights granted or affirmed under this License. For example, you may
499
+ not impose a license fee, royalty, or other charge for exercise of
500
+ rights granted under this License, and you may not initiate litigation
501
+ (including a cross-claim or counterclaim in a lawsuit) alleging that
502
+ any patent claim is infringed by making, using, selling, offering for
503
+ sale, or importing the Program or any portion of it.
504
+
505
+ 11. Patents.
506
+
507
+ A "contributor" is a copyright holder who authorizes use under this
508
+ License of the Program or a work on which the Program is based. The
509
+ work thus licensed is called the contributor's "contributor version".
510
+
511
+ A contributor's "essential patent claims" are all patent claims
512
+ owned or controlled by the contributor, whether already acquired or
513
+ hereafter acquired, that would be infringed by some manner, permitted
514
+ by this License, of making, using, or selling its contributor version,
515
+ but do not include claims that would be infringed only as a
516
+ consequence of further modification of the contributor version. For
517
+ purposes of this definition, "control" includes the right to grant
518
+ patent sublicenses in a manner consistent with the requirements of
519
+ this License.
520
+
521
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
522
+ patent license under the contributor's essential patent claims, to
523
+ make, use, sell, offer for sale, import and otherwise run, modify and
524
+ propagate the contents of its contributor version.
525
+
526
+ In the following three paragraphs, a "patent license" is any express
527
+ agreement or commitment, however denominated, not to enforce a patent
528
+ (such as an express permission to practice a patent or covenant not to
529
+ sue for patent infringement). To "grant" such a patent license to a
530
+ party means to make such an agreement or commitment not to enforce a
531
+ patent against the party.
532
+
533
+ If you convey a covered work, knowingly relying on a patent license,
534
+ and the Corresponding Source of the work is not available for anyone
535
+ to copy, free of charge and under the terms of this License, through a
536
+ publicly available network server or other readily accessible means,
537
+ then you must either (1) cause the Corresponding Source to be so
538
+ available, or (2) arrange to deprive yourself of the benefit of the
539
+ patent license for this particular work, or (3) arrange, in a manner
540
+ consistent with the requirements of this License, to extend the patent
541
+ license to downstream recipients. "Knowingly relying" means you have
542
+ actual knowledge that, but for the patent license, your conveying the
543
+ covered work in a country, or your recipient's use of the covered work
544
+ in a country, would infringe one or more identifiable patents in that
545
+ country that you have reason to believe are valid.
546
+
547
+ If, pursuant to or in connection with a single transaction or
548
+ arrangement, you convey, or propagate by procuring conveyance of, a
549
+ covered work, and grant a patent license to some of the parties
550
+ receiving the covered work authorizing them to use, propagate, modify
551
+ or convey a specific copy of the covered work, then the patent license
552
+ you grant is automatically extended to all recipients of the covered
553
+ work and works based on it.
554
+
555
+ A patent license is "discriminatory" if it does not include within
556
+ the scope of its coverage, prohibits the exercise of, or is
557
+ conditioned on the non-exercise of one or more of the rights that are
558
+ specifically granted under this License. You may not convey a covered
559
+ work if you are a party to an arrangement with a third party that is
560
+ in the business of distributing software, under which you make payment
561
+ to the third party based on the extent of your activity of conveying
562
+ the work, and under which the third party grants, to any of the
563
+ parties who would receive the covered work from you, a discriminatory
564
+ patent license (a) in connection with copies of the covered work
565
+ conveyed by you (or copies made from those copies), or (b) primarily
566
+ for and in connection with specific products or compilations that
567
+ contain the covered work, unless you entered into that arrangement,
568
+ or that patent license was granted, prior to 28 March 2007.
569
+
570
+ Nothing in this License shall be construed as excluding or limiting
571
+ any implied license or other defenses to infringement that may
572
+ otherwise be available to you under applicable patent law.
573
+
574
+ 12. No Surrender of Others' Freedom.
575
+
576
+ If conditions are imposed on you (whether by court order, agreement or
577
+ otherwise) that contradict the conditions of this License, they do not
578
+ excuse you from the conditions of this License. If you cannot convey a
579
+ covered work so as to satisfy simultaneously your obligations under this
580
+ License and any other pertinent obligations, then as a consequence you may
581
+ not convey it at all. For example, if you agree to terms that obligate you
582
+ to collect a royalty for further conveying from those to whom you convey
583
+ the Program, the only way you could satisfy both those terms and this
584
+ License would be to refrain entirely from conveying the Program.
585
+
586
+ 13. Use with the GNU Affero General Public License.
587
+
588
+ Notwithstanding any other provision of this License, you have
589
+ permission to link or combine any covered work with a work licensed
590
+ under version 3 of the GNU Affero General Public License into a single
591
+ combined work, and to convey the resulting work. The terms of this
592
+ License will continue to apply to the part which is the covered work,
593
+ but the special requirements of the GNU Affero General Public License,
594
+ section 13, concerning interaction through a network will apply to the
595
+ combination as such.
596
+
597
+ 14. Revised Versions of this License.
598
+
599
+ The Free Software Foundation may publish revised and/or new versions of
600
+ the GNU General Public License from time to time. Such new versions will
601
+ be similar in spirit to the present version, but may differ in detail to
602
+ address new problems or concerns.
603
+
604
+ Each version is given a distinguishing version number. If the
605
+ Program specifies that a certain numbered version of the GNU General
606
+ Public License "or any later version" applies to it, you have the
607
+ option of following the terms and conditions either of that numbered
608
+ version or of any later version published by the Free Software
609
+ Foundation. If the Program does not specify a version number of the
610
+ GNU General Public License, you may choose any version ever published
611
+ by the Free Software Foundation.
612
+
613
+ If the Program specifies that a proxy can decide which future
614
+ versions of the GNU General Public License can be used, that proxy's
615
+ public statement of acceptance of a version permanently authorizes you
616
+ to choose that version for the Program.
617
+
618
+ Later license versions may give you additional or different
619
+ permissions. However, no additional obligations are imposed on any
620
+ author or copyright holder as a result of your choosing to follow a
621
+ later version.
622
+
623
+ 15. Disclaimer of Warranty.
624
+
625
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
626
+ APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
627
+ HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
628
+ OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
629
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
630
+ PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
631
+ IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
632
+ ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
633
+
634
+ 16. Limitation of Liability.
635
+
636
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
637
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
638
+ THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
639
+ GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
640
+ USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
641
+ DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
642
+ PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
643
+ EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
644
+ SUCH DAMAGES.
645
+
646
+ 17. Interpretation of Sections 15 and 16.
647
+
648
+ If the disclaimer of warranty and limitation of liability provided
649
+ above cannot be given local legal effect according to their terms,
650
+ reviewing courts shall apply local law that most closely approximates
651
+ an absolute waiver of all civil liability in connection with the
652
+ Program, unless a warranty or assumption of liability accompanies a
653
+ copy of the Program in return for a fee.
654
+
655
+ END OF TERMS AND CONDITIONS
656
+
657
+ How to Apply These Terms to Your New Programs
658
+
659
+ If you develop a new program, and you want it to be of the greatest
660
+ possible use to the public, the best way to achieve this is to make it
661
+ free software which everyone can redistribute and change under these terms.
662
+
663
+ To do so, attach the following notices to the program. It is safest
664
+ to attach them to the start of each source file to most effectively
665
+ state the exclusion of warranty; and each file should have at least
666
+ the "copyright" line and a pointer to where the full notice is found.
667
+
668
+ <one line to give the program's name and a brief idea of what it does.>
669
+ Copyright © <year> <name of author>
670
+
671
+ This program is free software: you can redistribute it and/or modify
672
+ it under the terms of the GNU General Public License as published by
673
+ the Free Software Foundation, either version 3 of the License, or
674
+ (at your option) any later version.
675
+
676
+ This program is distributed in the hope that it will be useful,
677
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
678
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
679
+ GNU General Public License for more details.
680
+
681
+ You should have received a copy of the GNU General Public License
682
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
683
+
684
+ Also add information on how to contact you by electronic and paper mail.
685
+
686
+ If the program does terminal interaction, make it output a short
687
+ notice like this when it starts in an interactive mode:
688
+
689
+ <program> Copyright © <year> <name of author>
690
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
691
+ This is free software, and you are welcome to redistribute it
692
+ under certain conditions; type `show c' for details.
693
+
694
+ The hypothetical commands `show w' and `show c' should show the appropriate
695
+ parts of the General Public License. Of course, your program's commands
696
+ might be different; for a GUI interface, you would use an "about box".
697
+
698
+ You should also get your employer (if you work as a programmer) or school,
699
+ if any, to sign a "copyright disclaimer" for the program, if necessary.
700
+ For more information on this, and how to apply and follow the GNU GPL, see
701
+ <http://www.gnu.org/licenses/>.
702
+
703
+ The GNU General Public License does not permit incorporating your program
704
+ into proprietary programs. If your program is a subroutine library, you
705
+ may consider it more useful to permit linking proprietary applications with
706
+ the library. If this is what you want to do, use the GNU Lesser General
707
+ Public License instead of this License. But first, please read
708
  <http://www.gnu.org/philosophy/why-not-lgpl.html>.
product-csv-import-export.php CHANGED
@@ -1,130 +1,130 @@
1
- <?php
2
- /*
3
- Plugin Name: Product CSV Import Export (BASIC)
4
- Plugin URI: http://www.xadapter.com/product/product-import-export-plugin-for-woocommerce/
5
- Description: Import and Export Products From and To your WooCommerce Store.
6
- Author: HikeForce
7
- Author URI: http://www.xadapter.com/vendor/hikeforce/
8
- Version: 1.2.1
9
- Text Domain: wf_csv_import_export
10
- */
11
-
12
- if ( ! defined( 'ABSPATH' ) || ! is_admin() ) {
13
- return;
14
- }
15
-
16
- define( "WF_PROD_IMP_EXP_ID", "wf_prod_imp_exp" );
17
- define( "WF_WOOCOMMERCE_CSV_IM_EX", "wf_woocommerce_csv_im_ex" );
18
-
19
- /**
20
- * Check if WooCommerce is active
21
- */
22
- if (in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) )) {
23
-
24
- if ( ! class_exists( 'WF_Product_Import_Export_CSV' ) ) :
25
-
26
- /**
27
- * Main CSV Import class
28
- */
29
- class WF_Product_Import_Export_CSV {
30
-
31
- /**
32
- * Constructor
33
- */
34
- public function __construct() {
35
- define( 'WF_ProdImpExpCsv_FILE', __FILE__ );
36
-
37
- add_filter( 'woocommerce_screen_ids', array( $this, 'woocommerce_screen_ids' ) );
38
- add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'wf_plugin_action_links' ) );
39
- add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
40
- add_action( 'init', array( $this, 'catch_export_request' ), 20 );
41
- add_action( 'admin_init', array( $this, 'register_importers' ) );
42
-
43
- include_once( 'includes/class-wf-prodimpexpcsv-system-status-tools.php' );
44
- include_once( 'includes/class-wf-prodimpexpcsv-admin-screen.php' );
45
- include_once( 'includes/importer/class-wf-prodimpexpcsv-importer.php' );
46
-
47
- if ( defined('DOING_AJAX') ) {
48
- include_once( 'includes/class-wf-prodimpexpcsv-ajax-handler.php' );
49
- }
50
- }
51
-
52
- public function wf_plugin_action_links( $links ) {
53
- $plugin_links = array(
54
- '<a href="' . admin_url( 'admin.php?page=wf_woocommerce_csv_im_ex' ) . '">' . __( 'Import Export', 'wf_csv_import_export' ) . '</a>',
55
- '<a href="http://www.xadapter.com/product/product-import-export-plugin-for-woocommerce/" target="_blank">' . __( 'Premium Upgrade', 'wf_csv_import_export' ) . '</a>',
56
- '<a href="http://www.xadapter.com/support/forum/product-import-export-plugin-for-woocommerce/">' . __( 'Support', 'wf_csv_import_export' ) . '</a>',
57
- );
58
- return array_merge( $plugin_links, $links );
59
- }
60
-
61
- /**
62
- * Add screen ID
63
- */
64
- public function woocommerce_screen_ids( $ids ) {
65
- $ids[] = 'admin'; // For import screen
66
- return $ids;
67
- }
68
-
69
- /**
70
- * Handle localisation
71
- */
72
- public function load_plugin_textdomain() {
73
- load_plugin_textdomain( 'wf_csv_import_export', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/' );
74
- }
75
-
76
- /**
77
- * Catches an export request and exports the data. This class is only loaded in admin.
78
- */
79
- public function catch_export_request() {
80
- if ( ! empty( $_GET['action'] ) && ! empty( $_GET['page'] ) && $_GET['page'] == 'wf_woocommerce_csv_im_ex' ) {
81
- switch ( $_GET['action'] ) {
82
- case "export" :
83
- $user_ok = $this->hf_user_permission();
84
- if ($user_ok) {
85
- include_once( 'includes/exporter/class-wf-prodimpexpcsv-exporter.php' );
86
- WF_ProdImpExpCsv_Exporter::do_export( 'product' );
87
- } else {
88
- wp_redirect(wp_login_url());
89
- }
90
- break;
91
- }
92
- }
93
- }
94
-
95
- public function catch_save_settings() {
96
- if ( ! empty( $_GET['action'] ) && ! empty( $_GET['page'] ) && $_GET['page'] == 'wf_woocommerce_csv_im_ex' ) {
97
- switch ( $_GET['action'] ) {
98
- case "settings" :
99
- include_once( 'includes/settings/class-wf-prodimpexpcsv-settings.php' );
100
- WF_ProdImpExpCsv_Settings::save_settings( );
101
- break;
102
- }
103
- }
104
- }
105
-
106
- /**
107
- * Register importers for use
108
- */
109
- public function register_importers() {
110
- register_importer( 'woocommerce_csv', 'WooCommerce Products (CSV)', __('Import <strong>products</strong> to your store via a csv file.', 'wf_csv_import_export'), 'WF_ProdImpExpCsv_Importer::product_importer' );
111
- }
112
- private function hf_user_permission() {
113
- // Check if user has rights to export
114
- $current_user = wp_get_current_user();
115
- $user_ok = false;
116
- $wf_roles = apply_filters('hf_user_permission_roles', array('administrator', 'shop_manager'));
117
- if ($current_user instanceof WP_User) {
118
- $can_users = array_intersect($wf_roles, $current_user->roles);
119
- if (!empty($can_users)) {
120
- $user_ok = true;
121
- }
122
- }
123
- return $user_ok;
124
- }
125
- }
126
- endif;
127
-
128
- new WF_Product_Import_Export_CSV();
129
-
130
- }
1
+ <?php
2
+ /*
3
+ Plugin Name: Product CSV Import Export (BASIC)
4
+ Plugin URI: http://www.xadapter.com/product/product-import-export-plugin-for-woocommerce/
5
+ Description: Import and Export Products From and To your WooCommerce Store.
6
+ Author: HikeForce
7
+ Author URI: http://www.xadapter.com/vendor/hikeforce/
8
+ Version: 1.2.2
9
+ Text Domain: wf_csv_import_export
10
+ */
11
+
12
+ if ( ! defined( 'ABSPATH' ) || ! is_admin() ) {
13
+ return;
14
+ }
15
+
16
+ define( "WF_PROD_IMP_EXP_ID", "wf_prod_imp_exp" );
17
+ define( "WF_WOOCOMMERCE_CSV_IM_EX", "wf_woocommerce_csv_im_ex" );
18
+
19
+ /**
20
+ * Check if WooCommerce is active
21
+ */
22
+ if (in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) )) {
23
+
24
+ if ( ! class_exists( 'WF_Product_Import_Export_CSV' ) ) :
25
+
26
+ /**
27
+ * Main CSV Import class
28
+ */
29
+ class WF_Product_Import_Export_CSV {
30
+
31
+ /**
32
+ * Constructor
33
+ */
34
+ public function __construct() {
35
+ define( 'WF_ProdImpExpCsv_FILE', __FILE__ );
36
+
37
+ add_filter( 'woocommerce_screen_ids', array( $this, 'woocommerce_screen_ids' ) );
38
+ add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'wf_plugin_action_links' ) );
39
+ add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
40
+ add_action( 'init', array( $this, 'catch_export_request' ), 20 );
41
+ add_action( 'admin_init', array( $this, 'register_importers' ) );
42
+
43
+ include_once( 'includes/class-wf-prodimpexpcsv-system-status-tools.php' );
44
+ include_once( 'includes/class-wf-prodimpexpcsv-admin-screen.php' );
45
+ include_once( 'includes/importer/class-wf-prodimpexpcsv-importer.php' );
46
+
47
+ if ( defined('DOING_AJAX') ) {
48
+ include_once( 'includes/class-wf-prodimpexpcsv-ajax-handler.php' );
49
+ }
50
+ }
51
+
52
+ public function wf_plugin_action_links( $links ) {
53
+ $plugin_links = array(
54
+ '<a href="' . admin_url( 'admin.php?page=wf_woocommerce_csv_im_ex' ) . '">' . __( 'Import Export', 'wf_csv_import_export' ) . '</a>',
55
+ '<a href="http://www.xadapter.com/product/product-import-export-plugin-for-woocommerce/" target="_blank">' . __( 'Premium Upgrade', 'wf_csv_import_export' ) . '</a>',
56
+ '<a href="http://www.xadapter.com/support/forum/product-import-export-plugin-for-woocommerce/">' . __( 'Support', 'wf_csv_import_export' ) . '</a>',
57
+ );
58
+ return array_merge( $plugin_links, $links );
59
+ }
60
+
61
+ /**
62
+ * Add screen ID
63
+ */
64
+ public function woocommerce_screen_ids( $ids ) {
65
+ $ids[] = 'admin'; // For import screen
66
+ return $ids;
67
+ }
68
+
69
+ /**
70
+ * Handle localisation
71
+ */
72
+ public function load_plugin_textdomain() {
73
+ load_plugin_textdomain( 'wf_csv_import_export', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/' );
74
+ }
75
+
76
+ /**
77
+ * Catches an export request and exports the data. This class is only loaded in admin.
78
+ */
79
+ public function catch_export_request() {
80
+ if ( ! empty( $_GET['action'] ) && ! empty( $_GET['page'] ) && $_GET['page'] == 'wf_woocommerce_csv_im_ex' ) {
81
+ switch ( $_GET['action'] ) {
82
+ case "export" :
83
+ $user_ok = $this->hf_user_permission();
84
+ if ($user_ok) {
85
+ include_once( 'includes/exporter/class-wf-prodimpexpcsv-exporter.php' );
86
+ WF_ProdImpExpCsv_Exporter::do_export( 'product' );
87
+ } else {
88
+ wp_redirect(wp_login_url());
89
+ }
90
+ break;
91
+ }
92
+ }
93
+ }
94
+
95
+ public function catch_save_settings() {
96
+ if ( ! empty( $_GET['action'] ) && ! empty( $_GET['page'] ) && $_GET['page'] == 'wf_woocommerce_csv_im_ex' ) {
97
+ switch ( $_GET['action'] ) {
98
+ case "settings" :
99
+ include_once( 'includes/settings/class-wf-prodimpexpcsv-settings.php' );
100
+ WF_ProdImpExpCsv_Settings::save_settings( );
101
+ break;
102
+ }
103
+ }
104
+ }
105
+
106
+ /**
107
+ * Register importers for use
108
+ */
109
+ public function register_importers() {
110
+ register_importer( 'woocommerce_csv', 'WooCommerce Products (CSV)', __('Import <strong>products</strong> to your store via a csv file.', 'wf_csv_import_export'), 'WF_ProdImpExpCsv_Importer::product_importer' );
111
+ }
112
+ private function hf_user_permission() {
113
+ // Check if user has rights to export
114
+ $current_user = wp_get_current_user();
115
+ $user_ok = false;
116
+ $wf_roles = apply_filters('hf_user_permission_roles', array('administrator', 'shop_manager'));
117
+ if ($current_user instanceof WP_User) {
118
+ $can_users = array_intersect($wf_roles, $current_user->roles);
119
+ if (!empty($can_users)) {
120
+ $user_ok = true;
121
+ }
122
+ }
123
+ return $user_ok;
124
+ }
125
+ }
126
+ endif;
127
+
128
+ new WF_Product_Import_Export_CSV();
129
+
130
+ }
readme.txt CHANGED
@@ -1,180 +1,185 @@
1
- === Product Import Export for WooCommerce===
2
- Contributors: hikeforce, elvinwf
3
- Donate link:
4
- Tags: woocommerce import products, woocommerce export products, woocommerce export import products, export woocommerce products with images, woocommerce csv import variable products, woocommerce import products with attributes
5
- Requires at least: 3.0.1
6
- Tested up to: 4.7
7
- Stable tag: 1.2.1
8
- License: GPLv2 or later
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
-
11
- Easily import WooCommerce Products and Export products using this Plugin. Import Products from any CSV to WooCommerce.
12
-
13
- == Description ==
14
-
15
- = Introduction =
16
-
17
- WooCommerce Product Import Export Plugin helps you to easily export and import products in your store. This plugin lets you import/export simple products. It is super simple!
18
-
19
- <ul>
20
- <li>Export Simple Products in to a CSV file.</li>
21
- <li>Import Simple Products in CSV format in to WooCommerce Store.</li>
22
- </ul>
23
-
24
- Highlights: WooCommerce Product Export, WooCommerce Product CSV Import Suite, Export Products to xls. Pro Version supports both Simple and Variable products.
25
-
26
- = How does it work? =
27
-
28
- The WooCommerce Product Import Export Plugin takes CSV (Comma-Separated Values) file as input. You must create a CSV ( UTF-8 Encoded ) file and enter the product details in a structured format as explained in the tutorial. This is to match each field of CSV file to the field of a particular product that otherwise Admin need to input manually. For example: the post_title field gets mapped to the product name and the regular_price field gets mapped to the regular price of the product. For the plugin to work correctly, you must map headers of all of the column correctly and you must ensure that all of the fields you enter must be in the correct format.
29
-
30
- You can create the CSV from scratch or you can export the product to get the format of CSV. You can use a spreadsheet program, such as Excel, OpenOffice or Google Spreadsheets for creating and modifying the CSV file. Save this file with extension .CSV. After entering all details about products in spreadsheet, you can import product to your online store. With this plugin, you can also export and download product details as a CSV file.
31
-
32
- = Premium version video demo =
33
- [youtube http://www.youtube.com/watch?v=fBuf54rUakY&showinfo=0]
34
-
35
- <blockquote>
36
-
37
- = Premium version Features =
38
- Product Import Export Plugin for WooCommerce
39
-
40
- <ul>
41
- <li>Export Products (Simple, Group, External and Variations) in to a CSV file <strong>( Basic version supports only Simple Products )</strong>.</li>
42
- <li>Import Products (Simple, Group, External and Variations) in CSV format in to WooComemrce Store.</li>
43
- <li>Export Products by Category.</li>
44
- <li>Various Filter options for exporting Products. </li>
45
- <li>Map and Transform fields while Importing Products.</li>
46
- <li>Change values while improting products using Evaluation Fields.</li>
47
- <li>Choice to Update or Skip existing imported products. </li>
48
- <li>WPML Supported. French and German (Deutschland) language support Out of the Box.</li>
49
- <li>Import/Export file from/to a remote server via FTP.</li>
50
- <li>Excellent Support for setting it up!</li>
51
- </ul>
52
-
53
- Please visit <a rel="nofollow" href="http://www.xadapter.com/product/product-import-export-plugin-for-woocommerce/">Product Import Export Plugin for WooCommerce</a> for more details
54
-
55
- </blockquote>
56
-
57
- = About HikeForce.com =
58
-
59
- HikeForce creates quality WordPress/WooCommerce plugins that are easy to use and customize. We are proud to have thousands of customers actively using our plugins across the globe.
60
-
61
-
62
- == Installation ==
63
-
64
- 1. Upload the plugin folder to the /wp-content/plugins/ directory.
65
- 2. Activate the plugin through the Plugins menu in WordPress.
66
- 3. Thats it! you can now configure the plugin.
67
-
68
- == Frequently Asked Questions ==
69
-
70
- = Does this plugin support of images? =
71
-
72
- Yes. You can import or export product images along with other details
73
-
74
- == Screenshots ==
75
-
76
- 1. Product Import Screen
77
-
78
- 2. Product Export Screen
79
-
80
- 3. Premium Export Settings Screen
81
-
82
- == Changelog ==
83
- = 1.2.1 =
84
- * Optimization: Image URL parsing.
85
- = 1.2.0 =
86
- * Enhancement: German Translation updates.
87
- = 1.1.9 =
88
- * Enhancement: WPML Support updates.
89
- = 1.1.8 =
90
- * Enhancement: Security improvements and bug fix.
91
- = 1.1.7 =
92
- * Enhancement: Security improvements.
93
- = 1.1.6 =
94
- * Enhancement: Sample CSV updated.
95
- = 1.1.5 =
96
- * Bug fix: Improved parsing.
97
- = 1.1.4 =
98
- * Bug fix: Removed deprecated function.
99
- = 1.1.3 =
100
- * Bug fix: Empty check validation updated.
101
- = 1.1.2 =
102
- * Minor content change.
103
- = 1.1.1 =
104
- * Enhancement: Import products that have same title.
105
- = 1.1.0 =
106
- * Italian Translation added.
107
- = 1.0.9 =
108
- * Hungarian Translation added.
109
- = 1.0.8 =
110
- * Minor content change.
111
- = 1.0.7 =
112
- * Enhancement: Updated support forum links and contact details.
113
- = 1.0.6 =
114
- * Bug Fix: fixed issue with SKU while exporting.
115
- = 1.0.5 =
116
- * Feature: Added Multilingual support and French Translation.
117
- = 1.0.4 =
118
- * Bug Fix: Improved Evaluation field and help message in mapping section.
119
- = 1.0.3 =
120
- * Bug Fix: Sorting priority Set to ID by default while exporting.
121
- = 1.0.2 =
122
- * Bug Fix: Improved parsing while importing product price with currency symbol and thousand separator.
123
- = 1.0.1 =
124
- * Bug Fix: Fixed issue with Evaluation field with single quotes.
125
- * Bug Fix: Option to import gallery images.
126
- * Enhancement: Improved help text for Post name and Stock quantity.
127
- * Enhancement: Improved label text for Product type, category , tags and shipping class.
128
- * Enhancement: Included links to Documentation and sample CSV.
129
- = 1.0.0 =
130
- * Import /Export Woocommerce Products.
131
-
132
- == Upgrade Notice ==
133
- = 1.2.1 =
134
- * Optimization: Image URL parsing.
135
- = 1.2.0 =
136
- * Enhancement: German Translation updates.
137
- = 1.1.9 =
138
- * Enhancement: WPML Support updates.
139
- = 1.1.8 =
140
- * Enhancement: Security improvements and bug fix.
141
- = 1.1.7 =
142
- * Enhancement: Security improvements.
143
- = 1.1.6 =
144
- * Enhancement: Sample CSV updated.
145
- = 1.1.5 =
146
- * Bug fix: Improved parsing.
147
- = 1.1.4 =
148
- * Bug fix: Removed deprecated function.
149
- = 1.1.3 =
150
- * Bug fix: Empty check validation updated.
151
- = 1.1.2 =
152
- * Minor content change.
153
- = 1.1.1 =
154
- * Enhancement: Import products that have same title.
155
- = 1.1.0 =
156
- * Italian Translation added.
157
- = 1.0.9 =
158
- * Hungarian Translation added.
159
- = 1.0.8 =
160
- * Minor content change.
161
- = 1.0.7 =
162
- * Enhancement: Updated support forum links and contact details.
163
- = 1.0.6 =
164
- * Bug Fix: fixed issue with SKU while exporting.
165
- = 1.0.5 =
166
- * Feature: Added Multilingual support and French Translation.
167
- = 1.0.4 =
168
- * Bug Fix: Improved Evaluation field and help message in mapping section.
169
- = 1.0.3 =
170
- * Bug Fix: Sorting priority Set to ID by default while exporting.
171
- = 1.0.2 =
172
- * Bug Fix: Improved parsing while importing product price with currency symbol and thousand separator.
173
- = 1.0.1 =
174
- * Bug Fix: Fixed issue with Evaluation field with single quotes.
175
- * Bug Fix: Option to import gallery images.
176
- * Enhancement: Improved help text for Post name and Stock quantity.
177
- * Enhancement: Improved label text for Product type, category , tags and shipping class.
178
- * Enhancement: Included links to Documentation and sample CSV.
179
- = 1.0.0 =
180
- * Import /Export Woocommerce Products.
 
 
 
 
 
1
+ === Product Import Export for WooCommerce===
2
+ Contributors: hikeforce, elvinwf
3
+ Donate link:
4
+ Tags: woocommerce import products, woocommerce export products, woocommerce export import products, export woocommerce products with images, woocommerce csv import variable products, woocommerce import products with attributes
5
+ Requires at least: 3.0.1
6
+ Tested up to: 4.7
7
+ Stable tag: 1.2.2
8
+ License: GPLv2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
+
11
+ Easily import WooCommerce Products and Export products using this Plugin. Import Products from any CSV to WooCommerce.
12
+
13
+ == Description ==
14
+
15
+ = Introduction =
16
+
17
+ WooCommerce Product Import Export Plugin helps you to easily export and import products in your store. This plugin lets you import/export simple products. It is super simple!
18
+
19
+ <ul>
20
+ <li>Export Simple Products in to a CSV file.</li>
21
+ <li>Import Simple Products in CSV format in to WooCommerce Store.</li>
22
+ </ul>
23
+
24
+ Highlights: WooCommerce Product Export, WooCommerce Product CSV Import Suite, Export Products to xls. Pro Version supports both Simple and Variable products.
25
+
26
+ = How does it work? =
27
+
28
+ The WooCommerce Product Import Export Plugin takes CSV (Comma-Separated Values) file as input. You must create a CSV ( UTF-8 Encoded ) file and enter the product details in a structured format as explained in the tutorial. This is to match each field of CSV file to the field of a particular product that otherwise Admin need to input manually. For example: the post_title field gets mapped to the product name and the regular_price field gets mapped to the regular price of the product. For the plugin to work correctly, you must map headers of all of the column correctly and you must ensure that all of the fields you enter must be in the correct format.
29
+
30
+ You can create the CSV from scratch or you can export the product to get the format of CSV. You can use a spreadsheet program, such as Excel, OpenOffice or Google Spreadsheets for creating and modifying the CSV file. Save this file with extension .CSV. After entering all details about products in spreadsheet, you can import product to your online store. With this plugin, you can also export and download product details as a CSV file.
31
+
32
+ = Premium version video demo =
33
+ [youtube http://www.youtube.com/watch?v=fBuf54rUakY&showinfo=0]
34
+
35
+ <blockquote>
36
+
37
+ = Premium version Features =
38
+ Product Import Export Plugin for WooCommerce
39
+
40
+ <ul>
41
+ <li>Export Products (Simple, Group, External and Variations) in to a CSV file <strong>( Basic version supports only Simple Products )</strong>.</li>
42
+ <li>Import Products (Simple, Group, External and Variations) in CSV format in to WooComemrce Store.</li>
43
+ <li>Export Products by Category.</li>
44
+ <li>Various Filter options for exporting Products. </li>
45
+ <li>Map and Transform fields while Importing Products.</li>
46
+ <li>Change values while improting products using Evaluation Fields.</li>
47
+ <li>Choice to Update or Skip existing imported products. </li>
48
+ <li>WPML Supported. French and German (Deutschland) language support Out of the Box.</li>
49
+ <li>Import/Export file from/to a remote server via FTP.</li>
50
+ <li>Supports Product Reviews Export Import.</li>
51
+ <li>Excellent Support for setting it up!</li>
52
+ </ul>
53
+
54
+ Please visit <a rel="nofollow" href="http://www.xadapter.com/product/product-import-export-plugin-for-woocommerce/">Product Import Export Plugin for WooCommerce</a> for more details
55
+
56
+ </blockquote>
57
+
58
+ = About HikeForce.com =
59
+
60
+ HikeForce creates quality WordPress/WooCommerce plugins that are easy to use and customize. We are proud to have thousands of customers actively using our plugins across the globe.
61
+
62
+
63
+ == Installation ==
64
+
65
+ 1. Upload the plugin folder to the /wp-content/plugins/ directory.
66
+ 2. Activate the plugin through the Plugins menu in WordPress.
67
+ 3. Thats it! you can now configure the plugin.
68
+
69
+ == Frequently Asked Questions ==
70
+
71
+ = Does this plugin support of images? =
72
+
73
+ Yes. You can import or export product images along with other details
74
+
75
+ == Screenshots ==
76
+
77
+ 1. Product Import Screen
78
+
79
+ 2. Product Export Screen
80
+
81
+ 3. Premium Export Settings Screen
82
+
83
+ == Changelog ==
84
+ = 1.2.2 =
85
+ * Minor content change.
86
+ = 1.2.1 =
87
+ * Optimization: Image URL parsing.
88
+ = 1.2.0 =
89
+ * Enhancement: German Translation updates.
90
+ = 1.1.9 =
91
+ * Enhancement: WPML Support updates.
92
+ = 1.1.8 =
93
+ * Enhancement: Security improvements and bug fix.
94
+ = 1.1.7 =
95
+ * Enhancement: Security improvements.
96
+ = 1.1.6 =
97
+ * Enhancement: Sample CSV updated.
98
+ = 1.1.5 =
99
+ * Bug fix: Improved parsing.
100
+ = 1.1.4 =
101
+ * Bug fix: Removed deprecated function.
102
+ = 1.1.3 =
103
+ * Bug fix: Empty check validation updated.
104
+ = 1.1.2 =
105
+ * Minor content change.
106
+ = 1.1.1 =
107
+ * Enhancement: Import products that have same title.
108
+ = 1.1.0 =
109
+ * Italian Translation added.
110
+ = 1.0.9 =
111
+ * Hungarian Translation added.
112
+ = 1.0.8 =
113
+ * Minor content change.
114
+ = 1.0.7 =
115
+ * Enhancement: Updated support forum links and contact details.
116
+ = 1.0.6 =
117
+ * Bug Fix: fixed issue with SKU while exporting.
118
+ = 1.0.5 =
119
+ * Feature: Added Multilingual support and French Translation.
120
+ = 1.0.4 =
121
+ * Bug Fix: Improved Evaluation field and help message in mapping section.
122
+ = 1.0.3 =
123
+ * Bug Fix: Sorting priority Set to ID by default while exporting.
124
+ = 1.0.2 =
125
+ * Bug Fix: Improved parsing while importing product price with currency symbol and thousand separator.
126
+ = 1.0.1 =
127
+ * Bug Fix: Fixed issue with Evaluation field with single quotes.
128
+ * Bug Fix: Option to import gallery images.
129
+ * Enhancement: Improved help text for Post name and Stock quantity.
130
+ * Enhancement: Improved label text for Product type, category , tags and shipping class.
131
+ * Enhancement: Included links to Documentation and sample CSV.
132
+ = 1.0.0 =
133
+ * Import /Export Woocommerce Products.
134
+
135
+ == Upgrade Notice ==
136
+ = 1.2.2 =
137
+ * Minor content change.
138
+ = 1.2.1 =
139
+ * Optimization: Image URL parsing.
140
+ = 1.2.0 =
141
+ * Enhancement: German Translation updates.
142
+ = 1.1.9 =
143
+ * Enhancement: WPML Support updates.
144
+ = 1.1.8 =
145
+ * Enhancement: Security improvements and bug fix.
146
+ = 1.1.7 =
147
+ * Enhancement: Security improvements.
148
+ = 1.1.6 =
149
+ * Enhancement: Sample CSV updated.
150
+ = 1.1.5 =
151
+ * Bug fix: Improved parsing.
152
+ = 1.1.4 =
153
+ * Bug fix: Removed deprecated function.
154
+ = 1.1.3 =
155
+ * Bug fix: Empty check validation updated.
156
+ = 1.1.2 =
157
+ * Minor content change.
158
+ = 1.1.1 =
159
+ * Enhancement: Import products that have same title.
160
+ = 1.1.0 =
161
+ * Italian Translation added.
162
+ = 1.0.9 =
163
+ * Hungarian Translation added.
164
+ = 1.0.8 =
165
+ * Minor content change.
166
+ = 1.0.7 =
167
+ * Enhancement: Updated support forum links and contact details.
168
+ = 1.0.6 =
169
+ * Bug Fix: fixed issue with SKU while exporting.
170
+ = 1.0.5 =
171
+ * Feature: Added Multilingual support and French Translation.
172
+ = 1.0.4 =
173
+ * Bug Fix: Improved Evaluation field and help message in mapping section.
174
+ = 1.0.3 =
175
+ * Bug Fix: Sorting priority Set to ID by default while exporting.
176
+ = 1.0.2 =
177
+ * Bug Fix: Improved parsing while importing product price with currency symbol and thousand separator.
178
+ = 1.0.1 =
179
+ * Bug Fix: Fixed issue with Evaluation field with single quotes.
180
+ * Bug Fix: Option to import gallery images.
181
+ * Enhancement: Improved help text for Post name and Stock quantity.
182
+ * Enhancement: Improved label text for Product type, category , tags and shipping class.
183
+ * Enhancement: Included links to Documentation and sample CSV.
184
+ = 1.0.0 =
185
+ * Import /Export Woocommerce Products.
styles/wf-style.css CHANGED
@@ -1,113 +1,113 @@
1
- #icon-woocommerce-importer {
2
- background-image: url(../images/wf-import.png) !important;
3
- background-position: -3px -5px;
4
- }
5
- .widefat_importer td {
6
- vertical-align: middle;
7
- padding: 5px 9px;
8
- }
9
- #import-progress {
10
- width: 100%;
11
- }
12
- #import-progress td, #import-progress th {
13
- padding: .5em 1em;
14
- }
15
- #import-progress td.status, #import-progress th.status {
16
- width: 32px;
17
- }
18
- #import-progress td.row, #import-progress th.row {
19
- width: 3em;
20
- text-align: center;
21
- }
22
- #import-progress td.reason, #import-progress th.reason {
23
- text-align: right;
24
- }
25
- #import-progress tr.importer-loading td {
26
- background: url(../images/wf-ajax-loader.gif) no-repeat center center;
27
- height: 32px;
28
- }
29
- #import-progress .merged td,
30
- #import-progress .imported td {
31
- }
32
- #import-progress .skipped td {
33
- border-bottom-color: #dbcb83;
34
- background: #f2ecd2;
35
- }
36
- #import-progress .failed td {
37
- border-bottom-color: #e6adaa;
38
- background: #f2d3d2;
39
- }
40
- #import-progress mark.result {
41
- height: 0;
42
- display: block;
43
- line-height: 16px;
44
- overflow: hidden;
45
- padding: 16px 0 0 0;
46
- }
47
- #import-progress .skipped mark.result {
48
- background: url(../images/wf-notice.png) no-repeat center top;
49
- }
50
- #import-progress .merged mark.result,
51
- #import-progress .imported mark.result {
52
- background: url(../images/wf-success.png) no-repeat center top;
53
- }
54
- #import-progress .failed mark.result {
55
- background: url(../images/wf-failed.png) no-repeat center top;
56
- }
57
- #import-progress .complete td {
58
- background: #000;
59
- border-color: #000;
60
- border-top: 4px solid #000;
61
- color: #fff;
62
- font-size: 1.5em;
63
- padding: .95em 1em 1em;
64
- text-align: center;
65
- }
66
- #import-progress .regenerating td {
67
- padding: 0;
68
- }
69
- #import-progress .regenerating div.progress {
70
- background: #464646;
71
- padding: .95em 1em 1em;
72
- color: #fff;
73
- overflow: hidden;
74
- width: 0;
75
- float: left;
76
- text-align: left;
77
- white-space: nowrap;
78
- }
79
- .update{
80
- background: #fff;
81
- border-left: 4px solid #fff;
82
- padding: 1px 12px;
83
- border-left-color: #46b450;
84
- margin-top: 10px;
85
- }
86
- #datagrid { border-collapse: collapse; text-align: left; width: 80%; }
87
- #datagrid {
88
- background: #fff; overflow: hidden;
89
- }
90
- #datagrid td{ padding: 3px 10px; }
91
- #datagrid th { padding: 3px 25px; color: #fff; background-color: #ccc; font-weight: bold;font-size: 15px; }
92
-
93
- .woocommerce-message a.button-primary, .woocommerce-message button.button-primary{
94
- background: #0085ba none repeat scroll 0 0 !important;
95
- border-color: #0073aa #006799 #006799 !important;}
96
- .woocommerce-message{border-left-color:#46b450 !important;}
97
- .rate-star{
98
- background: rgba(0, 0, 0, 0) url("../images/stars.png") no-repeat scroll 0 0;
99
- display: inline-block;
100
- height: 24px;
101
- position: relative;
102
- top: 10px;
103
- width: 125px;
104
- }
105
- .rate-us{
106
- background-color: #ffeeff;
107
- border-color: #e6db55;
108
- border-radius: 3px;
109
- border-style: solid;
110
- border-width: 1px;
111
- margin: 15px 0;
112
- padding: 0 0.6em;
113
  }
1
+ #icon-woocommerce-importer {
2
+ background-image: url(../images/wf-import.png) !important;
3
+ background-position: -3px -5px;
4
+ }
5
+ .widefat_importer td {
6
+ vertical-align: middle;
7
+ padding: 5px 9px;
8
+ }
9
+ #import-progress {
10
+ width: 100%;
11
+ }
12
+ #import-progress td, #import-progress th {
13
+ padding: .5em 1em;
14
+ }
15
+ #import-progress td.status, #import-progress th.status {
16
+ width: 32px;
17
+ }
18
+ #import-progress td.row, #import-progress th.row {
19
+ width: 3em;
20
+ text-align: center;
21
+ }
22
+ #import-progress td.reason, #import-progress th.reason {
23
+ text-align: right;
24
+ }
25
+ #import-progress tr.importer-loading td {
26
+ background: url(../images/wf-ajax-loader.gif) no-repeat center center;
27
+ height: 32px;
28
+ }
29
+ #import-progress .merged td,
30
+ #import-progress .imported td {
31
+ }
32
+ #import-progress .skipped td {
33
+ border-bottom-color: #dbcb83;
34
+ background: #f2ecd2;
35
+ }
36
+ #import-progress .failed td {
37
+ border-bottom-color: #e6adaa;
38
+ background: #f2d3d2;
39
+ }
40
+ #import-progress mark.result {
41
+ height: 0;
42
+ display: block;
43
+ line-height: 16px;
44
+ overflow: hidden;
45
+ padding: 16px 0 0 0;
46
+ }
47
+ #import-progress .skipped mark.result {
48
+ background: url(../images/wf-notice.png) no-repeat center top;
49
+ }
50
+ #import-progress .merged mark.result,
51
+ #import-progress .imported mark.result {
52
+ background: url(../images/wf-success.png) no-repeat center top;
53
+ }
54
+ #import-progress .failed mark.result {
55
+ background: url(../images/wf-failed.png) no-repeat center top;
56
+ }
57
+ #import-progress .complete td {
58
+ background: #000;
59
+ border-color: #000;
60
+ border-top: 4px solid #000;
61
+ color: #fff;
62
+ font-size: 1.5em;
63
+ padding: .95em 1em 1em;
64
+ text-align: center;
65
+ }
66
+ #import-progress .regenerating td {
67
+ padding: 0;
68
+ }
69
+ #import-progress .regenerating div.progress {
70
+ background: #464646;
71
+ padding: .95em 1em 1em;
72
+ color: #fff;
73
+ overflow: hidden;
74
+ width: 0;
75
+ float: left;
76
+ text-align: left;
77
+ white-space: nowrap;
78
+ }
79
+ .update{
80
+ background: #fff;
81
+ border-left: 4px solid #fff;
82
+ padding: 1px 12px;
83
+ border-left-color: #46b450;
84
+ margin-top: 10px;
85
+ }
86
+ #datagrid { border-collapse: collapse; text-align: left; width: 80%; }
87
+ #datagrid {
88
+ background: #fff; overflow: hidden;
89
+ }
90
+ #datagrid td{ padding: 3px 10px; }
91
+ #datagrid th { padding: 3px 25px; color: #fff; background-color: #ccc; font-weight: bold;font-size: 15px; }
92
+
93
+ .woocommerce-message a.button-primary, .woocommerce-message button.button-primary{
94
+ background: #0085ba none repeat scroll 0 0 !important;
95
+ border-color: #0073aa #006799 #006799 !important;}
96
+ .woocommerce-message{border-left-color:#46b450 !important;}
97
+ .rate-star{
98
+ background: rgba(0, 0, 0, 0) url("../images/stars.png") no-repeat scroll 0 0;
99
+ display: inline-block;
100
+ height: 24px;
101
+ position: relative;
102
+ top: 10px;
103
+ width: 125px;
104
+ }
105
+ .rate-us{
106
+ background-color: #ffeeff;
107
+ border-color: #e6db55;
108
+ border-radius: 3px;
109
+ border-style: solid;
110
+ border-width: 1px;
111
+ margin: 15px 0;
112
+ padding: 0 0.6em;
113
  }