Fix: variations are counted as products in import message of number of products imported (#37829)
Co-authored-by: mujuonly <muju.only@gmail.com> Co-authored-by: barryhughes <3594411+barryhughes@users.noreply.github.com> Co-authored-by: Nestor Soriano <konamiman@konamiman.com>
This commit is contained in:
parent
c19a42398b
commit
9cfd58ad15
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: tweak
|
||||
|
||||
Fix typo in a function comment.
|
|
@ -0,0 +1,4 @@
|
|||
Significance: minor
|
||||
Type: add
|
||||
|
||||
Show the number of variations imported
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
// Number of import successes/failures.
|
||||
this.imported = 0;
|
||||
this.imported_variations = 0;
|
||||
this.failed = 0;
|
||||
this.updated = 0;
|
||||
this.skipped = 0;
|
||||
|
@ -54,6 +55,7 @@
|
|||
if ( response.success ) {
|
||||
$this.position = response.data.position;
|
||||
$this.imported += response.data.imported;
|
||||
$this.imported_variations += response.data.imported_variations;
|
||||
$this.failed += response.data.failed;
|
||||
$this.updated += response.data.updated;
|
||||
$this.skipped += response.data.skipped;
|
||||
|
@ -64,6 +66,8 @@
|
|||
window.location = response.data.url +
|
||||
'&products-imported=' +
|
||||
parseInt( $this.imported, 10 ) +
|
||||
'&products-imported-variations=' +
|
||||
parseInt( $this.imported_variations, 10 ) +
|
||||
'&products-failed=' +
|
||||
parseInt( $this.failed, 10 ) +
|
||||
'&products-updated=' +
|
||||
|
|
|
@ -294,6 +294,7 @@ class WC_Admin_Importers {
|
|||
'percentage' => 100,
|
||||
'url' => add_query_arg( array( '_wpnonce' => wp_create_nonce( 'woocommerce-csv-importer' ) ), admin_url( 'edit.php?post_type=product&page=product_importer&step=done' ) ),
|
||||
'imported' => count( $results['imported'] ),
|
||||
'imported_variations' => count( $results['imported_variations'] ),
|
||||
'failed' => count( $results['failed'] ),
|
||||
'updated' => count( $results['updated'] ),
|
||||
'skipped' => count( $results['skipped'] ),
|
||||
|
|
|
@ -462,6 +462,7 @@ class WC_Product_CSV_Importer_Controller {
|
|||
protected function done() {
|
||||
check_admin_referer( 'woocommerce-csv-importer' );
|
||||
$imported = isset( $_GET['products-imported'] ) ? absint( $_GET['products-imported'] ) : 0;
|
||||
$imported_variations = isset( $_GET['products-imported-variations'] ) ? absint( $_GET['products-imported-variations'] ) : 0;
|
||||
$updated = isset( $_GET['products-updated'] ) ? absint( $_GET['products-updated'] ) : 0;
|
||||
$failed = isset( $_GET['products-failed'] ) ? absint( $_GET['products-failed'] ) : 0;
|
||||
$skipped = isset( $_GET['products-skipped'] ) ? absint( $_GET['products-skipped'] ) : 0;
|
||||
|
|
|
@ -30,6 +30,14 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
);
|
||||
}
|
||||
|
||||
if ( 0 < $imported_variations ) {
|
||||
$results[] = sprintf(
|
||||
/* translators: %d: products count */
|
||||
_n( '%s variations imported', '%s variations imported', $imported_variations, 'woocommerce' ),
|
||||
'<strong>' . number_format_i18n( $imported_variations ) . '</strong>'
|
||||
);
|
||||
}
|
||||
|
||||
if ( 0 < $skipped ) {
|
||||
$results[] = sprintf(
|
||||
/* translators: %d: products count */
|
||||
|
|
|
@ -250,11 +250,12 @@ abstract class WC_Product_Importer implements WC_Importer_Interface {
|
|||
if ( 'external' === $object->get_type() ) {
|
||||
unset( $data['manage_stock'], $data['stock_status'], $data['backorders'], $data['low_stock_amount'] );
|
||||
}
|
||||
|
||||
$is_variation = false;
|
||||
if ( 'variation' === $object->get_type() ) {
|
||||
if ( isset( $data['status'] ) && -1 === $data['status'] ) {
|
||||
$data['status'] = 0; // Variations cannot be drafts - set to private.
|
||||
}
|
||||
$is_variation = true;
|
||||
}
|
||||
|
||||
if ( 'importing' === $object->get_status() ) {
|
||||
|
@ -285,6 +286,7 @@ abstract class WC_Product_Importer implements WC_Importer_Interface {
|
|||
return array(
|
||||
'id' => $object->get_id(),
|
||||
'updated' => $updating,
|
||||
'is_variation' => $is_variation,
|
||||
);
|
||||
} catch ( Exception $e ) {
|
||||
return new WP_Error( 'woocommerce_product_importer_error', $e->getMessage(), array( 'status' => $e->getCode() ) );
|
||||
|
|
|
@ -1081,6 +1081,7 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
|
|||
$update_existing = $this->params['update_existing'];
|
||||
$data = array(
|
||||
'imported' => array(),
|
||||
'imported_variations' => array(),
|
||||
'failed' => array(),
|
||||
'updated' => array(),
|
||||
'skipped' => array(),
|
||||
|
@ -1149,9 +1150,13 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
|
|||
$data['failed'][] = $result;
|
||||
} elseif ( $result['updated'] ) {
|
||||
$data['updated'][] = $result['id'];
|
||||
} else {
|
||||
if ( $result['is_variation'] ) {
|
||||
$data['imported_variations'][] = $result['id'];
|
||||
} else {
|
||||
$data['imported'][] = $result['id'];
|
||||
}
|
||||
}
|
||||
|
||||
$index ++;
|
||||
|
||||
|
|
|
@ -72,6 +72,7 @@ class WC_Importer_Tracking {
|
|||
|
||||
$properties = array(
|
||||
'imported' => isset( $_GET['products-imported'] ) ? absint( $_GET['products-imported'] ) : 0,
|
||||
'imported_variations' => isset( $_GET['products-imported-variations'] ) ? absint( $_GET['products-imported-variations'] ) : 0,
|
||||
'updated' => isset( $_GET['products-updated'] ) ? absint( $_GET['products-updated'] ) : 0,
|
||||
'failed' => isset( $_GET['products-failed'] ) ? absint( $_GET['products-failed'] ) : 0,
|
||||
'skipped' => isset( $_GET['products-skipped'] ) ? absint( $_GET['products-skipped'] ) : 0,
|
||||
|
|
|
@ -115,7 +115,7 @@ class WC_Tests_Product_CSV_Importer extends WC_Unit_Test_Case {
|
|||
$this->assertEquals( 0, count( $results['skipped'] ) );
|
||||
$this->assertEquals(
|
||||
7,
|
||||
count( $results['imported'] ),
|
||||
count( $results['imported'] ) + count( $results['imported_variations'] ),
|
||||
'One import item references a downloadable file stored in an unapproved location: if the import is triggered by an admin user, that location will be automatically approved.'
|
||||
);
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ class WC_Tests_Product_CSV_Importer extends WC_Unit_Test_Case {
|
|||
|
||||
$this->assertEquals( 0, count( $results['updated'] ) );
|
||||
$this->assertEquals( 0, count( $results['skipped'] ) );
|
||||
$this->assertEquals( 6, count( $results['imported'] ) );
|
||||
$this->assertEquals( 6, count( $results['imported'] ) + count( $results['imported_variations'] ) );
|
||||
$this->assertEquals(
|
||||
1,
|
||||
count( $results['failed'] ),
|
||||
|
|
Loading…
Reference in New Issue