Merge pull request #16408 from woocommerce/fix/16398
CSV Import; correctly set stock props.
This commit is contained in:
commit
4d87f94622
|
@ -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.
|
||||
|
|
|
@ -301,7 +301,7 @@ class WC_Tests_Product_CSV_Importer extends WC_Unit_Test_Case {
|
|||
'tax_status' => 'taxable',
|
||||
'tax_class' => 'standard',
|
||||
'stock_status' => 'instock',
|
||||
'stock_quantity' => 0,
|
||||
'stock_quantity' => '',
|
||||
'backorders' => '',
|
||||
'sold_individually' => '',
|
||||
'weight' => '',
|
||||
|
@ -352,7 +352,7 @@ class WC_Tests_Product_CSV_Importer extends WC_Unit_Test_Case {
|
|||
'tax_status' => 'taxable',
|
||||
'tax_class' => 'standard',
|
||||
'stock_status' => 'instock',
|
||||
'stock_quantity' => 0,
|
||||
'stock_quantity' => '',
|
||||
'backorders' => '',
|
||||
'sold_individually' => '',
|
||||
'weight' => '',
|
||||
|
@ -387,7 +387,7 @@ class WC_Tests_Product_CSV_Importer extends WC_Unit_Test_Case {
|
|||
'tax_status' => '',
|
||||
'tax_class' => '',
|
||||
'stock_status' => 'outofstock',
|
||||
'stock_quantity' => 0,
|
||||
'stock_quantity' => '',
|
||||
'backorders' => '',
|
||||
'sold_individually' => '',
|
||||
'weight' => '',
|
||||
|
@ -526,7 +526,7 @@ class WC_Tests_Product_CSV_Importer extends WC_Unit_Test_Case {
|
|||
'tax_status' => '',
|
||||
'tax_class' => '',
|
||||
'stock_status' => 'instock',
|
||||
'stock_quantity' => 0,
|
||||
'stock_quantity' => '',
|
||||
'backorders' => '',
|
||||
'sold_individually' => '',
|
||||
'weight' => '',
|
||||
|
|
Loading…
Reference in New Issue