Skip to content

Commit a20e349

Browse files
committed
move schema into separate class for readability
1 parent 6444e1f commit a20e349

File tree

2 files changed

+269
-248
lines changed

2 files changed

+269
-248
lines changed

src/Rest/AbandonedCarts/Controller.php

Lines changed: 3 additions & 248 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<?php
22
/**
3-
* REST API endpoint for collection of Abandoned Carts.
3+
* Controller for wc/cc-woo/abandoned-carts endpoint.
44
*
5-
* @author George Gecewicz <[email protected]>
65
* @package WebDevStudios\CCForWoo\Rest\AbandonedCarts
76
* @since 2019-10-16
87
*/
@@ -23,7 +22,6 @@
2322
/**
2423
* Class AbandonedCarts\Controller
2524
*
26-
* @author George Gecewicz <[email protected]>
2725
* @package WebDevStudios\CCForWoo\Rest\AbandonedCarts
2826
* @since 2019-10-16
2927
*/
@@ -63,9 +61,9 @@ public function register_routes() {
6361
'methods' => WP_REST_Server::READABLE,
6462
'callback' => [ $this, 'get_items' ],
6563
'permission_callback' => [ $this, 'get_items_permissions_check' ],
66-
'args' => $this->get_collection_params(),
64+
'args' => Schema::get_collection_params(),
6765
],
68-
'schema' => [ $this, 'get_public_item_schema' ],
66+
'schema' => [ '\WebDevStudios\CCForWoo\Rest\AbandonedCarts\Schema', 'get_public_item_schema' ],
6967
]
7068
);
7169
}
@@ -342,248 +340,5 @@ private function get_product_image_url( WC_Product $wc_product ) : string {
342340
return wp_get_attachment_url( $wc_product->get_image_id() );
343341
}
344342

345-
/**
346-
* Get the Abandoned Cart's schema for public consumption.
347-
*
348-
* @return array
349-
*/
350-
public function get_item_schema() {
351-
return [
352-
'$schema' => 'http://json-schema.org/draft-04/schema#',
353-
'title' => 'cc_woo_abandoned_cart',
354-
'type' => 'object',
355-
'properties' => [
356-
'cart_id' => [
357-
'description' => esc_html__( 'Database ID for the abandoned cart.', 'cc-woo' ),
358-
'type' => 'integer',
359-
'context' => [ 'view' ],
360-
'readonly' => true,
361-
],
362-
'user_id' => [
363-
'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' ),
364-
'type' => 'integer',
365-
'context' => [ 'view' ],
366-
'readonly' => true,
367-
],
368-
'user_email' => [
369-
'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' ),
370-
'type' => 'string',
371-
'context' => [ 'view' ],
372-
'readonly' => true,
373-
],
374-
'cart_contents' => [
375-
'description' => esc_html__( 'Object representation of the cart that was abandoned, and its contents, coupon codes, and billing data.', 'cc-woo' ),
376-
'type' => 'object',
377-
'context' => [ 'view' ],
378-
'readonly' => true,
379-
'properties' => [
380-
'products' => [
381-
'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' ),
382-
'type' => 'array',
383-
'context' => [ 'view' ],
384-
'readonly' => true,
385-
'properties' => [
386-
[
387-
'key' => [
388-
'description' => esc_html__( 'Unique WooCommerce-generated key identifying the cart in the database. This differs from the parent-level cart_hash property.', 'cc-woo' ),
389-
'type' => 'string',
390-
'context' => [ 'view' ],
391-
'readonly' => true,
392-
],
393-
'product_id' => [
394-
'description' => esc_html__( 'The WooCommerce product ID.', 'cc-woo' ),
395-
'type' => 'integer',
396-
'context' => [ 'view' ],
397-
'readonly' => true,
398-
],
399-
'variation_id' => [
400-
'description' => esc_html__( 'The WooCommerce product variation ID, if applicable.', 'cc-woo' ),
401-
'type' => 'integer',
402-
'context' => [ 'view' ],
403-
'readonly' => true,
404-
],
405-
'variation' => [
406-
'description' => esc_html__( 'Object representation of any applicable variations, where keys are variation names and values are the actual variation selection.', 'cc-woo' ),
407-
'type' => 'object',
408-
'context' => [ 'view' ],
409-
'readonly' => true,
410-
],
411-
'quantity' => [
412-
'description' => esc_html__( 'Item quantity.', 'cc-woo' ),
413-
'type' => 'integer',
414-
'context' => [ 'view' ],
415-
'readonly' => true,
416-
],
417-
'data_hash' => [
418-
'description' => esc_html__( 'MD5 hash of cart items to determine if contents are modified.', 'cc-woo' ),
419-
'type' => 'string',
420-
'context' => [ 'view' ],
421-
'readonly' => true,
422-
],
423-
'line_tax_data' => [
424-
'description' => esc_html__( 'Line subtotal tax and total tax data.', 'cc-woo' ),
425-
'type' => 'object',
426-
'context' => [ 'view' ],
427-
'readonly' => true,
428-
'properties' => [
429-
'subtotal' => [
430-
'description' => esc_html__( 'Line subtotal tax data.', 'cc-woo' ),
431-
'type' => 'string',
432-
'context' => [ 'view' ],
433-
'readonly' => true,
434-
],
435-
'total' => [
436-
'description' => esc_html__( 'Line total tax data.', 'cc-woo' ),
437-
'type' => 'string',
438-
'context' => [ 'view' ],
439-
'readonly' => true,
440-
],
441-
]
442-
],
443-
'line_subtotal' => [
444-
'description' => esc_html__( 'Line subtotal.', 'cc-woo' ),
445-
'type' => 'string',
446-
'context' => [ 'view' ],
447-
'readonly' => true,
448-
],
449-
'line_subtotal_tax' => [
450-
'description' => esc_html__( 'Line subtotal tax.', 'cc-woo' ),
451-
'type' => 'string',
452-
'context' => [ 'view' ],
453-
'readonly' => true,
454-
],
455-
'line_total' => [
456-
'description' => esc_html__( 'Line total.', 'cc-woo' ),
457-
'type' => 'string',
458-
'context' => [ 'view' ],
459-
'readonly' => true,
460-
],
461-
'line_tax' => [
462-
'description' => esc_html__( 'Line total tax.', 'cc-woo' ),
463-
'type' => 'string',
464-
'context' => [ 'view' ],
465-
'readonly' => true,
466-
],
467-
'data' => [
468-
'description' => esc_html__( 'Misc. product data in key-value pairs.', 'cc-woo' ),
469-
'type' => 'object',
470-
'context' => [ 'view' ],
471-
'readonly' => true,
472-
],
473-
'product_title' => [
474-
'description' => esc_html__( 'The product title.', 'cc-woo' ),
475-
'type' => 'string',
476-
'context' => [ 'view' ],
477-
'readonly' => true,
478-
],
479-
'product_sku' => [
480-
'description' => esc_html__( 'The product SKU.', 'cc-woo' ),
481-
'type' => 'string',
482-
'context' => [ 'view' ],
483-
'readonly' => true,
484-
],
485-
'product_permalink' => [
486-
'description' => esc_html__( 'Permalink to the product page.', 'cc-woo' ),
487-
'type' => 'string',
488-
'context' => [ 'view' ],
489-
'readonly' => true,
490-
],
491-
'product_image_url' => [
492-
'description' => esc_html__( 'URL to the full-size featured image for the product if one exists.', 'cc-woo' ),
493-
'type' => 'string',
494-
'context' => [ 'view' ],
495-
'readonly' => true,
496-
]
497-
]
498-
]
499-
],
500-
'coupons' => [
501-
'description' => esc_html__( '', 'cc-woo' ),
502-
'type' => 'string',
503-
'context' => [ 'view' ],
504-
'readonly' => true,
505-
],
506-
],
507-
],
508-
'cart_updated' => [
509-
'description' => esc_html__( '', 'cc-woo' ),
510-
'type' => 'string',
511-
'context' => [ 'view' ],
512-
'readonly' => true,
513-
],
514-
'cart_updated_ts' => [
515-
'description' => esc_html__( '', 'cc-woo' ),
516-
'type' => 'string',
517-
'context' => [ 'view' ],
518-
'readonly' => true,
519-
],
520-
'cart_created' => [
521-
'description' => esc_html__( '', 'cc-woo' ),
522-
'type' => 'string',
523-
'context' => [ 'view' ],
524-
'readonly' => true,
525-
],
526-
'cart_created_ts' => [
527-
'description' => esc_html__( '', 'cc-woo' ),
528-
'type' => 'string',
529-
'context' => [ 'view' ],
530-
'readonly' => true,
531-
],
532-
'cart_hash' => [
533-
'description' => esc_html__( '', 'cc-woo' ),
534-
'type' => 'string',
535-
'context' => [ 'view' ],
536-
'readonly' => true,
537-
],
538-
'cart_subtotal' => [
539-
'description' => esc_html__( '', 'cc-woo' ),
540-
'type' => 'string',
541-
'context' => [ 'view' ],
542-
'readonly' => true,
543-
],
544-
'cart_total' => [
545-
'description' => esc_html__( '', 'cc-woo' ),
546-
'type' => 'string',
547-
'context' => [ 'view' ],
548-
'readonly' => true,
549-
],
550-
'cart_subtotal_tax' => [
551-
'description' => esc_html__( '', 'cc-woo' ),
552-
'type' => 'string',
553-
'context' => [ 'view' ],
554-
'readonly' => true,
555-
],
556-
'cart_total_tax' => [
557-
'description' => esc_html__( '', 'cc-woo' ),
558-
'type' => 'string',
559-
'context' => [ 'view' ],
560-
'readonly' => true,
561-
],
562-
'cart_recovery_url' => [
563-
'description' => esc_html__( '', 'cc-woo' ),
564-
'type' => 'string',
565-
'context' => [ 'view' ],
566-
'readonly' => true,
567-
],
568-
]
569-
];
570-
571-
return $this->add_additional_fields_schema( $schema );
572-
}
573-
574-
/**
575-
* Get the query params for Abandoned Carts.
576-
*
577-
* @return array
578-
*/
579-
public function get_collection_params() {
580-
return [
581-
'page' => [],
582-
'per_page' => [],
583-
'date_min' => [],
584-
'date_max' => [],
585-
];
586-
}
587-
588343
}
589344

0 commit comments

Comments
 (0)