Clean up
This commit is contained in:
parent
f7cc3df222
commit
b2e8d31262
|
@ -5,19 +5,16 @@
|
|||
* productImportForm handles the import process.
|
||||
*/
|
||||
var productImportForm = function( $form ) {
|
||||
this.$form = $form;
|
||||
this.xhr = false;
|
||||
this.mapping = wc_product_import_params.mapping;
|
||||
this.$form = $form;
|
||||
this.xhr = false;
|
||||
this.mapping = wc_product_import_params.mapping;
|
||||
this.position = 0;
|
||||
this.file = wc_product_import_params.file;
|
||||
this.file = wc_product_import_params.file;
|
||||
this.security = wc_product_import_params.import_nonce;
|
||||
|
||||
// Number of import successes/failures.
|
||||
this.imported = 0;
|
||||
this.failed = 0;
|
||||
|
||||
// Number of lines to import in one batch.
|
||||
this.lines = 10;
|
||||
this.failed = 0;
|
||||
|
||||
// Initial state.
|
||||
this.$form.find('.woocommerce-importer-progress').val( 0 );
|
||||
|
@ -38,19 +35,18 @@
|
|||
type: 'POST',
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
action: 'woocommerce_do_ajax_product_import',
|
||||
position: $this.position,
|
||||
lines: $this.lines,
|
||||
mapping: $this.mapping,
|
||||
file: $this.file,
|
||||
action : 'woocommerce_do_ajax_product_import',
|
||||
position : $this.position,
|
||||
mapping : $this.mapping,
|
||||
file : $this.file,
|
||||
security : $this.security
|
||||
},
|
||||
dataType: 'json',
|
||||
success: function( response ) {
|
||||
if ( response.success ) {
|
||||
$this.position = response.data.position;
|
||||
$this.position = response.data.position;
|
||||
$this.imported += response.data.imported;
|
||||
$this.failed += response.data.failed;
|
||||
$this.failed += response.data.failed;
|
||||
$this.$form.find('.woocommerce-importer-progress').val( response.data.percentage );
|
||||
|
||||
if ( 'done' === response.data.position ) {
|
||||
|
|
|
@ -1 +1 @@
|
|||
!function(a,b){var c=function(a){this.$form=a,this.xhr=!1,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.imported=0,this.failed=0,this.lines=10,this.$form.find(".woocommerce-importer-progress").val(0),this.run_import=this.run_import.bind(this),this.run_import()};c.prototype.run_import=function(){var c=this;a.ajax({type:"POST",url:ajaxurl,data:{action:"woocommerce_do_ajax_product_import",position:c.position,lines:c.lines,mapping:c.mapping,file:c.file,security:c.security},dataType:"json",success:function(a){a.success&&(c.position=a.data.position,c.imported+=a.data.imported,c.failed+=a.data.failed,c.$form.find(".woocommerce-importer-progress").val(a.data.percentage),"done"===a.data.position?b.location=a.data.url+"&imported="+parseInt(c.imported,10)+"&failed="+parseInt(c.failed,10):c.run_import())}}).fail(function(a){b.console.log(a)})},a.fn.wc_product_importer=function(){return new c(this),this},a(".woocommerce-importer").wc_product_importer()}(jQuery,window);
|
||||
!function(a,b){var c=function(a){this.$form=a,this.xhr=!1,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.imported=0,this.failed=0,this.$form.find(".woocommerce-importer-progress").val(0),this.run_import=this.run_import.bind(this),this.run_import()};c.prototype.run_import=function(){var c=this;a.ajax({type:"POST",url:ajaxurl,data:{action:"woocommerce_do_ajax_product_import",position:c.position,mapping:c.mapping,file:c.file,security:c.security},dataType:"json",success:function(a){a.success&&(c.position=a.data.position,c.imported+=a.data.imported,c.failed+=a.data.failed,c.$form.find(".woocommerce-importer-progress").val(a.data.percentage),"done"===a.data.position?b.location=a.data.url+"&imported="+parseInt(c.imported,10)+"&failed="+parseInt(c.failed,10):c.run_import())}}).fail(function(a){b.console.log(a)})},a.fn.wc_product_importer=function(){return new c(this),this},a(".woocommerce-importer").wc_product_importer()}(jQuery,window);
|
|
@ -200,32 +200,32 @@ class WC_Admin_Importers {
|
|||
|
||||
include_once( WC_ABSPATH . 'includes/import/class-wc-product-csv-importer.php' );
|
||||
|
||||
$file = $_POST['file'];
|
||||
$file = wc_clean( $_POST['file'] );
|
||||
$params = array(
|
||||
'start_pos' => isset( $_POST['position'] ) ? absint( $_POST['position'] ) : 0,
|
||||
'lines' => isset( $_POST['lines'] ) ? absint( $_POST['lines'] ) : 10,
|
||||
'mapping' => isset( $_POST['mapping'] ) ? (array) $_POST['mapping'] : array(),
|
||||
'parse' => true,
|
||||
'mapping' => isset( $_POST['mapping'] ) ? (array) $_POST['mapping'] : array(),
|
||||
'lines' => apply_filters( 'woocommerce_product_import_batch_size', 10 ),
|
||||
'parse' => true,
|
||||
);
|
||||
|
||||
$importer = new WC_Product_CSV_Importer( $file, $params );
|
||||
$importer = WC_Product_CSV_Importer_Controller::get_importer( $file, $params );
|
||||
$results = $importer->import();
|
||||
$position = $importer->get_file_position();
|
||||
|
||||
if ( 100 == $importer->get_percent_complete() ) {
|
||||
wp_send_json_success( array(
|
||||
'position' => 'done',
|
||||
'position' => 'done',
|
||||
'percentage' => 100,
|
||||
'url' => add_query_arg( array( 'nonce' => wp_create_nonce( 'product-csv' ) ), admin_url( 'edit.php?post_type=product&page=product_importer&step=done' ) ),
|
||||
'imported' => count( $results['imported'] ),
|
||||
'failed' => count( $results['failed'] ),
|
||||
'url' => add_query_arg( array( 'nonce' => wp_create_nonce( 'product-csv' ) ), admin_url( 'edit.php?post_type=product&page=product_importer&step=done' ) ),
|
||||
'imported' => count( $results['imported'] ),
|
||||
'failed' => count( $results['failed'] ),
|
||||
) );
|
||||
} else {
|
||||
wp_send_json_success( array(
|
||||
'position' => $position,
|
||||
'position' => $position,
|
||||
'percentage' => $importer->get_percent_complete(),
|
||||
'imported' => count( $results['imported'] ),
|
||||
'failed' => count( $results['failed'] ),
|
||||
'imported' => count( $results['imported'] ),
|
||||
'failed' => count( $results['failed'] ),
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,6 +52,19 @@ class WC_Product_CSV_Importer_Controller {
|
|||
*/
|
||||
protected $delimiter = ',';
|
||||
|
||||
/**
|
||||
* Get importer instance.
|
||||
*
|
||||
* @param string $file File to import.
|
||||
* @param array $args Importer arguments.
|
||||
* @return WC_Product_CSV_Importer
|
||||
*/
|
||||
public static function get_importer( $file, $args = array() ) {
|
||||
$importer_class = apply_filters( 'woocommerce_product_csv_importer_class', 'WC_Product_CSV_Importer' );
|
||||
return new $importer_class( $file, $args );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
|
@ -137,18 +150,6 @@ class WC_Product_CSV_Importer_Controller {
|
|||
include( dirname( __FILE__ ) . '/views/html-csv-import-footer.php' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get importer instance.
|
||||
*
|
||||
* @param string $file File to import.
|
||||
* @param array $args Importer arguments.
|
||||
* @return WC_Product_CSV_Importer
|
||||
*/
|
||||
protected function get_importer( $file, $args = array() ) {
|
||||
$importer_class = apply_filters( 'woocommerce_product_csv_importer_class', 'WC_Product_CSV_Importer' );
|
||||
return new $importer_class( $file, $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add error message.
|
||||
*/
|
||||
|
@ -262,7 +263,7 @@ class WC_Product_CSV_Importer_Controller {
|
|||
* Mapping step @todo
|
||||
*/
|
||||
protected function mapping_form() {
|
||||
$importer = $this->get_importer( $this->file, array( 'lines' => 1 ) );
|
||||
$importer = $this::get_importer( $this->file, array( 'lines' => 1 ) );
|
||||
$headers = $importer->get_raw_keys();
|
||||
$sample = current( $importer->get_raw_data() );
|
||||
|
||||
|
@ -298,8 +299,8 @@ class WC_Product_CSV_Importer_Controller {
|
|||
include_once( dirname( __FILE__ ) . '/views/html-csv-import-progress.php' );
|
||||
wp_localize_script( 'wc-product-import', 'wc_product_import_params', array(
|
||||
'import_nonce' => wp_create_nonce( 'wc-product-import' ),
|
||||
'mapping' => $mapping,
|
||||
'file' => $this->file,
|
||||
'mapping' => $mapping,
|
||||
'file' => $this->file,
|
||||
) );
|
||||
wp_enqueue_script( 'wc-product-import' );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue