Merge pull request #18048 from woocommerce/fix/17722-2
Allow import and export draft products
This commit is contained in:
commit
03db5c4590
|
@ -130,7 +130,7 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter {
|
|||
public function prepare_data_to_export() {
|
||||
$columns = $this->get_column_names();
|
||||
$args = apply_filters( "woocommerce_product_export_{$this->export_type}_query_args", array(
|
||||
'status' => array( 'private', 'publish' ),
|
||||
'status' => array( 'private', 'publish', 'draft' ),
|
||||
'type' => $this->product_types_to_export,
|
||||
'limit' => $this->get_limit(),
|
||||
'page' => $this->get_page(),
|
||||
|
@ -188,7 +188,15 @@ class WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter {
|
|||
* @return int
|
||||
*/
|
||||
protected function get_column_value_published( $product ) {
|
||||
return 'publish' === $product->get_status( 'edit' ) ? 1 : 0;
|
||||
$statuses = array(
|
||||
'draft' => -1,
|
||||
'private' => 0,
|
||||
'publish' => 1,
|
||||
);
|
||||
|
||||
$status = $product->get_status( 'edit' );
|
||||
|
||||
return isset( $statuses[ $status ] ) ? $statuses[ $status ] : -1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -517,7 +517,7 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
|
|||
$data_formatting = array(
|
||||
'id' => array( $this, 'parse_id_field' ),
|
||||
'type' => array( $this, 'parse_comma_field' ),
|
||||
'published' => array( $this, 'parse_bool_field' ),
|
||||
'published' => array( $this, 'parse_float_field' ),
|
||||
'featured' => array( $this, 'parse_bool_field' ),
|
||||
'date_on_sale_from' => array( $this, 'parse_date_field' ),
|
||||
'date_on_sale_to' => array( $this, 'parse_date_field' ),
|
||||
|
@ -628,8 +628,13 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
|
|||
|
||||
// Status is mapped from a special published field.
|
||||
if ( isset( $data['published'] ) ) {
|
||||
$non_published_status = isset( $data['type'] ) && 'variation' === $data['type'] ? 'private' : 'draft';
|
||||
$data['status'] = ( $data['published'] ? 'publish' : $non_published_status );
|
||||
$statuses = array(
|
||||
-1 => 'draft',
|
||||
0 => 'private',
|
||||
1 => 'publish',
|
||||
);
|
||||
$data['status'] = isset( $statuses[ $data['published'] ] ) ? $statuses[ $data['published'] ] : -1;
|
||||
|
||||
unset( $data['published'] );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue