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.1.0 6.2.1 3.1.1 6.2.2 3.1.2 6.2.3 3.2.0 6.3.0 3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / src / Admin / API / ProductAttributes.php
woocommerce / src / Admin / API Last commit date
AI 1 year ago RateLimits 4 weeks ago Reports 4 weeks ago Templates 3 years ago views 4 weeks ago AnalyticsImports.php 5 months ago Coupons.php 4 years ago CustomAttributeTraits.php 4 years ago Customers.php 4 years ago Data.php 4 years ago DataCountries.php 4 years ago DataDownloadIPs.php 4 years ago Experiments.php 4 years ago Features.php 4 years ago Init.php 4 weeks ago LaunchYourStore.php 1 year ago Leaderboards.php 1 year ago Marketing.php 2 months ago MarketingCampaignTypes.php 3 years ago MarketingCampaigns.php 2 years ago MarketingChannels.php 3 years ago MarketingOverview.php 2 months ago MarketingRecommendations.php 2 years ago MobileAppMagicLink.php 3 years ago MobileAppQRLogin.php 4 weeks ago NoteActions.php 4 weeks ago Notes.php 4 weeks ago Notice.php 1 year ago OnboardingFreeExtensions.php 1 year ago OnboardingPlugins.php 4 weeks ago OnboardingProductTypes.php 4 years ago OnboardingProducts.php 2 years ago OnboardingProfile.php 1 year ago OnboardingTasks.php 9 months ago OnboardingThemes.php 9 months ago Options.php 4 weeks ago Orders.php 1 year ago PaymentGatewaySuggestions.php 2 months ago Plugins.php 2 months ago ProductAttributeTerms.php 4 years ago ProductAttributes.php 4 years ago ProductCategories.php 4 years ago ProductForm.php 3 years ago ProductReviews.php 4 years ago ProductVariations.php 1 year ago Products.php 1 year ago ProductsLowInStock.php 4 months ago SettingOptions.php 3 years ago ShippingPartnerSuggestions.php 1 month ago Taxes.php 4 years ago Themes.php 2 years ago
ProductAttributes.php
169 lines
1 <?php
2 /**
3 * REST API Product Attributes Controller
4 *
5 * Handles requests to /products/attributes.
6 */
7
8 namespace Automattic\WooCommerce\Admin\API;
9
10 defined( 'ABSPATH' ) || exit;
11
12 /**
13 * Product categories controller.
14 *
15 * @internal
16 * @extends WC_REST_Product_Attributes_Controller
17 */
18 class ProductAttributes extends \WC_REST_Product_Attributes_Controller {
19 use CustomAttributeTraits;
20
21 /**
22 * Endpoint namespace.
23 *
24 * @var string
25 */
26 protected $namespace = 'wc-analytics';
27
28 /**
29 * Register the routes for custom product attributes.
30 */
31 public function register_routes() {
32 parent::register_routes();
33
34 register_rest_route(
35 $this->namespace,
36 'products/attributes/(?P<slug>[a-z0-9_\-]+)',
37 array(
38 'args' => array(
39 'slug' => array(
40 'description' => __( 'Slug identifier for the resource.', 'woocommerce' ),
41 'type' => 'string',
42 ),
43 ),
44 array(
45 'methods' => \WP_REST_Server::READABLE,
46 'callback' => array( $this, 'get_item_by_slug' ),
47 'permission_callback' => array( $this, 'get_items_permissions_check' ),
48 ),
49 'schema' => array( $this, 'get_public_item_schema' ),
50 )
51 );
52 }
53
54 /**
55 * Get the query params for collections
56 *
57 * @return array
58 */
59 public function get_collection_params() {
60 $params = parent::get_collection_params();
61 $params['search'] = array(
62 'description' => __( 'Search by similar attribute name.', 'woocommerce' ),
63 'type' => 'string',
64 'validate_callback' => 'rest_validate_request_arg',
65 );
66
67 return $params;
68 }
69
70 /**
71 * Get the Attribute's schema, conforming to JSON Schema.
72 *
73 * @return array
74 */
75 public function get_item_schema() {
76 $schema = parent::get_item_schema();
77 // Custom attributes substitute slugs for numeric IDs.
78 $schema['properties']['id']['type'] = array( 'integer', 'string' );
79
80 return $schema;
81 }
82
83 /**
84 * Get a single attribute by it's slug.
85 *
86 * @param WP_REST_Request $request The API request.
87 * @return WP_REST_Response
88 */
89 public function get_item_by_slug( $request ) {
90 if ( empty( $request['slug'] ) ) {
91 return array();
92 }
93
94 $attributes = $this->get_custom_attribute_by_slug( $request['slug'] );
95
96 if ( is_wp_error( $attributes ) ) {
97 return $attributes;
98 }
99
100 $response_items = $this->format_custom_attribute_items_for_response( $attributes );
101
102 return reset( $response_items );
103 }
104
105 /**
106 * Format custom attribute items for response (mimic the structure of a taxonomy - backed attribute).
107 *
108 * @param array $custom_attributes - CustomAttributeTraits::get_custom_attributes().
109 * @return array
110 */
111 protected function format_custom_attribute_items_for_response( $custom_attributes ) {
112 $response = array();
113
114 foreach ( $custom_attributes as $attribute_key => $attribute_value ) {
115 $data = array(
116 'id' => $attribute_key,
117 'name' => $attribute_value['name'],
118 'slug' => $attribute_key,
119 'type' => 'select',
120 'order_by' => 'menu_order',
121 'has_archives' => false,
122 );
123
124 $item_response = rest_ensure_response( $data );
125 $item_response->add_links( $this->prepare_links( (object) array( 'attribute_id' => $attribute_key ) ) );
126 $item_response = $this->prepare_response_for_collection(
127 $item_response
128 );
129
130 $response[] = $item_response;
131 }
132
133 return $response;
134 }
135
136 /**
137 * Get all attributes, with support for searching (which includes custom attributes).
138 *
139 * @param WP_REST_Request $request The API request.
140 * @return WP_REST_Response
141 */
142 public function get_items( $request ) {
143 if ( empty( $request['search'] ) ) {
144 return parent::get_items( $request );
145 }
146
147 $search_string = $request['search'];
148 $custom_attributes = $this->get_custom_attributes( array( 'name' => $search_string ) );
149 $matching_attributes = $this->format_custom_attribute_items_for_response( $custom_attributes );
150 $taxonomy_attributes = wc_get_attribute_taxonomies();
151
152 foreach ( $taxonomy_attributes as $attribute_obj ) {
153 // Skip taxonomy attributes that didn't match the query.
154 if ( false === stripos( $attribute_obj->attribute_label, $search_string ) ) {
155 continue;
156 }
157
158 $attribute = $this->prepare_item_for_response( $attribute_obj, $request );
159 $matching_attributes[] = $this->prepare_response_for_collection( $attribute );
160 }
161
162 $response = rest_ensure_response( $matching_attributes );
163 $response->header( 'X-WP-Total', count( $matching_attributes ) );
164 $response->header( 'X-WP-TotalPages', 1 );
165
166 return $response;
167 }
168 }
169