AI
1 year ago
Agentic
7 months ago
AbstractAddressSchema.php
1 year ago
AbstractSchema.php
1 month ago
BatchSchema.php
2 years ago
BillingAddressSchema.php
2 years ago
CartCouponSchema.php
1 year ago
CartExtensionsSchema.php
1 year ago
CartFeeSchema.php
2 years ago
CartItemSchema.php
1 month ago
CartSchema.php
2 months ago
CartShippingRateSchema.php
1 month ago
CheckoutOrderSchema.php
2 years ago
CheckoutSchema.php
1 month ago
ErrorSchema.php
2 years ago
ImageAttachmentSchema.php
3 months ago
ItemSchema.php
11 months ago
OrderCouponSchema.php
2 years ago
OrderFeeSchema.php
2 years ago
OrderItemSchema.php
1 month ago
OrderSchema.php
2 months ago
PatternsSchema.php
1 year ago
ProductAttributeSchema.php
2 years ago
ProductAttributeTermSchema.php
1 month ago
ProductBrandSchema.php
1 year ago
ProductCategorySchema.php
2 years ago
ProductCollectionDataSchema.php
11 months ago
ProductReviewSchema.php
2 years ago
ProductSchema.php
1 month ago
ShippingAddressSchema.php
2 years ago
ShopperListItemSchema.php
1 month ago
ShopperListSchema.php
1 month ago
TermSchema.php
2 years ago
TermSchema.php
85 lines
| 1 | <?php |
| 2 | namespace Automattic\WooCommerce\StoreApi\Schemas\V1; |
| 3 | |
| 4 | /** |
| 5 | * TermSchema class. |
| 6 | */ |
| 7 | class TermSchema extends AbstractSchema { |
| 8 | /** |
| 9 | * The schema item name. |
| 10 | * |
| 11 | * @var string |
| 12 | */ |
| 13 | protected $title = 'term'; |
| 14 | |
| 15 | /** |
| 16 | * The schema item identifier. |
| 17 | * |
| 18 | * @var string |
| 19 | */ |
| 20 | const IDENTIFIER = 'term'; |
| 21 | |
| 22 | /** |
| 23 | * Term properties. |
| 24 | * |
| 25 | * @return array |
| 26 | */ |
| 27 | public function get_properties() { |
| 28 | return [ |
| 29 | 'id' => array( |
| 30 | 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
| 31 | 'type' => 'integer', |
| 32 | 'context' => array( 'view', 'edit' ), |
| 33 | 'readonly' => true, |
| 34 | ), |
| 35 | 'name' => array( |
| 36 | 'description' => __( 'Term name.', 'woocommerce' ), |
| 37 | 'type' => 'string', |
| 38 | 'context' => array( 'view', 'edit' ), |
| 39 | 'readonly' => true, |
| 40 | ), |
| 41 | 'slug' => array( |
| 42 | 'description' => __( 'String based identifier for the term.', 'woocommerce' ), |
| 43 | 'type' => 'string', |
| 44 | 'context' => array( 'view', 'edit' ), |
| 45 | 'readonly' => true, |
| 46 | ), |
| 47 | 'description' => array( |
| 48 | 'description' => __( 'Term description.', 'woocommerce' ), |
| 49 | 'type' => 'string', |
| 50 | 'context' => array( 'view', 'edit' ), |
| 51 | 'readonly' => true, |
| 52 | ), |
| 53 | 'parent' => array( |
| 54 | 'description' => __( 'Parent term ID, if applicable.', 'woocommerce' ), |
| 55 | 'type' => 'integer', |
| 56 | 'context' => array( 'view', 'edit' ), |
| 57 | 'readonly' => true, |
| 58 | ), |
| 59 | 'count' => array( |
| 60 | 'description' => __( 'Number of objects (posts of any type) assigned to the term.', 'woocommerce' ), |
| 61 | 'type' => 'integer', |
| 62 | 'context' => array( 'view', 'edit' ), |
| 63 | 'readonly' => true, |
| 64 | ), |
| 65 | ]; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Convert a term object into an object suitable for the response. |
| 70 | * |
| 71 | * @param \WP_Term $term Term object. |
| 72 | * @return array |
| 73 | */ |
| 74 | public function get_item_response( $term ) { |
| 75 | return [ |
| 76 | 'id' => (int) $term->term_id, |
| 77 | 'name' => $this->prepare_html_response( $term->name ), |
| 78 | 'slug' => $term->slug, |
| 79 | 'description' => $this->prepare_html_response( $term->description ), |
| 80 | 'parent' => (int) $term->parent, |
| 81 | 'count' => (int) $term->count, |
| 82 | ]; |
| 83 | } |
| 84 | } |
| 85 |