Merge pull request #23207 from woocommerce/update/23205

Introduce `parse_published_field` in CSV importer
This commit is contained in:
Rodrigo Primo 2019-05-21 16:24:03 -03:00 committed by GitHub
commit 5a15713f95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 1 deletions

View File

@ -593,6 +593,29 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
return implode( '\\\n', $parts );
}
/**
* Parse the published field. 1 is published, 0 is private, -1 is draft.
* Alternatively, 'true' can be used for published and 'false' for draft.
*
* @param string $value Field value.
*
* @return float|string
*/
public function parse_published_field( $value ) {
if ( '' === $value ) {
return $value;
}
// Remove the ' prepended to fields that start with - if needed.
$value = $this->unescape_data( $value );
if ( 'true' === strtolower( $value ) || 'false' === strtolower( $value ) ) {
return wc_string_to_bool( $value ) ? 1 : -1;
}
return floatval( $value );
}
/**
* Get formatting callback.
*
@ -607,7 +630,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_float_field' ),
'published' => array( $this, 'parse_published_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' ),