[Importer/Exporter] Fix "Published" column values

While variations only uses "published" and "private" statuses when
exporting we should display the variations as "draft" in case the parent
product it's also a draft.
This commit is contained in:
Claudio Sanches 2020-07-15 21:45:51 -03:00
parent a34835e489
commit 37777432d4
2 changed files with 13 additions and 2 deletions

View File

@ -268,7 +268,13 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter {
'publish' => 1,
);
$status = $product->get_status( 'edit' );
// Fix display for variations when parent product is a draft.
if ( 'variation' === $product->get_type() ) {
$parent = $product->get_parent_data();
$status = 'draft' === $parent['status'] ? $parent['status'] : $product->get_status( 'edit' );
} else {
$status = $product->get_status( 'edit' );
}
return isset( $statuses[ $status ] ) ? $statuses[ $status ] : -1;
}

View File

@ -824,7 +824,12 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
0 => 'private',
1 => 'publish',
);
$data['status'] = isset( $statuses[ $data['published'] ] ) ? $statuses[ $data['published'] ] : -1;
$data['status'] = isset( $statuses[ $data['published'] ] ) ? $statuses[ $data['published'] ] : 'draft';
// Fix draft status of variations.
if ( isset( $data['type'] ) && 'variation' === $data['type'] && -1 === $data['published'] ) {
$data['status'] = 'publish';
}
unset( $data['published'] );
}