diff --git a/assets/js/admin/wc-product-import.js b/assets/js/admin/wc-product-import.js index c707cb91fd7..2d6f0654a01 100644 --- a/assets/js/admin/wc-product-import.js +++ b/assets/js/admin/wc-product-import.js @@ -5,12 +5,13 @@ * productImportForm handles the import process. */ var productImportForm = function( $form ) { - this.$form = $form; - this.xhr = false; - this.mapping = wc_product_import_params.mapping; - this.position = 0; - this.file = wc_product_import_params.file; - this.security = wc_product_import_params.import_nonce; + this.$form = $form; + this.xhr = false; + this.mapping = wc_product_import_params.mapping; + this.position = 0; + this.file = wc_product_import_params.file; + this.skip_existing = wc_product_import_params.skip_existing; + this.security = wc_product_import_params.import_nonce; // Number of import successes/failures. this.imported = 0; @@ -35,11 +36,12 @@ type: 'POST', url: ajaxurl, data: { - action : 'woocommerce_do_ajax_product_import', - position : $this.position, - mapping : $this.mapping, - file : $this.file, - security : $this.security + action : 'woocommerce_do_ajax_product_import', + position : $this.position, + mapping : $this.mapping, + file : $this.file, + skip_existing : $this.skip_existing, + security : $this.security }, dataType: 'json', success: function( response ) { diff --git a/includes/admin/class-wc-admin-importers.php b/includes/admin/class-wc-admin-importers.php index 6acdaad55a4..35c397815ff 100644 --- a/includes/admin/class-wc-admin-importers.php +++ b/includes/admin/class-wc-admin-importers.php @@ -203,10 +203,11 @@ class WC_Admin_Importers { $file = wc_clean( $_POST['file'] ); $params = array( - 'start_pos' => isset( $_POST['position'] ) ? absint( $_POST['position'] ) : 0, - 'mapping' => isset( $_POST['mapping'] ) ? (array) $_POST['mapping'] : array(), - 'lines' => apply_filters( 'woocommerce_product_import_batch_size', 10 ), - 'parse' => true, + 'start_pos' => isset( $_POST['position'] ) ? absint( $_POST['position'] ) : 0, + 'mapping' => isset( $_POST['mapping'] ) ? (array) $_POST['mapping'] : array(), + 'skip_existing' => isset( $_POST['skip_existing'] ) ? (bool) $_POST['skip_existing'] : false, + 'lines' => apply_filters( 'woocommerce_product_import_batch_size', 10 ), + 'parse' => true, ); $importer = WC_Product_CSV_Importer_Controller::get_importer( $file, $params ); diff --git a/includes/admin/importers/class-wc-product-csv-importer-controller.php b/includes/admin/importers/class-wc-product-csv-importer-controller.php index b3718d787df..50a627f5206 100644 --- a/includes/admin/importers/class-wc-product-csv-importer-controller.php +++ b/includes/admin/importers/class-wc-product-csv-importer-controller.php @@ -52,6 +52,13 @@ class WC_Product_CSV_Importer_Controller { */ protected $delimiter = ','; + /** + * Whether to skip existing products. + * + * @var bool + */ + protected $skip_existing = false; + /** * Get importer instance. * @@ -92,6 +99,7 @@ class WC_Product_CSV_Importer_Controller { ); $this->step = isset( $_REQUEST['step'] ) ? sanitize_key( $_REQUEST['step'] ) : current( array_keys( $this->steps ) ); $this->file = isset( $_REQUEST['file'] ) ? wc_clean( $_REQUEST['file'] ) : ''; + $this->skip_existing = isset( $_REQUEST['skip_existing'] ) ? (bool) $_REQUEST['skip_existing'] : false; } /** @@ -119,10 +127,11 @@ class WC_Product_CSV_Importer_Controller { } $params = array( - 'step' => $keys[ $step_index + 1 ], - 'file' => $this->file, - 'delimiter' => $this->delimiter, - '_wpnonce' => wp_create_nonce( 'woocommerce-csv-importer' ), // wp_nonce_url() escapes & to & breaking redirects. + 'step' => $keys[ $step_index + 1 ], + 'file' => $this->file, + 'delimiter' => $this->delimiter, + 'skip_existing' => $this->skip_existing, + '_wpnonce' => wp_create_nonce( 'woocommerce-csv-importer' ), // wp_nonce_url() escapes & to & breaking redirects. ); return add_query_arg( $params ); @@ -300,9 +309,10 @@ class WC_Product_CSV_Importer_Controller { } wp_localize_script( 'wc-product-import', 'wc_product_import_params', array( - 'import_nonce' => wp_create_nonce( 'wc-product-import' ), - 'mapping' => $mapping, - 'file' => $this->file, + 'import_nonce' => wp_create_nonce( 'wc-product-import' ), + 'mapping' => $mapping, + 'file' => $this->file, + 'skip_existing' => $this->skip_existing, ) ); wp_enqueue_script( 'wc-product-import' ); diff --git a/includes/admin/importers/views/html-csv-import-mapping.php b/includes/admin/importers/views/html-csv-import-mapping.php index 12543f233d0..8209e34573c 100644 --- a/includes/admin/importers/views/html-csv-import-mapping.php +++ b/includes/admin/importers/views/html-csv-import-mapping.php @@ -54,6 +54,7 @@ if ( ! defined( 'ABSPATH' ) ) { + diff --git a/includes/admin/importers/views/html-product-csv-import-form.php b/includes/admin/importers/views/html-product-csv-import-form.php index 45c50521b51..e04ffb00006 100644 --- a/includes/admin/importers/views/html-product-csv-import-form.php +++ b/includes/admin/importers/views/html-product-csv-import-form.php @@ -56,6 +56,13 @@ if ( ! defined( 'ABSPATH' ) ) {