ID first for all elements in the REST API

cc @mikejolley
This commit is contained in:
Claudio Sanches 2016-08-22 16:58:34 -03:00
parent 0da91bb7d7
commit 38e1be71eb
4 changed files with 52 additions and 52 deletions

View File

@ -165,9 +165,9 @@ abstract class WC_Data {
$meta = (array) $meta;
if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) {
$this->_meta_data[] = (object) array(
'id' => $meta['id'],
'key' => $meta['key'],
'value' => $meta['value'],
'id' => $meta['id'],
);
}
}
@ -206,9 +206,9 @@ abstract class WC_Data {
}
if ( $array_key ) {
$this->_meta_data[ current( $array_key ) ] = (object) array(
'id' => $meta_id,
'key' => $key,
'value' => $value,
'id' => $meta_id,
);
} else {
$this->add_meta_data( $key, $value, true );
@ -272,9 +272,9 @@ abstract class WC_Data {
continue;
}
$this->_meta_data[] = (object) array(
'id' => $meta->{ $db_info['meta_id_field'] },
'key' => $meta->meta_key,
'value' => maybe_unserialize( $meta->meta_value ),
'id' => $meta->{ $db_info['meta_id_field'] },
);
}
}

View File

@ -334,6 +334,12 @@ class WC_REST_Order_Refunds_Controller extends WC_REST_Orders_Controller {
'type' => 'array',
'context' => array( 'view', 'edit' ),
'properties' => array(
'id' => array(
'description' => __( 'Meta ID.', 'woocommerce' ),
'type' => 'int',
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
'key' => array(
'description' => __( 'Meta key.', 'woocommerce' ),
'type' => 'string',
@ -344,12 +350,6 @@ class WC_REST_Order_Refunds_Controller extends WC_REST_Orders_Controller {
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
'id' => array(
'description' => __( 'Meta ID.', 'woocommerce' ),
'type' => 'int',
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
),
),
'line_items' => array(
@ -438,6 +438,12 @@ class WC_REST_Order_Refunds_Controller extends WC_REST_Orders_Controller {
'type' => 'array',
'context' => array( 'view', 'edit' ),
'properties' => array(
'id' => array(
'description' => __( 'Meta ID.', 'woocommerce' ),
'type' => 'int',
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
'key' => array(
'description' => __( 'Meta key.', 'woocommerce' ),
'type' => 'string',
@ -448,12 +454,6 @@ class WC_REST_Order_Refunds_Controller extends WC_REST_Orders_Controller {
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
'id' => array(
'description' => __( 'Meta ID.', 'woocommerce' ),
'type' => 'int',
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
),
),
'sku' => array(

View File

@ -1061,6 +1061,12 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
'type' => 'array',
'context' => array( 'view', 'edit' ),
'properties' => array(
'id' => array(
'description' => __( 'Meta ID.', 'woocommerce' ),
'type' => 'int',
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
'key' => array(
'description' => __( 'Meta key.', 'woocommerce' ),
'type' => 'string',
@ -1071,12 +1077,6 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
'id' => array(
'description' => __( 'Meta ID.', 'woocommerce' ),
'type' => 'int',
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
),
),
'line_items' => array(
@ -1165,6 +1165,12 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
'type' => 'array',
'context' => array( 'view', 'edit' ),
'properties' => array(
'id' => array(
'description' => __( 'Meta ID.', 'woocommerce' ),
'type' => 'int',
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
'key' => array(
'description' => __( 'Meta key.', 'woocommerce' ),
'type' => 'string',
@ -1175,12 +1181,6 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
'id' => array(
'description' => __( 'Meta ID.', 'woocommerce' ),
'type' => 'int',
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
),
),
'sku' => array(
@ -1276,6 +1276,12 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
'type' => 'array',
'context' => array( 'view', 'edit' ),
'properties' => array(
'id' => array(
'description' => __( 'Meta ID.', 'woocommerce' ),
'type' => 'int',
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
'key' => array(
'description' => __( 'Meta key.', 'woocommerce' ),
'type' => 'string',
@ -1286,12 +1292,6 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
'id' => array(
'description' => __( 'Meta ID.', 'woocommerce' ),
'type' => 'int',
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
),
),
),
@ -1353,6 +1353,12 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
'type' => 'array',
'context' => array( 'view', 'edit' ),
'properties' => array(
'id' => array(
'description' => __( 'Meta ID.', 'woocommerce' ),
'type' => 'int',
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
'key' => array(
'description' => __( 'Meta key.', 'woocommerce' ),
'type' => 'string',
@ -1363,12 +1369,6 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
'id' => array(
'description' => __( 'Meta ID.', 'woocommerce' ),
'type' => 'int',
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
),
),
),
@ -1442,6 +1442,12 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
'type' => 'array',
'context' => array( 'view', 'edit' ),
'properties' => array(
'id' => array(
'description' => __( 'Meta ID.', 'woocommerce' ),
'type' => 'int',
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
'key' => array(
'description' => __( 'Meta key.', 'woocommerce' ),
'type' => 'string',
@ -1452,12 +1458,6 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
'id' => array(
'description' => __( 'Meta ID.', 'woocommerce' ),
'type' => 'int',
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
),
),
),
@ -1494,6 +1494,12 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
'type' => 'array',
'context' => array( 'view', 'edit' ),
'properties' => array(
'id' => array(
'description' => __( 'Meta ID.', 'woocommerce' ),
'type' => 'int',
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
'key' => array(
'description' => __( 'Meta key.', 'woocommerce' ),
'type' => 'string',
@ -1504,12 +1510,6 @@ class WC_REST_Orders_Controller extends WC_REST_Posts_Controller {
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
'id' => array(
'description' => __( 'Meta ID.', 'woocommerce' ),
'type' => 'int',
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
),
),
),

View File

@ -94,9 +94,9 @@ class WC_Tests_CRUD_Meta extends WC_Unit_Test_Case {
foreach ( $raw_metadata as $meta ) {
$metadata[] = (object) array(
'id' => $meta->meta_id,
'key' => $meta->meta_key,
'value' => $meta->meta_value,
'id' => $meta->meta_id,
);
}