add get single tax class, support cli tax class delete
This commit is contained in:
parent
cbfe4bd595
commit
c605b93737
|
@ -144,13 +144,18 @@ class WC_CLI_REST_Command {
|
||||||
*/
|
*/
|
||||||
public function delete_item( $args, $assoc_args ) {
|
public function delete_item( $args, $assoc_args ) {
|
||||||
list( $status, $body ) = $this->do_request( 'DELETE', $this->get_filled_route( $args ), $assoc_args );
|
list( $status, $body ) = $this->do_request( 'DELETE', $this->get_filled_route( $args ), $assoc_args );
|
||||||
|
$object_id = isset( $body['id'] ) ? $body['id'] : '';
|
||||||
|
if ( ! $object_id && isset( $body['slug'] ) ) {
|
||||||
|
$object_id = $body['slug'];
|
||||||
|
}
|
||||||
|
|
||||||
if ( \WP_CLI\Utils\get_flag_value( $assoc_args, 'porcelain' ) ) {
|
if ( \WP_CLI\Utils\get_flag_value( $assoc_args, 'porcelain' ) ) {
|
||||||
WP_CLI::line( $body['id'] );
|
WP_CLI::line( $object_id );
|
||||||
} else {
|
} else {
|
||||||
if ( empty( $assoc_args['force'] ) ) {
|
if ( empty( $assoc_args['force'] ) ) {
|
||||||
WP_CLI::success( __( 'Trashed', 'woocommerce' ) . " {$this->name} {$body['id']}" );
|
WP_CLI::success( __( 'Trashed', 'woocommerce' ) . " {$this->name} {$object_id}" );
|
||||||
} else {
|
} else {
|
||||||
WP_CLI::success( __( 'Deleted', 'woocommerce' ) . " {$this->name} {$body['id']}." );
|
WP_CLI::success( __( 'Deleted', 'woocommerce' ) . " {$this->name} {$object_id}." );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -404,7 +409,7 @@ EOT;
|
||||||
|
|
||||||
foreach ( $this->get_supported_ids() as $id_name => $id_desc ) {
|
foreach ( $this->get_supported_ids() as $id_name => $id_desc ) {
|
||||||
if ( 'id' !== $id_name && strpos( $route, '<' . $id_name . '>' ) !== false && ! empty( $args ) ) {
|
if ( 'id' !== $id_name && strpos( $route, '<' . $id_name . '>' ) !== false && ! empty( $args ) ) {
|
||||||
$route = str_replace( '(?P<' . $id_name . '>[\d]+)', $args[0], $route );
|
$route = str_replace( array( '(?P<' . $id_name . '>[\d]+)', '(?P<' . $id_name . '>\w[\w\s\-]*)' ), $args[0], $route );
|
||||||
$supported_id_matched = true;
|
$supported_id_matched = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,10 +115,10 @@ class WC_CLI_Runner {
|
||||||
'zone_id' => __( 'Zone ID.', 'woocommerce' ),
|
'zone_id' => __( 'Zone ID.', 'woocommerce' ),
|
||||||
'instance_id' => __( 'Instance ID.', 'woocommerce' ),
|
'instance_id' => __( 'Instance ID.', 'woocommerce' ),
|
||||||
'id' => __( 'The ID for the resource.', 'woocommerce' ),
|
'id' => __( 'The ID for the resource.', 'woocommerce' ),
|
||||||
|
'slug' => __( 'The slug for the resource.', 'woocommerce' ),
|
||||||
);
|
);
|
||||||
$rest_command->set_supported_ids( $supported_ids );
|
$rest_command->set_supported_ids( $supported_ids );
|
||||||
$positional_args = array_keys( $supported_ids );
|
$positional_args = array_keys( $supported_ids );
|
||||||
|
|
||||||
$parent = "wc {$route_data['schema']['title']}";
|
$parent = "wc {$route_data['schema']['title']}";
|
||||||
$supported_commands = array();
|
$supported_commands = array();
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,11 @@ class WC_REST_Tax_Classes_V1_Controller extends WC_REST_Controller {
|
||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
array(
|
||||||
|
'methods' => WP_REST_Server::READABLE,
|
||||||
|
'callback' => array( $this, 'get_item' ),
|
||||||
|
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||||
|
),
|
||||||
array(
|
array(
|
||||||
'methods' => WP_REST_Server::DELETABLE,
|
'methods' => WP_REST_Server::DELETABLE,
|
||||||
'callback' => array( $this, 'delete_item' ),
|
'callback' => array( $this, 'delete_item' ),
|
||||||
|
@ -157,6 +162,32 @@ class WC_REST_Tax_Classes_V1_Controller extends WC_REST_Controller {
|
||||||
return rest_ensure_response( $data );
|
return rest_ensure_response( $data );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get one tax class.
|
||||||
|
*
|
||||||
|
* @param WP_REST_Request $request
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get_item( $request ) {
|
||||||
|
if ( 'standard' === $request['slug'] ) {
|
||||||
|
$tax_class = array(
|
||||||
|
'slug' => 'standard',
|
||||||
|
'name' => __( 'Standard rate', 'woocommerce' ),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$tax_class = WC_Tax::get_tax_class_by( 'slug', sanitize_title( $request['slug'] ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = array();
|
||||||
|
if ( $tax_class ) {
|
||||||
|
$class = $this->prepare_item_for_response( $tax_class, $request );
|
||||||
|
$class = $this->prepare_response_for_collection( $class );
|
||||||
|
$data[] = $class;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rest_ensure_response( $data );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a single tax class.
|
* Create a single tax class.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue