| 1 |
<?php |
| 2 |
namespace StoreEngine\API\Schema; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
trait CartSchema { |
| 9 |
|
| 10 |
public function get_public_item_schema() { |
| 11 |
$schema = array( |
| 12 |
'$schema' => 'http://json-schema.org/draft-04/schema#', |
| 13 |
'title' => 'order', |
| 14 |
'type' => 'object', |
| 15 |
'properties' => array( |
| 16 |
'cart_id' => [ |
| 17 |
'type' => 'integer', |
| 18 |
'sanitize_callback' => 'absint', |
| 19 |
'validate_callback' => 'rest_validate_request_arg', |
| 20 |
], |
| 21 |
|
| 22 |
'user_id' => [ |
| 23 |
'type' => 'integer', |
| 24 |
'sanitize_callback' => 'absint', |
| 25 |
'validate_callback' => 'rest_validate_request_arg', |
| 26 |
], |
| 27 |
'cart_data' => [ |
| 28 |
'type' => 'stringstring', |
| 29 |
'sanitize_callback' => 'absint', |
| 30 |
'validate_callback' => 'rest_validate_request_arg', |
| 31 |
], |
| 32 |
'cart_hash' => [ |
| 33 |
'type' => 'string', |
| 34 |
'sanitize_callback' => 'absint', |
| 35 |
'validate_callback' => 'rest_validate_request_arg', |
| 36 |
], |
| 37 |
'date_created' => [ |
| 38 |
'type' => 'string', |
| 39 |
'format' => 'date-time', |
| 40 |
'sanitize_callback' => 'sanitize_text_field', |
| 41 |
], |
| 42 |
'date_modified' => [ |
| 43 |
'type' => 'string', |
| 44 |
'format' => 'date-time', |
| 45 |
'sanitize_callback' => 'sanitize_text_field', |
| 46 |
], |
| 47 |
), |
| 48 |
); |
| 49 |
|
| 50 |
return apply_filters( 'storeengine/api/cart/get_public_cart_schema', $schema ); |
| 51 |
} |
| 52 |
|
| 53 |
public function get_post_cart_schema() { |
| 54 |
$schema = [ |
| 55 |
'cart_id' => [ |
| 56 |
'type' => 'integer', |
| 57 |
'sanitize_callback' => 'absint', |
| 58 |
'validate_callback' => 'rest_validate_request_arg', |
| 59 |
], |
| 60 |
|
| 61 |
'user_id' => [ |
| 62 |
'type' => 'integer', |
| 63 |
'sanitize_callback' => 'absint', |
| 64 |
'validate_callback' => 'rest_validate_request_arg', |
| 65 |
], |
| 66 |
'cart_data' => [ |
| 67 |
'type' => 'string', |
| 68 |
'sanitize_callback' => 'absint', |
| 69 |
'validate_callback' => 'rest_validate_request_arg', |
| 70 |
], |
| 71 |
'cart_hash' => [ |
| 72 |
'type' => 'string', |
| 73 |
'sanitize_callback' => 'absint', |
| 74 |
'validate_callback' => 'rest_validate_request_arg', |
| 75 |
], |
| 76 |
'date_created' => [ |
| 77 |
'type' => 'string', |
| 78 |
'format' => 'date-time', |
| 79 |
'sanitize_callback' => 'sanitize_text_field', |
| 80 |
], |
| 81 |
'date_modified' => [ |
| 82 |
'type' => 'string', |
| 83 |
'format' => 'date-time', |
| 84 |
'sanitize_callback' => 'sanitize_text_field', |
| 85 |
], |
| 86 |
|
| 87 |
]; |
| 88 |
return apply_filters( 'storeengine/api/cart/cart_schema', $schema ); |
| 89 |
} |
| 90 |
|
| 91 |
public function get_cart_schema() { |
| 92 |
if ( $this->schema ) { |
| 93 |
return $this->add_additional_fields_schema( $this->schema ); |
| 94 |
} |
| 95 |
|
| 96 |
$schema = [ |
| 97 |
'$schema' => 'http://json-schema.org/draft-04/schema#', |
| 98 |
'title' => 'order', |
| 99 |
'type' => 'object', |
| 100 |
'properties' => [ |
| 101 |
'cart_id' => [ |
| 102 |
'type' => 'integer', |
| 103 |
'sanitize_callback' => 'absint', |
| 104 |
'validate_callback' => 'rest_validate_request_arg', |
| 105 |
], |
| 106 |
|
| 107 |
'user_id' => [ |
| 108 |
'type' => 'integer', |
| 109 |
'sanitize_callback' => 'absint', |
| 110 |
'validate_callback' => 'rest_validate_request_arg', |
| 111 |
], |
| 112 |
'cart_data' => [ |
| 113 |
'type' => 'stringstring', |
| 114 |
'sanitize_callback' => 'absint', |
| 115 |
'validate_callback' => 'rest_validate_request_arg', |
| 116 |
], |
| 117 |
'cart_hash' => [ |
| 118 |
'type' => 'string', |
| 119 |
'sanitize_callback' => 'absint', |
| 120 |
'validate_callback' => 'rest_validate_request_arg', |
| 121 |
], |
| 122 |
], |
| 123 |
]; |
| 124 |
|
| 125 |
$this->schema = $schema; |
| 126 |
|
| 127 |
return $this->add_additional_fields_schema( $this->schema ); |
| 128 |
} |
| 129 |
} |
| 130 |
|