AI
1 year ago
Agentic
4 months ago
AbstractCartRoute.php
4 months ago
AbstractRoute.php
3 months ago
AbstractTermsRoute.php
4 months ago
Batch.php
4 months ago
Cart.php
1 year ago
CartAddItem.php
4 months ago
CartApplyCoupon.php
1 year ago
CartCoupons.php
3 months ago
CartCouponsByCode.php
1 year ago
CartExtensions.php
2 years ago
CartItems.php
2 years ago
CartItemsByKey.php
2 years ago
CartRemoveCoupon.php
1 year ago
CartRemoveItem.php
4 months ago
CartSelectShippingRate.php
5 months ago
CartUpdateCustomer.php
4 months ago
CartUpdateItem.php
4 months ago
Checkout.php
1 month ago
CheckoutOrder.php
1 year ago
Order.php
7 months ago
Patterns.php
1 year ago
ProductAttributeTerms.php
1 month ago
ProductAttributes.php
1 year ago
ProductAttributesById.php
1 year ago
ProductBrands.php
1 year ago
ProductBrandsById.php
1 year ago
ProductCategories.php
1 year ago
ProductCategoriesById.php
1 year ago
ProductCollectionData.php
11 months ago
ProductReviews.php
4 months ago
ProductTags.php
1 year ago
Products.php
3 months ago
ProductsById.php
3 months ago
ProductsBySlug.php
3 months ago
ShopperListItems.php
1 month ago
ShopperListItemsByKey.php
1 month ago
ShopperLists.php
1 month ago
ShopperListsBySlug.php
1 month ago
ShopperListsNonceCheck.php
1 month ago
ProductAttributes.php
77 lines
| 1 | <?php |
| 2 | namespace Automattic\WooCommerce\StoreApi\Routes\V1; |
| 3 | |
| 4 | /** |
| 5 | * ProductAttributes class. |
| 6 | */ |
| 7 | class ProductAttributes extends AbstractRoute { |
| 8 | /** |
| 9 | * The route identifier. |
| 10 | * |
| 11 | * @var string |
| 12 | */ |
| 13 | const IDENTIFIER = 'product-attributes'; |
| 14 | |
| 15 | /** |
| 16 | * The routes schema. |
| 17 | * |
| 18 | * @var string |
| 19 | */ |
| 20 | const SCHEMA_TYPE = 'product-attribute'; |
| 21 | |
| 22 | /** |
| 23 | * Get the path of this REST route. |
| 24 | * |
| 25 | * @return string |
| 26 | */ |
| 27 | public function get_path() { |
| 28 | return self::get_path_regex(); |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Get the path of this rest route. |
| 33 | * |
| 34 | * @return string |
| 35 | */ |
| 36 | public static function get_path_regex() { |
| 37 | return '/products/attributes'; |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Get method arguments for this REST route. |
| 42 | * |
| 43 | * @return array An array of endpoints. |
| 44 | */ |
| 45 | public function get_args() { |
| 46 | return [ |
| 47 | [ |
| 48 | 'methods' => \WP_REST_Server::READABLE, |
| 49 | 'callback' => [ $this, 'get_response' ], |
| 50 | 'permission_callback' => '__return_true', |
| 51 | 'args' => $this->get_collection_params(), |
| 52 | 'allow_batch' => [ 'v1' => true ], |
| 53 | ], |
| 54 | 'schema' => [ $this->schema, 'get_public_item_schema' ], |
| 55 | ]; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Get a collection of attributes. |
| 60 | * |
| 61 | * @param \WP_REST_Request $request Request object. |
| 62 | * @return \WP_REST_Response |
| 63 | */ |
| 64 | protected function get_route_response( \WP_REST_Request $request ) { |
| 65 | $ids = wc_get_attribute_taxonomy_ids(); |
| 66 | $return = []; |
| 67 | |
| 68 | foreach ( $ids as $id ) { |
| 69 | $object = wc_get_attribute( $id ); |
| 70 | $data = $this->prepare_item_for_response( $object, $request ); |
| 71 | $return[] = $this->prepare_response_for_collection( $data ); |
| 72 | } |
| 73 | |
| 74 | return rest_ensure_response( $return ); |
| 75 | } |
| 76 | } |
| 77 |