CSV Import; correctly set stock props.

Closes #16398
This commit is contained in:
Mike Jolley 2017-08-11 11:07:12 +01:00
parent e124841cbf
commit 0f54e57093
1 changed files with 22 additions and 2 deletions

View File

@ -283,6 +283,20 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
return floatval( $value );
}
/**
* Parse the stock qty field.
*
* @param string $value Field value.
* @return float|string
*/
public function parse_stock_quantity_field( $value ) {
if ( '' === $value ) {
return $value;
}
return wc_stock_amount( $value );
}
/**
* Parse a category field from a CSV.
* Categories are separated by commas and subcategories are "parent > subcategory".
@ -488,7 +502,7 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
'purchase_note' => 'wp_filter_post_kses',
'price' => 'wc_format_decimal',
'regular_price' => 'wc_format_decimal',
'stock_quantity' => 'wc_stock_amount',
'stock_quantity' => array( $this, 'parse_stock_quantity_field' ),
'category_ids' => array( $this, 'parse_categories_field' ),
'tag_ids' => array( $this, 'parse_tags_field' ),
'shipping_class_id' => array( $this, 'parse_shipping_class_field' ),
@ -584,7 +598,13 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
}
if ( isset( $data['stock_quantity'] ) ) {
$data['manage_stock'] = 0 < $data['stock_quantity'];
if ( '' === $data['stock_quantity'] ) {
$data['manage_stock'] = false;
$data['stock_status'] = isset( $data['stock_status'] ) ? $data['stock_status'] : true;
} else {
$data['manage_stock'] = true;
$data['stock_status'] = 0 < $data['stock_quantity'];
}
}
// Stock is bool.