Add support for low stock amount to REST API v3. Ref #27371.
This commit is contained in:
parent
f7755f123e
commit
b48a389264
|
@ -766,6 +766,9 @@ class WC_REST_Products_V2_Controller extends WC_REST_CRUD_Controller {
|
|||
case 'backordered':
|
||||
$base_data['backordered'] = $product->is_on_backorder();
|
||||
break;
|
||||
case 'low_stock_amount':
|
||||
$base_data['low_stock_amount'] = $product->get_low_stock_amount();
|
||||
break;
|
||||
case 'sold_individually':
|
||||
$base_data['sold_individually'] = $product->is_sold_individually();
|
||||
break;
|
||||
|
|
|
@ -65,6 +65,7 @@ class WC_REST_Product_Variations_Controller extends WC_REST_Product_Variations_V
|
|||
'backorders' => $object->get_backorders(),
|
||||
'backorders_allowed' => $object->backorders_allowed(),
|
||||
'backordered' => $object->is_on_backorder(),
|
||||
'low_stock_amount' => $object->get_low_stock_amount(),
|
||||
'weight' => $object->get_weight(),
|
||||
'dimensions' => array(
|
||||
'length' => $object->get_length(),
|
||||
|
@ -185,9 +186,13 @@ class WC_REST_Product_Variations_Controller extends WC_REST_Product_Variations_V
|
|||
$stock_quantity += wc_stock_amount( $request['inventory_delta'] );
|
||||
$variation->set_stock_quantity( $stock_quantity );
|
||||
}
|
||||
if ( isset( $request['low_stock_amount'] ) ) {
|
||||
$variation->set_low_stock_amount( wc_stock_amount( $request['low_stock_amount'] ) );
|
||||
}
|
||||
} else {
|
||||
$variation->set_backorders( 'no' );
|
||||
$variation->set_stock_quantity( '' );
|
||||
$variation->set_low_stock_amount( '' );
|
||||
}
|
||||
|
||||
// Regular Price.
|
||||
|
@ -597,6 +602,11 @@ class WC_REST_Product_Variations_Controller extends WC_REST_Product_Variations_V
|
|||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'low_stock_amount' => array(
|
||||
'description' => __( 'Low Stock amount for the variation.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'weight' => array(
|
||||
/* translators: %s: weight unit */
|
||||
'description' => sprintf( __( 'Variation weight (%s).', 'woocommerce' ), $weight_unit ),
|
||||
|
|
|
@ -551,11 +551,17 @@ class WC_REST_Products_Controller extends WC_REST_Products_V2_Controller {
|
|||
$stock_quantity += wc_stock_amount( $request['inventory_delta'] );
|
||||
$product->set_stock_quantity( wc_stock_amount( $stock_quantity ) );
|
||||
}
|
||||
|
||||
// Low stock amount.
|
||||
if ( isset( $request['low_stock_amount'] ) ) {
|
||||
$product->set_low_stock_amount( wc_stock_amount( $request['low_stock_amount'] ) );
|
||||
}
|
||||
} else {
|
||||
// Don't manage stock.
|
||||
$product->set_manage_stock( 'no' );
|
||||
$product->set_stock_quantity( '' );
|
||||
$product->set_stock_status( $stock_status );
|
||||
$product->set_low_stock_amount( '' );
|
||||
}
|
||||
} elseif ( ! $product->is_type( 'variable' ) ) {
|
||||
$product->set_stock_status( $stock_status );
|
||||
|
@ -985,6 +991,11 @@ class WC_REST_Products_Controller extends WC_REST_Products_V2_Controller {
|
|||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'low_stock_amount' => array(
|
||||
'description' => __( 'Low Stock amount for the product.', 'woocommerce' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'sold_individually' => array(
|
||||
'description' => __( 'Allow one item to be bought in a single order.', 'woocommerce' ),
|
||||
'type' => 'boolean',
|
||||
|
|
Loading…
Reference in New Issue