Skip to content

Commit

Permalink
Merge pull request woocommerce#17258 from woocommerce/fix/17249
Browse files Browse the repository at this point in the history
[REST API] Fixed variations 'visible' description in schema
  • Loading branch information
mikejolley authored Oct 17, 2017
2 parents 0284bf6 + c739c80 commit c762a63
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions includes/api/class-wc-rest-product-variations-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
class WC_REST_Product_Variations_Controller extends WC_REST_Products_Controller {

/**
* Endpoint namespace.
* Endpoint namespace.
*
* @var string
*/
Expand Down Expand Up @@ -92,7 +92,9 @@ public function register_routes() {
'callback' => array( $this, 'get_item' ),
'permission_callback' => array( $this, 'get_item_permissions_check' ),
'args' => array(
'context' => $this->get_context_param( array( 'default' => 'view' ) ),
'context' => $this->get_context_param( array(
'default' => 'view',
) ),
),
),
array(
Expand Down Expand Up @@ -396,7 +398,9 @@ protected function prepare_object_for_database( $request, $creating = false ) {

if ( $parent_attributes[ $attribute_name ]->is_taxonomy() ) {
// If dealing with a taxonomy, we need to get the slug from the name posted to the API.
// @codingStandardsIgnoreStart
$term = get_term_by( 'name', $attribute_value, $attribute_name );
// @codingStandardsIgnoreEnd

if ( $term && ! is_wp_error( $term ) ) {
$attribute_value = $term->slug;
Expand Down Expand Up @@ -449,7 +453,7 @@ public function clear_transients( $object ) {
/**
* Delete a variation.
*
* @param WP_REST_Request $request Full details about the request
* @param WP_REST_Request $request Full details about the request.
*
* @return bool|WP_Error|WP_REST_Response
*/
Expand All @@ -459,7 +463,9 @@ public function delete_item( $request ) {
$result = false;

if ( ! $object || 0 === $object->get_id() ) {
return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce' ), array( 'status' => 404 ) );
return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce' ), array(
'status' => 404,
) );
}

$supports_trash = EMPTY_TRASH_DAYS > 0 && is_callable( array( $object, 'get_status' ) );
Expand All @@ -476,7 +482,9 @@ public function delete_item( $request ) {

if ( ! wc_rest_check_post_permissions( $this->post_type, 'delete', $object->get_id() ) ) {
/* translators: %s: post type */
return new WP_Error( "woocommerce_rest_user_cannot_delete_{$this->post_type}", sprintf( __( 'Sorry, you are not allowed to delete %s.', 'woocommerce' ), $this->post_type ), array( 'status' => rest_authorization_required_code() ) );
return new WP_Error( "woocommerce_rest_user_cannot_delete_{$this->post_type}", sprintf( __( 'Sorry, you are not allowed to delete %s.', 'woocommerce' ), $this->post_type ), array(
'status' => rest_authorization_required_code(),
) );
}

$request->set_param( 'context', 'edit' );
Expand All @@ -490,14 +498,18 @@ public function delete_item( $request ) {
// If we don't support trashing for this type, error out.
if ( ! $supports_trash ) {
/* translators: %s: post type */
return new WP_Error( 'woocommerce_rest_trash_not_supported', sprintf( __( 'The %s does not support trashing.', 'woocommerce' ), $this->post_type ), array( 'status' => 501 ) );
return new WP_Error( 'woocommerce_rest_trash_not_supported', sprintf( __( 'The %s does not support trashing.', 'woocommerce' ), $this->post_type ), array(
'status' => 501,
) );
}

// Otherwise, only trash if we haven't already.
if ( is_callable( array( $object, 'get_status' ) ) ) {
if ( 'trash' === $object->get_status() ) {
/* translators: %s: post type */
return new WP_Error( 'woocommerce_rest_already_trashed', sprintf( __( 'The %s has already been deleted.', 'woocommerce' ), $this->post_type ), array( 'status' => 410 ) );
return new WP_Error( 'woocommerce_rest_already_trashed', sprintf( __( 'The %s has already been deleted.', 'woocommerce' ), $this->post_type ), array(
'status' => 410,
) );
}

$object->delete();
Expand All @@ -507,7 +519,9 @@ public function delete_item( $request ) {

if ( ! $result ) {
/* translators: %s: post type */
return new WP_Error( 'woocommerce_rest_cannot_delete', sprintf( __( 'The %s cannot be deleted.', 'woocommerce' ), $this->post_type ), array( 'status' => 500 ) );
return new WP_Error( 'woocommerce_rest_cannot_delete', sprintf( __( 'The %s cannot be deleted.', 'woocommerce' ), $this->post_type ), array(
'status' => 500,
) );
}

// Delete parent product transients.
Expand Down Expand Up @@ -544,7 +558,9 @@ public function batch_items( $request ) {
if ( ! empty( $items[ $batch_type ] ) ) {
$injected_items = array();
foreach ( $items[ $batch_type ] as $item ) {
$injected_items[] = is_array( $item ) ? array_merge( array( 'product_id' => $product_id ), $item ) : $item;
$injected_items[] = is_array( $item ) ? array_merge( array(
'product_id' => $product_id,
), $item ) : $item;
}
$body_params[ $batch_type ] = $injected_items;
}
Expand Down Expand Up @@ -671,7 +687,7 @@ public function get_item_schema() {
'readonly' => true,
),
'visible' => array(
'description' => __( "Define if the attribute is visible on the \"Additional information\" tab in the product's page.", 'woocommerce' ),
'description' => __( "Define if the variation is visible on the product's page.", 'woocommerce' ),
'type' => 'boolean',
'default' => true,
'context' => array( 'view', 'edit' ),
Expand Down

0 comments on commit c762a63

Please sign in to comment.