From a7cee6b6429ee15abe5693961f0156dd6ff9a710 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Fri, 3 Jun 2016 14:56:25 -0300 Subject: [PATCH 1/3] [REST API] Allow filters schemas, closes #11028 --- .../abstracts/abstract-wc-rest-controller.php | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/includes/abstracts/abstract-wc-rest-controller.php b/includes/abstracts/abstract-wc-rest-controller.php index 4beefaed2ef..9f90156f4f4 100644 --- a/includes/abstracts/abstract-wc-rest-controller.php +++ b/includes/abstracts/abstract-wc-rest-controller.php @@ -29,6 +29,38 @@ abstract class WC_REST_Controller extends WP_REST_Controller { */ protected $rest_base = ''; + /** + * Add the schema from additional fields to an schema array. + * + * The type of object is inferred from the passed schema. + * + * @param array $schema Schema array. + */ + protected function add_additional_fields_schema( $schema ) { + if ( empty( $schema['title'] ) ) { + return $schema; + } + + /** + * Can't use $this->get_object_type otherwise we cause an inf loop. + */ + $object_type = $schema['title']; + + $additional_fields = $this->get_additional_fields( $object_type ); + + foreach ( $additional_fields as $field_name => $field_options ) { + if ( ! $field_options['schema'] ) { + continue; + } + + $schema['properties'][ $field_name ] = $field_options['schema']; + } + + $schema['properties'] = apply_filters( 'woocommerce_rest_' . $object_type . '_schema', $schema['properties'] ); + + return $schema; + } + /** * Get normalized rest base. * From d85fd0bcd56011af83348c5f463f69e17c7063d9 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Sat, 4 Jun 2016 10:34:37 -0300 Subject: [PATCH 2/3] [REST API] Fixed product backordered description --- includes/api/class-wc-rest-products-controller.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/api/class-wc-rest-products-controller.php b/includes/api/class-wc-rest-products-controller.php index 021ebe0eb6e..89da9c7a377 100644 --- a/includes/api/class-wc-rest-products-controller.php +++ b/includes/api/class-wc-rest-products-controller.php @@ -1946,7 +1946,7 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller { 'readonly' => true, ), 'backordered' => array( - 'description' => __( 'Shows if a product is on backorder.', 'woocommerce' ), + 'description' => __( 'Shows if the product is on backordered.', 'woocommerce' ), 'type' => 'boolean', 'context' => array( 'view', 'edit' ), 'readonly' => true, @@ -2368,7 +2368,7 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller { 'readonly' => true, ), 'backordered' => array( - 'description' => __( 'Shows if a variation is on backorder.', 'woocommerce' ), + 'description' => __( 'Shows if the variation is on backordered.', 'woocommerce' ), 'type' => 'boolean', 'context' => array( 'view', 'edit' ), 'readonly' => true, From 83a843a7061cee3ec3bf98b78b532b443a82078f Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Sun, 5 Jun 2016 15:17:29 -0300 Subject: [PATCH 3/3] [REST API] Changed "product title" to "product name" --- .../api/class-wc-rest-report-top-sellers-controller.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/api/class-wc-rest-report-top-sellers-controller.php b/includes/api/class-wc-rest-report-top-sellers-controller.php index 5fee090d14b..4239e64d0ce 100644 --- a/includes/api/class-wc-rest-report-top-sellers-controller.php +++ b/includes/api/class-wc-rest-report-top-sellers-controller.php @@ -80,7 +80,7 @@ class WC_REST_Report_Top_Sellers_Controller extends WC_REST_Report_Sales_Control if ( $product ) { $top_sellers[] = array( - 'title' => $product->get_title(), + 'name' => $product->get_title(), 'product_id' => (int) $item->product_id, 'quantity' => wc_stock_amount( $item->order_item_qty ), ); @@ -105,7 +105,7 @@ class WC_REST_Report_Top_Sellers_Controller extends WC_REST_Report_Sales_Control */ public function prepare_item_for_response( $top_seller, $request ) { $data = array( - 'title' => $top_seller->title, + 'name' => $top_seller->name, 'product_id' => $top_seller->product_id, 'quantity' => $top_seller->quantity, ); @@ -148,8 +148,8 @@ class WC_REST_Report_Top_Sellers_Controller extends WC_REST_Report_Sales_Control 'title' => 'top_sellers_report', 'type' => 'object', 'properties' => array( - 'title' => array( - 'description' => __( 'Product title.', 'woocommerce' ), + 'name' => array( + 'description' => __( 'Product name.', 'woocommerce' ), 'type' => 'string', 'context' => array( 'view' ), 'readonly' => true,