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
ProductAttributeSchema.php
92 lines
| 1 | <?php |
| 2 | namespace Automattic\WooCommerce\StoreApi\Schemas\V1; |
| 3 | |
| 4 | /** |
| 5 | * ProductAttributeSchema class. |
| 6 | */ |
| 7 | class ProductAttributeSchema extends AbstractSchema { |
| 8 | /** |
| 9 | * The schema item name. |
| 10 | * |
| 11 | * @var string |
| 12 | */ |
| 13 | protected $title = 'product_attribute'; |
| 14 | |
| 15 | /** |
| 16 | * The schema item identifier. |
| 17 | * |
| 18 | * @var string |
| 19 | */ |
| 20 | const IDENTIFIER = 'product-attribute'; |
| 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' => __( 'Attribute name.', 'woocommerce' ), |
| 37 | 'type' => 'string', |
| 38 | 'context' => array( 'view', 'edit' ), |
| 39 | 'readonly' => true, |
| 40 | ), |
| 41 | 'taxonomy' => array( |
| 42 | 'description' => __( 'The attribute taxonomy name.', 'woocommerce' ), |
| 43 | 'type' => 'string', |
| 44 | 'context' => array( 'view', 'edit' ), |
| 45 | 'readonly' => true, |
| 46 | ), |
| 47 | 'type' => array( |
| 48 | 'description' => __( 'Attribute type.', 'woocommerce' ), |
| 49 | 'type' => 'string', |
| 50 | 'context' => array( 'view', 'edit' ), |
| 51 | 'readonly' => true, |
| 52 | ), |
| 53 | 'order' => array( |
| 54 | 'description' => __( 'How terms in this attribute are sorted by default.', 'woocommerce' ), |
| 55 | 'type' => 'string', |
| 56 | 'context' => array( 'view', 'edit' ), |
| 57 | 'readonly' => true, |
| 58 | ), |
| 59 | 'has_archives' => array( |
| 60 | 'description' => __( 'If this attribute has term archive pages.', 'woocommerce' ), |
| 61 | 'type' => 'boolean', |
| 62 | 'context' => array( 'view', 'edit' ), |
| 63 | 'readonly' => true, |
| 64 | ), |
| 65 | 'count' => array( |
| 66 | 'description' => __( 'Number of terms in the attribute taxonomy.', 'woocommerce' ), |
| 67 | 'type' => 'integer', |
| 68 | 'context' => array( 'view', 'edit' ), |
| 69 | 'readonly' => true, |
| 70 | ), |
| 71 | ]; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Convert an attribute object into an object suitable for the response. |
| 76 | * |
| 77 | * @param object $attribute Attribute object. |
| 78 | * @return array |
| 79 | */ |
| 80 | public function get_item_response( $attribute ) { |
| 81 | return [ |
| 82 | 'id' => (int) $attribute->id, |
| 83 | 'name' => $this->prepare_html_response( $attribute->name ), |
| 84 | 'taxonomy' => $attribute->slug, |
| 85 | 'type' => $attribute->type, |
| 86 | 'order' => $attribute->order_by, |
| 87 | 'has_archives' => $attribute->has_archives, |
| 88 | 'count' => (int) \wp_count_terms( $attribute->slug ), |
| 89 | ]; |
| 90 | } |
| 91 | } |
| 92 |