Product Import Export for WooCommerce - Version 1.3.8

Version Description

  • BugFix: Product not importing at 100n. n=1,2...
Download this release

Release Info

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

Code changes from version 1.3.7 to 1.3.8

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;
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,870 +1,870 @@
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
- if(!empty($eval_field[strtolower( $heading )]))
109
- $row[$s_heading] = $this->evaluate_field($row[$s_heading], $eval_field[strtolower( $heading )]);
110
-
111
- // Raw Headers stores the actual column name in the CSV
112
- $raw_headers[ $s_heading ] = $heading;
113
- }
114
- $parsed_data[] = $row;
115
-
116
- unset( $postmeta, $row );
117
-
118
- $position = ftell( $handle );
119
-
120
- if ( $end_pos && $position >= $end_pos )
121
- break;
122
- }
123
- fclose( $handle );
124
- }
125
- return array( $parsed_data, $raw_headers, $position );
126
- }
127
-
128
- private function evaluate_field($value, $evaluation_field){
129
- //echo "value:$value, $evaluation_field </br>";
130
- $processed_value = $value;
131
- if(!empty($evaluation_field)){
132
- $operator = substr($evaluation_field, 0, 1);
133
- if(in_array($operator, array('=', '+', '-', '*', '/', '&'))){
134
- $eval_val = substr($evaluation_field, 1);
135
- //echo "operator:$operator";
136
- switch($operator){
137
- case '=':
138
- $processed_value = trim($eval_val);
139
- break;
140
- case '+':
141
- $processed_value = $value + $eval_val;
142
- break;
143
- case '-':
144
- $processed_value = $value - $eval_val;
145
- break;
146
- case '*':
147
- $processed_value = $value * $eval_val;
148
- break;
149
- case '/':
150
- $processed_value = $value / $eval_val;
151
- break;
152
- case '&':
153
- if (strpos($eval_val, '[VAL]') !== false) {
154
- $processed_value = str_replace('[VAL]',$value,$eval_val);
155
- }
156
- else{
157
- $processed_value = $value . $eval_val;
158
- }
159
- break;
160
- }
161
- }
162
- }
163
- return $processed_value;
164
- }
165
-
166
- /**
167
- * Parse product
168
- * @param array $item
169
- * @param integer $merge_empty_cells
170
- * @return array
171
- */
172
- public function parse_product( $item, $merge_empty_cells = 0 ) {
173
- global $WF_CSV_Product_Import, $wpdb;
174
- $this->row++;
175
-
176
- $terms_array = $postmeta = $product = array();
177
- $attributes = $default_attributes = $gpf_data = null;
178
-
179
- // Merging
180
- $merging = ( ! empty( $_GET['merge'] ) && $_GET['merge'] ) ? true : false;
181
- //if($item['post_parent']!== '' && $item['parent_sku'] !== ''){
182
-
183
- $this->post_defaults['post_type'] = 'product';
184
- $this->post_type = 'product';
185
- // Post ID field mapping
186
- $post_id = ( ! empty( $item['id'] ) ) ? $item['id'] : 0;
187
- $post_id = ( ! empty( $item['post_id'] ) ) ? $item['post_id'] : $post_id;
188
- if ( $merging ) {
189
-
190
- $product['merging'] = true;
191
-
192
-
193
- $WF_CSV_Product_Import->hf_log_data_change( 'csv-import', sprintf( __('> Row %s - preparing for merge.', 'wf_csv_import_export'), $this->row ) );
194
-
195
- // Required fields
196
- if ( ! $post_id && empty( $item['sku'] ) ) {
197
-
198
- $WF_CSV_Product_Import->hf_log_data_change( 'csv-import', __( '> > Cannot merge without id or sku. Importing instead.', 'wf_csv_import_export') );
199
-
200
- $merging = false;
201
- } else {
202
-
203
- // Check product exists
204
- if ( ! $post_id ) {
205
- // Check product to merge exists
206
- $db_query = $wpdb->prepare("
207
- SELECT $wpdb->posts.ID
208
- FROM $wpdb->posts
209
- LEFT JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id)
210
- WHERE $wpdb->posts.post_type = 'product'
211
- AND $wpdb->posts.post_status IN ( 'publish', 'private', 'draft', 'pending', 'future' )
212
- AND $wpdb->postmeta.meta_key = '_sku' AND $wpdb->postmeta.meta_value = '%s'
213
- ", $item['sku']);
214
- $found_product_id = $wpdb->get_var($db_query);
215
- if ( ! $found_product_id ) {
216
- $WF_CSV_Product_Import->hf_log_data_change( 'csv-import', sprintf(__( '> > Skipped. Cannot find product with sku %s. Importing instead.', 'wf_csv_import_export'), $item['sku']) );
217
- $merging = false;
218
-
219
- } else {
220
-
221
- $post_id = $found_product_id;
222
-
223
- $WF_CSV_Product_Import->hf_log_data_change( 'csv-import', sprintf(__( '> > Found product with ID %s.', 'wf_csv_import_export'), $post_id) );
224
-
225
- }
226
- }
227
- $product['merging'] = true;
228
- }
229
- }
230
-
231
- if ( ! $merging ) {
232
-
233
- $product['merging'] = false;
234
- $WF_CSV_Product_Import->hf_log_data_change( 'csv-import', sprintf( __('> Row %s - preparing for import.', 'wf_csv_import_export'), $this->row ) );
235
-
236
- // Required fields
237
- if ( isset($item['post_parent']) && $item['post_parent']=== '' && $item['post_title']=== '') {
238
- $WF_CSV_Product_Import->hf_log_data_change( 'csv-import', __( '> > Skipped. No post_title set for new product.', 'wf_csv_import_export') );
239
- return new WP_Error( 'parse-error', __( 'No post_title set for new product.', 'wf_csv_import_export' ) );
240
- }
241
- if ( !empty($item['post_parent']) && $item['post_parent']!== '' && $item['post_parent']!== null && $item['parent_sku'] === '' ) {
242
- $WF_CSV_Product_Import->hf_log_data_change( 'csv-import', __( '> > Skipped. No parent set for new variation product.', 'wf_csv_import_export') );
243
- //return new WP_Error( 'parse-error', __( 'No post_title set for new product.', 'wf_csv_import_export' ) );
244
- return new WP_Error( 'parse-error', __( 'No parent set for new variation product.', 'wf_csv_import_export' ) );
245
- }
246
-
247
- }
248
-
249
- $product['post_id'] = $post_id;
250
-
251
-
252
- // Get post fields
253
- foreach ( $this->post_defaults as $column => $default ) {
254
- if ( isset( $item[ $column ] ) ) $product[ $column ] = $item[ $column ];
255
- }
256
-
257
- // Get custom fields
258
- foreach ( $this->postmeta_defaults as $column => $default ) {
259
- if ( isset( $item[$column] ) )
260
- $postmeta[$column] = (string) $item[$column];
261
- elseif ( isset( $item['_' . $column] ) )
262
- $postmeta[$column] = (string) $item['_' . $column];
263
-
264
- // Check custom fields are valid
265
- if ( isset( $postmeta[$column] ) && isset( $this->postmeta_allowed[$column] ) && ! in_array( $postmeta[$column], $this->postmeta_allowed[$column] ) ) {
266
- $postmeta[$column] = $this->postmeta_defaults[$column];
267
- }
268
- }
269
-
270
- if ( ! $merging ) {
271
- // Merge post meta with defaults
272
- $product = wp_parse_args( $product, $this->post_defaults );
273
- $postmeta = wp_parse_args( $postmeta, $this->postmeta_defaults );
274
- }
275
-
276
- // Handle special meta fields
277
- if ( isset($item['post_parent']) ) {
278
-
279
- // price
280
- if ( $merging ) {
281
- if ( ! isset( $postmeta['regular_price'] ) )
282
- $postmeta['regular_price'] = get_post_meta( $post_id, '_regular_price', true );
283
- $postmeta['regular_price'] = $this->hf_currency_formatter($postmeta['regular_price']);
284
- if ( ! isset( $postmeta['sale_price'] ) )
285
- $postmeta['sale_price'] = get_post_meta( $post_id, '_sale_price', true );
286
- $postmeta['sale_price'] = $this->hf_currency_formatter($postmeta['sale_price']);
287
- }
288
-
289
- if ( isset( $postmeta['regular_price'] ) && isset( $postmeta['sale_price'] ) && $postmeta['sale_price'] !== '' ) {
290
- $postmeta['sale_price'] = $this->hf_currency_formatter($postmeta['sale_price']);
291
- $postmeta['regular_price'] = $this->hf_currency_formatter($postmeta['regular_price']);
292
- $price = min( $postmeta['sale_price'], $postmeta['regular_price']);
293
- $postmeta['price'] = $price;
294
- } elseif ( isset( $postmeta['regular_price'] ) ) {
295
- $postmeta['price'] = $this->hf_currency_formatter($postmeta['regular_price']);
296
- }
297
-
298
- } else {
299
-
300
- // price
301
- if ( $merging ) {
302
- if ( ! isset( $postmeta['regular_price'] ) )
303
- $postmeta['regular_price'] = get_post_meta( $post_id, '_regular_price', true );
304
- $postmeta['regular_price'] = $this->hf_currency_formatter($postmeta['regular_price']);
305
- if ( ! isset( $postmeta['sale_price'] ) )
306
- $postmeta['sale_price'] = get_post_meta( $post_id, '_sale_price', true );
307
- $postmeta['sale_price'] = $this->hf_currency_formatter($postmeta['sale_price']);
308
- }
309
-
310
- if ( isset( $postmeta['regular_price'] ) && isset( $postmeta['sale_price'] ) && $postmeta['sale_price'] !== '' ) {
311
- $postmeta['sale_price'] = $this->hf_currency_formatter($postmeta['sale_price']);
312
- $postmeta['regular_price'] = $this->hf_currency_formatter($postmeta['regular_price']);
313
- $price = min( $postmeta['sale_price'], $postmeta['regular_price']);
314
- $postmeta['price'] = $price;
315
- } elseif ( isset( $postmeta['regular_price'] ) ) {
316
- $postmeta['price'] = $this->hf_currency_formatter($postmeta['regular_price']);
317
- }
318
-
319
- // Reset dynamically generated meta
320
- $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'] = '';
321
- }
322
-
323
- // upsells
324
- if ( isset( $postmeta['upsell_ids'] ) && ! is_array( $postmeta['upsell_ids'] ) ) {
325
- $ids = array_filter( array_map( 'trim', explode( '|', $postmeta['upsell_ids'] ) ) );
326
- $postmeta['upsell_ids'] = $ids;
327
- }
328
-
329
- // crosssells
330
- if ( isset( $postmeta['crosssell_ids'] ) && ! is_array( $postmeta['crosssell_ids'] ) ) {
331
- $ids = array_filter( array_map( 'trim', explode( '|', $postmeta['crosssell_ids'] ) ) );
332
- $postmeta['crosssell_ids'] = $ids;
333
- }
334
-
335
- // Sale dates
336
- if ( isset( $postmeta['sale_price_dates_from'] ) ) {
337
- $postmeta['sale_price_dates_from'] = empty( $postmeta['sale_price_dates_from'] ) ? '' : strtotime( $postmeta['sale_price_dates_from'] );
338
- }
339
-
340
- if ( isset( $postmeta['sale_price_dates_to'] ) ) {
341
- $postmeta['sale_price_dates_to'] = empty( $postmeta['sale_price_dates_to'] ) ? '' : strtotime( $postmeta['sale_price_dates_to'] );
342
- }
343
-
344
- // Relative stock updates
345
- if ( $merging ) {
346
- if ( isset( $postmeta['stock'] ) ) {
347
-
348
- $postmeta['stock'] = trim( $postmeta['stock'] );
349
-
350
- $mode = substr( $postmeta['stock'], 0, 3 );
351
-
352
- if ( $mode == '(+)' ) {
353
- $old_stock = absint( get_post_meta( $post_id, '_stock', true ) );
354
- $amount = absint( substr( $postmeta['stock'], 3 ) );
355
- $new_stock = $old_stock + $amount;
356
- $postmeta['stock'] = $new_stock;
357
- }
358
-
359
- if ( $mode == '(-)' ) {
360
- $old_stock = absint( get_post_meta( $post_id, '_stock', true ) );
361
- $amount = absint( substr( $postmeta['stock'], 3 ) );
362
- $new_stock = $old_stock - $amount;
363
- $postmeta['stock'] = $new_stock;
364
- }
365
- }
366
- }
367
-
368
- // Format post status
369
- if ( ! empty( $product['post_status'] ) ) {
370
- $product['post_status'] = strtolower( $product['post_status'] );
371
-
372
- if ( empty($item['post_parent']) ) {
373
- if ( ! in_array( $product['post_status'], array( 'publish', 'private', 'draft', 'pending', 'future', 'inherit', 'trash' ) ) ) {
374
- $product['post_status'] = 'publish';
375
- }
376
- } else {
377
- if ( ! in_array( $product['post_status'], array( 'private', 'publish' ) ) ) {
378
- $product['post_status'] = 'publish';
379
- }
380
- }
381
- }
382
-
383
- // Put set core product postmeta into product array
384
- foreach ( $postmeta as $key => $value ) {
385
- $product['postmeta'][] = array( 'key' => '_' . esc_attr($key), 'value' => $value );
386
- }
387
-
388
- /**
389
- * Handle other columns
390
- */
391
- foreach ( $item as $key => $value ) {
392
-
393
- if ( empty($item['post_parent']) && ! $merge_empty_cells && $value == "" )
394
- continue;
395
-
396
- /**
397
- * File path handling
398
- */
399
- if ( $key == 'file_paths' || $key == 'downloadable_files' ) {
400
-
401
- $file_paths = explode( '|', $value );
402
- $_file_paths = array();
403
- foreach ( $file_paths as $file_path ) {
404
- // 2.1
405
- if ( function_exists( 'wc_get_filename_from_url' ) ) {
406
- $file_path = array_map( 'trim', explode( '::', $file_path ) );
407
- if ( sizeof( $file_path ) === 2 ) {
408
- $file_name = $file_path[0];
409
- $file_path = $file_path[1];
410
- } else {
411
- $file_name = wc_get_filename_from_url( $file_path[0] );
412
- $file_path = $file_path[0];
413
- }
414
- $_file_paths[ md5( $file_path ) ] = array(
415
- 'name' => $file_name,
416
- 'file' => $file_path
417
- );
418
- } else {
419
- $file_path = trim( $file_path );
420
- $_file_paths[ md5( $file_path ) ] = $file_path;
421
- }
422
- }
423
- $value = $_file_paths;
424
-
425
- $product['postmeta'][] = array( 'key' => '_' . esc_attr( $key ), 'value' => $value );
426
- }
427
-
428
- elseif ( strstr( $key, 'tax:' ) ) {
429
-
430
- // Get taxonomy
431
- $taxonomy = trim( str_replace( 'tax:', '', $key ) );
432
-
433
- // Exists?
434
- if ( ! taxonomy_exists( $taxonomy ) ) {
435
- $WF_CSV_Product_Import->hf_log_data_change( 'csv-import', sprintf( __('> > Skipping taxonomy "%s" - it does not exist.', 'wf_csv_import_export'), $taxonomy ) );
436
- continue;
437
- }
438
-
439
- // Product type check
440
- if ( $taxonomy == 'product_type' ) {
441
- $term = strtolower( $value );
442
-
443
- if ( ! array_key_exists( $term, $this->allowed_product_types ) ) {
444
- $WF_CSV_Product_Import->hf_log_data_change( 'csv-import', sprintf( __('> > > Product type "%s" not allowed - using simple.', 'wf_csv_import_export'), $term ) );
445
- $term_id = $this->allowed_product_types['simple'];
446
- } else {
447
- $term_id = $this->allowed_product_types[ $term ];
448
- }
449
-
450
- // Add to array
451
- $terms_array[] = array(
452
- 'taxonomy' => $taxonomy,
453
- 'terms' => array( $term_id )
454
- );
455
-
456
- continue;
457
- }
458
-
459
- // Get terms - ID => parent
460
- $terms = array();
461
- $raw_terms = explode( '|', $value );
462
- $raw_terms = array_map( 'trim', $raw_terms );
463
-
464
- // Handle term hierachy (>)
465
- foreach ( $raw_terms as $raw_term ) {
466
-
467
- if ( strstr( $raw_term, '>' ) ) {
468
-
469
- $raw_term = explode( '>', $raw_term );
470
- $raw_term = array_map( 'trim', $raw_term );
471
-
472
- if(WC()->version < '2.7.0')
473
- {
474
- $raw_term = array_map( 'wp_specialchars', $raw_term );
475
- $raw_term = array_filter( $raw_term );
476
-
477
- }
478
- else
479
- {
480
- $raw_term = array_map( 'esc_html', $raw_term );
481
- $raw_term = array_filter( $raw_term );
482
-
483
- }
484
-
485
- $parent = 0;
486
- $loop = 0;
487
-
488
- foreach ( $raw_term as $term ) {
489
- $loop ++;
490
- $term_id = '';
491
-
492
- if ( isset( $this->inserted_terms[ $taxonomy ][ $parent ][ $term ] ) ) {
493
- $term_id = $this->inserted_terms[ $taxonomy ][ $parent ][ $term ];
494
- } elseif ( $term ) {
495
-
496
- /**
497
- * Check term existance
498
- */
499
- $term_may_exist = term_exists( $term, $taxonomy, absint( $parent ) );
500
-
501
- $WF_CSV_Product_Import->hf_log_data_change( '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 ) : '-' ) );
502
-
503
- if ( is_array( $term_may_exist ) ) {
504
- $possible_term = get_term( $term_may_exist['term_id'], 'product_cat' );
505
-
506
- if ( $possible_term->parent == $parent ) {
507
- $term_id = $term_may_exist['term_id'];
508
- }
509
- }
510
-
511
- if ( ! $term_id ) {
512
-
513
- // Create appropriate slug
514
- $slug = array();
515
-
516
- for ( $i = 0; $i < $loop; $i ++ )
517
- $slug[] = $raw_term[ $i ];
518
-
519
- $slug = sanitize_title( implode( '-', $slug ) );
520
-
521
- $t = wp_insert_term( $term, $taxonomy, array( 'parent' => $parent, 'slug' => $slug ) );
522
-
523
- if ( ! is_wp_error( $t ) ) {
524
- $term_id = $t['term_id'];
525
- } else {
526
- $WF_CSV_Product_Import->hf_log_data_change( '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 ) ) );
527
- break;
528
- }
529
- }
530
-
531
- $this->inserted_terms[$taxonomy][$parent][$term] = $term_id;
532
-
533
- }
534
-
535
- if ( ! $term_id )
536
- break;
537
-
538
- // Add to product terms, ready to set if this is the final term
539
- if ( sizeof( $raw_term ) == $loop )
540
- $terms[] = $term_id;
541
-
542
- $parent = $term_id;
543
- }
544
-
545
- } else {
546
-
547
- $term_id = '';
548
- $raw_term = (WC()->version < '2.7.0') ? wp_specialchars( $raw_term ) : esc_html( $raw_term );
549
-
550
- if ( isset( $this->inserted_terms[$taxonomy][0][$raw_term] ) ) {
551
-
552
- $term_id = $this->inserted_terms[$taxonomy][0][$raw_term];
553
-
554
- } elseif ( $raw_term ) {
555
-
556
- // Check term existance
557
- $term_exists = term_exists( $raw_term, $taxonomy, 0 );
558
- $term_id = is_array( $term_exists ) ? $term_exists['term_id'] : 0;
559
-
560
- if ( ! $term_id ) {
561
- $t = wp_insert_term( trim( $raw_term ), $taxonomy, array( 'parent' => 0 ) );
562
-
563
- if ( ! is_wp_error( $t ) ) {
564
- $term_id = $t['term_id'];
565
- } else {
566
- $WF_CSV_Product_Import->hf_log_data_change( 'csv-import', sprintf( __( '> > Failed to import term %s %s', 'wf_csv_import_export' ), esc_html($raw_term), esc_html($taxonomy) ) );
567
- break;
568
- }
569
- }
570
-
571
- $this->inserted_terms[$taxonomy][0][$raw_term] = $term_id;
572
-
573
- }
574
-
575
- // Store terms for later insertion
576
- if ( $term_id )
577
- $terms[] = $term_id;
578
-
579
- }
580
-
581
- }
582
-
583
- // Any defined?
584
- if ( sizeof( $terms ) == 0 )
585
- continue;
586
-
587
- // Add to array
588
- $terms_array[] = array(
589
- 'taxonomy' => $taxonomy,
590
- 'terms' => $terms
591
- );
592
- }
593
-
594
- /**
595
- * Handle Attributes
596
- */
597
- elseif ( strstr( $key, 'attribute:' ) ) {
598
-
599
- $attribute_key = sanitize_title( trim( str_replace( 'attribute:', '', $key ) ) );
600
- $attribute_name = str_replace( 'attribute:', '', $WF_CSV_Product_Import->raw_headers[ $key ] );
601
-
602
- if ( ! $attribute_key )
603
- continue;
604
-
605
- // Taxonomy
606
- if ( substr( $attribute_key, 0, 3 ) == 'pa_' ) {
607
-
608
- $taxonomy = $attribute_key;
609
-
610
- // Exists?
611
- if ( ! taxonomy_exists( $taxonomy ) ) {
612
-
613
- $nicename = strtolower( sanitize_title( str_replace( 'pa_', '', $taxonomy ) ) );
614
-
615
- $WF_CSV_Product_Import->hf_log_data_change( 'csv-import', sprintf( __('> > Attribute taxonomy "%s" does not exist. Adding it. Nicename: %s', 'wf_csv_import_export'), $taxonomy, $nicename ) );
616
-
617
- $exists_in_db = $wpdb->get_var( "SELECT attribute_id FROM " . $wpdb->prefix . "woocommerce_attribute_taxonomies WHERE attribute_name = '" . $nicename . "';" );
618
-
619
- if ( ! $exists_in_db ) {
620
- // Create the taxonomy
621
- $wpdb->insert( $wpdb->prefix . "woocommerce_attribute_taxonomies", array( 'attribute_name' => $nicename, 'attribute_label' => $nicename, 'attribute_type' => 'select', 'attribute_orderby' => 'menu_order' ) );
622
- } else {
623
- $WF_CSV_Product_Import->hf_log_data_change( 'csv-import', sprintf( __('> > Attribute taxonomy %s already exists in DB.', 'wf_csv_import_export'), $taxonomy ) );
624
- }
625
-
626
- // Register the taxonomy now so that the import works!
627
- register_taxonomy( $taxonomy,
628
- array( 'product', 'product_variation' ),
629
- array(
630
- 'hierarchical' => true,
631
- 'show_ui' => false,
632
- 'query_var' => true,
633
- 'rewrite' => false,
634
- )
635
- );
636
- }
637
-
638
- // Get terms
639
- $terms = array();
640
- $raw_terms = explode( '|', $value );
641
- if(WC()->version < '2.7.0')
642
- {
643
- $raw_terms = array_map( 'wp_specialchars', $raw_terms );
644
- $raw_terms = array_map( 'trim', $raw_terms );
645
-
646
- }else{
647
-
648
- $raw_terms = array_map( 'esc_html', $raw_terms );
649
- $raw_terms = array_map( 'trim', $raw_terms );
650
-
651
- }
652
-
653
- if ( sizeof( $raw_terms ) > 0 ) {
654
-
655
- foreach ( $raw_terms as $raw_term ) {
656
-
657
- if ( empty( $raw_term ) && 0 != $raw_term ) {
658
- continue;
659
- }
660
-
661
- // Check term existance
662
- $term_exists = term_exists( $raw_term, $taxonomy, 0 );
663
- $term_id = is_array( $term_exists ) ? $term_exists['term_id'] : 0;
664
-
665
- if ( ! $term_id ) {
666
- $t = wp_insert_term( trim( $raw_term ), $taxonomy );
667
-
668
- if ( ! is_wp_error( $t ) ) {
669
- $term_id = $t['term_id'];
670
-
671
- $WF_CSV_Product_Import->hf_log_data_change( 'csv-import', sprintf( __( '> > Inserted Raw Term %s ID = %s', 'wf_csv_import_export' ), esc_html( $raw_term ), $term_id ) );
672
- } else {
673
- $WF_CSV_Product_Import->hf_log_data_change( 'csv-import', sprintf( __( '> > Failed to import term %s %s', 'wf_csv_import_export' ), esc_html($raw_term), esc_html($taxonomy) ) );
674
- break;
675
- }
676
- } else {
677
- $WF_CSV_Product_Import->hf_log_data_change( 'csv-import', sprintf( __( '> > Raw Term %s ID = %s', 'wf_csv_import_export' ), esc_html( $raw_term ), $term_id ) );
678
- }
679
-
680
- if ( $term_id ) {
681
- $terms[] = $term_id;
682
- }
683
- }
684
-
685
- }
686
-
687
- // Add to array
688
- $terms_array[] = array(
689
- 'taxonomy' => $taxonomy,
690
- 'terms' => $terms
691
- );
692
-
693
- // Ensure we have original attributes
694
- if ( is_null( $attributes ) && $merging ) {
695
- $attributes = array_filter( (array) maybe_unserialize( get_post_meta( $post_id, '_product_attributes', true ) ) );
696
- } elseif ( is_null( $attributes ) ) {
697
- $attributes = array();
698
- }
699
-
700
- // Set attribute
701
- if ( ! isset( $attributes[$taxonomy] ) )
702
- $attributes[$taxonomy] = array();
703
-
704
- $attributes[$taxonomy]['name'] = $taxonomy;
705
- $attributes[$taxonomy]['value'] = null;
706
- $attributes[$taxonomy]['is_taxonomy'] = 1;
707
-
708
- if ( ! isset( $attributes[$taxonomy]['position'] ) )
709
- $attributes[$taxonomy]['position'] = 0;
710
- if ( ! isset( $attributes[$taxonomy]['is_visible'] ) )
711
- $attributes[$taxonomy]['is_visible'] = 1;
712
- if ( ! isset( $attributes[$taxonomy]['is_variation'] ) )
713
- $attributes[$taxonomy]['is_variation'] = 0;
714
-
715
- } else {
716
-
717
- if ( ! $value || ! $attribute_key ) continue;
718
-
719
- // Set attribute
720
- if ( ! isset( $attributes[$attribute_key] ) )
721
- $attributes[$attribute_key] = array();
722
-
723
- $attributes[$attribute_key]['name'] = $attribute_name;
724
- $attributes[$attribute_key]['value'] = $value;
725
- $attributes[$attribute_key]['is_taxonomy'] = 0;
726
-
727
- if ( ! isset( $attributes[$attribute_key]['position'] ) )
728
- $attributes[$attribute_key]['position'] = 0;
729
- if ( ! isset( $attributes[$attribute_key]['is_visible'] ) )
730
- $attributes[$attribute_key]['is_visible'] = 1;
731
- if ( ! isset( $attributes[$attribute_key]['is_variation'] ) )
732
- $attributes[$attribute_key]['is_variation'] = 0;
733
- }
734
-
735
- }
736
-
737
- /**
738
- * Handle Attributes Data - position|is_visible|is_variation
739
- */
740
- elseif ( strstr( $key, 'attribute_data:' ) ) {
741
-
742
- $attribute_key = sanitize_title( trim( str_replace( 'attribute_data:', '', $key ) ) );
743
-
744
- if ( ! $attribute_key ) {
745
- continue;
746
- }
747
-
748
- $values = explode( '|', $value );
749
- $position = isset( $values[0] ) ? (int) $values[0] : 0;
750
- $visible = isset( $values[1] ) ? (int) $values[1] : 1;
751
- $variation = isset( $values[2] ) ? (int) $values[2] : 0;
752
-
753
- // Ensure we have original attributes
754
- if ( ! isset( $attributes[ $attribute_key ] ) ) {
755
- if ( $merging ) {
756
- $existing_attributes = array_filter( (array) maybe_unserialize( get_post_meta( $post_id, '_product_attributes', true ) ) );
757
- $attributes[ $attribute_key ] = isset( $existing_attributes[ $attribute_key ] ) ? $existing_attributes[ $attribute_key ] : array();
758
- } else {
759
- $attributes[ $attribute_key ] = array();
760
- }
761
- }
762
-
763
- $attributes[ $attribute_key ]['position'] = $position;
764
- $attributes[ $attribute_key ]['is_visible'] = $visible;
765
- $attributes[ $attribute_key ]['is_variation'] = $variation;
766
- }
767
-
768
- /**
769
- * Handle Attributes Default Values
770
- */
771
- elseif ( strstr( $key, 'attribute_default:' ) ) {
772
-
773
- $attribute_key = sanitize_title( trim( str_replace( 'attribute_default:', '', $key ) ) );
774
-
775
- if ( ! $attribute_key ) continue;
776
-
777
- // Ensure we have original attributes
778
- if ( is_null( $default_attributes ) && $merging ) {
779
- $default_attributes = array_filter( (array) maybe_unserialize( get_post_meta( $post_id, '_default_attributes', true ) ) );
780
- } elseif ( is_null( $default_attributes ) ) {
781
- $default_attributes = array();
782
- }
783
-
784
- $default_attributes[ $attribute_key ] = $value;
785
- }
786
-
787
- /**
788
- * Handle gpf: google product feed columns
789
- */
790
- elseif ( strstr( $key, 'gpf:' ) ) {
791
-
792
- $gpf_key = trim( str_replace( 'gpf:', '', $key ) );
793
-
794
- // Get original values
795
- if ( is_null( $gpf_data ) && $merging ) {
796
- $gpf_data = array_filter( (array) maybe_unserialize( get_post_meta( $post_id, '_woocommerce_gpf_data', true ) ) );
797
- } elseif ( is_null( $gpf_data ) ) {
798
- $gpf_data = array(
799
- 'availability' => '',
800
- 'condition' => '',
801
- 'brand' => '',
802
- 'product_type' => '',
803
- 'google_product_category' => '',
804
- 'gtin' => '',
805
- 'mpn' => '',
806
- 'gender' => '',
807
- 'age_group' => '',
808
- 'color' => '',
809
- 'size' => ''
810
- );
811
- }
812
-
813
- $gpf_data[$gpf_key] = $value;
814
-
815
- }
816
-
817
- /**
818
- * Handle upsell SKUs which we cannot assign until we get IDs later on
819
- */
820
- elseif ( strstr( $key, 'upsell_skus' ) ) {
821
- if ( $value ) {
822
- $skus = array_filter( array_map( 'trim', explode( '|', $value ) ) );
823
- $product['upsell_skus'] = $skus;
824
- }
825
- }
826
-
827
- /**
828
- * Handle crosssells SKUs which we cannot assign until we get IDs later on
829
- */
830
- elseif ( strstr( $key, 'crosssell_skus' ) ) {
831
- if ( $value ) {
832
- $skus = array_filter( array_map( 'trim', explode( '|', $value ) ) );
833
- $product['crosssell_skus'] = $skus;
834
- }
835
- }
836
-
837
- }
838
-
839
- // Remove empty attribues
840
- if(!empty($attributes))
841
- foreach ( $attributes as $key => $value ) {
842
- if ( ! isset($value['name']) ) unset( $attributes[$key] );
843
- }
844
-
845
- /**
846
- * Handle images
847
- */
848
- if ( ! empty( $item['images'] ) ) {
849
- $images = array_map( 'trim', explode( '|', $item['images'] ) );
850
- } else {
851
- $images = '';
852
- }
853
-
854
- $product['postmeta'][] = array( 'key' => '_default_attributes', 'value' => $default_attributes );
855
- $product['attributes'] = $attributes;
856
- $product['gpf_data'] = $gpf_data;
857
- $product['images'] = $images;
858
- $product['terms'] = $terms_array;
859
- $product['sku'] = ( ! empty( $item['sku'] ) ) ? $item['sku'] : '';
860
- $product['post_title'] = ( ! empty( $item['post_title'] ) ) ? $item['post_title'] : '';
861
- $product['post_type'] = $this->post_type;
862
- unset( $item, $terms_array, $postmeta, $attributes, $gpf_data, $images );
863
- return $product;
864
- }
865
- function hf_currency_formatter($price){
866
- $decimal_seperator = wc_get_price_decimal_separator();
867
- //return ereg_replace("[^0-9\\'.$decimal_seperator.']", "", $price);
868
- return preg_replace("[^0-9\\'.$decimal_seperator.']", "", $price);
869
- }
870
- }
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
+ if(!empty($eval_field[strtolower( $heading )]))
109
+ $row[$s_heading] = $this->evaluate_field($row[$s_heading], $eval_field[strtolower( $heading )]);
110
+
111
+ // Raw Headers stores the actual column name in the CSV
112
+ $raw_headers[ $s_heading ] = $heading;
113
+ }
114
+ $parsed_data[] = $row;
115
+
116
+ unset( $postmeta, $row );
117
+
118
+ $position = ftell( $handle );
119
+
120
+ if ( $end_pos && $position >= $end_pos )
121
+ break;
122
+ }
123
+ fclose( $handle );
124
+ }
125
+ return array( $parsed_data, $raw_headers, $position );
126
+ }
127
+
128
+ private function evaluate_field($value, $evaluation_field){
129
+ //echo "value:$value, $evaluation_field </br>";
130
+ $processed_value = $value;
131
+ if(!empty($evaluation_field)){
132
+ $operator = substr($evaluation_field, 0, 1);
133
+ if(in_array($operator, array('=', '+', '-', '*', '/', '&'))){
134
+ $eval_val = substr($evaluation_field, 1);
135
+ //echo "operator:$operator";
136
+ switch($operator){
137
+ case '=':
138
+ $processed_value = trim($eval_val);
139
+ break;
140
+ case '+':
141
+ $processed_value = $value + $eval_val;
142
+ break;
143
+ case '-':
144
+ $processed_value = $value - $eval_val;
145
+ break;
146
+ case '*':
147
+ $processed_value = $value * $eval_val;
148
+ break;
149
+ case '/':
150
+ $processed_value = $value / $eval_val;
151
+ break;
152
+ case '&':
153
+ if (strpos($eval_val, '[VAL]') !== false) {
154
+ $processed_value = str_replace('[VAL]',$value,$eval_val);
155
+ }
156
+ else{
157
+ $processed_value = $value . $eval_val;
158
+ }
159
+ break;
160
+ }
161
+ }
162
+ }
163
+ return $processed_value;
164
+ }
165
+
166
+ /**
167
+ * Parse product
168
+ * @param array $item
169
+ * @param integer $merge_empty_cells
170
+ * @return array
171
+ */
172
+ public function parse_product( $item, $merge_empty_cells = 0 ) {
173
+ global $WF_CSV_Product_Import, $wpdb;
174
+ $this->row++;
175
+
176
+ $terms_array = $postmeta = $product = array();
177
+ $attributes = $default_attributes = $gpf_data = null;
178
+
179
+ // Merging
180
+ $merging = ( ! empty( $_GET['merge'] ) && $_GET['merge'] ) ? true : false;
181
+ //if($item['post_parent']!== '' && $item['parent_sku'] !== ''){
182
+
183
+ $this->post_defaults['post_type'] = 'product';
184
+ $this->post_type = 'product';
185
+ // Post ID field mapping
186
+ $post_id = ( ! empty( $item['id'] ) ) ? $item['id'] : 0;
187
+ $post_id = ( ! empty( $item['post_id'] ) ) ? $item['post_id'] : $post_id;
188
+ if ( $merging ) {
189
+
190
+ $product['merging'] = true;
191
+
192
+
193
+ $WF_CSV_Product_Import->hf_log_data_change( 'csv-import', sprintf( __('> Row %s - preparing for merge.', 'wf_csv_import_export'), $this->row ) );
194
+
195
+ // Required fields
196
+ if ( ! $post_id && empty( $item['sku'] ) ) {
197
+
198
+ $WF_CSV_Product_Import->hf_log_data_change( 'csv-import', __( '> > Cannot merge without id or sku. Importing instead.', 'wf_csv_import_export') );
199
+
200
+ $merging = false;
201
+ } else {
202
+
203
+ // Check product exists
204
+ if ( ! $post_id ) {
205
+ // Check product to merge exists
206
+ $db_query = $wpdb->prepare("
207
+ SELECT $wpdb->posts.ID
208
+ FROM $wpdb->posts
209
+ LEFT JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id)
210
+ WHERE $wpdb->posts.post_type = 'product'
211
+ AND $wpdb->posts.post_status IN ( 'publish', 'private', 'draft', 'pending', 'future' )
212
+ AND $wpdb->postmeta.meta_key = '_sku' AND $wpdb->postmeta.meta_value = '%s'
213
+ ", $item['sku']);
214
+ $found_product_id = $wpdb->get_var($db_query);
215
+ if ( ! $found_product_id ) {
216
+ $WF_CSV_Product_Import->hf_log_data_change( 'csv-import', sprintf(__( '> > Skipped. Cannot find product with sku %s. Importing instead.', 'wf_csv_import_export'), $item['sku']) );
217
+ $merging = false;
218
+
219
+ } else {
220
+
221
+ $post_id = $found_product_id;
222
+
223
+ $WF_CSV_Product_Import->hf_log_data_change( 'csv-import', sprintf(__( '> > Found product with ID %s.', 'wf_csv_import_export'), $post_id) );
224
+
225
+ }
226
+ }
227
+ $product['merging'] = true;
228
+ }
229
+ }
230
+
231
+ if ( ! $merging ) {
232
+
233
+ $product['merging'] = false;
234
+ $WF_CSV_Product_Import->hf_log_data_change( 'csv-import', sprintf( __('> Row %s - preparing for import.', 'wf_csv_import_export'), $this->row ) );
235
+
236
+ // Required fields
237
+ if ( isset($item['post_parent']) && $item['post_parent']=== '' && $item['post_title']=== '') {
238
+ $WF_CSV_Product_Import->hf_log_data_change( 'csv-import', __( '> > Skipped. No post_title set for new product.', 'wf_csv_import_export') );
239
+ return new WP_Error( 'parse-error', __( 'No post_title set for new product.', 'wf_csv_import_export' ) );
240
+ }
241
+ if ( !empty($item['post_parent']) && $item['post_parent']!== '' && $item['post_parent']!== null && $item['parent_sku'] === '' ) {
242
+ $WF_CSV_Product_Import->hf_log_data_change( 'csv-import', __( '> > Skipped. No parent set for new variation product.', 'wf_csv_import_export') );
243
+ //return new WP_Error( 'parse-error', __( 'No post_title set for new product.', 'wf_csv_import_export' ) );
244
+ return new WP_Error( 'parse-error', __( 'No parent set for new variation product.', 'wf_csv_import_export' ) );
245
+ }
246
+
247
+ }
248
+
249
+ $product['post_id'] = $post_id;
250
+
251
+
252
+ // Get post fields
253
+ foreach ( $this->post_defaults as $column => $default ) {
254
+ if ( isset( $item[ $column ] ) ) $product[ $column ] = $item[ $column ];
255
+ }
256
+
257
+ // Get custom fields
258
+ foreach ( $this->postmeta_defaults as $column => $default ) {
259
+ if ( isset( $item[$column] ) )
260
+ $postmeta[$column] = (string) $item[$column];
261
+ elseif ( isset( $item['_' . $column] ) )
262
+ $postmeta[$column] = (string) $item['_' . $column];
263
+
264
+ // Check custom fields are valid
265
+ if ( isset( $postmeta[$column] ) && isset( $this->postmeta_allowed[$column] ) && ! in_array( $postmeta[$column], $this->postmeta_allowed[$column] ) ) {
266
+ $postmeta[$column] = $this->postmeta_defaults[$column];
267
+ }
268
+ }
269
+
270
+ if ( ! $merging ) {
271
+ // Merge post meta with defaults
272
+ $product = wp_parse_args( $product, $this->post_defaults );
273
+ $postmeta = wp_parse_args( $postmeta, $this->postmeta_defaults );
274
+ }
275
+
276
+ // Handle special meta fields
277
+ if ( isset($item['post_parent']) ) {
278
+
279
+ // price
280
+ if ( $merging ) {
281
+ if ( ! isset( $postmeta['regular_price'] ) )
282
+ $postmeta['regular_price'] = get_post_meta( $post_id, '_regular_price', true );
283
+ $postmeta['regular_price'] = $this->hf_currency_formatter($postmeta['regular_price']);
284
+ if ( ! isset( $postmeta['sale_price'] ) )
285
+ $postmeta['sale_price'] = get_post_meta( $post_id, '_sale_price', true );
286
+ $postmeta['sale_price'] = $this->hf_currency_formatter($postmeta['sale_price']);
287
+ }
288
+
289
+ if ( isset( $postmeta['regular_price'] ) && isset( $postmeta['sale_price'] ) && $postmeta['sale_price'] !== '' ) {
290
+ $postmeta['sale_price'] = $this->hf_currency_formatter($postmeta['sale_price']);
291
+ $postmeta['regular_price'] = $this->hf_currency_formatter($postmeta['regular_price']);
292
+ $price = min( $postmeta['sale_price'], $postmeta['regular_price']);
293
+ $postmeta['price'] = $price;
294
+ } elseif ( isset( $postmeta['regular_price'] ) ) {
295
+ $postmeta['price'] = $this->hf_currency_formatter($postmeta['regular_price']);
296
+ }
297
+
298
+ } else {
299
+
300
+ // price
301
+ if ( $merging ) {
302
+ if ( ! isset( $postmeta['regular_price'] ) )
303
+ $postmeta['regular_price'] = get_post_meta( $post_id, '_regular_price', true );
304
+ $postmeta['regular_price'] = $this->hf_currency_formatter($postmeta['regular_price']);
305
+ if ( ! isset( $postmeta['sale_price'] ) )
306
+ $postmeta['sale_price'] = get_post_meta( $post_id, '_sale_price', true );
307
+ $postmeta['sale_price'] = $this->hf_currency_formatter($postmeta['sale_price']);
308
+ }
309
+
310
+ if ( isset( $postmeta['regular_price'] ) && isset( $postmeta['sale_price'] ) && $postmeta['sale_price'] !== '' ) {
311
+ $postmeta['sale_price'] = $this->hf_currency_formatter($postmeta['sale_price']);
312
+ $postmeta['regular_price'] = $this->hf_currency_formatter($postmeta['regular_price']);
313
+ $price = min( $postmeta['sale_price'], $postmeta['regular_price']);
314
+ $postmeta['price'] = $price;
315
+ } elseif ( isset( $postmeta['regular_price'] ) ) {
316
+ $postmeta['price'] = $this->hf_currency_formatter($postmeta['regular_price']);
317
+ }
318
+
319
+ // Reset dynamically generated meta
320
+ $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'] = '';
321
+ }
322
+
323
+ // upsells
324
+ if ( isset( $postmeta['upsell_ids'] ) && ! is_array( $postmeta['upsell_ids'] ) ) {
325
+ $ids = array_filter( array_map( 'trim', explode( '|', $postmeta['upsell_ids'] ) ) );
326
+ $postmeta['upsell_ids'] = $ids;
327
+ }
328
+
329
+ // crosssells
330
+ if ( isset( $postmeta['crosssell_ids'] ) && ! is_array( $postmeta['crosssell_ids'] ) ) {
331
+ $ids = array_filter( array_map( 'trim', explode( '|', $postmeta['crosssell_ids'] ) ) );
332
+ $postmeta['crosssell_ids'] = $ids;
333
+ }
334
+
335
+ // Sale dates
336
+ if ( isset( $postmeta['sale_price_dates_from'] ) ) {
337
+ $postmeta['sale_price_dates_from'] = empty( $postmeta['sale_price_dates_from'] ) ? '' : strtotime( $postmeta['sale_price_dates_from'] );
338
+ }
339
+
340
+ if ( isset( $postmeta['sale_price_dates_to'] ) ) {
341
+ $postmeta['sale_price_dates_to'] = empty( $postmeta['sale_price_dates_to'] ) ? '' : strtotime( $postmeta['sale_price_dates_to'] );
342
+ }
343
+
344
+ // Relative stock updates
345
+ if ( $merging ) {
346
+ if ( isset( $postmeta['stock'] ) ) {
347
+
348
+ $postmeta['stock'] = trim( $postmeta['stock'] );
349
+
350
+ $mode = substr( $postmeta['stock'], 0, 3 );
351
+
352
+ if ( $mode == '(+)' ) {
353
+ $old_stock = absint( get_post_meta( $post_id, '_stock', true ) );
354
+ $amount = absint( substr( $postmeta['stock'], 3 ) );
355
+ $new_stock = $old_stock + $amount;
356
+ $postmeta['stock'] = $new_stock;
357
+ }
358
+
359
+ if ( $mode == '(-)' ) {
360
+ $old_stock = absint( get_post_meta( $post_id, '_stock', true ) );
361
+ $amount = absint( substr( $postmeta['stock'], 3 ) );
362
+ $new_stock = $old_stock - $amount;
363
+ $postmeta['stock'] = $new_stock;
364
+ }
365
+ }
366
+ }
367
+
368
+ // Format post status
369
+ if ( ! empty( $product['post_status'] ) ) {
370
+ $product['post_status'] = strtolower( $product['post_status'] );
371
+
372
+ if ( empty($item['post_parent']) ) {
373
+ if ( ! in_array( $product['post_status'], array( 'publish', 'private', 'draft', 'pending', 'future', 'inherit', 'trash' ) ) ) {
374
+ $product['post_status'] = 'publish';
375
+ }
376
+ } else {
377
+ if ( ! in_array( $product['post_status'], array( 'private', 'publish' ) ) ) {
378
+ $product['post_status'] = 'publish';
379
+ }
380
+ }
381
+ }
382
+
383
+ // Put set core product postmeta into product array
384
+ foreach ( $postmeta as $key => $value ) {
385
+ $product['postmeta'][] = array( 'key' => '_' . esc_attr($key), 'value' => $value );
386
+ }
387
+
388
+ /**
389
+ * Handle other columns
390
+ */
391
+ foreach ( $item as $key => $value ) {
392
+
393
+ if ( empty($item['post_parent']) && ! $merge_empty_cells && $value == "" )
394
+ continue;
395
+
396
+ /**
397
+ * File path handling
398
+ */
399
+ if ( $key == 'file_paths' || $key == 'downloadable_files' ) {
400
+
401
+ $file_paths = explode( '|', $value );
402
+ $_file_paths = array();
403
+ foreach ( $file_paths as $file_path ) {
404
+ // 2.1
405
+ if ( function_exists( 'wc_get_filename_from_url' ) ) {
406
+ $file_path = array_map( 'trim', explode( '::', $file_path ) );
407
+ if ( sizeof( $file_path ) === 2 ) {
408
+ $file_name = $file_path[0];
409
+ $file_path = $file_path[1];
410
+ } else {
411
+ $file_name = wc_get_filename_from_url( $file_path[0] );
412
+ $file_path = $file_path[0];
413
+ }
414
+ $_file_paths[ md5( $file_path ) ] = array(
415
+ 'name' => $file_name,
416
+ 'file' => $file_path
417
+ );
418
+ } else {
419
+ $file_path = trim( $file_path );
420
+ $_file_paths[ md5( $file_path ) ] = $file_path;
421
+ }
422
+ }
423
+ $value = $_file_paths;
424
+
425
+ $product['postmeta'][] = array( 'key' => '_' . esc_attr( $key ), 'value' => $value );
426
+ }
427
+
428
+ elseif ( strstr( $key, 'tax:' ) ) {
429
+
430
+ // Get taxonomy
431
+ $taxonomy = trim( str_replace( 'tax:', '', $key ) );
432
+
433
+ // Exists?
434
+ if ( ! taxonomy_exists( $taxonomy ) ) {
435
+ $WF_CSV_Product_Import->hf_log_data_change( 'csv-import', sprintf( __('> > Skipping taxonomy "%s" - it does not exist.', 'wf_csv_import_export'), $taxonomy ) );
436
+ continue;
437
+ }
438
+
439
+ // Product type check
440
+ if ( $taxonomy == 'product_type' ) {
441
+ $term = strtolower( $value );
442
+
443
+ if ( ! array_key_exists( $term, $this->allowed_product_types ) ) {
444
+ $WF_CSV_Product_Import->hf_log_data_change( 'csv-import', sprintf( __('> > > Product type "%s" not allowed - using simple.', 'wf_csv_import_export'), $term ) );
445
+ $term_id = $this->allowed_product_types['simple'];
446
+ } else {
447
+ $term_id = $this->allowed_product_types[ $term ];
448
+ }
449
+
450
+ // Add to array
451
+ $terms_array[] = array(
452
+ 'taxonomy' => $taxonomy,
453
+ 'terms' => array( $term_id )
454
+ );
455
+
456
+ continue;
457
+ }
458
+
459
+ // Get terms - ID => parent
460
+ $terms = array();
461
+ $raw_terms = explode( '|', $value );
462
+ $raw_terms = array_map( 'trim', $raw_terms );
463
+
464
+ // Handle term hierachy (>)
465
+ foreach ( $raw_terms as $raw_term ) {
466
+
467
+ if ( strstr( $raw_term, '>' ) ) {
468
+
469
+ $raw_term = explode( '>', $raw_term );
470
+ $raw_term = array_map( 'trim', $raw_term );
471
+
472
+ if(WC()->version < '2.7.0')
473
+ {
474
+ $raw_term = array_map( 'wp_specialchars', $raw_term );
475
+ $raw_term = array_filter( $raw_term );
476
+
477
+ }
478
+ else
479
+ {
480
+ $raw_term = array_map( 'esc_html', $raw_term );
481
+ $raw_term = array_filter( $raw_term );
482
+
483
+ }
484
+
485
+ $parent = 0;
486
+ $loop = 0;
487
+
488
+ foreach ( $raw_term as $term ) {
489
+ $loop ++;
490
+ $term_id = '';
491
+
492
+ if ( isset( $this->inserted_terms[ $taxonomy ][ $parent ][ $term ] ) ) {
493
+ $term_id = $this->inserted_terms[ $taxonomy ][ $parent ][ $term ];
494
+ } elseif ( $term ) {
495
+
496
+ /**
497
+ * Check term existance
498
+ */
499
+ $term_may_exist = term_exists( $term, $taxonomy, absint( $parent ) );
500
+
501
+ $WF_CSV_Product_Import->hf_log_data_change( '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 ) : '-' ) );
502
+
503
+ if ( is_array( $term_may_exist ) ) {
504
+ $possible_term = get_term( $term_may_exist['term_id'], 'product_cat' );
505
+
506
+ if ( $possible_term->parent == $parent ) {
507
+ $term_id = $term_may_exist['term_id'];
508
+ }
509
+ }
510
+
511
+ if ( ! $term_id ) {
512
+
513
+ // Create appropriate slug
514
+ $slug = array();
515
+
516
+ for ( $i = 0; $i < $loop; $i ++ )
517
+ $slug[] = $raw_term[ $i ];
518
+
519
+ $slug = sanitize_title( implode( '-', $slug ) );
520
+
521
+ $t = wp_insert_term( $term, $taxonomy, array( 'parent' => $parent, 'slug' => $slug ) );
522
+
523
+ if ( ! is_wp_error( $t ) ) {
524
+ $term_id = $t['term_id'];
525
+ } else {
526
+ $WF_CSV_Product_Import->hf_log_data_change( '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 ) ) );
527
+ break;
528
+ }
529
+ }
530
+
531
+ $this->inserted_terms[$taxonomy][$parent][$term] = $term_id;
532
+
533
+ }
534
+
535
+ if ( ! $term_id )
536
+ break;
537
+
538
+ // Add to product terms, ready to set if this is the final term
539
+ if ( sizeof( $raw_term ) == $loop )
540
+ $terms[] = $term_id;
541
+
542
+ $parent = $term_id;
543
+ }
544
+
545
+ } else {
546
+
547
+ $term_id = '';
548
+ $raw_term = (WC()->version < '2.7.0') ? wp_specialchars( $raw_term ) : esc_html( $raw_term );
549
+
550
+ if ( isset( $this->inserted_terms[$taxonomy][0][$raw_term] ) ) {
551
+
552
+ $term_id = $this->inserted_terms[$taxonomy][0][$raw_term];
553
+
554
+ } elseif ( $raw_term ) {
555
+
556
+ // Check term existance
557
+ $term_exists = term_exists( $raw_term, $taxonomy, 0 );
558
+ $term_id = is_array( $term_exists ) ? $term_exists['term_id'] : 0;
559
+
560
+ if ( ! $term_id ) {
561
+ $t = wp_insert_term( trim( $raw_term ), $taxonomy, array( 'parent' => 0 ) );
562
+
563
+ if ( ! is_wp_error( $t ) ) {
564
+ $term_id = $t['term_id'];
565
+ } else {
566
+ $WF_CSV_Product_Import->hf_log_data_change( 'csv-import', sprintf( __( '> > Failed to import term %s %s', 'wf_csv_import_export' ), esc_html($raw_term), esc_html($taxonomy) ) );
567
+ break;
568
+ }
569
+ }
570
+
571
+ $this->inserted_terms[$taxonomy][0][$raw_term] = $term_id;
572
+
573
+ }
574
+
575
+ // Store terms for later insertion
576
+ if ( $term_id )
577
+ $terms[] = $term_id;
578
+
579
+ }
580
+
581
+ }
582
+
583
+ // Any defined?
584
+ if ( sizeof( $terms ) == 0 )
585
+ continue;
586
+
587
+ // Add to array
588
+ $terms_array[] = array(
589
+ 'taxonomy' => $taxonomy,
590
+ 'terms' => $terms
591
+ );
592
+ }
593
+
594
+ /**
595
+ * Handle Attributes
596
+ */
597
+ elseif ( strstr( $key, 'attribute:' ) ) {
598
+
599
+ $attribute_key = sanitize_title( trim( str_replace( 'attribute:', '', $key ) ) );
600
+ $attribute_name = str_replace( 'attribute:', '', $WF_CSV_Product_Import->raw_headers[ $key ] );
601
+
602
+ if ( ! $attribute_key )
603
+ continue;
604
+
605
+ // Taxonomy
606
+ if ( substr( $attribute_key, 0, 3 ) == 'pa_' ) {
607
+
608
+ $taxonomy = $attribute_key;
609
+
610
+ // Exists?
611
+ if ( ! taxonomy_exists( $taxonomy ) ) {
612
+
613
+ $nicename = strtolower( sanitize_title( str_replace( 'pa_', '', $taxonomy ) ) );
614
+
615
+ $WF_CSV_Product_Import->hf_log_data_change( 'csv-import', sprintf( __('> > Attribute taxonomy "%s" does not exist. Adding it. Nicename: %s', 'wf_csv_import_export'), $taxonomy, $nicename ) );
616
+
617
+ $exists_in_db = $wpdb->get_var( "SELECT attribute_id FROM " . $wpdb->prefix . "woocommerce_attribute_taxonomies WHERE attribute_name = '" . $nicename . "';" );
618
+
619
+ if ( ! $exists_in_db ) {
620
+ // Create the taxonomy
621
+ $wpdb->insert( $wpdb->prefix . "woocommerce_attribute_taxonomies", array( 'attribute_name' => $nicename, 'attribute_label' => $nicename, 'attribute_type' => 'select', 'attribute_orderby' => 'menu_order' ) );
622
+ } else {
623
+ $WF_CSV_Product_Import->hf_log_data_change( 'csv-import', sprintf( __('> > Attribute taxonomy %s already exists in DB.', 'wf_csv_import_export'), $taxonomy ) );
624
+ }
625
+
626
+ // Register the taxonomy now so that the import works!
627
+ register_taxonomy( $taxonomy,
628
+ array( 'product', 'product_variation' ),
629
+ array(
630
+ 'hierarchical' => true,
631
+ 'show_ui' => false,
632
+ 'query_var' => true,
633
+ 'rewrite' => false,
634
+ )
635
+ );
636
+ }
637
+
638
+ // Get terms
639
+ $terms = array();
640
+ $raw_terms = explode( '|', $value );
641
+ if(WC()->version < '2.7.0')
642
+ {
643
+ $raw_terms = array_map( 'wp_specialchars', $raw_terms );
644
+ $raw_terms = array_map( 'trim', $raw_terms );
645
+
646
+ }else{
647
+
648
+ $raw_terms = array_map( 'esc_html', $raw_terms );
649
+ $raw_terms = array_map( 'trim', $raw_terms );
650
+
651
+ }
652
+
653
+ if ( sizeof( $raw_terms ) > 0 ) {
654
+
655
+ foreach ( $raw_terms as $raw_term ) {
656
+
657
+ if ( empty( $raw_term ) && 0 != $raw_term ) {
658
+ continue;
659
+ }
660
+
661
+ // Check term existance
662
+ $term_exists = term_exists( $raw_term, $taxonomy, 0 );
663
+ $term_id = is_array( $term_exists ) ? $term_exists['term_id'] : 0;
664
+
665
+ if ( ! $term_id ) {
666
+ $t = wp_insert_term( trim( $raw_term ), $taxonomy );
667
+
668
+ if ( ! is_wp_error( $t ) ) {
669
+ $term_id = $t['term_id'];
670
+
671
+ $WF_CSV_Product_Import->hf_log_data_change( 'csv-import', sprintf( __( '> > Inserted Raw Term %s ID = %s', 'wf_csv_import_export' ), esc_html( $raw_term ), $term_id ) );
672
+ } else {
673
+ $WF_CSV_Product_Import->hf_log_data_change( 'csv-import', sprintf( __( '> > Failed to import term %s %s', 'wf_csv_import_export' ), esc_html($raw_term), esc_html($taxonomy) ) );
674
+ break;
675
+ }
676
+ } else {
677
+ $WF_CSV_Product_Import->hf_log_data_change( 'csv-import', sprintf( __( '> > Raw Term %s ID = %s', 'wf_csv_import_export' ), esc_html( $raw_term ), $term_id ) );
678
+ }
679
+
680
+ if ( $term_id ) {
681
+ $terms[] = $term_id;
682
+ }
683
+ }
684
+
685
+ }
686
+
687
+ // Add to array
688
+ $terms_array[] = array(
689
+ 'taxonomy' => $taxonomy,
690
+ 'terms' => $terms
691
+ );
692
+
693
+ // Ensure we have original attributes
694
+ if ( is_null( $attributes ) && $merging ) {
695
+ $attributes = array_filter( (array) maybe_unserialize( get_post_meta( $post_id, '_product_attributes', true ) ) );
696
+ } elseif ( is_null( $attributes ) ) {
697
+ $attributes = array();
698
+ }
699
+
700
+ // Set attribute
701
+ if ( ! isset( $attributes[$taxonomy] ) )
702
+ $attributes[$taxonomy] = array();
703
+
704
+ $attributes[$taxonomy]['name'] = $taxonomy;
705
+ $attributes[$taxonomy]['value'] = null;
706
+ $attributes[$taxonomy]['is_taxonomy'] = 1;
707
+
708
+ if ( ! isset( $attributes[$taxonomy]['position'] ) )
709
+ $attributes[$taxonomy]['position'] = 0;
710
+ if ( ! isset( $attributes[$taxonomy]['is_visible'] ) )
711
+ $attributes[$taxonomy]['is_visible'] = 1;
712
+ if ( ! isset( $attributes[$taxonomy]['is_variation'] ) )
713
+ $attributes[$taxonomy]['is_variation'] = 0;
714
+
715
+ } else {
716
+
717
+ if ( ! $value || ! $attribute_key ) continue;
718
+
719
+ // Set attribute
720
+ if ( ! isset( $attributes[$attribute_key] ) )
721
+ $attributes[$attribute_key] = array();
722
+
723
+ $attributes[$attribute_key]['name'] = $attribute_name;
724
+ $attributes[$attribute_key]['value'] = $value;
725
+ $attributes[$attribute_key]['is_taxonomy'] = 0;
726
+
727
+ if ( ! isset( $attributes[$attribute_key]['position'] ) )
728
+ $attributes[$attribute_key]['position'] = 0;
729
+ if ( ! isset( $attributes[$attribute_key]['is_visible'] ) )
730
+ $attributes[$attribute_key]['is_visible'] = 1;
731
+ if ( ! isset( $attributes[$attribute_key]['is_variation'] ) )
732
+ $attributes[$attribute_key]['is_variation'] = 0;
733
+ }
734
+
735
+ }
736
+
737
+ /**
738
+ * Handle Attributes Data - position|is_visible|is_variation
739
+ */
740
+ elseif ( strstr( $key, 'attribute_data:' ) ) {
741
+
742
+ $attribute_key = sanitize_title( trim( str_replace( 'attribute_data:', '', $key ) ) );
743
+
744
+ if ( ! $attribute_key ) {
745
+ continue;
746
+ }
747
+
748
+ $values = explode( '|', $value );
749
+ $position = isset( $values[0] ) ? (int) $values[0] : 0;
750
+ $visible = isset( $values[1] ) ? (int) $values[1] : 1;
751
+ $variation = isset( $values[2] ) ? (int) $values[2] : 0;
752
+
753
+ // Ensure we have original attributes
754
+ if ( ! isset( $attributes[ $attribute_key ] ) ) {
755
+ if ( $merging ) {
756
+ $existing_attributes = array_filter( (array) maybe_unserialize( get_post_meta( $post_id, '_product_attributes', true ) ) );
757
+ $attributes[ $attribute_key ] = isset( $existing_attributes[ $attribute_key ] ) ? $existing_attributes[ $attribute_key ] : array();
758
+ } else {
759
+ $attributes[ $attribute_key ] = array();
760
+ }
761
+ }
762
+
763
+ $attributes[ $attribute_key ]['position'] = $position;
764
+ $attributes[ $attribute_key ]['is_visible'] = $visible;
765
+ $attributes[ $attribute_key ]['is_variation'] = $variation;
766
+ }
767
+
768
+ /**
769
+ * Handle Attributes Default Values
770
+ */
771
+ elseif ( strstr( $key, 'attribute_default:' ) ) {
772
+
773
+ $attribute_key = sanitize_title( trim( str_replace( 'attribute_default:', '', $key ) ) );
774
+
775
+ if ( ! $attribute_key ) continue;
776
+
777
+ // Ensure we have original attributes
778
+ if ( is_null( $default_attributes ) && $merging ) {
779
+ $default_attributes = array_filter( (array) maybe_unserialize( get_post_meta( $post_id, '_default_attributes', true ) ) );
780
+ } elseif ( is_null( $default_attributes ) ) {
781
+ $default_attributes = array();
782
+ }
783
+
784
+ $default_attributes[ $attribute_key ] = $value;
785
+ }
786
+
787
+ /**
788
+ * Handle gpf: google product feed columns
789
+ */
790
+ elseif ( strstr( $key, 'gpf:' ) ) {
791
+
792
+ $gpf_key = trim( str_replace( 'gpf:', '', $key ) );
793
+
794
+ // Get original values
795
+ if ( is_null( $gpf_data ) && $merging ) {
796
+ $gpf_data = array_filter( (array) maybe_unserialize( get_post_meta( $post_id, '_woocommerce_gpf_data', true ) ) );
797
+ } elseif ( is_null( $gpf_data ) ) {
798
+ $gpf_data = array(
799
+ 'availability' => '',
800
+ 'condition' => '',
801
+ 'brand' => '',
802
+ 'product_type' => '',
803
+ 'google_product_category' => '',
804
+ 'gtin' => '',
805
+ 'mpn' => '',
806
+ 'gender' => '',
807
+ 'age_group' => '',
808
+ 'color' => '',
809
+ 'size' => ''
810
+ );
811
+ }
812
+
813
+ $gpf_data[$gpf_key] = $value;
814
+
815
+ }
816
+
817
+ /**
818
+ * Handle upsell SKUs which we cannot assign until we get IDs later on
819
+ */
820
+ elseif ( strstr( $key, 'upsell_skus' ) ) {
821
+ if ( $value ) {
822
+ $skus = array_filter( array_map( 'trim', explode( '|', $value ) ) );
823
+ $product['upsell_skus'] = $skus;
824
+ }
825
+ }
826
+
827
+ /**
828
+ * Handle crosssells SKUs which we cannot assign until we get IDs later on
829
+ */
830
+ elseif ( strstr( $key, 'crosssell_skus' ) ) {
831
+ if ( $value ) {
832
+ $skus = array_filter( array_map( 'trim', explode( '|', $value ) ) );
833
+ $product['crosssell_skus'] = $skus;
834
+ }
835
+ }
836
+
837
+ }
838
+
839
+ // Remove empty attribues
840
+ if(!empty($attributes))
841
+ foreach ( $attributes as $key => $value ) {
842
+ if ( ! isset($value['name']) ) unset( $attributes[$key] );
843
+ }
844
+
845
+ /**
846
+ * Handle images
847
+ */
848
+ if ( ! empty( $item['images'] ) ) {
849
+ $images = array_map( 'trim', explode( '|', $item['images'] ) );
850
+ } else {
851
+ $images = '';
852
+ }
853
+
854
+ $product['postmeta'][] = array( 'key' => '_default_attributes', 'value' => $default_attributes );
855
+ $product['attributes'] = $attributes;
856
+ $product['gpf_data'] = $gpf_data;
857
+ $product['images'] = $images;
858
+ $product['terms'] = $terms_array;
859
+ $product['sku'] = ( ! empty( $item['sku'] ) ) ? $item['sku'] : '';
860
+ $product['post_title'] = ( ! empty( $item['post_title'] ) ) ? $item['post_title'] : '';
861
+ $product['post_type'] = $this->post_type;
862
+ unset( $item, $terms_array, $postmeta, $attributes, $gpf_data, $images );
863
+ return $product;
864
+ }
865
+ function hf_currency_formatter($price){
866
+ $decimal_seperator = wc_get_price_decimal_separator();
867
+ //return ereg_replace("[^0-9\\'.$decimal_seperator.']", "", $price);
868
+ return preg_replace("[^0-9\\'.$decimal_seperator.']", "", $price);
869
+ }
870
+ }
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,1504 +1,1504 @@
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
- if(WC()->version < '2.7.0'){
35
- $this->log = new WC_Logger();
36
-
37
- }else
38
- {
39
- $this->log = wc_get_logger();
40
-
41
- }
42
-
43
- $this->import_page = 'woocommerce_csv';
44
- $this->file_url_import_enabled = apply_filters( 'woocommerce_csv_product_file_url_import_enabled', true );
45
- }
46
-
47
- /**
48
- * Registered callback function for the WordPress Importer
49
- *
50
- * Manages the three separate stages of the CSV import process
51
- */
52
- public function dispatch() {
53
- global $woocommerce, $wpdb;
54
-
55
- if ( ! empty( $_POST['delimiter'] ) ) {
56
- $this->delimiter = stripslashes( trim( $_POST['delimiter'] ) );
57
- }else if ( ! empty( $_GET['delimiter'] ) ) {
58
- $this->delimiter = stripslashes( trim( $_GET['delimiter'] ) );
59
- }
60
-
61
- if ( ! $this->delimiter )
62
- $this->delimiter = ',';
63
-
64
- if ( ! empty( $_POST['merge_empty_cells'] ) || ! empty( $_GET['merge_empty_cells'] ) ) {
65
- $this->merge_empty_cells = 1;
66
- } else{
67
- $this->merge_empty_cells = 0;
68
- }
69
-
70
- $step = empty( $_GET['step'] ) ? 0 : (int) $_GET['step'];
71
-
72
- switch ( $step ) {
73
- case 0 :
74
- $this->header();
75
- $this->greet();
76
- break;
77
- case 1 :
78
- $this->header();
79
-
80
- check_admin_referer( 'import-upload' );
81
-
82
- if(!empty($_GET['file_url']))
83
- $this->file_url = esc_attr( $_GET['file_url'] );
84
- if(!empty($_GET['file_id']))
85
- $this->id = $_GET['file_id'] ;
86
-
87
- if ( !empty($_GET['clearmapping']) || $this->handle_upload() )
88
- $this->import_options();
89
- else
90
- _e( 'Error with handle_upload!', 'wf_csv_import_export' );
91
- break;
92
- case 2 :
93
- $this->header();
94
-
95
- check_admin_referer( 'import-woocommerce' );
96
-
97
- $this->id = (int) $_POST['import_id'];
98
-
99
- if ( $this->file_url_import_enabled )
100
- $this->file_url = esc_attr( $_POST['import_url'] );
101
-
102
- if ( $this->id )
103
- $file = get_attached_file( $this->id );
104
- else if ( $this->file_url_import_enabled )
105
- $file = ABSPATH . $this->file_url;
106
-
107
- $file = str_replace( "\\", "/", $file );
108
-
109
- if ( $file ) {
110
- ?>
111
- <table id="import-progress" class="widefat_importer widefat">
112
- <thead>
113
- <tr>
114
- <th class="status">&nbsp;</th>
115
- <th class="row"><?php _e( 'Row', 'wf_csv_import_export' ); ?></th>
116
- <th><?php _e( 'SKU', 'wf_csv_import_export' ); ?></th>
117
- <th><?php _e( 'Product', 'wf_csv_import_export' ); ?></th>
118
- <th class="reason"><?php _e( 'Status Msg', 'wf_csv_import_export' ); ?></th>
119
- </tr>
120
- </thead>
121
- <tfoot>
122
- <tr class="importer-loading">
123
- <td colspan="5"></td>
124
- </tr>
125
- </tfoot>
126
- <tbody></tbody>
127
- </table>
128
- <script type="text/javascript">
129
- jQuery(document).ready(function($) {
130
-
131
- if ( ! window.console ) { window.console = function(){}; }
132
-
133
- var processed_terms = [];
134
- var processed_posts = [];
135
- var post_orphans = [];
136
- var attachments = [];
137
- var upsell_skus = [];
138
- var crosssell_skus = [];
139
- var i = 1;
140
- var done_count = 0;
141
-
142
- function import_rows( start_pos, end_pos ) {
143
-
144
- var data = {
145
- action: 'woocommerce_csv_import_request',
146
- file: '<?php echo addslashes( $file ); ?>',
147
- mapping: '<?php echo json_encode( $_POST['map_from'] ); ?>',
148
- eval_field: '<?php echo stripslashes(json_encode(($_POST['eval_field']),JSON_HEX_APOS)) ?>',
149
- delimiter: '<?php echo $this->delimiter; ?>',
150
- merge_empty_cells: '<?php echo $this->merge_empty_cells; ?>',
151
- start_pos: start_pos,
152
- end_pos: end_pos,
153
- };
154
- data.eval_field = $.parseJSON(data.eval_field);
155
- return $.ajax({
156
- 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' ) ); ?>',
157
- data: data,
158
- type: 'POST',
159
- success: function( response ) {
160
- console.log( response );
161
- if ( response ) {
162
-
163
- try {
164
- // Get the valid JSON only from the returned string
165
- if ( response.indexOf("<!--WC_START-->") >= 0 )
166
- response = response.split("<!--WC_START-->")[1]; // Strip off before after WC_START
167
-
168
- if ( response.indexOf("<!--WC_END-->") >= 0 )
169
- response = response.split("<!--WC_END-->")[0]; // Strip off anything after WC_END
170
-
171
- // Parse
172
- var results = $.parseJSON( response );
173
-
174
- if ( results.error ) {
175
-
176
- $('#import-progress tbody').append( '<tr id="row-' + i + '" class="error"><td class="status" colspan="5">' + results.error + '</td></tr>' );
177
-
178
- i++;
179
-
180
- } else if ( results.import_results && $( results.import_results ).size() > 0 ) {
181
-
182
- $.each( results.processed_terms, function( index, value ) {
183
- processed_terms.push( value );
184
- });
185
-
186
- $.each( results.processed_posts, function( index, value ) {
187
- processed_posts.push( value );
188
- });
189
-
190
- $.each( results.post_orphans, function( index, value ) {
191
- post_orphans.push( value );
192
- });
193
-
194
- $.each( results.attachments, function( index, value ) {
195
- attachments.push( value );
196
- });
197
-
198
- upsell_skus = jQuery.extend( {}, upsell_skus, results.upsell_skus );
199
- crosssell_skus = jQuery.extend( {}, crosssell_skus, results.crosssell_skus );
200
-
201
- $( results.import_results ).each(function( index, row ) {
202
- $('#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>' );
203
-
204
- i++;
205
- });
206
- }
207
-
208
- } catch(err) {}
209
-
210
- } else {
211
- $('#import-progress tbody').append( '<tr class="error"><td class="status" colspan="5">' + '<?php _e( 'AJAX Error', 'wf_csv_import_export' ); ?>' + '</td></tr>' );
212
- }
213
-
214
- var w = $(window);
215
- var row = $( "#row-" + ( i - 1 ) );
216
-
217
- if ( row.length ) {
218
- w.scrollTop( row.offset().top - (w.height()/2) );
219
- }
220
-
221
- done_count++;
222
-
223
- $('body').trigger( 'woocommerce_csv_import_request_complete' );
224
- }
225
- });
226
- }
227
-
228
- var rows = [];
229
-
230
- <?php
231
- $limit = apply_filters( 'woocommerce_csv_import_limit_per_request', 10 );
232
- $enc = mb_detect_encoding( $file, 'UTF-8, ISO-8859-1', true );
233
- if ( $enc )
234
- setlocale( LC_ALL, 'en_US.' . $enc );
235
- @ini_set( 'auto_detect_line_endings', true );
236
-
237
- $count = 0;
238
- $previous_position = 0;
239
- $position = 0;
240
- $import_count = 0;
241
-
242
- // Get CSV positions
243
- if ( ( $handle = fopen( $file, "r" ) ) !== FALSE ) {
244
-
245
- while ( ( $postmeta = fgetcsv( $handle, 0, $this->delimiter ) ) !== FALSE ) {
246
- $count++;
247
-
248
- if ( $count >= $limit ) {
249
- $previous_position = $position;
250
- $position = ftell( $handle );
251
- $count = 0;
252
- $import_count ++;
253
-
254
- // Import rows between $previous_position $position
255
- ?>rows.push( [ <?php echo $previous_position; ?>, <?php echo $position; ?> ] ); <?php
256
- }
257
- }
258
-
259
- // Remainder
260
- if ( $count > 0 ) {
261
- ?>rows.push( [ <?php echo $position; ?>, '' ] ); <?php
262
- $import_count ++;
263
- }
264
-
265
- fclose( $handle );
266
- }
267
- ?>
268
-
269
- var data = rows.shift();
270
- var regen_count = 0;
271
- import_rows( data[0], data[1] );
272
-
273
- $('body').on( 'woocommerce_csv_import_request_complete', function() {
274
- if ( done_count == <?php echo $import_count; ?> ) {
275
-
276
- if ( attachments.length ) {
277
-
278
- $('#import-progress tbody').append( '<tr class="regenerating"><td colspan="5"><div class="progress"></div></td></tr>' );
279
-
280
- index = 0;
281
-
282
- $.each( attachments, function( i, value ) {
283
- regenerate_thumbnail( value );
284
- index ++;
285
- if ( index == attachments.length ) {
286
- import_done();
287
- }
288
- });
289
-
290
- } else {
291
- import_done();
292
- }
293
-
294
- } else {
295
- // Call next request
296
- data = rows.shift();
297
- import_rows( data[0], data[1] );
298
- }
299
- } );
300
-
301
- // Regenerate a specified image via AJAX
302
- function regenerate_thumbnail( id ) {
303
- $.ajax({
304
- type: 'POST',
305
- url: ajaxurl,
306
- data: { action: "woocommerce_csv_import_regenerate_thumbnail", id: id },
307
- success: function( response ) {
308
- if ( response !== Object( response ) || ( typeof response.success === "undefined" && typeof response.error === "undefined" ) ) {
309
- response = new Object;
310
- response.success = false;
311
- 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 + "' ); ?>";
312
- }
313
-
314
- regen_count ++;
315
-
316
- $('#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' ) ); ?>' );
317
-
318
- if ( ! response.success ) {
319
- $('#import-progress tbody').append( '<tr><td colspan="5">' + response.error + '</td></tr>' );
320
- }
321
- },
322
- error: function( response ) {
323
- $('#import-progress tbody').append( '<tr><td colspan="5">' + response.error + '</td></tr>' );
324
- }
325
- });
326
- }
327
-
328
- function import_done() {
329
- var data = {
330
- action: 'woocommerce_csv_import_request',
331
- file: '<?php echo $file; ?>',
332
- processed_terms: processed_terms,
333
- processed_posts: processed_posts,
334
- post_orphans: post_orphans,
335
- upsell_skus: upsell_skus,
336
- crosssell_skus: crosssell_skus
337
- };
338
-
339
- $.ajax({
340
- 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' ) ); ?>',
341
- data: data,
342
- type: 'POST',
343
- success: function( response ) {
344
- console.log( response );
345
- $('#import-progress tbody').append( '<tr class="complete"><td colspan="5">' + response + '</td></tr>' );
346
- $('.importer-loading').hide();
347
- }
348
- });
349
- }
350
- });
351
- </script>
352
- <?php
353
- } else {
354
- echo '<p class="error">' . __( 'Error finding uploaded file!', 'wf_csv_import_export' ) . '</p>';
355
- }
356
- break;
357
- case 3 :
358
- // Check access - cannot use nonce here as it will expire after multiple requests
359
- if ( ! current_user_can( 'manage_woocommerce' ) )
360
- die();
361
-
362
- add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) );
363
-
364
- if ( function_exists( 'gc_enable' ) )
365
- gc_enable();
366
-
367
- @set_time_limit(0);
368
- @ob_flush();
369
- @flush();
370
- $wpdb->hide_errors();
371
-
372
- $file = stripslashes( $_POST['file'] );
373
- $mapping = json_decode( stripslashes( $_POST['mapping'] ), true );
374
- $eval_field = $_POST['eval_field'];
375
- $start_pos = isset( $_POST['start_pos'] ) ? absint( $_POST['start_pos'] ) : 0;
376
- $end_pos = isset( $_POST['end_pos'] ) ? absint( $_POST['end_pos'] ) : '';
377
-
378
- update_option( 'wf_prod_csv_imp_exp_mapping', array($mapping,$eval_field ));
379
-
380
- $position = $this->import_start( $file, $mapping, $start_pos, $end_pos, $eval_field );
381
- $this->import();
382
- $this->import_end();
383
-
384
- $results = array();
385
- $results['import_results'] = $this->import_results;
386
- $results['processed_terms'] = $this->processed_terms;
387
- $results['processed_posts'] = $this->processed_posts;
388
- $results['post_orphans'] = $this->post_orphans;
389
- $results['attachments'] = $this->attachments;
390
- $results['upsell_skus'] = $this->upsell_skus;
391
- $results['crosssell_skus'] = $this->crosssell_skus;
392
-
393
- echo "<!--WC_START-->";
394
- echo json_encode( $results );
395
- echo "<!--WC_END-->";
396
- exit;
397
- break;
398
- case 4 :
399
- // Check access - cannot use nonce here as it will expire after multiple requests
400
- if ( ! current_user_can( 'manage_woocommerce' ) )
401
- die();
402
-
403
- add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) );
404
-
405
- if ( function_exists( 'gc_enable' ) )
406
- gc_enable();
407
-
408
- @set_time_limit(0);
409
- @ob_flush();
410
- @flush();
411
- $wpdb->hide_errors();
412
-
413
- $this->processed_terms = isset( $_POST['processed_terms'] ) ? $_POST['processed_terms'] : array();
414
- $this->processed_posts = isset( $_POST['processed_posts']) ? $_POST['processed_posts'] : array();
415
- $this->post_orphans = isset( $_POST['post_orphans']) ? $_POST['post_orphans'] : array();
416
- $this->crosssell_skus = isset( $_POST['crosssell_skus']) ? array_filter( (array) $_POST['crosssell_skus'] ) : array();
417
- $this->upsell_skus = isset( $_POST['upsell_skus']) ? array_filter( (array) $_POST['upsell_skus'] ) : array();
418
-
419
- _e( 'Step 1...', 'wf_csv_import_export' ) . ' ';
420
-
421
- wp_defer_term_counting( true );
422
- wp_defer_comment_counting( true );
423
-
424
- _e( 'Step 2...', 'wf_csv_import_export' ) . ' ';
425
-
426
- echo 'Step 3...' . ' '; // Easter egg
427
-
428
- // reset transients for products
429
- if ( function_exists( 'wc_delete_product_transients' ) ) {
430
- wc_delete_product_transients();
431
- } else {
432
- $woocommerce->clear_product_transients();
433
- }
434
-
435
- delete_transient( 'wc_attribute_taxonomies' );
436
-
437
- $wpdb->query("DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_wc_product_type_%')");
438
-
439
- _e( 'Finalizing...', 'wf_csv_import_export' ) . ' ';
440
-
441
- $this->backfill_parents();
442
-
443
- if ( ! empty( $this->upsell_skus ) ) {
444
-
445
- _e( 'Linking upsells...', 'wf_csv_import_export' ) . ' ';
446
-
447
- foreach ( $this->upsell_skus as $post_id => $skus ) {
448
- $this->link_product_skus( 'upsell', $post_id, $skus );
449
- }
450
- }
451
-
452
- if ( ! empty( $this->crosssell_skus ) ) {
453
-
454
- _e( 'Linking crosssells...', 'wf_csv_import_export' ) . ' ';
455
-
456
- foreach ( $this->crosssell_skus as $post_id => $skus ) {
457
- $this->link_product_skus( 'crosssell', $post_id, $skus );
458
- }
459
- }
460
- // SUCCESS
461
- _e( 'Finished. Import complete.', 'wf_csv_import_export' );
462
-
463
- $this->import_end();
464
- exit;
465
- break;
466
- }
467
-
468
- $this->footer();
469
- }
470
-
471
- /**
472
- * format_data_from_csv
473
- */
474
- public function format_data_from_csv( $data, $enc ) {
475
- return ( $enc == 'UTF-8' ) ? $data : utf8_encode( $data );
476
- }
477
-
478
- /**
479
- * Display pre-import options
480
- */
481
- public function import_options() {
482
- $j = 0;
483
-
484
- if ( $this->id )
485
- $file = get_attached_file( $this->id );
486
- else if ( $this->file_url_import_enabled )
487
- $file = ABSPATH . $this->file_url;
488
- else
489
- return;
490
-
491
- // Set locale
492
- $enc = mb_detect_encoding( $file, 'UTF-8, ISO-8859-1', true );
493
- if ( $enc ) setlocale( LC_ALL, 'en_US.' . $enc );
494
- @ini_set( 'auto_detect_line_endings', true );
495
-
496
- // Get headers
497
- if ( ( $handle = fopen( $file, "r" ) ) !== FALSE ) {
498
-
499
- $row = $raw_headers = array();
500
- $header = fgetcsv( $handle, 0, $this->delimiter );
501
-
502
- while ( ( $postmeta = fgetcsv( $handle, 0, $this->delimiter ) ) !== FALSE ) {
503
- foreach ( $header as $key => $heading ) {
504
- if ( ! $heading ) continue;
505
- $s_heading = strtolower( $heading );
506
- $row[$s_heading] = ( isset( $postmeta[$key] ) ) ? $this->format_data_from_csv( $postmeta[$key], $enc ) : '';
507
- $raw_headers[ $s_heading ] = $heading;
508
- }
509
- break;
510
- }
511
- fclose( $handle );
512
- }
513
-
514
- $mapping_from_db = get_option( 'wf_prod_csv_imp_exp_mapping');
515
- $saved_mapping = null;
516
- $saved_evaluation = null;
517
- if($mapping_from_db && is_array($mapping_from_db) && count($mapping_from_db) == 2 && empty($_GET['clearmapping'])){
518
- //if(count(array_intersect_key ( $mapping_from_db[0] , $row)) == count($mapping_from_db[0])){
519
- $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 . '';
520
- $reset_action = esc_attr(wp_nonce_url($reset_action, 'import-upload'));
521
- 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>';
522
- $saved_mapping = $mapping_from_db[0];
523
- $saved_evaluation = $mapping_from_db[1];
524
- //}
525
- }
526
-
527
- $merge = (!empty($_GET['merge']) && $_GET['merge']) ? 1 : 0;
528
-
529
- $attrs = self::get_all_product_attributes();
530
- $attr_keys = array_values($attrs);
531
-
532
- $attributes = array();
533
- if(!empty($attr_keys) && !empty($attrs))
534
- $attributes = array_combine($attr_keys , $attrs);
535
-
536
- $product_ptaxonomies = get_object_taxonomies( 'product', 'name' );
537
- $product_vtaxonomies = get_object_taxonomies( 'product_variation', 'name' );
538
- $product_taxonomies = array_merge($product_ptaxonomies, $product_vtaxonomies);
539
- $taxonomies = array_keys($product_taxonomies);
540
- $new_keys = array_values($taxonomies);
541
- $taxonomies = array_combine($new_keys , $taxonomies);
542
- include( 'views/html-wf-import-options.php' );
543
- }
544
-
545
- /**
546
- * The main controller for the actual import stage.
547
- */
548
- public function import() {
549
- global $woocommerce, $wpdb;
550
-
551
- wp_suspend_cache_invalidation( true );
552
-
553
- $this->hf_log_data_change( 'csv-import', '---' );
554
- $this->hf_log_data_change( 'csv-import', __( 'Processing products.', 'wf_csv_import_export' ) );
555
- foreach ( $this->parsed_data as $key => &$item ) {
556
-
557
- $product = $this->parser->parse_product( $item, $this->merge_empty_cells );
558
- if ( ! is_wp_error( $product ) )
559
- $this->process_product( $product );
560
- else
561
- $this->add_import_result( 'failed', $product->get_error_message(), 'Not parsed', json_encode( $item ), '-' );
562
-
563
- unset( $item, $product );
564
- }
565
- $this->hf_log_data_change( 'csv-import', __( 'Finished processing products.', 'wf_csv_import_export' ) );
566
- wp_suspend_cache_invalidation( false );
567
- }
568
-
569
- /**
570
- * Parses the CSV file and prepares us for the task of processing parsed data
571
- *
572
- * @param string $file Path to the CSV file for importing
573
- */
574
-
575
- public function hf_log_data_change ($content = 'csv-import',$data='')
576
- {
577
- if (WC()->version < '2.7.0')
578
- {
579
- $this->log->add($content,$data);
580
- }else
581
- {
582
- $context = array( 'source' => $content );
583
- $this->log->log("debug", $data ,$context);
584
- }
585
- }
586
- public function import_start( $file, $mapping, $start_pos, $end_pos, $eval_field ) {
587
-
588
- if(WC()->version < '2.7.0'){
589
- $memory = size_format( woocommerce_let_to_num( ini_get( 'memory_limit' ) ) );
590
- $wp_memory = size_format( woocommerce_let_to_num( WP_MEMORY_LIMIT ) );
591
- }else
592
- {
593
- $memory = size_format( wc_let_to_num( ini_get( 'memory_limit' ) ) );
594
- $wp_memory = size_format( wc_let_to_num( WP_MEMORY_LIMIT ) );
595
-
596
- }
597
- $this->hf_log_data_change( 'csv-import', '---[ New Import ] PHP Memory: ' . $memory . ', WP Memory: ' . $wp_memory );
598
- $this->hf_log_data_change( 'csv-import', __( 'Parsing products CSV.', 'wf_csv_import_export' ) );
599
-
600
- $this->parser = new WF_CSV_Parser( 'product' );
601
-
602
- list( $this->parsed_data, $this->raw_headers, $position ) = $this->parser->parse_data( $file, $this->delimiter, $mapping, $start_pos, $end_pos, $eval_field );
603
-
604
- $this->hf_log_data_change( 'csv-import', __( 'Finished parsing products CSV.', 'wf_csv_import_export' ) );
605
-
606
- unset( $import_data );
607
-
608
- wp_defer_term_counting( true );
609
- wp_defer_comment_counting( true );
610
-
611
- return $position;
612
- }
613
-
614
- /**
615
- * Performs post-import cleanup of files and the cache
616
- */
617
- public function import_end() {
618
-
619
- //wp_cache_flush(); Stops output in some hosting environments
620
- foreach ( get_taxonomies() as $tax ) {
621
- delete_option( "{$tax}_children" );
622
- _get_term_hierarchy( $tax );
623
- }
624
-
625
- wp_defer_term_counting( false );
626
- wp_defer_comment_counting( false );
627
-
628
- do_action( 'import_end' );
629
- }
630
-
631
- /**
632
- * Handles the CSV upload and initial parsing of the file to prepare for
633
- * displaying author import options
634
- *
635
- * @return bool False if error uploading or invalid file, true otherwise
636
- */
637
- public function handle_upload() {
638
- if($this->handle_ftp()){
639
- return true;
640
- }
641
- if ( empty( $_POST['file_url'] ) ) {
642
-
643
- $file = wp_import_handle_upload();
644
-
645
- if ( isset( $file['error'] ) ) {
646
- echo '<p><strong>' . __( 'Sorry, there has been an error.', 'wf_csv_import_export' ) . '</strong><br />';
647
- echo esc_html( $file['error'] ) . '</p>';
648
- return false;
649
- }
650
-
651
- $this->id = (int) $file['id'];
652
- return true;
653
-
654
- } else {
655
-
656
- if ( file_exists( ABSPATH . $_POST['file_url'] ) ) {
657
-
658
- $this->file_url = esc_attr( $_POST['file_url'] );
659
- return true;
660
-
661
- } else {
662
-
663
- echo '<p><strong>' . __( 'Sorry, there has been an error.', 'wf_csv_import_export' ) . '</strong></p>';
664
- return false;
665
-
666
- }
667
-
668
- }
669
-
670
- return false;
671
- }
672
-
673
- public function product_exists( $title, $sku = '', $post_name = '' ) {
674
- global $wpdb;
675
-
676
- // Post Title Check
677
- $post_title = stripslashes( sanitize_post_field( 'post_title', $title, 0, 'db' ) );
678
-
679
- $query = "SELECT ID FROM $wpdb->posts WHERE post_type = 'product' AND post_status IN ( 'publish', 'private', 'draft', 'pending', 'future' )";
680
- $args = array();
681
-
682
- /*
683
- * removed title check
684
- if ( ! empty ( $title ) ) {
685
- $query .= ' AND post_title = %s';
686
- $args[] = $post_title;
687
- }
688
-
689
-
690
- if ( ! empty ( $post_name ) ) {
691
- $query .= ' AND post_name = %s';
692
- $args[] = $post_name;
693
- }
694
-
695
- */
696
-
697
- if ( ! empty ( $args ) ) {
698
- $posts_that_exist = $wpdb->get_col( $wpdb->prepare( $query, $args ) );
699
-
700
- if ( $posts_that_exist ) {
701
-
702
- foreach( $posts_that_exist as $post_exists ) {
703
-
704
- // Check unique SKU
705
- $post_exists_sku = get_post_meta( $post_exists, '_sku', true );
706
-
707
- if ( $sku == $post_exists_sku ) {
708
- return true;
709
- }
710
-
711
- }
712
-
713
- }
714
- }
715
-
716
- // Sku Check
717
- if ( $sku ) {
718
-
719
- $post_exists_sku = $wpdb->get_var( $wpdb->prepare( "
720
- SELECT $wpdb->posts.ID
721
- FROM $wpdb->posts
722
- LEFT JOIN $wpdb->postmeta ON ( $wpdb->posts.ID = $wpdb->postmeta.post_id )
723
- WHERE $wpdb->posts.post_status IN ( 'publish', 'private', 'draft', 'pending', 'future' )
724
- AND $wpdb->postmeta.meta_key = '_sku' AND $wpdb->postmeta.meta_value = '%s'
725
- ", $sku ) );
726
-
727
- if ( $post_exists_sku ) {
728
- return true;
729
- }
730
- }
731
-
732
- return false;
733
- }
734
-
735
- /**
736
- * Create new posts based on import information
737
- */
738
- public function process_product( $post ) {
739
-
740
- $processing_product_id = absint( $post['post_id'] );
741
- $processing_product = get_post( $processing_product_id );
742
- $processing_product_title = $processing_product ? $processing_product->post_title : '';
743
- $processing_product_sku = $processing_product ? $processing_product->sku : '';
744
- $merging = ! empty( $post['merging'] );
745
-
746
- if ( ! empty( $post['post_title'] ) ) {
747
- $processing_product_title = $post['post_title'];
748
- }
749
-
750
- if ( ! empty( $post['sku'] ) ) {
751
- $processing_product_sku = $post['sku'];
752
- }
753
-
754
- if ( ! empty( $processing_product_id ) && isset( $this->processed_posts[ $processing_product_id ] ) ) {
755
- $this->add_import_result( 'skipped', __( 'Product already processed', 'wf_csv_import_export' ), $processing_product_id, $processing_product_title, $processing_product_sku );
756
- $this->hf_log_data_change( 'csv-import', __('> Post ID already processed. Skipping.', 'wf_csv_import_export'), true );
757
- unset( $post );
758
- return;
759
- }
760
-
761
- if ( ! empty ( $post['post_status'] ) && $post['post_status'] == 'auto-draft' ) {
762
- $this->add_import_result( 'skipped', __( 'Skipping auto-draft', 'wf_csv_import_export' ), $processing_product_id, $processing_product_title, $processing_product_sku );
763
- $this->hf_log_data_change( 'csv-import', __('> Skipping auto-draft.', 'wf_csv_import_export'), true );
764
- unset( $post );
765
- return;
766
- }
767
- // Check if post exists when importing
768
- if ( ! $merging ) {
769
- if ( $this->product_exists( $processing_product_title, $processing_product_sku, $post['post_name'] ) ) {
770
- if(!$processing_product_id && empty($processing_product_sku)) {
771
- // if no sku , no id and no merge + is product in db with same title -> just give message
772
- $usr_msg = 'Product with same title already exist.';
773
- }else{
774
- $usr_msg = 'Product already exists.';
775
- }
776
- $this->add_import_result( 'skipped', __( $usr_msg, 'wf_csv_import_export' ), $processing_product_id, $processing_product_title, $processing_product_sku );
777
- $this->hf_log_data_change( 'csv-import', sprintf( __('> &#8220;%s&#8221;'.$usr_msg, 'wf_csv_import_export'), esc_html($processing_product_title) ), true );
778
- unset( $post );
779
- return;
780
- }
781
-
782
- if ( $processing_product_id && is_string( get_post_status( $processing_product_id ) ) ) {
783
- $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 ), '' );
784
- $this->hf_log_data_change( 'csv-import', sprintf( __('> &#8220;%s&#8221; ID already exists.', 'wf_csv_import_export'), esc_html( $processing_product_id ) ), true );
785
- unset( $post );
786
- return;
787
- }
788
- }
789
- // Check post type to avoid conflicts with IDs
790
- $is_post_exist_in_db = get_post_type( $processing_product_id );
791
- if ( $merging && $processing_product_id && !empty($is_post_exist_in_db) && (get_post_type( $processing_product_id ) !== $post['post_type'] )) {
792
- $this->add_import_result( 'skipped', __( 'Post is not a product', 'wf_csv_import_export' ), $processing_product_id, $processing_product_title, $processing_product_sku );
793
- $this->hf_log_data_change( 'csv-import', sprintf( __('> &#8220;%s&#8221; is not a product.', 'wf_csv_import_export'), esc_html($processing_product_id) ), true );
794
- unset( $post );
795
- return;
796
- }
797
-
798
- if ( $merging && !empty($is_post_exist_in_db) ) {
799
-
800
- // Only merge fields which are set
801
- $post_id = $processing_product_id;
802
-
803
- $this->hf_log_data_change( 'csv-import', sprintf( __('> Merging post ID %s.', 'wf_csv_import_export'), $post_id ), true );
804
-
805
- $postdata = array(
806
- 'ID' => $post_id
807
- );
808
-
809
- if ( $this->merge_empty_cells ) {
810
- if ( isset( $post['post_content'] ) ) {
811
- $postdata['post_content'] = $post['post_content'];
812
- }
813
- if ( isset( $post['post_excerpt'] ) ) {
814
- $postdata['post_excerpt'] = $post['post_excerpt'];
815
- }
816
- if ( isset( $post['post_password'] ) ) {
817
- $postdata['post_password'] = $post['post_password'];
818
- }
819
- if ( isset( $post['post_parent'] ) ) {
820
- $postdata['post_parent'] = $post['post_parent'];
821
- }
822
- } else {
823
- if ( ! empty( $post['post_content'] ) ) {
824
- $postdata['post_content'] = $post['post_content'];
825
- }
826
- if ( ! empty( $post['post_excerpt'] ) ) {
827
- $postdata['post_excerpt'] = $post['post_excerpt'];
828
- }
829
- if ( ! empty( $post['post_password'] ) ) {
830
- $postdata['post_password'] = $post['post_password'];
831
- }
832
- if ( isset( $post['post_parent'] ) && $post['post_parent'] !== '' ) {
833
- $postdata['post_parent'] = $post['post_parent'];
834
- }
835
- }
836
-
837
- if ( ! empty( $post['post_title'] ) ) {
838
- $postdata['post_title'] = $post['post_title'];
839
- }
840
-
841
- if ( ! empty( $post['post_author'] ) ) {
842
- $postdata['post_author'] = absint( $post['post_author'] );
843
- }
844
- if ( ! empty( $post['post_date'] ) ) {
845
- $postdata['post_date'] = date("Y-m-d H:i:s", strtotime( $post['post_date'] ) );
846
- }
847
- if ( ! empty( $post['post_date_gmt'] ) ) {
848
- $postdata['post_date_gmt'] = date("Y-m-d H:i:s", strtotime( $post['post_date_gmt'] ) );
849
- }
850
- if ( ! empty( $post['post_name'] ) ) {
851
- $postdata['post_name'] = $post['post_name'];
852
- }
853
- if ( ! empty( $post['post_status'] ) ) {
854
- $postdata['post_status'] = $post['post_status'];
855
- }
856
- if ( ! empty( $post['menu_order'] ) ) {
857
- $postdata['menu_order'] = $post['menu_order'];
858
- }
859
- if ( ! empty( $post['comment_status'] ) ) {
860
- $postdata['comment_status'] = $post['comment_status'];
861
- }
862
- if ( sizeof( $postdata ) > 1 ) {
863
- $result = wp_update_post( $postdata );
864
-
865
- if ( ! $result ) {
866
- $this->add_import_result( 'failed', __( 'Failed to update product', 'wf_csv_import_export' ), $post_id, $processing_product_title, $processing_product_sku );
867
- $this->hf_log_data_change( 'csv-import', sprintf( __('> Failed to update product %s', 'wf_csv_import_export'), $post_id ), true );
868
- unset( $post );
869
- return;
870
- } else {
871
- $this->hf_log_data_change( 'csv-import', __( '> Merged post data: ', 'wf_csv_import_export' ) . print_r( $postdata, true ) );
872
- }
873
- }
874
-
875
- } else {
876
- $merging = FALSE;
877
- // Get parent
878
- $post_parent = $post['post_parent'];
879
-
880
- if ( $post_parent !== "" ) {
881
- $post_parent = absint( $post_parent );
882
-
883
- if ( $post_parent > 0 ) {
884
- // if we already know the parent, map it to the new local ID
885
- if ( isset( $this->processed_posts[ $post_parent ] ) ) {
886
- $post_parent = $this->processed_posts[ $post_parent ];
887
-
888
- // otherwise record the parent for later
889
- } else {
890
-
891
- $this->post_orphans[ intval( $processing_product_id ) ] = $post_parent;
892
- //$post_parent = 0;
893
-
894
- }
895
-
896
- }
897
- }
898
-
899
- // Insert product
900
- $this->hf_log_data_change( 'csv-import', sprintf( __('> Inserting %s', 'wf_csv_import_export'), esc_html( $processing_product_title ) ), true );
901
-
902
- $postdata = array(
903
- 'import_id' => $processing_product_id,
904
- 'post_author' => $post['post_author'] ? absint( $post['post_author'] ) : get_current_user_id(),
905
- 'post_date' => ( $post['post_date'] ) ? date( 'Y-m-d H:i:s', strtotime( $post['post_date'] )) : '',
906
- 'post_date_gmt' => ( $post['post_date_gmt'] ) ? date( 'Y-m-d H:i:s', strtotime( $post['post_date_gmt'] )) : '',
907
- 'post_content' => $post['post_content'],
908
- 'post_excerpt' => $post['post_excerpt'],
909
- 'post_title' => $processing_product_title,
910
- 'post_name' => ( $post['post_name'] ) ? $post['post_name'] : sanitize_title( $processing_product_title ),
911
- 'post_status' => ( $post['post_status'] ) ? $post['post_status'] : 'publish',
912
- 'post_parent' => $post_parent,
913
- 'menu_order' => $post['menu_order'],
914
- 'post_type' => $post['post_type'],
915
- 'post_password' => $post['post_password'],
916
- 'comment_status' => $post['comment_status'],
917
- );
918
- $post_id = wp_insert_post( $postdata, true );
919
-
920
- if ( is_wp_error( $post_id ) ) {
921
-
922
- $this->add_import_result( 'failed', __( 'Failed to import product', 'wf_csv_import_export' ), $processing_product_id, $processing_product_title, $processing_product_sku );
923
- $this->hf_log_data_change( 'csv-import', sprintf( __( 'Failed to import product &#8220;%s&#8221;', 'wf_csv_import_export' ), esc_html($processing_product_title) ) );
924
- unset( $post );
925
- return;
926
-
927
- } else {
928
-
929
- $this->hf_log_data_change( 'csv-import', sprintf( __('> Inserted - post ID is %s.', 'wf_csv_import_export'), $post_id ) );
930
-
931
- }
932
- }
933
-
934
- unset( $postdata );
935
-
936
- // map pre-import ID to local ID
937
- if ( empty( $processing_product_id ) ) {
938
- $processing_product_id = (int) $post_id;
939
- }
940
-
941
- $this->processed_posts[ intval( $processing_product_id ) ] = (int) $post_id;
942
-
943
- // add categories, tags and other terms
944
- if ( ! empty( $post['terms'] ) && is_array( $post['terms'] ) ) {
945
-
946
- $terms_to_set = array();
947
-
948
- foreach ( $post['terms'] as $term_group ) {
949
-
950
- $taxonomy = $term_group['taxonomy'];
951
- $terms = $term_group['terms'];
952
-
953
- if ( ! $taxonomy || ! taxonomy_exists( $taxonomy ) ) {
954
- continue;
955
- }
956
-
957
- if ( ! is_array( $terms ) ) {
958
- $terms = array( $terms );
959
- }
960
-
961
- $terms_to_set[ $taxonomy ] = array();
962
-
963
- foreach ( $terms as $term_id ) {
964
-
965
- if ( ! $term_id ) continue;
966
-
967
- $terms_to_set[ $taxonomy ][] = intval( $term_id );
968
- }
969
-
970
- }
971
-
972
- foreach ( $terms_to_set as $tax => $ids ) {
973
- $tt_ids = wp_set_post_terms( $post_id, $ids, $tax, false );
974
- }
975
-
976
- unset( $post['terms'], $terms_to_set );
977
- }
978
-
979
- // add/update post meta
980
- if ( ! empty( $post['postmeta'] ) && is_array( $post['postmeta'] ) ) {
981
- foreach ( $post['postmeta'] as $meta ) {
982
- $key = apply_filters( 'import_post_meta_key', $meta['key'] );
983
-
984
- if ( $key ) {
985
- update_post_meta( $post_id, $key, maybe_unserialize( $meta['value'] ) );
986
- }
987
-
988
- if ( $key == '_file_paths' ) {
989
- do_action( 'woocommerce_process_product_file_download_paths', $post_id, 0, maybe_unserialize( $meta['value'] ) );
990
- }
991
-
992
- }
993
-
994
- unset( $post['postmeta'] );
995
- }
996
-
997
- // Import images and add to post
998
- if ( ! empty( $post['images'] ) && is_array($post['images']) ) {
999
-
1000
- $featured = true;
1001
- $gallery_ids = array();
1002
-
1003
- if ($merging) {
1004
-
1005
- // Get basenames
1006
- $image_basenames = array();
1007
-
1008
- foreach( $post['images'] as $image )
1009
- $image_basenames[] = basename( $image );
1010
-
1011
- // Loop attachments already attached to the product
1012
- $attachments = get_posts( 'post_parent=' . $post_id . '&post_type=attachment&fields=ids&post_mime_type=image&numberposts=-1' );
1013
-
1014
- foreach ( $attachments as $attachment_key => $attachment ) {
1015
-
1016
- $attachment_url = wp_get_attachment_url( $attachment );
1017
- $attachment_basename = basename( $attachment_url );
1018
-
1019
- // Don't import existing images
1020
- if ( in_array( $attachment_url, $post['images'] ) || in_array( $attachment_basename, $image_basenames ) ) {
1021
-
1022
- foreach( $post['images'] as $key => $image ) {
1023
-
1024
- if ( $image == $attachment_url || basename( $image ) == $attachment_basename ) {
1025
- unset( $post['images'][ $key ] );
1026
-
1027
- $this->hf_log_data_change( 'csv-import', sprintf( __( '> > Image exists - skipping %s', 'wf_csv_import_export' ), basename( $image ) ) );
1028
-
1029
- if ( $key == 0 ) {
1030
- update_post_meta( $post_id, '_thumbnail_id', $attachment );
1031
- $featured = false;
1032
- } else {
1033
- $gallery_ids[ $key ] = $attachment;
1034
- }
1035
- }
1036
-
1037
- }
1038
-
1039
- } else {
1040
-
1041
- // Detach image which is not being merged
1042
- $attachment_post = array();
1043
- $attachment_post['ID'] = $attachment;
1044
- $attachment_post['post_parent'] = '';
1045
- wp_update_post( $attachment_post );
1046
- unset( $attachment_post );
1047
-
1048
- }
1049
-
1050
- }
1051
-
1052
- unset( $attachments );
1053
- }
1054
-
1055
- if ( $post['images'] ) foreach ( $post['images'] as $image_key => $image ) {
1056
-
1057
- $this->hf_log_data_change( 'csv-import', sprintf( __( '> > Importing image "%s"', 'wf_csv_import_export' ), $image ) );
1058
-
1059
- $filename = basename( $image );
1060
-
1061
- $attachment = array(
1062
- 'post_title' => preg_replace( '/\.[^.]+$/', '', $processing_product_title . ' ' . ( $image_key + 1 ) ),
1063
- 'post_content' => '',
1064
- 'post_status' => 'inherit',
1065
- 'post_parent' => $post_id
1066
- );
1067
-
1068
- $attachment_id = $this->process_attachment( $attachment, $image, $post_id );
1069
-
1070
- if ( ! is_wp_error( $attachment_id ) && $attachment_id ) {
1071
-
1072
- $this->hf_log_data_change( 'csv-import', sprintf( __( '> > Imported image "%s"', 'wf_csv_import_export' ), $image ) );
1073
-
1074
- // Set alt
1075
- update_post_meta( $attachment_id, '_wp_attachment_image_alt', $processing_product_title );
1076
-
1077
- if ( $featured ) {
1078
- update_post_meta( $post_id, '_thumbnail_id', $attachment_id );
1079
- } else {
1080
- $gallery_ids[ $image_key ] = $attachment_id;
1081
- }
1082
-
1083
- update_post_meta( $attachment_id, '_woocommerce_exclude_image', 0 );
1084
-
1085
- $featured = false;
1086
- } else {
1087
- $this->hf_log_data_change( 'csv-import', sprintf( __( '> > Error importing image "%s"', 'wf_csv_import_export' ), $image ) );
1088
- $this->hf_log_data_change( 'csv-import', '> > ' . $attachment_id->get_error_message() );
1089
- }
1090
-
1091
- unset( $attachment, $attachment_id );
1092
- }
1093
-
1094
- $this->hf_log_data_change( 'csv-import', __( '> > Images set', 'wf_csv_import_export' ) );
1095
-
1096
- ksort( $gallery_ids );
1097
-
1098
- update_post_meta( $post_id, '_product_image_gallery', implode( ',', $gallery_ids ) );
1099
-
1100
- unset( $post['images'], $featured, $gallery_ids );
1101
- }
1102
-
1103
- // Import attributes
1104
- if ( ! empty( $post['attributes'] ) && is_array($post['attributes']) ) {
1105
-
1106
- if ($merging) {
1107
- $attributes = array_filter( (array) maybe_unserialize( get_post_meta( $post_id, '_product_attributes', true ) ) );
1108
- $attributes = array_merge( $attributes, $post['attributes'] );
1109
- } else {
1110
- $attributes = $post['attributes'];
1111
- }
1112
-
1113
- // Sort attribute positions
1114
- if ( ! function_exists( 'attributes_cmp' ) ) {
1115
- function attributes_cmp( $a, $b ) {
1116
- if ( $a['position'] == $b['position'] ) return 0;
1117
- return ( $a['position'] < $b['position'] ) ? -1 : 1;
1118
- }
1119
- }
1120
- uasort( $attributes, 'attributes_cmp' );
1121
-
1122
- update_post_meta( $post_id, '_product_attributes', $attributes );
1123
-
1124
- unset( $post['attributes'], $attributes );
1125
- }
1126
-
1127
- // Import GPF
1128
- if ( ! empty( $post['gpf_data'] ) && is_array( $post['gpf_data'] ) ) {
1129
-
1130
- update_post_meta( $post_id, '_woocommerce_gpf_data', $post['gpf_data'] );
1131
-
1132
- unset( $post['gpf_data'] );
1133
- }
1134
-
1135
- if ( ! empty( $post['upsell_skus'] ) && is_array( $post['upsell_skus'] ) ) {
1136
- $this->upsell_skus[ $post_id ] = $post['upsell_skus'];
1137
- }
1138
-
1139
- if ( ! empty( $post['crosssell_skus'] ) && is_array( $post['crosssell_skus'] ) ) {
1140
- $this->crosssell_skus[ $post_id ] = $post['crosssell_skus'];
1141
- }
1142
-
1143
- add_post_meta( $post_id, 'total_sales', 0 );
1144
-
1145
- if ( $merging ) {
1146
- $this->add_import_result( 'merged', 'Merge successful', $post_id, $processing_product_title, $processing_product_sku );
1147
- $this->hf_log_data_change( 'csv-import', sprintf( __('> Finished merging post ID %s.', 'wf_csv_import_export'), $post_id ) );
1148
- } else {
1149
- $this->add_import_result( 'imported', 'Import successful', $post_id, $processing_product_title, $processing_product_sku );
1150
- $this->hf_log_data_change( 'csv-import', sprintf( __('> Finished importing post ID %s.', 'wf_csv_import_export'), $post_id ) );
1151
- }
1152
-
1153
- unset( $post );
1154
- }
1155
-
1156
- /**
1157
- * Log a row's import status
1158
- */
1159
- protected function add_import_result( $status, $reason, $post_id = '', $post_title = '', $sku = '' ) {
1160
- $this->import_results[] = array(
1161
- 'post_title' => $post_title,
1162
- 'post_id' => $post_id,
1163
- 'sku' => $sku,
1164
- 'status' => $status,
1165
- 'reason' => $reason
1166
- );
1167
- }
1168
-
1169
- /**
1170
- * If fetching attachments is enabled then attempt to create a new attachment
1171
- *
1172
- * @param array $post Attachment post details from WXR
1173
- * @param string $url URL to fetch attachment from
1174
- * @return int|WP_Error Post ID on success, WP_Error otherwise
1175
- */
1176
- public function process_attachment( $post, $url, $post_id ) {
1177
-
1178
- $attachment_id = '';
1179
- $attachment_url = '';
1180
- $attachment_file = '';
1181
- $upload_dir = wp_upload_dir();
1182
-
1183
- // If same server, make it a path and move to upload directory
1184
- /*if ( strstr( $url, $upload_dir['baseurl'] ) ) {
1185
-
1186
- $url = str_replace( $upload_dir['baseurl'], $upload_dir['basedir'], $url );
1187
-
1188
- } else*/
1189
- if ( strstr( $url, site_url() ) ) {
1190
- $abs_url = str_replace( trailingslashit( site_url() ), trailingslashit( ABSPATH ), urldecode($url) );
1191
- $new_name = wp_unique_filename( $upload_dir['path'], basename( urldecode($url) ) );
1192
- $new_url = trailingslashit( $upload_dir['path'] ) . $new_name;
1193
-
1194
- if ( copy( $abs_url, $new_url ) ) {
1195
- $url = basename( $new_url );
1196
- }
1197
- }
1198
-
1199
- if ( ! strstr( $url, 'http' ) ) {
1200
-
1201
- // Local file
1202
- $attachment_file = trailingslashit( $upload_dir['basedir'] ) . 'product_images/' . $url;
1203
-
1204
- // We have the path, check it exists
1205
- if ( ! file_exists( $attachment_file ) )
1206
- $attachment_file = trailingslashit( $upload_dir['path'] ) . $url;
1207
-
1208
- // We have the path, check it exists
1209
- if ( file_exists( $attachment_file ) ) {
1210
-
1211
- $attachment_url = str_replace( trailingslashit( ABSPATH ), trailingslashit( site_url() ), $attachment_file );
1212
-
1213
- if ( $info = wp_check_filetype( $attachment_file ) )
1214
- $post['post_mime_type'] = $info['type'];
1215
- else
1216
- return new WP_Error( 'attachment_processing_error', __('Invalid file type', 'wordpress-importer') );
1217
-
1218
- $post['guid'] = $attachment_url;
1219
-
1220
- $attachment_id = wp_insert_attachment( $post, $attachment_file, $post_id );
1221
-
1222
- } else {
1223
- return new WP_Error( 'attachment_processing_error', __('Local image did not exist!', 'wordpress-importer') );
1224
- }
1225
-
1226
- } else {
1227
-
1228
- // if the URL is absolute, but does not contain address, then upload it assuming base_site_url
1229
- if ( preg_match( '|^/[\w\W]+$|', $url ) )
1230
- $url = rtrim( site_url(), '/' ) . $url;
1231
-
1232
- $upload = $this->fetch_remote_file( $url, $post );
1233
-
1234
- if ( is_wp_error( $upload ) )
1235
- return $upload;
1236
-
1237
- if ( $info = wp_check_filetype( $upload['file'] ) )
1238
- $post['post_mime_type'] = $info['type'];
1239
- else
1240
- return new WP_Error( 'attachment_processing_error', __('Invalid file type', 'wordpress-importer') );
1241
-
1242
- $post['guid'] = $upload['url'];
1243
- $attachment_file = $upload['file'];
1244
- $attachment_url = $upload['url'];
1245
-
1246
- // as per wp-admin/includes/upload.php
1247
- $attachment_id = wp_insert_attachment( $post, $upload['file'], $post_id );
1248
-
1249
- unset( $upload );
1250
- }
1251
-
1252
- if ( ! is_wp_error( $attachment_id ) && $attachment_id > 0 ) {
1253
- $this->hf_log_data_change( 'csv-import', sprintf( __( '> > Inserted image attachment "%s"', 'wf_csv_import_export' ), $url ) );
1254
-
1255
- $this->attachments[] = $attachment_id;
1256
- }
1257
-
1258
- return $attachment_id;
1259
- }
1260
-
1261
- /**
1262
- * Attempt to download a remote file attachment
1263
- */
1264
- public function fetch_remote_file( $url, $post ) {
1265
-
1266
- // extract the file name and extension from the url
1267
- $file_name = basename( current( explode( '?', $url ) ) );
1268
- $wp_filetype = wp_check_filetype( $file_name, null );
1269
- $parsed_url = @parse_url( $url );
1270
-
1271
- // Check parsed URL
1272
- if ( ! $parsed_url || ! is_array( $parsed_url ) )
1273
- return new WP_Error( 'import_file_error', 'Invalid URL' );
1274
-
1275
- // Ensure url is valid
1276
- $url = str_replace( " ", '%20', $url );
1277
-
1278
- // Get the file
1279
- $response = wp_remote_get( $url, array(
1280
- 'timeout' => 10
1281
- ) );
1282
-
1283
- if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) !== 200 )
1284
- return new WP_Error( 'import_file_error', 'Error getting remote image' );
1285
-
1286
- // Ensure we have a file name and type
1287
- if ( ! $wp_filetype['type'] ) {
1288
-
1289
- $headers = wp_remote_retrieve_headers( $response );
1290
-
1291
- if ( isset( $headers['content-disposition'] ) && strstr( $headers['content-disposition'], 'filename=' ) ) {
1292
-
1293
- $disposition = end( explode( 'filename=', $headers['content-disposition'] ) );
1294
- $disposition = sanitize_file_name( $disposition );
1295
- $file_name = $disposition;
1296
-
1297
- } elseif ( isset( $headers['content-type'] ) && strstr( $headers['content-type'], 'image/' ) ) {
1298
-
1299
- $file_name = 'image.' . str_replace( 'image/', '', $headers['content-type'] );
1300
-
1301
- }
1302
-
1303
- unset( $headers );
1304
- }
1305
-
1306
- // Upload the file
1307
- $upload = wp_upload_bits( $file_name, '', wp_remote_retrieve_body( $response ) );
1308
-
1309
- if ( $upload['error'] )
1310
- return new WP_Error( 'upload_dir_error', $upload['error'] );
1311
-
1312
- // Get filesize
1313
- $filesize = filesize( $upload['file'] );
1314
-
1315
- if ( 0 == $filesize ) {
1316
- @unlink( $upload['file'] );
1317
- unset( $upload );
1318
- return new WP_Error( 'import_file_error', __('Zero size file downloaded', 'wf_csv_import_export') );
1319
- }
1320
-
1321
- unset( $response );
1322
-
1323
- return $upload;
1324
- }
1325
-
1326
- /**
1327
- * Decide what the maximum file size for downloaded attachments is.
1328
- * Default is 0 (unlimited), can be filtered via import_attachment_size_limit
1329
- *
1330
- * @return int Maximum attachment file size to import
1331
- */
1332
- public function max_attachment_size() {
1333
- return apply_filters( 'import_attachment_size_limit', 0 );
1334
- }
1335
-
1336
- /**
1337
- * Attempt to associate posts and menu items with previously missing parents
1338
- */
1339
- public function backfill_parents() {
1340
- global $wpdb;
1341
-
1342
- // find parents for post orphans
1343
- if ( ! empty( $this->post_orphans ) && is_array( $this->post_orphans ) )
1344
- foreach ( $this->post_orphans as $child_id => $parent_id ) {
1345
- $local_child_id = $local_parent_id = false;
1346
- if ( isset( $this->processed_posts[$child_id] ) )
1347
- $local_child_id = $this->processed_posts[$child_id];
1348
- if ( isset( $this->processed_posts[$parent_id] ) )
1349
- $local_parent_id = $this->processed_posts[$parent_id];
1350
-
1351
- if ( $local_child_id && $local_parent_id )
1352
- $wpdb->update( $wpdb->posts, array( 'post_parent' => $local_parent_id ), array( 'ID' => $local_child_id ), '%d', '%d' );
1353
- }
1354
- }
1355
-
1356
- /**
1357
- * Attempt to associate posts and menu items with previously missing parents
1358
- */
1359
- public function link_product_skus( $type, $product_id, $skus ) {
1360
- global $wpdb;
1361
-
1362
- $ids = array();
1363
-
1364
- foreach ( $skus as $sku ) {
1365
- $ids[] = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_sku' AND meta_value = %s;", $sku ) );
1366
- }
1367
-
1368
- $ids = array_filter( $ids );
1369
-
1370
- update_post_meta( $product_id, "_{$type}_ids", $ids );
1371
- }
1372
-
1373
- private function handle_ftp(){
1374
- $enable_ftp_ie = !empty( $_POST['enable_ftp_ie'] ) ? true : false;
1375
- if($enable_ftp_ie == false) return false;
1376
-
1377
- $ftp_server = ! empty( $_POST['ftp_server'] ) ? $_POST['ftp_server'] : '';
1378
- $ftp_server_path = ! empty( $_POST['ftp_server_path'] ) ? $_POST['ftp_server_path'] : '';
1379
- $ftp_user = ! empty( $_POST['ftp_user'] ) ? $_POST['ftp_user'] : '';
1380
- $ftp_password = ! empty( $_POST['ftp_password'] ) ? $_POST['ftp_password'] : '';
1381
- $use_ftps = ! empty( $_POST['use_ftps'] ) ? true : false;
1382
-
1383
-
1384
- $settings = array();
1385
- $settings[ 'ftp_server' ] = $ftp_server;
1386
- $settings[ 'ftp_user' ] = $ftp_user;
1387
- $settings[ 'ftp_password' ] = $ftp_password;
1388
- $settings[ 'use_ftps' ] = $use_ftps;
1389
- $settings[ 'enable_ftp_ie' ] = $enable_ftp_ie;
1390
- $settings[ 'ftp_server_path' ] = $ftp_server_path;
1391
-
1392
-
1393
- $local_file = 'wp-content/plugins/product-csv-import-export-for-woocommerce/temp-import.csv';
1394
- $server_file = $ftp_server_path;
1395
-
1396
- update_option( 'wf_shipment_tracking_importer_ftp', $settings );
1397
-
1398
- $ftp_conn = $use_ftps ? ftp_ssl_connect($ftp_server) : ftp_connect($ftp_server);
1399
- $error_message = "";
1400
- $success = false;
1401
- if($ftp_conn == false){
1402
- $error_message = "There is connection problem\n";
1403
- }
1404
-
1405
- if(empty($error_message)){
1406
- if(ftp_login($ftp_conn, $ftp_user, $ftp_password) == false){
1407
- $error_message = "Not able to login \n";
1408
- }
1409
- }
1410
- if(empty($error_message)){
1411
-
1412
- if (ftp_get($ftp_conn, ABSPATH.$local_file, $server_file, FTP_BINARY)) {
1413
- $error_message = "";
1414
- $success = true;
1415
- } else {
1416
- $error_message = "There was a problem\n";
1417
- }
1418
- }
1419
-
1420
- ftp_close($ftp_conn);
1421
- if($success){
1422
- $this->file_url = $local_file;
1423
- }else{
1424
- die($error_message);
1425
- }
1426
- return true;
1427
- }
1428
-
1429
- // Display import page title
1430
- public function header() {
1431
- echo '<div class="wrap"><div class="icon32" id="icon-woocommerce-importer"><br></div>';
1432
- echo '<h2>' . ( empty( $_GET['merge'] ) ? __( 'Import', 'wf_csv_import_export' ) : __( 'Merge Products', 'wf_csv_import_export' ) ) . '</h2>';
1433
- }
1434
-
1435
- // Close div.wrap
1436
- public function footer() {
1437
- echo '</div>';
1438
- }
1439
-
1440
- /**
1441
- * Display introductory text and file upload form
1442
- */
1443
- public function greet() {
1444
- $action = 'admin.php?import=woocommerce_csv&amp;step=1&amp;merge=' . ( ! empty( $_GET['merge'] ) ? 1 : 0 );
1445
- $bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() );
1446
- $size = size_format( $bytes );
1447
- $upload_dir = wp_upload_dir();
1448
-
1449
- include( 'views/html-wf-import-greeting.php' );
1450
- }
1451
-
1452
- /**
1453
- * Added to http_request_timeout filter to force timeout at 60 seconds during import
1454
- * @return int 60
1455
- */
1456
- public function bump_request_timeout( $val ) {
1457
- return 60;
1458
- }
1459
- /**
1460
- * Get a list of all the product attributes for a post type.
1461
- * These require a bit more digging into the values.
1462
- */
1463
- public static function get_all_product_attributes( $post_type = 'product' ) {
1464
- global $wpdb;
1465
-
1466
- $results = $wpdb->get_col( $wpdb->prepare(
1467
- "SELECT DISTINCT pm.meta_value
1468
- FROM {$wpdb->postmeta} AS pm
1469
- LEFT JOIN {$wpdb->posts} AS p ON p.ID = pm.post_id
1470
- WHERE p.post_type = %s
1471
- AND p.post_status IN ( 'publish', 'pending', 'private', 'draft' )
1472
- AND pm.meta_key = '_product_attributes'",
1473
- $post_type
1474
- ) );
1475
-
1476
- // Go through each result, and look at the attribute keys within them.
1477
- $result = array();
1478
-
1479
- if ( ! empty( $results ) ) {
1480
- foreach( $results as $_product_attributes ) {
1481
- $attributes = maybe_unserialize( maybe_unserialize( $_product_attributes ) );
1482
- if ( ! empty( $attributes ) && is_array( $attributes ) ) {
1483
- foreach( $attributes as $key => $attribute ) {
1484
- if ( ! $key ) {
1485
- continue;
1486
- }
1487
- if ( ! strstr( $key, 'pa_' ) ) {
1488
- if ( empty( $attribute['name'] ) ) {
1489
- continue;
1490
- }
1491
- $key = $attribute['name'];
1492
- }
1493
-
1494
- $result[ $key ] = $key;
1495
- }
1496
- }
1497
- }
1498
- }
1499
-
1500
- sort( $result );
1501
-
1502
- return $result;
1503
- }
1504
- }
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
+ if(WC()->version < '2.7.0'){
35
+ $this->log = new WC_Logger();
36
+
37
+ }else
38
+ {
39
+ $this->log = wc_get_logger();
40
+
41
+ }
42
+
43
+ $this->import_page = 'woocommerce_csv';
44
+ $this->file_url_import_enabled = apply_filters( 'woocommerce_csv_product_file_url_import_enabled', true );
45
+ }
46
+
47
+ /**
48
+ * Registered callback function for the WordPress Importer
49
+ *
50
+ * Manages the three separate stages of the CSV import process
51
+ */
52
+ public function dispatch() {
53
+ global $woocommerce, $wpdb;
54
+
55
+ if ( ! empty( $_POST['delimiter'] ) ) {
56
+ $this->delimiter = stripslashes( trim( $_POST['delimiter'] ) );
57
+ }else if ( ! empty( $_GET['delimiter'] ) ) {
58
+ $this->delimiter = stripslashes( trim( $_GET['delimiter'] ) );
59
+ }
60
+
61
+ if ( ! $this->delimiter )
62
+ $this->delimiter = ',';
63
+
64
+ if ( ! empty( $_POST['merge_empty_cells'] ) || ! empty( $_GET['merge_empty_cells'] ) ) {
65
+ $this->merge_empty_cells = 1;
66
+ } else{
67
+ $this->merge_empty_cells = 0;
68
+ }
69
+
70
+ $step = empty( $_GET['step'] ) ? 0 : (int) $_GET['step'];
71
+
72
+ switch ( $step ) {
73
+ case 0 :
74
+ $this->header();
75
+ $this->greet();
76
+ break;
77
+ case 1 :
78
+ $this->header();
79
+
80
+ check_admin_referer( 'import-upload' );
81
+
82
+ if(!empty($_GET['file_url']))
83
+ $this->file_url = esc_attr( $_GET['file_url'] );
84
+ if(!empty($_GET['file_id']))
85
+ $this->id = $_GET['file_id'] ;
86
+
87
+ if ( !empty($_GET['clearmapping']) || $this->handle_upload() )
88
+ $this->import_options();
89
+ else
90
+ _e( 'Error with handle_upload!', 'wf_csv_import_export' );
91
+ break;
92
+ case 2 :
93
+ $this->header();
94
+
95
+ check_admin_referer( 'import-woocommerce' );
96
+
97
+ $this->id = (int) $_POST['import_id'];
98
+
99
+ if ( $this->file_url_import_enabled )
100
+ $this->file_url = esc_attr( $_POST['import_url'] );
101
+
102
+ if ( $this->id )
103
+ $file = get_attached_file( $this->id );
104
+ else if ( $this->file_url_import_enabled )
105
+ $file = ABSPATH . $this->file_url;
106
+
107
+ $file = str_replace( "\\", "/", $file );
108
+
109
+ if ( $file ) {
110
+ ?>
111
+ <table id="import-progress" class="widefat_importer widefat">
112
+ <thead>
113
+ <tr>
114
+ <th class="status">&nbsp;</th>
115
+ <th class="row"><?php _e( 'Row', 'wf_csv_import_export' ); ?></th>
116
+ <th><?php _e( 'SKU', 'wf_csv_import_export' ); ?></th>
117
+ <th><?php _e( 'Product', 'wf_csv_import_export' ); ?></th>
118
+ <th class="reason"><?php _e( 'Status Msg', 'wf_csv_import_export' ); ?></th>
119
+ </tr>
120
+ </thead>
121
+ <tfoot>
122
+ <tr class="importer-loading">
123
+ <td colspan="5"></td>
124
+ </tr>
125
+ </tfoot>
126
+ <tbody></tbody>
127
+ </table>
128
+ <script type="text/javascript">
129
+ jQuery(document).ready(function($) {
130
+
131
+ if ( ! window.console ) { window.console = function(){}; }
132
+
133
+ var processed_terms = [];
134
+ var processed_posts = [];
135
+ var post_orphans = [];
136
+ var attachments = [];
137
+ var upsell_skus = [];
138
+ var crosssell_skus = [];
139
+ var i = 1;
140
+ var done_count = 0;
141
+
142
+ function import_rows( start_pos, end_pos ) {
143
+
144
+ var data = {
145
+ action: 'woocommerce_csv_import_request',
146
+ file: '<?php echo addslashes( $file ); ?>',
147
+ mapping: '<?php echo json_encode( $_POST['map_from'] ); ?>',
148
+ eval_field: '<?php echo stripslashes(json_encode(($_POST['eval_field']),JSON_HEX_APOS)) ?>',
149
+ delimiter: '<?php echo $this->delimiter; ?>',
150
+ merge_empty_cells: '<?php echo $this->merge_empty_cells; ?>',
151
+ start_pos: start_pos,
152
+ end_pos: end_pos,
153
+ };
154
+ data.eval_field = $.parseJSON(data.eval_field);
155
+ return $.ajax({
156
+ 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' ) ); ?>',
157
+ data: data,
158
+ type: 'POST',
159
+ success: function( response ) {
160
+ console.log( response );
161
+ if ( response ) {
162
+
163
+ try {
164
+ // Get the valid JSON only from the returned string
165
+ if ( response.indexOf("<!--WC_START-->") >= 0 )
166
+ response = response.split("<!--WC_START-->")[1]; // Strip off before after WC_START
167
+
168
+ if ( response.indexOf("<!--WC_END-->") >= 0 )
169
+ response = response.split("<!--WC_END-->")[0]; // Strip off anything after WC_END
170
+
171
+ // Parse
172
+ var results = $.parseJSON( response );
173
+
174
+ if ( results.error ) {
175
+
176
+ $('#import-progress tbody').append( '<tr id="row-' + i + '" class="error"><td class="status" colspan="5">' + results.error + '</td></tr>' );
177
+
178
+ i++;
179
+
180
+ } else if ( results.import_results && $( results.import_results ).size() > 0 ) {
181
+
182
+ $.each( results.processed_terms, function( index, value ) {
183
+ processed_terms.push( value );
184
+ });
185
+
186
+ $.each( results.processed_posts, function( index, value ) {
187
+ processed_posts.push( value );
188
+ });
189
+
190
+ $.each( results.post_orphans, function( index, value ) {
191
+ post_orphans.push( value );
192
+ });
193
+
194
+ $.each( results.attachments, function( index, value ) {
195
+ attachments.push( value );
196
+ });
197
+
198
+ upsell_skus = jQuery.extend( {}, upsell_skus, results.upsell_skus );
199
+ crosssell_skus = jQuery.extend( {}, crosssell_skus, results.crosssell_skus );
200
+
201
+ $( results.import_results ).each(function( index, row ) {
202
+ $('#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>' );
203
+
204
+ i++;
205
+ });
206
+ }
207
+
208
+ } catch(err) {}
209
+
210
+ } else {
211
+ $('#import-progress tbody').append( '<tr class="error"><td class="status" colspan="5">' + '<?php _e( 'AJAX Error', 'wf_csv_import_export' ); ?>' + '</td></tr>' );
212
+ }
213
+
214
+ var w = $(window);
215
+ var row = $( "#row-" + ( i - 1 ) );
216
+
217
+ if ( row.length ) {
218
+ w.scrollTop( row.offset().top - (w.height()/2) );
219
+ }
220
+
221
+ done_count++;
222
+
223
+ $('body').trigger( 'woocommerce_csv_import_request_complete' );
224
+ }
225
+ });
226
+ }
227
+
228
+ var rows = [];
229
+
230
+ <?php
231
+ $limit = apply_filters( 'woocommerce_csv_import_limit_per_request', 10 );
232
+ $enc = mb_detect_encoding( $file, 'UTF-8, ISO-8859-1', true );
233
+ if ( $enc )
234
+ setlocale( LC_ALL, 'en_US.' . $enc );
235
+ @ini_set( 'auto_detect_line_endings', true );
236
+
237
+ $count = 0;
238
+ $previous_position = 0;
239
+ $position = 0;
240
+ $import_count = 0;
241
+
242
+ // Get CSV positions
243
+ if ( ( $handle = fopen( $file, "r" ) ) !== FALSE ) {
244
+
245
+ while ( ( $postmeta = fgetcsv( $handle, 0, $this->delimiter ) ) !== FALSE ) {
246
+ $count++;
247
+
248
+ if ( $count >= $limit ) {
249
+ $previous_position = $position;
250
+ $position = ftell( $handle );
251
+ $count = 0;
252
+ $import_count ++;
253
+
254
+ // Import rows between $previous_position $position
255
+ ?>rows.push( [ <?php echo $previous_position; ?>, <?php echo $position; ?> ] ); <?php
256
+ }
257
+ }
258
+
259
+ // Remainder
260
+ if ( $count > 0 ) {
261
+ ?>rows.push( [ <?php echo $position; ?>, '' ] ); <?php
262
+ $import_count ++;
263
+ }
264
+
265
+ fclose( $handle );
266
+ }
267
+ ?>
268
+
269
+ var data = rows.shift();
270
+ var regen_count = 0;
271
+ import_rows( data[0], data[1] );
272
+
273
+ $('body').on( 'woocommerce_csv_import_request_complete', function() {
274
+ if ( done_count == <?php echo $import_count; ?> ) {
275
+
276
+ if ( attachments.length ) {
277
+
278
+ $('#import-progress tbody').append( '<tr class="regenerating"><td colspan="5"><div class="progress"></div></td></tr>' );
279
+
280
+ index = 0;
281
+
282
+ $.each( attachments, function( i, value ) {
283
+ regenerate_thumbnail( value );
284
+ index ++;
285
+ if ( index == attachments.length ) {
286
+ import_done();
287
+ }
288
+ });
289
+
290
+ } else {
291
+ import_done();
292
+ }
293
+
294
+ } else {
295
+ // Call next request
296
+ data = rows.shift();
297
+ import_rows( data[0], data[1] );
298
+ }
299
+ } );
300
+
301
+ // Regenerate a specified image via AJAX
302
+ function regenerate_thumbnail( id ) {
303
+ $.ajax({
304
+ type: 'POST',
305
+ url: ajaxurl,
306
+ data: { action: "woocommerce_csv_import_regenerate_thumbnail", id: id },
307
+ success: function( response ) {
308
+ if ( response !== Object( response ) || ( typeof response.success === "undefined" && typeof response.error === "undefined" ) ) {
309
+ response = new Object;
310
+ response.success = false;
311
+ 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 + "' ); ?>";
312
+ }
313
+
314
+ regen_count ++;
315
+
316
+ $('#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' ) ); ?>' );
317
+
318
+ if ( ! response.success ) {
319
+ $('#import-progress tbody').append( '<tr><td colspan="5">' + response.error + '</td></tr>' );
320
+ }
321
+ },
322
+ error: function( response ) {
323
+ $('#import-progress tbody').append( '<tr><td colspan="5">' + response.error + '</td></tr>' );
324
+ }
325
+ });
326
+ }
327
+
328
+ function import_done() {
329
+ var data = {
330
+ action: 'woocommerce_csv_import_request',
331
+ file: '<?php echo $file; ?>',
332
+ processed_terms: processed_terms,
333
+ processed_posts: processed_posts,
334
+ post_orphans: post_orphans,
335
+ upsell_skus: upsell_skus,
336
+ crosssell_skus: crosssell_skus
337
+ };
338
+
339
+ $.ajax({
340
+ 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' ) ); ?>',
341
+ data: data,
342
+ type: 'POST',
343
+ success: function( response ) {
344
+ console.log( response );
345
+ $('#import-progress tbody').append( '<tr class="complete"><td colspan="5">' + response + '</td></tr>' );
346
+ $('.importer-loading').hide();
347
+ }
348
+ });
349
+ }
350
+ });
351
+ </script>
352
+ <?php
353
+ } else {
354
+ echo '<p class="error">' . __( 'Error finding uploaded file!', 'wf_csv_import_export' ) . '</p>';
355
+ }
356
+ break;
357
+ case 3 :
358
+ // Check access - cannot use nonce here as it will expire after multiple requests
359
+ if ( ! current_user_can( 'manage_woocommerce' ) )
360
+ die();
361
+
362
+ add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) );
363
+
364
+ if ( function_exists( 'gc_enable' ) )
365
+ gc_enable();
366
+
367
+ @set_time_limit(0);
368
+ @ob_flush();
369
+ @flush();
370
+ $wpdb->hide_errors();
371
+
372
+ $file = stripslashes( $_POST['file'] );
373
+ $mapping = json_decode( stripslashes( $_POST['mapping'] ), true );
374
+ $eval_field = $_POST['eval_field'];
375
+ $start_pos = isset( $_POST['start_pos'] ) ? absint( $_POST['start_pos'] ) : 0;
376
+ $end_pos = isset( $_POST['end_pos'] ) ? absint( $_POST['end_pos'] ) : '';
377
+
378
+ update_option( 'wf_prod_csv_imp_exp_mapping', array($mapping,$eval_field ));
379
+
380
+ $position = $this->import_start( $file, $mapping, $start_pos, $end_pos, $eval_field );
381
+ $this->import();
382
+ $this->import_end();
383
+
384
+ $results = array();
385
+ $results['import_results'] = $this->import_results;
386
+ $results['processed_terms'] = $this->processed_terms;
387
+ $results['processed_posts'] = $this->processed_posts;
388
+ $results['post_orphans'] = $this->post_orphans;
389
+ $results['attachments'] = $this->attachments;
390
+ $results['upsell_skus'] = $this->upsell_skus;
391
+ $results['crosssell_skus'] = $this->crosssell_skus;
392
+
393
+ echo "<!--WC_START-->";
394
+ echo json_encode( $results );
395
+ echo "<!--WC_END-->";
396
+ exit;
397
+ break;
398
+ case 4 :
399
+ // Check access - cannot use nonce here as it will expire after multiple requests
400
+ if ( ! current_user_can( 'manage_woocommerce' ) )
401
+ die();
402
+
403
+ add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) );
404
+
405
+ if ( function_exists( 'gc_enable' ) )
406
+ gc_enable();
407
+
408
+ @set_time_limit(0);
409
+ @ob_flush();
410
+ @flush();
411
+ $wpdb->hide_errors();
412
+
413
+ $this->processed_terms = isset( $_POST['processed_terms'] ) ? $_POST['processed_terms'] : array();
414
+ $this->processed_posts = isset( $_POST['processed_posts']) ? $_POST['processed_posts'] : array();
415
+ $this->post_orphans = isset( $_POST['post_orphans']) ? $_POST['post_orphans'] : array();
416
+ $this->crosssell_skus = isset( $_POST['crosssell_skus']) ? array_filter( (array) $_POST['crosssell_skus'] ) : array();
417
+ $this->upsell_skus = isset( $_POST['upsell_skus']) ? array_filter( (array) $_POST['upsell_skus'] ) : array();
418
+
419
+ _e( 'Step 1...', 'wf_csv_import_export' ) . ' ';
420
+
421
+ wp_defer_term_counting( true );
422
+ wp_defer_comment_counting( true );
423
+
424
+ _e( 'Step 2...', 'wf_csv_import_export' ) . ' ';
425
+
426
+ echo 'Step 3...' . ' '; // Easter egg
427
+
428
+ // reset transients for products
429
+ if ( function_exists( 'wc_delete_product_transients' ) ) {
430
+ wc_delete_product_transients();
431
+ } else {
432
+ $woocommerce->clear_product_transients();
433
+ }
434
+
435
+ delete_transient( 'wc_attribute_taxonomies' );
436
+
437
+ $wpdb->query("DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_wc_product_type_%')");
438
+
439
+ _e( 'Finalizing...', 'wf_csv_import_export' ) . ' ';
440
+
441
+ $this->backfill_parents();
442
+
443
+ if ( ! empty( $this->upsell_skus ) ) {
444
+
445
+ _e( 'Linking upsells...', 'wf_csv_import_export' ) . ' ';
446
+
447
+ foreach ( $this->upsell_skus as $post_id => $skus ) {
448
+ $this->link_product_skus( 'upsell', $post_id, $skus );
449
+ }
450
+ }
451
+
452
+ if ( ! empty( $this->crosssell_skus ) ) {
453
+
454
+ _e( 'Linking crosssells...', 'wf_csv_import_export' ) . ' ';
455
+
456
+ foreach ( $this->crosssell_skus as $post_id => $skus ) {
457
+ $this->link_product_skus( 'crosssell', $post_id, $skus );
458
+ }
459
+ }
460
+ // SUCCESS
461
+ _e( 'Finished. Import complete.', 'wf_csv_import_export' );
462
+
463
+ $this->import_end();
464
+ exit;
465
+ break;
466
+ }
467
+
468
+ $this->footer();
469
+ }
470
+
471
+ /**
472
+ * format_data_from_csv
473
+ */
474
+ public function format_data_from_csv( $data, $enc ) {
475
+ return ( $enc == 'UTF-8' ) ? $data : utf8_encode( $data );
476
+ }
477
+
478
+ /**
479
+ * Display pre-import options
480
+ */
481
+ public function import_options() {
482
+ $j = 0;
483
+
484
+ if ( $this->id )
485
+ $file = get_attached_file( $this->id );
486
+ else if ( $this->file_url_import_enabled )
487
+ $file = ABSPATH . $this->file_url;
488
+ else
489
+ return;
490
+
491
+ // Set locale
492
+ $enc = mb_detect_encoding( $file, 'UTF-8, ISO-8859-1', true );
493
+ if ( $enc ) setlocale( LC_ALL, 'en_US.' . $enc );
494
+ @ini_set( 'auto_detect_line_endings', true );
495
+
496
+ // Get headers
497
+ if ( ( $handle = fopen( $file, "r" ) ) !== FALSE ) {
498
+
499
+ $row = $raw_headers = array();
500
+ $header = fgetcsv( $handle, 0, $this->delimiter );
501
+
502
+ while ( ( $postmeta = fgetcsv( $handle, 0, $this->delimiter ) ) !== FALSE ) {
503
+ foreach ( $header as $key => $heading ) {
504
+ if ( ! $heading ) continue;
505
+ $s_heading = strtolower( $heading );
506
+ $row[$s_heading] = ( isset( $postmeta[$key] ) ) ? $this->format_data_from_csv( $postmeta[$key], $enc ) : '';
507
+ $raw_headers[ $s_heading ] = $heading;
508
+ }
509
+ break;
510
+ }
511
+ fclose( $handle );
512
+ }
513
+
514
+ $mapping_from_db = get_option( 'wf_prod_csv_imp_exp_mapping');
515
+ $saved_mapping = null;
516
+ $saved_evaluation = null;
517
+ if($mapping_from_db && is_array($mapping_from_db) && count($mapping_from_db) == 2 && empty($_GET['clearmapping'])){
518
+ //if(count(array_intersect_key ( $mapping_from_db[0] , $row)) == count($mapping_from_db[0])){
519
+ $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 . '';
520
+ $reset_action = esc_attr(wp_nonce_url($reset_action, 'import-upload'));
521
+ 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>';
522
+ $saved_mapping = $mapping_from_db[0];
523
+ $saved_evaluation = $mapping_from_db[1];
524
+ //}
525
+ }
526
+
527
+ $merge = (!empty($_GET['merge']) && $_GET['merge']) ? 1 : 0;
528
+
529
+ $attrs = self::get_all_product_attributes();
530
+ $attr_keys = array_values($attrs);
531
+
532
+ $attributes = array();
533
+ if(!empty($attr_keys) && !empty($attrs))
534
+ $attributes = array_combine($attr_keys , $attrs);
535
+
536
+ $product_ptaxonomies = get_object_taxonomies( 'product', 'name' );
537
+ $product_vtaxonomies = get_object_taxonomies( 'product_variation', 'name' );
538
+ $product_taxonomies = array_merge($product_ptaxonomies, $product_vtaxonomies);
539
+ $taxonomies = array_keys($product_taxonomies);
540
+ $new_keys = array_values($taxonomies);
541
+ $taxonomies = array_combine($new_keys , $taxonomies);
542
+ include( 'views/html-wf-import-options.php' );
543
+ }
544
+
545
+ /**
546
+ * The main controller for the actual import stage.
547
+ */
548
+ public function import() {
549
+ global $woocommerce, $wpdb;
550
+
551
+ wp_suspend_cache_invalidation( true );
552
+
553
+ $this->hf_log_data_change( 'csv-import', '---' );
554
+ $this->hf_log_data_change( 'csv-import', __( 'Processing products.', 'wf_csv_import_export' ) );
555
+ foreach ( $this->parsed_data as $key => &$item ) {
556
+
557
+ $product = $this->parser->parse_product( $item, $this->merge_empty_cells );
558
+ if ( ! is_wp_error( $product ) )
559
+ $this->process_product( $product );
560
+ else
561
+ $this->add_import_result( 'failed', $product->get_error_message(), 'Not parsed', json_encode( $item ), '-' );
562
+
563
+ unset( $item, $product );
564
+ }
565
+ $this->hf_log_data_change( 'csv-import', __( 'Finished processing products.', 'wf_csv_import_export' ) );
566
+ wp_suspend_cache_invalidation( false );
567
+ }
568
+
569
+ /**
570
+ * Parses the CSV file and prepares us for the task of processing parsed data
571
+ *
572
+ * @param string $file Path to the CSV file for importing
573
+ */
574
+
575
+ public function hf_log_data_change ($content = 'csv-import',$data='')
576
+ {
577
+ if (WC()->version < '2.7.0')
578
+ {
579
+ $this->log->add($content,$data);
580
+ }else
581
+ {
582
+ $context = array( 'source' => $content );
583
+ $this->log->log("debug", $data ,$context);
584
+ }
585
+ }
586
+ public function import_start( $file, $mapping, $start_pos, $end_pos, $eval_field ) {
587
+
588
+ if(WC()->version < '2.7.0'){
589
+ $memory = size_format( woocommerce_let_to_num( ini_get( 'memory_limit' ) ) );
590
+ $wp_memory = size_format( woocommerce_let_to_num( WP_MEMORY_LIMIT ) );
591
+ }else
592
+ {
593
+ $memory = size_format( wc_let_to_num( ini_get( 'memory_limit' ) ) );
594
+ $wp_memory = size_format( wc_let_to_num( WP_MEMORY_LIMIT ) );
595
+
596
+ }
597
+ $this->hf_log_data_change( 'csv-import', '---[ New Import ] PHP Memory: ' . $memory . ', WP Memory: ' . $wp_memory );
598
+ $this->hf_log_data_change( 'csv-import', __( 'Parsing products CSV.', 'wf_csv_import_export' ) );
599
+
600
+ $this->parser = new WF_CSV_Parser( 'product' );
601
+
602
+ list( $this->parsed_data, $this->raw_headers, $position ) = $this->parser->parse_data( $file, $this->delimiter, $mapping, $start_pos, $end_pos, $eval_field );
603
+
604
+ $this->hf_log_data_change( 'csv-import', __( 'Finished parsing products CSV.', 'wf_csv_import_export' ) );
605
+
606
+ unset( $import_data );
607
+
608
+ wp_defer_term_counting( true );
609
+ wp_defer_comment_counting( true );
610
+
611
+ return $position;
612
+ }
613
+
614
+ /**
615
+ * Performs post-import cleanup of files and the cache
616
+ */
617
+ public function import_end() {
618
+
619
+ //wp_cache_flush(); Stops output in some hosting environments
620
+ foreach ( get_taxonomies() as $tax ) {
621
+ delete_option( "{$tax}_children" );
622
+ _get_term_hierarchy( $tax );
623
+ }
624
+
625
+ wp_defer_term_counting( false );
626
+ wp_defer_comment_counting( false );
627
+
628
+ do_action( 'import_end' );
629
+ }
630
+
631
+ /**
632
+ * Handles the CSV upload and initial parsing of the file to prepare for
633
+ * displaying author import options
634
+ *
635
+ * @return bool False if error uploading or invalid file, true otherwise
636
+ */
637
+ public function handle_upload() {
638
+ if($this->handle_ftp()){
639
+ return true;
640
+ }
641
+ if ( empty( $_POST['file_url'] ) ) {
642
+
643
+ $file = wp_import_handle_upload();
644
+
645
+ if ( isset( $file['error'] ) ) {
646
+ echo '<p><strong>' . __( 'Sorry, there has been an error.', 'wf_csv_import_export' ) . '</strong><br />';
647
+ echo esc_html( $file['error'] ) . '</p>';
648
+ return false;
649
+ }
650
+
651
+ $this->id = (int) $file['id'];
652
+ return true;
653
+
654
+ } else {
655
+
656
+ if ( file_exists( ABSPATH . $_POST['file_url'] ) ) {
657
+
658
+ $this->file_url = esc_attr( $_POST['file_url'] );
659
+ return true;
660
+
661
+ } else {
662
+
663
+ echo '<p><strong>' . __( 'Sorry, there has been an error.', 'wf_csv_import_export' ) . '</strong></p>';
664
+ return false;
665
+
666
+ }
667
+
668
+ }
669
+
670
+ return false;
671
+ }
672
+
673
+ public function product_exists( $title, $sku = '', $post_name = '' ) {
674
+ global $wpdb;
675
+
676
+ // Post Title Check
677
+ $post_title = stripslashes( sanitize_post_field( 'post_title', $title, 0, 'db' ) );
678
+
679
+ $query = "SELECT ID FROM $wpdb->posts WHERE post_type = 'product' AND post_status IN ( 'publish', 'private', 'draft', 'pending', 'future' )";
680
+ $args = array();
681
+
682
+ /*
683
+ * removed title check
684
+ if ( ! empty ( $title ) ) {
685
+ $query .= ' AND post_title = %s';
686
+ $args[] = $post_title;
687
+ }
688
+
689
+
690
+ if ( ! empty ( $post_name ) ) {
691
+ $query .= ' AND post_name = %s';
692
+ $args[] = $post_name;
693
+ }
694
+
695
+ */
696
+
697
+ if ( ! empty ( $args ) ) {
698
+ $posts_that_exist = $wpdb->get_col( $wpdb->prepare( $query, $args ) );
699
+
700
+ if ( $posts_that_exist ) {
701
+
702
+ foreach( $posts_that_exist as $post_exists ) {
703
+
704
+ // Check unique SKU
705
+ $post_exists_sku = get_post_meta( $post_exists, '_sku', true );
706
+
707
+ if ( $sku == $post_exists_sku ) {
708
+ return true;
709
+ }
710
+
711
+ }
712
+
713
+ }
714
+ }
715
+
716
+ // Sku Check
717
+ if ( $sku ) {
718
+
719
+ $post_exists_sku = $wpdb->get_var( $wpdb->prepare( "
720
+ SELECT $wpdb->posts.ID
721
+ FROM $wpdb->posts
722
+ LEFT JOIN $wpdb->postmeta ON ( $wpdb->posts.ID = $wpdb->postmeta.post_id )
723
+ WHERE $wpdb->posts.post_status IN ( 'publish', 'private', 'draft', 'pending', 'future' )
724
+ AND $wpdb->postmeta.meta_key = '_sku' AND $wpdb->postmeta.meta_value = '%s'
725
+ ", $sku ) );
726
+
727
+ if ( $post_exists_sku ) {
728
+ return true;
729
+ }
730
+ }
731
+
732
+ return false;
733
+ }
734
+
735
+ /**
736
+ * Create new posts based on import information
737
+ */
738
+ public function process_product( $post ) {
739
+
740
+ $processing_product_id = absint( $post['post_id'] );
741
+ $processing_product = get_post( $processing_product_id );
742
+ $processing_product_title = $processing_product ? $processing_product->post_title : '';
743
+ $processing_product_sku = $processing_product ? $processing_product->sku : '';
744
+ $merging = ! empty( $post['merging'] );
745
+
746
+ if ( ! empty( $post['post_title'] ) ) {
747
+ $processing_product_title = $post['post_title'];
748
+ }
749
+
750
+ if ( ! empty( $post['sku'] ) ) {
751
+ $processing_product_sku = $post['sku'];
752
+ }
753
+
754
+ if ( ! empty( $processing_product_id ) && isset( $this->processed_posts[ $processing_product_id ] ) ) {
755
+ $this->add_import_result( 'skipped', __( 'Product already processed', 'wf_csv_import_export' ), $processing_product_id, $processing_product_title, $processing_product_sku );
756
+ $this->hf_log_data_change( 'csv-import', __('> Post ID already processed. Skipping.', 'wf_csv_import_export'), true );
757
+ unset( $post );
758
+ return;
759
+ }
760
+
761
+ if ( ! empty ( $post['post_status'] ) && $post['post_status'] == 'auto-draft' ) {
762
+ $this->add_import_result( 'skipped', __( 'Skipping auto-draft', 'wf_csv_import_export' ), $processing_product_id, $processing_product_title, $processing_product_sku );
763
+ $this->hf_log_data_change( 'csv-import', __('> Skipping auto-draft.', 'wf_csv_import_export'), true );
764
+ unset( $post );
765
+ return;
766
+ }
767
+ // Check if post exists when importing
768
+ if ( ! $merging ) {
769
+ if ( $this->product_exists( $processing_product_title, $processing_product_sku, $post['post_name'] ) ) {
770
+ if(!$processing_product_id && empty($processing_product_sku)) {
771
+ // if no sku , no id and no merge + is product in db with same title -> just give message
772
+ $usr_msg = 'Product with same title already exist.';
773
+ }else{
774
+ $usr_msg = 'Product already exists.';
775
+ }
776
+ $this->add_import_result( 'skipped', __( $usr_msg, 'wf_csv_import_export' ), $processing_product_id, $processing_product_title, $processing_product_sku );
777
+ $this->hf_log_data_change( 'csv-import', sprintf( __('> &#8220;%s&#8221;'.$usr_msg, 'wf_csv_import_export'), esc_html($processing_product_title) ), true );
778
+ unset( $post );
779
+ return;
780
+ }
781
+
782
+ if ( $processing_product_id && is_string( get_post_status( $processing_product_id ) ) ) {
783
+ $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 ), '' );
784
+ $this->hf_log_data_change( 'csv-import', sprintf( __('> &#8220;%s&#8221; ID already exists.', 'wf_csv_import_export'), esc_html( $processing_product_id ) ), true );
785
+ unset( $post );
786
+ return;
787
+ }
788
+ }
789
+ // Check post type to avoid conflicts with IDs
790
+ $is_post_exist_in_db = get_post_type( $processing_product_id );
791
+ if ( $merging && $processing_product_id && !empty($is_post_exist_in_db) && (get_post_type( $processing_product_id ) !== $post['post_type'] )) {
792
+ $this->add_import_result( 'skipped', __( 'Post is not a product', 'wf_csv_import_export' ), $processing_product_id, $processing_product_title, $processing_product_sku );
793
+ $this->hf_log_data_change( 'csv-import', sprintf( __('> &#8220;%s&#8221; is not a product.', 'wf_csv_import_export'), esc_html($processing_product_id) ), true );
794
+ unset( $post );
795
+ return;
796
+ }
797
+
798
+ if ( $merging && !empty($is_post_exist_in_db) ) {
799
+
800
+ // Only merge fields which are set
801
+ $post_id = $processing_product_id;
802
+
803
+ $this->hf_log_data_change( 'csv-import', sprintf( __('> Merging post ID %s.', 'wf_csv_import_export'), $post_id ), true );
804
+
805
+ $postdata = array(
806
+ 'ID' => $post_id
807
+ );
808
+
809
+ if ( $this->merge_empty_cells ) {
810
+ if ( isset( $post['post_content'] ) ) {
811
+ $postdata['post_content'] = $post['post_content'];
812
+ }
813
+ if ( isset( $post['post_excerpt'] ) ) {
814
+ $postdata['post_excerpt'] = $post['post_excerpt'];
815
+ }
816
+ if ( isset( $post['post_password'] ) ) {
817
+ $postdata['post_password'] = $post['post_password'];
818
+ }
819
+ if ( isset( $post['post_parent'] ) ) {
820
+ $postdata['post_parent'] = $post['post_parent'];
821
+ }
822
+ } else {
823
+ if ( ! empty( $post['post_content'] ) ) {
824
+ $postdata['post_content'] = $post['post_content'];
825
+ }
826
+ if ( ! empty( $post['post_excerpt'] ) ) {
827
+ $postdata['post_excerpt'] = $post['post_excerpt'];
828
+ }
829
+ if ( ! empty( $post['post_password'] ) ) {
830
+ $postdata['post_password'] = $post['post_password'];
831
+ }
832
+ if ( isset( $post['post_parent'] ) && $post['post_parent'] !== '' ) {
833
+ $postdata['post_parent'] = $post['post_parent'];
834
+ }
835
+ }
836
+
837
+ if ( ! empty( $post['post_title'] ) ) {
838
+ $postdata['post_title'] = $post['post_title'];
839
+ }
840
+
841
+ if ( ! empty( $post['post_author'] ) ) {
842
+ $postdata['post_author'] = absint( $post['post_author'] );
843
+ }
844
+ if ( ! empty( $post['post_date'] ) ) {
845
+ $postdata['post_date'] = date("Y-m-d H:i:s", strtotime( $post['post_date'] ) );
846
+ }
847
+ if ( ! empty( $post['post_date_gmt'] ) ) {
848
+ $postdata['post_date_gmt'] = date("Y-m-d H:i:s", strtotime( $post['post_date_gmt'] ) );
849
+ }
850
+ if ( ! empty( $post['post_name'] ) ) {
851
+ $postdata['post_name'] = $post['post_name'];
852
+ }
853
+ if ( ! empty( $post['post_status'] ) ) {
854
+ $postdata['post_status'] = $post['post_status'];
855
+ }
856
+ if ( ! empty( $post['menu_order'] ) ) {
857
+ $postdata['menu_order'] = $post['menu_order'];
858
+ }
859
+ if ( ! empty( $post['comment_status'] ) ) {
860
+ $postdata['comment_status'] = $post['comment_status'];
861
+ }
862
+ if ( sizeof( $postdata ) > 1 ) {
863
+ $result = wp_update_post( $postdata );
864
+
865
+ if ( ! $result ) {
866
+ $this->add_import_result( 'failed', __( 'Failed to update product', 'wf_csv_import_export' ), $post_id, $processing_product_title, $processing_product_sku );
867
+ $this->hf_log_data_change( 'csv-import', sprintf( __('> Failed to update product %s', 'wf_csv_import_export'), $post_id ), true );
868
+ unset( $post );
869
+ return;
870
+ } else {
871
+ $this->hf_log_data_change( 'csv-import', __( '> Merged post data: ', 'wf_csv_import_export' ) . print_r( $postdata, true ) );
872
+ }
873
+ }
874
+
875
+ } else {
876
+ $merging = FALSE;
877
+ // Get parent
878
+ $post_parent = $post['post_parent'];
879
+
880
+ if ( $post_parent !== "" ) {
881
+ $post_parent = absint( $post_parent );
882
+
883
+ if ( $post_parent > 0 ) {
884
+ // if we already know the parent, map it to the new local ID
885
+ if ( isset( $this->processed_posts[ $post_parent ] ) ) {
886
+ $post_parent = $this->processed_posts[ $post_parent ];
887
+
888
+ // otherwise record the parent for later
889
+ } else {
890
+
891
+ $this->post_orphans[ intval( $processing_product_id ) ] = $post_parent;
892
+ //$post_parent = 0;
893
+
894
+ }
895
+
896
+ }
897
+ }
898
+
899
+ // Insert product
900
+ $this->hf_log_data_change( 'csv-import', sprintf( __('> Inserting %s', 'wf_csv_import_export'), esc_html( $processing_product_title ) ), true );
901
+
902
+ $postdata = array(
903
+ 'import_id' => $processing_product_id,
904
+ 'post_author' => $post['post_author'] ? absint( $post['post_author'] ) : get_current_user_id(),
905
+ 'post_date' => ( $post['post_date'] ) ? date( 'Y-m-d H:i:s', strtotime( $post['post_date'] )) : '',
906
+ 'post_date_gmt' => ( $post['post_date_gmt'] ) ? date( 'Y-m-d H:i:s', strtotime( $post['post_date_gmt'] )) : '',
907
+ 'post_content' => $post['post_content'],
908
+ 'post_excerpt' => $post['post_excerpt'],
909
+ 'post_title' => $processing_product_title,
910
+ 'post_name' => ( $post['post_name'] ) ? $post['post_name'] : sanitize_title( $processing_product_title ),
911
+ 'post_status' => ( $post['post_status'] ) ? $post['post_status'] : 'publish',
912
+ 'post_parent' => $post_parent,
913
+ 'menu_order' => $post['menu_order'],
914
+ 'post_type' => $post['post_type'],
915
+ 'post_password' => $post['post_password'],
916
+ 'comment_status' => $post['comment_status'],
917
+ );
918
+ $post_id = wp_insert_post( $postdata, true );
919
+
920
+ if ( is_wp_error( $post_id ) ) {
921
+
922
+ $this->add_import_result( 'failed', __( 'Failed to import product', 'wf_csv_import_export' ), $processing_product_id, $processing_product_title, $processing_product_sku );
923
+ $this->hf_log_data_change( 'csv-import', sprintf( __( 'Failed to import product &#8220;%s&#8221;', 'wf_csv_import_export' ), esc_html($processing_product_title) ) );
924
+ unset( $post );
925
+ return;
926
+
927
+ } else {
928
+
929
+ $this->hf_log_data_change( 'csv-import', sprintf( __('> Inserted - post ID is %s.', 'wf_csv_import_export'), $post_id ) );
930
+
931
+ }
932
+ }
933
+
934
+ unset( $postdata );
935
+
936
+ // map pre-import ID to local ID
937
+ if ( empty( $processing_product_id ) ) {
938
+ $processing_product_id = (int) $post_id;
939
+ }
940
+
941
+ $this->processed_posts[ intval( $processing_product_id ) ] = (int) $post_id;
942
+
943
+ // add categories, tags and other terms
944
+ if ( ! empty( $post['terms'] ) && is_array( $post['terms'] ) ) {
945
+
946
+ $terms_to_set = array();
947
+
948
+ foreach ( $post['terms'] as $term_group ) {
949
+
950
+ $taxonomy = $term_group['taxonomy'];
951
+ $terms = $term_group['terms'];
952
+
953
+ if ( ! $taxonomy || ! taxonomy_exists( $taxonomy ) ) {
954
+ continue;
955
+ }
956
+
957
+ if ( ! is_array( $terms ) ) {
958
+ $terms = array( $terms );
959
+ }
960
+
961
+ $terms_to_set[ $taxonomy ] = array();
962
+
963
+ foreach ( $terms as $term_id ) {
964
+
965
+ if ( ! $term_id ) continue;
966
+
967
+ $terms_to_set[ $taxonomy ][] = intval( $term_id );
968
+ }
969
+
970
+ }
971
+
972
+ foreach ( $terms_to_set as $tax => $ids ) {
973
+ $tt_ids = wp_set_post_terms( $post_id, $ids, $tax, false );
974
+ }
975
+
976
+ unset( $post['terms'], $terms_to_set );
977
+ }
978
+
979
+ // add/update post meta
980
+ if ( ! empty( $post['postmeta'] ) && is_array( $post['postmeta'] ) ) {
981
+ foreach ( $post['postmeta'] as $meta ) {
982
+ $key = apply_filters( 'import_post_meta_key', $meta['key'] );
983
+
984
+ if ( $key ) {
985
+ update_post_meta( $post_id, $key, maybe_unserialize( $meta['value'] ) );
986
+ }
987
+
988
+ if ( $key == '_file_paths' ) {
989
+ do_action( 'woocommerce_process_product_file_download_paths', $post_id, 0, maybe_unserialize( $meta['value'] ) );
990
+ }
991
+
992
+ }
993
+
994
+ unset( $post['postmeta'] );
995
+ }
996
+
997
+ // Import images and add to post
998
+ if ( ! empty( $post['images'] ) && is_array($post['images']) ) {
999
+
1000
+ $featured = true;
1001
+ $gallery_ids = array();
1002
+
1003
+ if ($merging) {
1004
+
1005
+ // Get basenames
1006
+ $image_basenames = array();
1007
+
1008
+ foreach( $post['images'] as $image )
1009
+ $image_basenames[] = basename( $image );
1010
+
1011
+ // Loop attachments already attached to the product
1012
+ $attachments = get_posts( 'post_parent=' . $post_id . '&post_type=attachment&fields=ids&post_mime_type=image&numberposts=-1' );
1013
+
1014
+ foreach ( $attachments as $attachment_key => $attachment ) {
1015
+
1016
+ $attachment_url = wp_get_attachment_url( $attachment );
1017
+ $attachment_basename = basename( $attachment_url );
1018
+
1019
+ // Don't import existing images
1020
+ if ( in_array( $attachment_url, $post['images'] ) || in_array( $attachment_basename, $image_basenames ) ) {
1021
+
1022
+ foreach( $post['images'] as $key => $image ) {
1023
+
1024
+ if ( $image == $attachment_url || basename( $image ) == $attachment_basename ) {
1025
+ unset( $post['images'][ $key ] );
1026
+
1027
+ $this->hf_log_data_change( 'csv-import', sprintf( __( '> > Image exists - skipping %s', 'wf_csv_import_export' ), basename( $image ) ) );
1028
+
1029
+ if ( $key == 0 ) {
1030
+ update_post_meta( $post_id, '_thumbnail_id', $attachment );
1031
+ $featured = false;
1032
+ } else {
1033
+ $gallery_ids[ $key ] = $attachment;
1034
+ }
1035
+ }
1036
+
1037
+ }
1038
+
1039
+ } else {
1040
+
1041
+ // Detach image which is not being merged
1042
+ $attachment_post = array();
1043
+ $attachment_post['ID'] = $attachment;
1044
+ $attachment_post['post_parent'] = '';
1045
+ wp_update_post( $attachment_post );
1046
+ unset( $attachment_post );
1047
+
1048
+ }
1049
+
1050
+ }
1051
+
1052
+ unset( $attachments );
1053
+ }
1054
+
1055
+ if ( $post['images'] ) foreach ( $post['images'] as $image_key => $image ) {
1056
+
1057
+ $this->hf_log_data_change( 'csv-import', sprintf( __( '> > Importing image "%s"', 'wf_csv_import_export' ), $image ) );
1058
+
1059
+ $filename = basename( $image );
1060
+
1061
+ $attachment = array(
1062
+ 'post_title' => preg_replace( '/\.[^.]+$/', '', $processing_product_title . ' ' . ( $image_key + 1 ) ),
1063
+ 'post_content' => '',
1064
+ 'post_status' => 'inherit',
1065
+ 'post_parent' => $post_id
1066
+ );
1067
+
1068
+ $attachment_id = $this->process_attachment( $attachment, $image, $post_id );
1069
+
1070
+ if ( ! is_wp_error( $attachment_id ) && $attachment_id ) {
1071
+
1072
+ $this->hf_log_data_change( 'csv-import', sprintf( __( '> > Imported image "%s"', 'wf_csv_import_export' ), $image ) );
1073
+
1074
+ // Set alt
1075
+ update_post_meta( $attachment_id, '_wp_attachment_image_alt', $processing_product_title );
1076
+
1077
+ if ( $featured ) {
1078
+ update_post_meta( $post_id, '_thumbnail_id', $attachment_id );
1079
+ } else {
1080
+ $gallery_ids[ $image_key ] = $attachment_id;
1081
+ }
1082
+
1083
+ update_post_meta( $attachment_id, '_woocommerce_exclude_image', 0 );
1084
+
1085
+ $featured = false;
1086
+ } else {
1087
+ $this->hf_log_data_change( 'csv-import', sprintf( __( '> > Error importing image "%s"', 'wf_csv_import_export' ), $image ) );
1088
+ $this->hf_log_data_change( 'csv-import', '> > ' . $attachment_id->get_error_message() );
1089
+ }
1090
+
1091
+ unset( $attachment, $attachment_id );
1092
+ }
1093
+
1094
+ $this->hf_log_data_change( 'csv-import', __( '> > Images set', 'wf_csv_import_export' ) );
1095
+
1096
+ ksort( $gallery_ids );
1097
+
1098
+ update_post_meta( $post_id, '_product_image_gallery', implode( ',', $gallery_ids ) );
1099
+
1100
+ unset( $post['images'], $featured, $gallery_ids );
1101
+ }
1102
+
1103
+ // Import attributes
1104
+ if ( ! empty( $post['attributes'] ) && is_array($post['attributes']) ) {
1105
+
1106
+ if ($merging) {
1107
+ $attributes = array_filter( (array) maybe_unserialize( get_post_meta( $post_id, '_product_attributes', true ) ) );
1108
+ $attributes = array_merge( $attributes, $post['attributes'] );
1109
+ } else {
1110
+ $attributes = $post['attributes'];
1111
+ }
1112
+
1113
+ // Sort attribute positions
1114
+ if ( ! function_exists( 'attributes_cmp' ) ) {
1115
+ function attributes_cmp( $a, $b ) {
1116
+ if ( $a['position'] == $b['position'] ) return 0;
1117
+ return ( $a['position'] < $b['position'] ) ? -1 : 1;
1118
+ }
1119
+ }
1120
+ uasort( $attributes, 'attributes_cmp' );
1121
+
1122
+ update_post_meta( $post_id, '_product_attributes', $attributes );
1123
+
1124
+ unset( $post['attributes'], $attributes );
1125
+ }
1126
+
1127
+ // Import GPF
1128
+ if ( ! empty( $post['gpf_data'] ) && is_array( $post['gpf_data'] ) ) {
1129
+
1130
+ update_post_meta( $post_id, '_woocommerce_gpf_data', $post['gpf_data'] );
1131
+
1132
+ unset( $post['gpf_data'] );
1133
+ }
1134
+
1135
+ if ( ! empty( $post['upsell_skus'] ) && is_array( $post['upsell_skus'] ) ) {
1136
+ $this->upsell_skus[ $post_id ] = $post['upsell_skus'];
1137
+ }
1138
+
1139
+ if ( ! empty( $post['crosssell_skus'] ) && is_array( $post['crosssell_skus'] ) ) {
1140
+ $this->crosssell_skus[ $post_id ] = $post['crosssell_skus'];
1141
+ }
1142
+
1143
+ add_post_meta( $post_id, 'total_sales', 0 );
1144
+
1145
+ if ( $merging ) {
1146
+ $this->add_import_result( 'merged', 'Merge successful', $post_id, $processing_product_title, $processing_product_sku );
1147
+ $this->hf_log_data_change( 'csv-import', sprintf( __('> Finished merging post ID %s.', 'wf_csv_import_export'), $post_id ) );
1148
+ } else {
1149
+ $this->add_import_result( 'imported', 'Import successful', $post_id, $processing_product_title, $processing_product_sku );
1150
+ $this->hf_log_data_change( 'csv-import', sprintf( __('> Finished importing post ID %s.', 'wf_csv_import_export'), $post_id ) );
1151
+ }
1152
+
1153
+ unset( $post );
1154
+ }
1155
+
1156
+ /**
1157
+ * Log a row's import status
1158
+ */
1159
+ protected function add_import_result( $status, $reason, $post_id = '', $post_title = '', $sku = '' ) {
1160
+ $this->import_results[] = array(
1161
+ 'post_title' => $post_title,
1162
+ 'post_id' => $post_id,
1163
+ 'sku' => $sku,
1164
+ 'status' => $status,
1165
+ 'reason' => $reason
1166
+ );
1167
+ }
1168
+
1169
+ /**
1170
+ * If fetching attachments is enabled then attempt to create a new attachment
1171
+ *
1172
+ * @param array $post Attachment post details from WXR
1173
+ * @param string $url URL to fetch attachment from
1174
+ * @return int|WP_Error Post ID on success, WP_Error otherwise
1175
+ */
1176
+ public function process_attachment( $post, $url, $post_id ) {
1177
+
1178
+ $attachment_id = '';
1179
+ $attachment_url = '';
1180
+ $attachment_file = '';
1181
+ $upload_dir = wp_upload_dir();
1182
+
1183
+ // If same server, make it a path and move to upload directory
1184
+ /*if ( strstr( $url, $upload_dir['baseurl'] ) ) {
1185
+
1186
+ $url = str_replace( $upload_dir['baseurl'], $upload_dir['basedir'], $url );
1187
+
1188
+ } else*/
1189
+ if ( strstr( $url, site_url() ) ) {
1190
+ $abs_url = str_replace( trailingslashit( site_url() ), trailingslashit( ABSPATH ), urldecode($url) );
1191
+ $new_name = wp_unique_filename( $upload_dir['path'], basename( urldecode($url) ) );
1192
+ $new_url = trailingslashit( $upload_dir['path'] ) . $new_name;
1193
+
1194
+ if ( copy( $abs_url, $new_url ) ) {
1195
+ $url = basename( $new_url );
1196
+ }
1197
+ }
1198
+
1199
+ if ( ! strstr( $url, 'http' ) ) {
1200
+
1201
+ // Local file
1202
+ $attachment_file = trailingslashit( $upload_dir['basedir'] ) . 'product_images/' . $url;
1203
+
1204
+ // We have the path, check it exists
1205
+ if ( ! file_exists( $attachment_file ) )
1206
+ $attachment_file = trailingslashit( $upload_dir['path'] ) . $url;
1207
+
1208
+ // We have the path, check it exists
1209
+ if ( file_exists( $attachment_file ) ) {
1210
+
1211
+ $attachment_url = str_replace( trailingslashit( ABSPATH ), trailingslashit( site_url() ), $attachment_file );
1212
+
1213
+ if ( $info = wp_check_filetype( $attachment_file ) )
1214
+ $post['post_mime_type'] = $info['type'];
1215
+ else
1216
+ return new WP_Error( 'attachment_processing_error', __('Invalid file type', 'wordpress-importer') );
1217
+
1218
+ $post['guid'] = $attachment_url;
1219
+
1220
+ $attachment_id = wp_insert_attachment( $post, $attachment_file, $post_id );
1221
+
1222
+ } else {
1223
+ return new WP_Error( 'attachment_processing_error', __('Local image did not exist!', 'wordpress-importer') );
1224
+ }
1225
+
1226
+ } else {
1227
+
1228
+ // if the URL is absolute, but does not contain address, then upload it assuming base_site_url
1229
+ if ( preg_match( '|^/[\w\W]+$|', $url ) )
1230
+ $url = rtrim( site_url(), '/' ) . $url;
1231
+
1232
+ $upload = $this->fetch_remote_file( $url, $post );
1233
+
1234
+ if ( is_wp_error( $upload ) )
1235
+ return $upload;
1236
+
1237
+ if ( $info = wp_check_filetype( $upload['file'] ) )
1238
+ $post['post_mime_type'] = $info['type'];
1239
+ else
1240
+ return new WP_Error( 'attachment_processing_error', __('Invalid file type', 'wordpress-importer') );
1241
+
1242
+ $post['guid'] = $upload['url'];
1243
+ $attachment_file = $upload['file'];
1244
+ $attachment_url = $upload['url'];
1245
+
1246
+ // as per wp-admin/includes/upload.php
1247
+ $attachment_id = wp_insert_attachment( $post, $upload['file'], $post_id );
1248
+
1249
+ unset( $upload );
1250
+ }
1251
+
1252
+ if ( ! is_wp_error( $attachment_id ) && $attachment_id > 0 ) {
1253
+ $this->hf_log_data_change( 'csv-import', sprintf( __( '> > Inserted image attachment "%s"', 'wf_csv_import_export' ), $url ) );
1254
+
1255
+ $this->attachments[] = $attachment_id;
1256
+ }
1257
+
1258
+ return $attachment_id;
1259
+ }
1260
+
1261
+ /**
1262
+ * Attempt to download a remote file attachment
1263
+ */
1264
+ public function fetch_remote_file( $url, $post ) {
1265
+
1266
+ // extract the file name and extension from the url
1267
+ $file_name = basename( current( explode( '?', $url ) ) );
1268
+ $wp_filetype = wp_check_filetype( $file_name, null );
1269
+ $parsed_url = @parse_url( $url );
1270
+
1271
+ // Check parsed URL
1272
+ if ( ! $parsed_url || ! is_array( $parsed_url ) )
1273
+ return new WP_Error( 'import_file_error', 'Invalid URL' );
1274
+
1275
+ // Ensure url is valid
1276
+ $url = str_replace( " ", '%20', $url );
1277
+
1278
+ // Get the file
1279
+ $response = wp_remote_get( $url, array(
1280
+ 'timeout' => 10
1281
+ ) );
1282
+
1283
+ if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) !== 200 )
1284
+ return new WP_Error( 'import_file_error', 'Error getting remote image' );
1285
+
1286
+ // Ensure we have a file name and type
1287
+ if ( ! $wp_filetype['type'] ) {
1288
+
1289
+ $headers = wp_remote_retrieve_headers( $response );
1290
+
1291
+ if ( isset( $headers['content-disposition'] ) && strstr( $headers['content-disposition'], 'filename=' ) ) {
1292
+
1293
+ $disposition = end( explode( 'filename=', $headers['content-disposition'] ) );
1294
+ $disposition = sanitize_file_name( $disposition );
1295
+ $file_name = $disposition;
1296
+
1297
+ } elseif ( isset( $headers['content-type'] ) && strstr( $headers['content-type'], 'image/' ) ) {
1298
+
1299
+ $file_name = 'image.' . str_replace( 'image/', '', $headers['content-type'] );
1300
+
1301
+ }
1302
+
1303
+ unset( $headers );
1304
+ }
1305
+
1306
+ // Upload the file
1307
+ $upload = wp_upload_bits( $file_name, '', wp_remote_retrieve_body( $response ) );
1308
+
1309
+ if ( $upload['error'] )
1310
+ return new WP_Error( 'upload_dir_error', $upload['error'] );
1311
+
1312
+ // Get filesize
1313
+ $filesize = filesize( $upload['file'] );
1314
+
1315
+ if ( 0 == $filesize ) {
1316
+ @unlink( $upload['file'] );
1317
+ unset( $upload );
1318
+ return new WP_Error( 'import_file_error', __('Zero size file downloaded', 'wf_csv_import_export') );
1319
+ }
1320
+
1321
+ unset( $response );
1322
+
1323
+ return $upload;
1324
+ }
1325
+
1326
+ /**
1327
+ * Decide what the maximum file size for downloaded attachments is.
1328
+ * Default is 0 (unlimited), can be filtered via import_attachment_size_limit
1329
+ *
1330
+ * @return int Maximum attachment file size to import
1331
+ */
1332
+ public function max_attachment_size() {
1333
+ return apply_filters( 'import_attachment_size_limit', 0 );
1334
+ }
1335
+
1336
+ /**
1337
+ * Attempt to associate posts and menu items with previously missing parents
1338
+ */
1339
+ public function backfill_parents() {
1340
+ global $wpdb;
1341
+
1342
+ // find parents for post orphans
1343
+ if ( ! empty( $this->post_orphans ) && is_array( $this->post_orphans ) )
1344
+ foreach ( $this->post_orphans as $child_id => $parent_id ) {
1345
+ $local_child_id = $local_parent_id = false;
1346
+ if ( isset( $this->processed_posts[$child_id] ) )
1347
+ $local_child_id = $this->processed_posts[$child_id];
1348
+ if ( isset( $this->processed_posts[$parent_id] ) )
1349
+ $local_parent_id = $this->processed_posts[$parent_id];
1350
+
1351
+ if ( $local_child_id && $local_parent_id )
1352
+ $wpdb->update( $wpdb->posts, array( 'post_parent' => $local_parent_id ), array( 'ID' => $local_child_id ), '%d', '%d' );
1353
+ }
1354
+ }
1355
+
1356
+ /**
1357
+ * Attempt to associate posts and menu items with previously missing parents
1358
+ */
1359
+ public function link_product_skus( $type, $product_id, $skus ) {
1360
+ global $wpdb;
1361
+
1362
+ $ids = array();
1363
+
1364
+ foreach ( $skus as $sku ) {
1365
+ $ids[] = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_sku' AND meta_value = %s;", $sku ) );
1366
+ }
1367
+
1368
+ $ids = array_filter( $ids );
1369
+
1370
+ update_post_meta( $product_id, "_{$type}_ids", $ids );
1371
+ }
1372
+
1373
+ private function handle_ftp(){
1374
+ $enable_ftp_ie = !empty( $_POST['enable_ftp_ie'] ) ? true : false;
1375
+ if($enable_ftp_ie == false) return false;
1376
+
1377
+ $ftp_server = ! empty( $_POST['ftp_server'] ) ? $_POST['ftp_server'] : '';
1378
+ $ftp_server_path = ! empty( $_POST['ftp_server_path'] ) ? $_POST['ftp_server_path'] : '';
1379
+ $ftp_user = ! empty( $_POST['ftp_user'] ) ? $_POST['ftp_user'] : '';
1380
+ $ftp_password = ! empty( $_POST['ftp_password'] ) ? $_POST['ftp_password'] : '';
1381
+ $use_ftps = ! empty( $_POST['use_ftps'] ) ? true : false;
1382
+
1383
+
1384
+ $settings = array();
1385
+ $settings[ 'ftp_server' ] = $ftp_server;
1386
+ $settings[ 'ftp_user' ] = $ftp_user;
1387
+ $settings[ 'ftp_password' ] = $ftp_password;
1388
+ $settings[ 'use_ftps' ] = $use_ftps;
1389
+ $settings[ 'enable_ftp_ie' ] = $enable_ftp_ie;
1390
+ $settings[ 'ftp_server_path' ] = $ftp_server_path;
1391
+
1392
+
1393
+ $local_file = 'wp-content/plugins/product-csv-import-export-for-woocommerce/temp-import.csv';
1394
+ $server_file = $ftp_server_path;
1395
+
1396
+ update_option( 'wf_shipment_tracking_importer_ftp', $settings );
1397
+
1398
+ $ftp_conn = $use_ftps ? ftp_ssl_connect($ftp_server) : ftp_connect($ftp_server);
1399
+ $error_message = "";
1400
+ $success = false;
1401
+ if($ftp_conn == false){
1402
+ $error_message = "There is connection problem\n";
1403
+ }
1404
+
1405
+ if(empty($error_message)){
1406
+ if(ftp_login($ftp_conn, $ftp_user, $ftp_password) == false){
1407
+ $error_message = "Not able to login \n";
1408
+ }
1409
+ }
1410
+ if(empty($error_message)){
1411
+
1412
+ if (ftp_get($ftp_conn, ABSPATH.$local_file, $server_file, FTP_BINARY)) {
1413
+ $error_message = "";
1414
+ $success = true;
1415
+ } else {
1416
+ $error_message = "There was a problem\n";
1417
+ }
1418
+ }
1419
+
1420
+ ftp_close($ftp_conn);
1421
+ if($success){
1422
+ $this->file_url = $local_file;
1423
+ }else{
1424
+ die($error_message);
1425
+ }
1426
+ return true;
1427
+ }
1428
+
1429
+ // Display import page title
1430
+ public function header() {
1431
+ echo '<div class="wrap"><div class="icon32" id="icon-woocommerce-importer"><br></div>';
1432
+ echo '<h2>' . ( empty( $_GET['merge'] ) ? __( 'Import', 'wf_csv_import_export' ) : __( 'Merge Products', 'wf_csv_import_export' ) ) . '</h2>';
1433
+ }
1434
+
1435
+ // Close div.wrap
1436
+ public function footer() {
1437
+ echo '</div>';
1438
+ }
1439
+
1440
+ /**
1441
+ * Display introductory text and file upload form
1442
+ */
1443
+ public function greet() {
1444
+ $action = 'admin.php?import=woocommerce_csv&amp;step=1&amp;merge=' . ( ! empty( $_GET['merge'] ) ? 1 : 0 );
1445
+ $bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() );
1446
+ $size = size_format( $bytes );
1447
+ $upload_dir = wp_upload_dir();
1448
+
1449
+ include( 'views/html-wf-import-greeting.php' );
1450
+ }
1451
+
1452
+ /**
1453
+ * Added to http_request_timeout filter to force timeout at 60 seconds during import
1454
+ * @return int 60
1455
+ */
1456
+ public function bump_request_timeout( $val ) {
1457
+ return 60;
1458
+ }
1459
+ /**
1460
+ * Get a list of all the product attributes for a post type.
1461
+ * These require a bit more digging into the values.
1462
+ */
1463
+ public static function get_all_product_attributes( $post_type = 'product' ) {
1464
+ global $wpdb;
1465
+
1466
+ $results = $wpdb->get_col( $wpdb->prepare(
1467
+ "SELECT DISTINCT pm.meta_value
1468
+ FROM {$wpdb->postmeta} AS pm
1469
+ LEFT JOIN {$wpdb->posts} AS p ON p.ID = pm.post_id
1470
+ WHERE p.post_type = %s
1471
+ AND p.post_status IN ( 'publish', 'pending', 'private', 'draft' )
1472
+ AND pm.meta_key = '_product_attributes'",
1473
+ $post_type
1474
+ ) );
1475
+
1476
+ // Go through each result, and look at the attribute keys within them.
1477
+ $result = array();
1478
+
1479
+ if ( ! empty( $results ) ) {
1480
+ foreach( $results as $_product_attributes ) {
1481
+ $attributes = maybe_unserialize( maybe_unserialize( $_product_attributes ) );
1482
+ if ( ! empty( $attributes ) && is_array( $attributes ) ) {
1483
+ foreach( $attributes as $key => $attribute ) {
1484
+ if ( ! $key ) {
1485
+ continue;
1486
+ }
1487
+ if ( ! strstr( $key, 'pa_' ) ) {
1488
+ if ( empty( $attribute['name'] ) ) {
1489
+ continue;
1490
+ }
1491
+ $key = $attribute['name'];
1492
+ }
1493
+
1494
+ $result[ $key ] = $key;
1495
+ }
1496
+ }
1497
+ }
1498
+ }
1499
+
1500
+ sort( $result );
1501
+
1502
+ return $result;
1503
+ }
1504
+ }
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,19 +1,19 @@
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>
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,23 +1,23 @@
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>
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>
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,177 +1,177 @@
1
- <?php
2
- /*
3
- Plugin Name: Product CSV Import Export (BASIC)
4
- Plugin URI: https://www.xadapter.com/product/product-import-export-plugin-for-woocommerce/
5
- Description: Import and Export Products From and To your WooCommerce Store.
6
- Author: XAdapter
7
- Author URI: https://www.xadapter.com/
8
- Version: 1.3.7
9
- Text Domain: wf_csv_import_export
10
- */
11
-
12
- if ( ! defined( 'ABSPATH' ) || ! is_admin() ) {
13
- return;
14
- }
15
-
16
- if( !defined('WF_PROD_IMP_EXP_ID') ){
17
- define( "WF_PROD_IMP_EXP_ID", "wf_prod_imp_exp" );
18
- }
19
- if( !defined('WF_WOOCOMMERCE_CSV_IM_EX') ){
20
- define( "WF_WOOCOMMERCE_CSV_IM_EX", "wf_woocommerce_csv_im_ex" );
21
- }
22
- /**
23
- * Check if WooCommerce is active
24
- */
25
- if (in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) )) {
26
-
27
- if ( ! class_exists( 'WF_Product_Import_Export_CSV' ) ) :
28
-
29
- /**
30
- * Main CSV Import class
31
- */
32
- class WF_Product_Import_Export_CSV {
33
-
34
- /**
35
- * Constructor
36
- */
37
- public function __construct() {
38
- if( !defined('WF_ProdImpExpCsv_FILE') ){
39
- define( 'WF_ProdImpExpCsv_FILE', __FILE__ );
40
- }
41
-
42
- add_filter( 'woocommerce_screen_ids', array( $this, 'woocommerce_screen_ids' ) );
43
- add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'wf_plugin_action_links' ) );
44
- add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
45
- add_action( 'init', array( $this, 'catch_export_request' ), 20 );
46
- add_action( 'admin_init', array( $this, 'register_importers' ) );
47
-
48
- include_once( 'includes/class-wf-prodimpexpcsv-system-status-tools.php' );
49
- include_once( 'includes/class-wf-prodimpexpcsv-admin-screen.php' );
50
- include_once( 'includes/importer/class-wf-prodimpexpcsv-importer.php' );
51
-
52
- if ( defined('DOING_AJAX') ) {
53
- include_once( 'includes/class-wf-prodimpexpcsv-ajax-handler.php' );
54
- }
55
- }
56
-
57
- public function wf_plugin_action_links( $links ) {
58
- $plugin_links = array(
59
- '<a href="' . admin_url( 'admin.php?page=wf_woocommerce_csv_im_ex' ) . '">' . __( 'Import Export', 'wf_csv_import_export' ) . '</a>',
60
- '<a href="https://www.xadapter.com/product/product-import-export-plugin-for-woocommerce/" target="_blank">' . __( 'Premium Upgrade', 'wf_csv_import_export' ) . '</a>',
61
- '<a href="https://www.xadapter.com/support/forum/product-import-export-plugin-for-woocommerce/">' . __( 'Support', 'wf_csv_import_export' ) . '</a>',
62
- );
63
- return array_merge( $plugin_links, $links );
64
- }
65
-
66
- /**
67
- * Add screen ID
68
- */
69
- public function woocommerce_screen_ids( $ids ) {
70
- $ids[] = 'admin'; // For import screen
71
- return $ids;
72
- }
73
-
74
- /**
75
- * Handle localisation
76
- */
77
- public function load_plugin_textdomain() {
78
- load_plugin_textdomain( 'wf_csv_import_export', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/' );
79
- }
80
-
81
- /**
82
- * Catches an export request and exports the data. This class is only loaded in admin.
83
- */
84
- public function catch_export_request() {
85
- if ( ! empty( $_GET['action'] ) && ! empty( $_GET['page'] ) && $_GET['page'] == 'wf_woocommerce_csv_im_ex' ) {
86
- switch ( $_GET['action'] ) {
87
- case "export" :
88
- $user_ok = $this->hf_user_permission();
89
- if ($user_ok) {
90
- include_once( 'includes/exporter/class-wf-prodimpexpcsv-exporter.php' );
91
- WF_ProdImpExpCsv_Exporter::do_export( 'product' );
92
- } else {
93
- wp_redirect(wp_login_url());
94
- }
95
- break;
96
- }
97
- }
98
- }
99
-
100
- public function catch_save_settings() {
101
- if ( ! empty( $_GET['action'] ) && ! empty( $_GET['page'] ) && $_GET['page'] == 'wf_woocommerce_csv_im_ex' ) {
102
- switch ( $_GET['action'] ) {
103
- case "settings" :
104
- include_once( 'includes/settings/class-wf-prodimpexpcsv-settings.php' );
105
- WF_ProdImpExpCsv_Settings::save_settings( );
106
- break;
107
- }
108
- }
109
- }
110
-
111
- /**
112
- * Register importers for use
113
- */
114
- public function register_importers() {
115
- 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' );
116
- }
117
- private function hf_user_permission() {
118
- // Check if user has rights to export
119
- $current_user = wp_get_current_user();
120
- $user_ok = false;
121
- $wf_roles = apply_filters('hf_user_permission_roles', array('administrator', 'shop_manager'));
122
- if ($current_user instanceof WP_User) {
123
- $can_users = array_intersect($wf_roles, $current_user->roles);
124
- if (!empty($can_users)) {
125
- $user_ok = true;
126
- }
127
- }
128
- return $user_ok;
129
- }
130
- }
131
- endif;
132
-
133
- new WF_Product_Import_Export_CSV();
134
-
135
- }
136
-
137
- // Welcome screen tutorial video
138
- add_action('admin_init', 'impexp_welcome');
139
- add_action('admin_menu', 'impexp_welcome_screen');
140
- add_action('admin_head', 'impexp_welcome_screen_remove_menus');
141
- register_activation_hook(__FILE__, 'hf_welcome_screen_activate_basic');
142
-
143
- function hf_welcome_screen_activate_basic() {
144
- if ( is_plugin_active('product-csv-import-export-for-woocommerce/product-csv-import-export.php') ){
145
- deactivate_plugins( basename( __FILE__ ) );
146
- wp_die(__("Is everything fine? You already have the Premium version installed in your website. For any issues, kindly raise a ticket via <a target='_blank' href='//support.xadapter.com/'>support.xadapter.com</a>","wf-shipping-fedex"), "", array('back_link' => 1 ));
147
- }
148
- set_transient('_welcome_screen_activation_redirect', true, 30);
149
- }
150
-
151
- if( !function_exists('impexp_welcome') ){
152
- function impexp_welcome() {
153
- if (!get_transient('_welcome_screen_activation_redirect')) {
154
- return;
155
- }
156
- delete_transient('_welcome_screen_activation_redirect');
157
- wp_safe_redirect(add_query_arg(array('page' => 'impexp-welcome'), admin_url('index.php')));
158
- }
159
- }
160
-
161
- if( !function_exists('impexp_welcome_screen') ){
162
- function impexp_welcome_screen() {
163
- add_dashboard_page('Welcome To Import Export', 'Welcome To Import Export', 'read', 'impexp-welcome', 'impexp_screen_content');
164
- }
165
- }
166
-
167
- if( !function_exists('impexp_screen_content') ){
168
- function impexp_screen_content() {
169
- include 'welcome/welcome.php';
170
- }
171
- }
172
-
173
- if( !function_exists('impexp_welcome_screen_remove_menus') ){
174
- function impexp_welcome_screen_remove_menus() {
175
- remove_submenu_page('index.php', 'impexp-welcome');
176
- }
177
- }
1
+ <?php
2
+ /*
3
+ Plugin Name: Product CSV Import Export (BASIC)
4
+ Plugin URI: https://www.xadapter.com/product/product-import-export-plugin-for-woocommerce/
5
+ Description: Import and Export Products From and To your WooCommerce Store.
6
+ Author: XAdapter
7
+ Author URI: https://www.xadapter.com/
8
+ Version: 1.3.8
9
+ Text Domain: wf_csv_import_export
10
+ */
11
+
12
+ if ( ! defined( 'ABSPATH' ) || ! is_admin() ) {
13
+ return;
14
+ }
15
+
16
+ if( !defined('WF_PROD_IMP_EXP_ID') ){
17
+ define( "WF_PROD_IMP_EXP_ID", "wf_prod_imp_exp" );
18
+ }
19
+ if( !defined('WF_WOOCOMMERCE_CSV_IM_EX') ){
20
+ define( "WF_WOOCOMMERCE_CSV_IM_EX", "wf_woocommerce_csv_im_ex" );
21
+ }
22
+ /**
23
+ * Check if WooCommerce is active
24
+ */
25
+ if (in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) )) {
26
+
27
+ if ( ! class_exists( 'WF_Product_Import_Export_CSV' ) ) :
28
+
29
+ /**
30
+ * Main CSV Import class
31
+ */
32
+ class WF_Product_Import_Export_CSV {
33
+
34
+ /**
35
+ * Constructor
36
+ */
37
+ public function __construct() {
38
+ if( !defined('WF_ProdImpExpCsv_FILE') ){
39
+ define( 'WF_ProdImpExpCsv_FILE', __FILE__ );
40
+ }
41
+
42
+ add_filter( 'woocommerce_screen_ids', array( $this, 'woocommerce_screen_ids' ) );
43
+ add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'wf_plugin_action_links' ) );
44
+ add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
45
+ add_action( 'init', array( $this, 'catch_export_request' ), 20 );
46
+ add_action( 'admin_init', array( $this, 'register_importers' ) );
47
+
48
+ include_once( 'includes/class-wf-prodimpexpcsv-system-status-tools.php' );
49
+ include_once( 'includes/class-wf-prodimpexpcsv-admin-screen.php' );
50
+ include_once( 'includes/importer/class-wf-prodimpexpcsv-importer.php' );
51
+
52
+ if ( defined('DOING_AJAX') ) {
53
+ include_once( 'includes/class-wf-prodimpexpcsv-ajax-handler.php' );
54
+ }
55
+ }
56
+
57
+ public function wf_plugin_action_links( $links ) {
58
+ $plugin_links = array(
59
+ '<a href="' . admin_url( 'admin.php?page=wf_woocommerce_csv_im_ex' ) . '">' . __( 'Import Export', 'wf_csv_import_export' ) . '</a>',
60
+ '<a href="https://www.xadapter.com/product/product-import-export-plugin-for-woocommerce/" target="_blank">' . __( 'Premium Upgrade', 'wf_csv_import_export' ) . '</a>',
61
+ '<a href="https://www.xadapter.com/support/forum/product-import-export-plugin-for-woocommerce/">' . __( 'Support', 'wf_csv_import_export' ) . '</a>',
62
+ );
63
+ return array_merge( $plugin_links, $links );
64
+ }
65
+
66
+ /**
67
+ * Add screen ID
68
+ */
69
+ public function woocommerce_screen_ids( $ids ) {
70
+ $ids[] = 'admin'; // For import screen
71
+ return $ids;
72
+ }
73
+
74
+ /**
75
+ * Handle localisation
76
+ */
77
+ public function load_plugin_textdomain() {
78
+ load_plugin_textdomain( 'wf_csv_import_export', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/' );
79
+ }
80
+
81
+ /**
82
+ * Catches an export request and exports the data. This class is only loaded in admin.
83
+ */
84
+ public function catch_export_request() {
85
+ if ( ! empty( $_GET['action'] ) && ! empty( $_GET['page'] ) && $_GET['page'] == 'wf_woocommerce_csv_im_ex' ) {
86
+ switch ( $_GET['action'] ) {
87
+ case "export" :
88
+ $user_ok = $this->hf_user_permission();
89
+ if ($user_ok) {
90
+ include_once( 'includes/exporter/class-wf-prodimpexpcsv-exporter.php' );
91
+ WF_ProdImpExpCsv_Exporter::do_export( 'product' );
92
+ } else {
93
+ wp_redirect(wp_login_url());
94
+ }
95
+ break;
96
+ }
97
+ }
98
+ }
99
+
100
+ public function catch_save_settings() {
101
+ if ( ! empty( $_GET['action'] ) && ! empty( $_GET['page'] ) && $_GET['page'] == 'wf_woocommerce_csv_im_ex' ) {
102
+ switch ( $_GET['action'] ) {
103
+ case "settings" :
104
+ include_once( 'includes/settings/class-wf-prodimpexpcsv-settings.php' );
105
+ WF_ProdImpExpCsv_Settings::save_settings( );
106
+ break;
107
+ }
108
+ }
109
+ }
110
+
111
+ /**
112
+ * Register importers for use
113
+ */
114
+ public function register_importers() {
115
+ 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' );
116
+ }
117
+ private function hf_user_permission() {
118
+ // Check if user has rights to export
119
+ $current_user = wp_get_current_user();
120
+ $user_ok = false;
121
+ $wf_roles = apply_filters('hf_user_permission_roles', array('administrator', 'shop_manager'));
122
+ if ($current_user instanceof WP_User) {
123
+ $can_users = array_intersect($wf_roles, $current_user->roles);
124
+ if (!empty($can_users)) {
125
+ $user_ok = true;
126
+ }
127
+ }
128
+ return $user_ok;
129
+ }
130
+ }
131
+ endif;
132
+
133
+ new WF_Product_Import_Export_CSV();
134
+
135
+ }
136
+
137
+ // Welcome screen tutorial video
138
+ add_action('admin_init', 'impexp_welcome');
139
+ add_action('admin_menu', 'impexp_welcome_screen');
140
+ add_action('admin_head', 'impexp_welcome_screen_remove_menus');
141
+ register_activation_hook(__FILE__, 'hf_welcome_screen_activate_basic');
142
+
143
+ function hf_welcome_screen_activate_basic() {
144
+ if ( is_plugin_active('product-csv-import-export-for-woocommerce/product-csv-import-export.php') ){
145
+ deactivate_plugins( basename( __FILE__ ) );
146
+ wp_die(__("Is everything fine? You already have the Premium version installed in your website. For any issues, kindly raise a ticket via <a target='_blank' href='//support.xadapter.com/'>support.xadapter.com</a>","wf-shipping-fedex"), "", array('back_link' => 1 ));
147
+ }
148
+ set_transient('_welcome_screen_activation_redirect', true, 30);
149
+ }
150
+
151
+ if( !function_exists('impexp_welcome') ){
152
+ function impexp_welcome() {
153
+ if (!get_transient('_welcome_screen_activation_redirect')) {
154
+ return;
155
+ }
156
+ delete_transient('_welcome_screen_activation_redirect');
157
+ wp_safe_redirect(add_query_arg(array('page' => 'impexp-welcome'), admin_url('index.php')));
158
+ }
159
+ }
160
+
161
+ if( !function_exists('impexp_welcome_screen') ){
162
+ function impexp_welcome_screen() {
163
+ add_dashboard_page('Welcome To Import Export', 'Welcome To Import Export', 'read', 'impexp-welcome', 'impexp_screen_content');
164
+ }
165
+ }
166
+
167
+ if( !function_exists('impexp_screen_content') ){
168
+ function impexp_screen_content() {
169
+ include 'welcome/welcome.php';
170
+ }
171
+ }
172
+
173
+ if( !function_exists('impexp_welcome_screen_remove_menus') ){
174
+ function impexp_welcome_screen_remove_menus() {
175
+ remove_submenu_page('index.php', 'impexp-welcome');
176
+ }
177
+ }
readme.txt CHANGED
@@ -1,229 +1,233 @@
1
- === Product Import Export for WooCommerce===
2
- Contributors: xadapter, niwf, mujeebur, thilakhearly
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,import export
5
- Requires at least: 3.0.1
6
- Tested up to: 4.8
7
- Stable tag: 1.3.7
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 LibreOffice , Microsoft 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&rel=0&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 importing 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
- = Getting Started With Import Export =
59
-
60
- [youtube http://www.youtube.com/watch?v=L-01qI1EZWE&rel=0&showinfo=0]
61
-
62
- = About XAdapter.com =
63
-
64
- XAdapter 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.
65
-
66
-
67
- == Installation ==
68
-
69
- 1. Upload the plugin folder to the /wp-content/plugins/ directory.
70
- 2. Activate the plugin through the Plugins menu in WordPress.
71
- 3. Thats it! you can now configure the plugin.
72
-
73
- == Frequently Asked Questions ==
74
-
75
- = Does this plugin support of images? =
76
-
77
- Yes. You can import or export product images along with other details
78
-
79
- == Screenshots ==
80
-
81
- 1. Product Import Screen
82
-
83
- 2. Product Export Screen
84
-
85
- 3. Premium Export Settings Screen
86
-
87
- == Changelog ==
88
- = 1.3.7 =
89
- * Fixed conflict with Plus version.
90
- = 1.3.6 =
91
- * Fixed some warnings.
92
- = 1.3.5 =
93
- * Minor Content Change.
94
- = 1.3.4 =
95
- * Updates: Added video tutorial.
96
- = 1.3.3 =
97
- * BugFix: Same title product import message update.
98
- = 1.3.2 =
99
- * Minor content change.
100
- = 1.3.1 =
101
- * Function modified for Woocommerce 3.0 Compatibility.
102
- = 1.3.0 =
103
- * Woocommerce 3.0 Compatibility.
104
- = 1.2.4 =
105
- * Marketing Content Changed.
106
- = 1.2.3 =
107
- * New Icon Updated.
108
- = 1.2.2 =
109
- * Minor content change.
110
- = 1.2.1 =
111
- * Optimization: Image URL parsing.
112
- = 1.2.0 =
113
- * Enhancement: German Translation updates.
114
- = 1.1.9 =
115
- * Enhancement: WPML Support updates.
116
- = 1.1.8 =
117
- * Enhancement: Security improvements and bug fix.
118
- = 1.1.7 =
119
- * Enhancement: Security improvements.
120
- = 1.1.6 =
121
- * Enhancement: Sample CSV updated.
122
- = 1.1.5 =
123
- * Bug fix: Improved parsing.
124
- = 1.1.4 =
125
- * Bug fix: Removed deprecated function.
126
- = 1.1.3 =
127
- * Bug fix: Empty check validation updated.
128
- = 1.1.2 =
129
- * Minor content change.
130
- = 1.1.1 =
131
- * Enhancement: Import products that have same title.
132
- = 1.1.0 =
133
- * Italian Translation added.
134
- = 1.0.9 =
135
- * Hungarian Translation added.
136
- = 1.0.8 =
137
- * Minor content change.
138
- = 1.0.7 =
139
- * Enhancement: Updated support forum links and contact details.
140
- = 1.0.6 =
141
- * Bug Fix: fixed issue with SKU while exporting.
142
- = 1.0.5 =
143
- * Feature: Added Multilingual support and French Translation.
144
- = 1.0.4 =
145
- * Bug Fix: Improved Evaluation field and help message in mapping section.
146
- = 1.0.3 =
147
- * Bug Fix: Sorting priority Set to ID by default while exporting.
148
- = 1.0.2 =
149
- * Bug Fix: Improved parsing while importing product price with currency symbol and thousand separator.
150
- = 1.0.1 =
151
- * Bug Fix: Fixed issue with Evaluation field with single quotes.
152
- * Bug Fix: Option to import gallery images.
153
- * Enhancement: Improved help text for Post name and Stock quantity.
154
- * Enhancement: Improved label text for Product type, category , tags and shipping class.
155
- * Enhancement: Included links to Documentation and sample CSV.
156
- = 1.0.0 =
157
- * Import /Export Woocommerce Products.
158
-
159
- == Upgrade Notice ==
160
- = 1.3.7 =
161
- * Fixed conflict with Plus version.
162
- = 1.3.6 =
163
- * Fixed some warnings.
164
- = 1.3.5 =
165
- * Minor Content Change.
166
- = 1.3.4 =
167
- * Updates: Added video tutorial.
168
- = 1.3.3 =
169
- * BugFix: Same title product import message update.
170
- = 1.3.2 =
171
- * Minor content change.
172
- = 1.3.1 =
173
- * Function modified for Woocommerce 3.0 Compatibility.
174
- = 1.3.0 =
175
- * Woocommerce 3.0 Compatibility.
176
- = 1.2.4 =
177
- * Marketing Content Changed.
178
- = 1.2.3 =
179
- * New Icon Updated.
180
- = 1.2.2 =
181
- * Minor content change.
182
- = 1.2.1 =
183
- * Optimization: Image URL parsing.
184
- = 1.2.0 =
185
- * Enhancement: German Translation updates.
186
- = 1.1.9 =
187
- * Enhancement: WPML Support updates.
188
- = 1.1.8 =
189
- * Enhancement: Security improvements and bug fix.
190
- = 1.1.7 =
191
- * Enhancement: Security improvements.
192
- = 1.1.6 =
193
- * Enhancement: Sample CSV updated.
194
- = 1.1.5 =
195
- * Bug fix: Improved parsing.
196
- = 1.1.4 =
197
- * Bug fix: Removed deprecated function.
198
- = 1.1.3 =
199
- * Bug fix: Empty check validation updated.
200
- = 1.1.2 =
201
- * Minor content change.
202
- = 1.1.1 =
203
- * Enhancement: Import products that have same title.
204
- = 1.1.0 =
205
- * Italian Translation added.
206
- = 1.0.9 =
207
- * Hungarian Translation added.
208
- = 1.0.8 =
209
- * Minor content change.
210
- = 1.0.7 =
211
- * Enhancement: Updated support forum links and contact details.
212
- = 1.0.6 =
213
- * Bug Fix: fixed issue with SKU while exporting.
214
- = 1.0.5 =
215
- * Feature: Added Multilingual support and French Translation.
216
- = 1.0.4 =
217
- * Bug Fix: Improved Evaluation field and help message in mapping section.
218
- = 1.0.3 =
219
- * Bug Fix: Sorting priority Set to ID by default while exporting.
220
- = 1.0.2 =
221
- * Bug Fix: Improved parsing while importing product price with currency symbol and thousand separator.
222
- = 1.0.1 =
223
- * Bug Fix: Fixed issue with Evaluation field with single quotes.
224
- * Bug Fix: Option to import gallery images.
225
- * Enhancement: Improved help text for Post name and Stock quantity.
226
- * Enhancement: Improved label text for Product type, category , tags and shipping class.
227
- * Enhancement: Included links to Documentation and sample CSV.
228
- = 1.0.0 =
229
- * Import /Export Woocommerce Products.
 
 
 
 
1
+ === Product Import Export for WooCommerce===
2
+ Contributors: xadapter, niwf, mujeebur, thilakhearly
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,import export
5
+ Requires at least: 3.0.1
6
+ Tested up to: 4.8
7
+ Stable tag: 1.3.8
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 LibreOffice , Microsoft 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&rel=0&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 importing 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
+ = Getting Started With Import Export =
59
+
60
+ [youtube http://www.youtube.com/watch?v=L-01qI1EZWE&rel=0&showinfo=0]
61
+
62
+ = About XAdapter.com =
63
+
64
+ XAdapter 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.
65
+
66
+
67
+ == Installation ==
68
+
69
+ 1. Upload the plugin folder to the /wp-content/plugins/ directory.
70
+ 2. Activate the plugin through the Plugins menu in WordPress.
71
+ 3. Thats it! you can now configure the plugin.
72
+
73
+ == Frequently Asked Questions ==
74
+
75
+ = Does this plugin support of images? =
76
+
77
+ Yes. You can import or export product images along with other details
78
+
79
+ == Screenshots ==
80
+
81
+ 1. Product Import Screen
82
+
83
+ 2. Product Export Screen
84
+
85
+ 3. Premium Export Settings Screen
86
+
87
+ == Changelog ==
88
+ = 1.3.8 =
89
+ * BugFix: Product not importing at 100n. n=1,2...
90
+ = 1.3.7 =
91
+ * Fixed conflict with Plus version.
92
+ = 1.3.6 =
93
+ * Fixed some warnings.
94
+ = 1.3.5 =
95
+ * Minor Content Change.
96
+ = 1.3.4 =
97
+ * Updates: Added video tutorial.
98
+ = 1.3.3 =
99
+ * BugFix: Same title product import message update.
100
+ = 1.3.2 =
101
+ * Minor content change.
102
+ = 1.3.1 =
103
+ * Function modified for Woocommerce 3.0 Compatibility.
104
+ = 1.3.0 =
105
+ * Woocommerce 3.0 Compatibility.
106
+ = 1.2.4 =
107
+ * Marketing Content Changed.
108
+ = 1.2.3 =
109
+ * New Icon Updated.
110
+ = 1.2.2 =
111
+ * Minor content change.
112
+ = 1.2.1 =
113
+ * Optimization: Image URL parsing.
114
+ = 1.2.0 =
115
+ * Enhancement: German Translation updates.
116
+ = 1.1.9 =
117
+ * Enhancement: WPML Support updates.
118
+ = 1.1.8 =
119
+ * Enhancement: Security improvements and bug fix.
120
+ = 1.1.7 =
121
+ * Enhancement: Security improvements.
122
+ = 1.1.6 =
123
+ * Enhancement: Sample CSV updated.
124
+ = 1.1.5 =
125
+ * Bug fix: Improved parsing.
126
+ = 1.1.4 =
127
+ * Bug fix: Removed deprecated function.
128
+ = 1.1.3 =
129
+ * Bug fix: Empty check validation updated.
130
+ = 1.1.2 =
131
+ * Minor content change.
132
+ = 1.1.1 =
133
+ * Enhancement: Import products that have same title.
134
+ = 1.1.0 =
135
+ * Italian Translation added.
136
+ = 1.0.9 =
137
+ * Hungarian Translation added.
138
+ = 1.0.8 =
139
+ * Minor content change.
140
+ = 1.0.7 =
141
+ * Enhancement: Updated support forum links and contact details.
142
+ = 1.0.6 =
143
+ * Bug Fix: fixed issue with SKU while exporting.
144
+ = 1.0.5 =
145
+ * Feature: Added Multilingual support and French Translation.
146
+ = 1.0.4 =
147
+ * Bug Fix: Improved Evaluation field and help message in mapping section.
148
+ = 1.0.3 =
149
+ * Bug Fix: Sorting priority Set to ID by default while exporting.
150
+ = 1.0.2 =
151
+ * Bug Fix: Improved parsing while importing product price with currency symbol and thousand separator.
152
+ = 1.0.1 =
153
+ * Bug Fix: Fixed issue with Evaluation field with single quotes.
154
+ * Bug Fix: Option to import gallery images.
155
+ * Enhancement: Improved help text for Post name and Stock quantity.
156
+ * Enhancement: Improved label text for Product type, category , tags and shipping class.
157
+ * Enhancement: Included links to Documentation and sample CSV.
158
+ = 1.0.0 =
159
+ * Import /Export Woocommerce Products.
160
+
161
+ == Upgrade Notice ==
162
+ = 1.3.8 =
163
+ * BugFix: Product not importing at 100n. n=1,2...
164
+ = 1.3.7 =
165
+ * Fixed conflict with Plus version.
166
+ = 1.3.6 =
167
+ * Fixed some warnings.
168
+ = 1.3.5 =
169
+ * Minor Content Change.
170
+ = 1.3.4 =
171
+ * Updates: Added video tutorial.
172
+ = 1.3.3 =
173
+ * BugFix: Same title product import message update.
174
+ = 1.3.2 =
175
+ * Minor content change.
176
+ = 1.3.1 =
177
+ * Function modified for Woocommerce 3.0 Compatibility.
178
+ = 1.3.0 =
179
+ * Woocommerce 3.0 Compatibility.
180
+ = 1.2.4 =
181
+ * Marketing Content Changed.
182
+ = 1.2.3 =
183
+ * New Icon Updated.
184
+ = 1.2.2 =
185
+ * Minor content change.
186
+ = 1.2.1 =
187
+ * Optimization: Image URL parsing.
188
+ = 1.2.0 =
189
+ * Enhancement: German Translation updates.
190
+ = 1.1.9 =
191
+ * Enhancement: WPML Support updates.
192
+ = 1.1.8 =
193
+ * Enhancement: Security improvements and bug fix.
194
+ = 1.1.7 =
195
+ * Enhancement: Security improvements.
196
+ = 1.1.6 =
197
+ * Enhancement: Sample CSV updated.
198
+ = 1.1.5 =
199
+ * Bug fix: Improved parsing.
200
+ = 1.1.4 =
201
+ * Bug fix: Removed deprecated function.
202
+ = 1.1.3 =
203
+ * Bug fix: Empty check validation updated.
204
+ = 1.1.2 =
205
+ * Minor content change.
206
+ = 1.1.1 =
207
+ * Enhancement: Import products that have same title.
208
+ = 1.1.0 =
209
+ * Italian Translation added.
210
+ = 1.0.9 =
211
+ * Hungarian Translation added.
212
+ = 1.0.8 =
213
+ * Minor content change.
214
+ = 1.0.7 =
215
+ * Enhancement: Updated support forum links and contact details.
216
+ = 1.0.6 =
217
+ * Bug Fix: fixed issue with SKU while exporting.
218
+ = 1.0.5 =
219
+ * Feature: Added Multilingual support and French Translation.
220
+ = 1.0.4 =
221
+ * Bug Fix: Improved Evaluation field and help message in mapping section.
222
+ = 1.0.3 =
223
+ * Bug Fix: Sorting priority Set to ID by default while exporting.
224
+ = 1.0.2 =
225
+ * Bug Fix: Improved parsing while importing product price with currency symbol and thousand separator.
226
+ = 1.0.1 =
227
+ * Bug Fix: Fixed issue with Evaluation field with single quotes.
228
+ * Bug Fix: Option to import gallery images.
229
+ * Enhancement: Improved help text for Post name and Stock quantity.
230
+ * Enhancement: Improved label text for Product type, category , tags and shipping class.
231
+ * Enhancement: Included links to Documentation and sample CSV.
232
+ = 1.0.0 =
233
+ * 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
  }