[2.6] [REST API] Allow fetch, edit and delete a single product variation
This commit is contained in:
parent
3ab6a22146
commit
11534cf457
|
@ -132,6 +132,15 @@ abstract class WC_REST_Posts_Controller extends WC_REST_Controller {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get post types.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function get_post_types() {
|
||||
return array( $post->post_type );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single item.
|
||||
*
|
||||
|
@ -142,7 +151,7 @@ abstract class WC_REST_Posts_Controller extends WC_REST_Controller {
|
|||
$id = (int) $request['id'];
|
||||
$post = get_post( $id );
|
||||
|
||||
if ( empty( $id ) || empty( $post->ID ) || $this->post_type !== $post->post_type ) {
|
||||
if ( empty( $id ) || empty( $post->ID ) || ! in_array( $post->post_type, $this->get_post_types() ) ) {
|
||||
return new WP_Error( "woocommerce_rest_invalid_{$this->post_type}_id", __( 'Invalid id.', 'woocommerce' ), array( 'status' => 404 ) );
|
||||
}
|
||||
|
||||
|
@ -246,7 +255,7 @@ abstract class WC_REST_Posts_Controller extends WC_REST_Controller {
|
|||
$id = (int) $request['id'];
|
||||
$post = get_post( $id );
|
||||
|
||||
if ( empty( $id ) || empty( $post->ID ) || $this->post_type !== $post->post_type ) {
|
||||
if ( empty( $id ) || empty( $post->ID ) || ! in_array( $post->post_type, $this->get_post_types() ) ) {
|
||||
return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'ID is invalid.', 'woocommerce' ), array( 'status' => 400 ) );
|
||||
}
|
||||
|
||||
|
@ -405,7 +414,7 @@ abstract class WC_REST_Posts_Controller extends WC_REST_Controller {
|
|||
$force = (bool) $request['force'];
|
||||
$post = get_post( $id );
|
||||
|
||||
if ( empty( $id ) || empty( $post->ID ) || $this->post_type !== $post->post_type ) {
|
||||
if ( empty( $id ) || empty( $post->ID ) || ! in_array( $post->post_type, $this->get_post_types() ) ) {
|
||||
return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid post id.', 'woocommerce' ), array( 'status' => 404 ) );
|
||||
}
|
||||
|
||||
|
|
|
@ -112,6 +112,15 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller {
|
|||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get post types.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function get_post_types() {
|
||||
return array( 'product', 'product_variation' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Query args.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue