|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Schema for wc/cc-woo/abandoned-carts endpoint. |
| 4 | + * |
| 5 | + * @package WebDevStudios\CCForWoo\Rest\AbandonedCarts |
| 6 | + * @since 2019-11-13 |
| 7 | + */ |
| 8 | + |
| 9 | +namespace WebDevStudios\CCForWoo\Rest\AbandonedCarts; |
| 10 | + |
| 11 | +/** |
| 12 | + * Class AbandonedCarts\Schema |
| 13 | + * |
| 14 | + * @package WebDevStudios\CCForWoo\Rest\AbandonedCarts |
| 15 | + * @since 2019-11-13 |
| 16 | + */ |
| 17 | +class Schema { |
| 18 | + |
| 19 | + /** |
| 20 | + * Get the query params for Abandoned Carts. |
| 21 | + * |
| 22 | + * @author George Gecewicz <[email protected]> |
| 23 | + * @since 2019-11-13 |
| 24 | + * |
| 25 | + * @return array |
| 26 | + */ |
| 27 | + public static function get_collection_params() { |
| 28 | + return [ |
| 29 | + 'page' => [ |
| 30 | + 'description' => esc_html__( 'Current page of paginated results.', 'woocommerce' ), |
| 31 | + 'required' => false, |
| 32 | + 'type' => 'integer', |
| 33 | + ], |
| 34 | + 'per_page' => [ |
| 35 | + 'description' => esc_html__( 'How many abandoned carts to show per page.', 'woocommerce' ), |
| 36 | + 'required' => false, |
| 37 | + 'type' => 'integer', |
| 38 | + 'default' => 10, |
| 39 | + ], |
| 40 | + 'date_min' => [ |
| 41 | + 'description' => esc_html__( 'Filters results to only show abandoned carts created after this date. Accepts dates in any format acceptable for comparison of MySQL DATETIME column values.', 'woocommerce' ), |
| 42 | + 'required' => false, |
| 43 | + 'type' => 'string', |
| 44 | + ], |
| 45 | + 'date_max' => [ |
| 46 | + 'description' => esc_html__( 'Filters results to only show abandoned carts created before this date. Accepts dates in any format acceptable for comparison of MySQL DATETIME column values.', 'woocommerce' ), |
| 47 | + 'required' => false, |
| 48 | + 'type' => 'string', |
| 49 | + ], |
| 50 | + ]; |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * Get the Abandoned Cart's schema for public consumption. |
| 55 | + * |
| 56 | + * @author George Gecewicz <[email protected]> |
| 57 | + * @since 2019-11-13 |
| 58 | + * |
| 59 | + * @return array |
| 60 | + */ |
| 61 | + public static function get_public_item_schema() { |
| 62 | + return [ |
| 63 | + '$schema' => 'http://json-schema.org/draft-04/schema#', |
| 64 | + 'title' => 'cc_woo_abandoned_cart', |
| 65 | + 'type' => 'object', |
| 66 | + 'properties' => [ |
| 67 | + 'cart_id' => [ |
| 68 | + 'description' => esc_html__( 'Database ID for the abandoned cart.', 'cc-woo' ), |
| 69 | + 'type' => 'integer', |
| 70 | + 'context' => [ 'view' ], |
| 71 | + 'readonly' => true, |
| 72 | + ], |
| 73 | + 'user_id' => [ |
| 74 | + 'description' => esc_html__( 'WordPress user ID of the user the cart belongs to; defaults to 0 if a guest or non-logged-in user.', 'cc-woo' ), |
| 75 | + 'type' => 'integer', |
| 76 | + 'context' => [ 'view' ], |
| 77 | + 'readonly' => true, |
| 78 | + ], |
| 79 | + 'user_email' => [ |
| 80 | + 'description' => esc_html__( 'The billing email the user entered at checkout before abandoning it. Note that this may be different than the email address the user has in their WordPress user profile.', 'cc-woo' ), |
| 81 | + 'type' => 'string', |
| 82 | + 'context' => [ 'view' ], |
| 83 | + 'readonly' => true, |
| 84 | + ], |
| 85 | + 'cart_contents' => [ |
| 86 | + 'description' => esc_html__( 'Object representation of the cart that was abandoned, and its contents, coupon codes, and billing data.', 'cc-woo' ), |
| 87 | + 'type' => 'object', |
| 88 | + 'context' => [ 'view' ], |
| 89 | + 'readonly' => true, |
| 90 | + 'properties' => [ |
| 91 | + 'products' => [ |
| 92 | + 'description' => esc_html__( 'Key-value listing of products in the cart. Keys are unique WooCommerce-generated keys identifying the cart in the database; values are objects representing the items in the cart.', 'cc-woo' ), |
| 93 | + 'type' => 'array', |
| 94 | + 'context' => [ 'view' ], |
| 95 | + 'readonly' => true, |
| 96 | + 'properties' => self::get_products_properties(), |
| 97 | + ], |
| 98 | + 'coupons' => [ |
| 99 | + 'description' => esc_html__( 'Array of coupon code strings used in the checkout.', 'cc-woo' ), |
| 100 | + 'type' => 'array', |
| 101 | + 'context' => [ 'view' ], |
| 102 | + 'readonly' => true, |
| 103 | + ], |
| 104 | + ], |
| 105 | + ], |
| 106 | + 'cart_updated' => [ |
| 107 | + 'description' => esc_html__( 'The MySQL-format datetime of when the cart was last updated, in GMT+0 time zone.', 'cc-woo' ), |
| 108 | + 'type' => 'string', |
| 109 | + 'context' => [ 'view' ], |
| 110 | + 'readonly' => true, |
| 111 | + ], |
| 112 | + 'cart_updated_ts' => [ |
| 113 | + 'description' => esc_html__( 'Unix timestamp of when the cart was last updated, in GMT+0 time zone.', 'cc-woo' ), |
| 114 | + 'type' => 'string', |
| 115 | + 'context' => [ 'view' ], |
| 116 | + 'readonly' => true, |
| 117 | + ], |
| 118 | + 'cart_created' => [ |
| 119 | + 'description' => esc_html__( 'The MySQL-format datetime of when the cart was first created, in GMT+0 time zone.', 'cc-woo' ), |
| 120 | + 'type' => 'string', |
| 121 | + 'context' => [ 'view' ], |
| 122 | + 'readonly' => true, |
| 123 | + ], |
| 124 | + 'cart_created_ts' => [ |
| 125 | + 'description' => esc_html__( 'Unix timestamp of when the cart was first created, in GMT+0 time zone.', 'cc-woo' ), |
| 126 | + 'type' => 'string', |
| 127 | + 'context' => [ 'view' ], |
| 128 | + 'readonly' => true, |
| 129 | + ], |
| 130 | + 'cart_hash' => [ |
| 131 | + 'description' => esc_html__( 'MD5 hash of cart\'s user ID and email address.', 'cc-woo' ), |
| 132 | + 'type' => 'string', |
| 133 | + 'context' => [ 'view' ], |
| 134 | + 'readonly' => true, |
| 135 | + ], |
| 136 | + 'cart_subtotal' => [ |
| 137 | + 'description' => esc_html__( 'Cart subtotal.', 'cc-woo' ), |
| 138 | + 'type' => 'string', |
| 139 | + 'context' => [ 'view' ], |
| 140 | + 'readonly' => true, |
| 141 | + ], |
| 142 | + 'cart_total' => [ |
| 143 | + 'description' => esc_html__( 'Cart total.', 'cc-woo' ), |
| 144 | + 'type' => 'string', |
| 145 | + 'context' => [ 'view' ], |
| 146 | + 'readonly' => true, |
| 147 | + ], |
| 148 | + 'cart_subtotal_tax' => [ |
| 149 | + 'description' => esc_html__( 'Cart subtotal tax.', 'cc-woo' ), |
| 150 | + 'type' => 'string', |
| 151 | + 'context' => [ 'view' ], |
| 152 | + 'readonly' => true, |
| 153 | + ], |
| 154 | + 'cart_total_tax' => [ |
| 155 | + 'description' => esc_html__( 'Cart total tax.', 'cc-woo' ), |
| 156 | + 'type' => 'string', |
| 157 | + 'context' => [ 'view' ], |
| 158 | + 'readonly' => true, |
| 159 | + ], |
| 160 | + 'cart_recovery_url' => [ |
| 161 | + 'description' => esc_html__( 'Recovery URL that recreates cart the cart for checkout when visited.', 'cc-woo' ), |
| 162 | + 'type' => 'string', |
| 163 | + 'context' => [ 'view' ], |
| 164 | + 'readonly' => true, |
| 165 | + ], |
| 166 | + ] |
| 167 | + ]; |
| 168 | + } |
| 169 | + |
| 170 | + /** |
| 171 | + * Get properties for individual Products definition in Schema. |
| 172 | + * |
| 173 | + * @author George Gecewicz <[email protected]> |
| 174 | + * @since 2019-11-13 |
| 175 | + * |
| 176 | + * @return array |
| 177 | + */ |
| 178 | + public static function get_products_properties() { |
| 179 | + return [ |
| 180 | + 'key' => [ |
| 181 | + 'description' => esc_html__( 'Unique WooCommerce-generated key identifying the cart in the database. This differs from the parent-level cart_hash property.', 'cc-woo' ), |
| 182 | + 'type' => 'string', |
| 183 | + 'context' => [ 'view' ], |
| 184 | + 'readonly' => true, |
| 185 | + ], |
| 186 | + 'product_id' => [ |
| 187 | + 'description' => esc_html__( 'The WooCommerce product ID.', 'cc-woo' ), |
| 188 | + 'type' => 'integer', |
| 189 | + 'context' => [ 'view' ], |
| 190 | + 'readonly' => true, |
| 191 | + ], |
| 192 | + 'variation_id' => [ |
| 193 | + 'description' => esc_html__( 'The WooCommerce product variation ID, if applicable.', 'cc-woo' ), |
| 194 | + 'type' => 'integer', |
| 195 | + 'context' => [ 'view' ], |
| 196 | + 'readonly' => true, |
| 197 | + ], |
| 198 | + 'variation' => [ |
| 199 | + 'description' => esc_html__( 'Object representation of any applicable variations, where keys are variation names and values are the actual variation selection.', 'cc-woo' ), |
| 200 | + 'type' => 'object', |
| 201 | + 'context' => [ 'view' ], |
| 202 | + 'readonly' => true, |
| 203 | + ], |
| 204 | + 'quantity' => [ |
| 205 | + 'description' => esc_html__( 'Item quantity.', 'cc-woo' ), |
| 206 | + 'type' => 'integer', |
| 207 | + 'context' => [ 'view' ], |
| 208 | + 'readonly' => true, |
| 209 | + ], |
| 210 | + 'data_hash' => [ |
| 211 | + 'description' => esc_html__( 'MD5 hash of cart items to determine if contents are modified.', 'cc-woo' ), |
| 212 | + 'type' => 'string', |
| 213 | + 'context' => [ 'view' ], |
| 214 | + 'readonly' => true, |
| 215 | + ], |
| 216 | + 'line_tax_data' => [ |
| 217 | + 'description' => esc_html__( 'Line subtotal tax and total tax data.', 'cc-woo' ), |
| 218 | + 'type' => 'object', |
| 219 | + 'context' => [ 'view' ], |
| 220 | + 'readonly' => true, |
| 221 | + 'properties' => [ |
| 222 | + 'subtotal' => [ |
| 223 | + 'description' => esc_html__( 'Line subtotal tax data.', 'cc-woo' ), |
| 224 | + 'type' => 'string', |
| 225 | + 'context' => [ 'view' ], |
| 226 | + 'readonly' => true, |
| 227 | + ], |
| 228 | + 'total' => [ |
| 229 | + 'description' => esc_html__( 'Line total tax data.', 'cc-woo' ), |
| 230 | + 'type' => 'string', |
| 231 | + 'context' => [ 'view' ], |
| 232 | + 'readonly' => true, |
| 233 | + ], |
| 234 | + ] |
| 235 | + ], |
| 236 | + 'line_subtotal' => [ |
| 237 | + 'description' => esc_html__( 'Line subtotal.', 'cc-woo' ), |
| 238 | + 'type' => 'string', |
| 239 | + 'context' => [ 'view' ], |
| 240 | + 'readonly' => true, |
| 241 | + ], |
| 242 | + 'line_subtotal_tax' => [ |
| 243 | + 'description' => esc_html__( 'Line subtotal tax.', 'cc-woo' ), |
| 244 | + 'type' => 'string', |
| 245 | + 'context' => [ 'view' ], |
| 246 | + 'readonly' => true, |
| 247 | + ], |
| 248 | + 'line_total' => [ |
| 249 | + 'description' => esc_html__( 'Line total.', 'cc-woo' ), |
| 250 | + 'type' => 'string', |
| 251 | + 'context' => [ 'view' ], |
| 252 | + 'readonly' => true, |
| 253 | + ], |
| 254 | + 'line_tax' => [ |
| 255 | + 'description' => esc_html__( 'Line total tax.', 'cc-woo' ), |
| 256 | + 'type' => 'string', |
| 257 | + 'context' => [ 'view' ], |
| 258 | + 'readonly' => true, |
| 259 | + ], |
| 260 | + 'data' => [ |
| 261 | + 'description' => esc_html__( 'Misc. product data in key-value pairs.', 'cc-woo' ), |
| 262 | + 'type' => 'object', |
| 263 | + 'context' => [ 'view' ], |
| 264 | + 'readonly' => true, |
| 265 | + ], |
| 266 | + 'product_title' => [ |
| 267 | + 'description' => esc_html__( 'The product title.', 'cc-woo' ), |
| 268 | + 'type' => 'string', |
| 269 | + 'context' => [ 'view' ], |
| 270 | + 'readonly' => true, |
| 271 | + ], |
| 272 | + 'product_sku' => [ |
| 273 | + 'description' => esc_html__( 'The product SKU.', 'cc-woo' ), |
| 274 | + 'type' => 'string', |
| 275 | + 'context' => [ 'view' ], |
| 276 | + 'readonly' => true, |
| 277 | + ], |
| 278 | + 'product_permalink' => [ |
| 279 | + 'description' => esc_html__( 'Permalink to the product page.', 'cc-woo' ), |
| 280 | + 'type' => 'string', |
| 281 | + 'context' => [ 'view' ], |
| 282 | + 'readonly' => true, |
| 283 | + ], |
| 284 | + 'product_image_url' => [ |
| 285 | + 'description' => esc_html__( 'URL to the full-size featured image for the product if one exists.', 'cc-woo' ), |
| 286 | + 'type' => 'string', |
| 287 | + 'context' => [ 'view' ], |
| 288 | + 'readonly' => true, |
| 289 | + ] |
| 290 | + ]; |
| 291 | + } |
| 292 | + |
| 293 | +} |
0 commit comments