| Total Complexity | 105 |
| Total Lines | 1173 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like ProductVariations often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ProductVariations, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 17 | class ProductVariations extends Products { |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Route base. |
||
| 21 | * |
||
| 22 | * @var string |
||
| 23 | */ |
||
| 24 | protected $rest_base = 'products/(?P<product_id>[\d]+)/variations'; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Post type. |
||
| 28 | * |
||
| 29 | * @var string |
||
| 30 | */ |
||
| 31 | protected $post_type = 'product_variation'; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Initialize product actions (parent). |
||
| 35 | */ |
||
| 36 | public function __construct() { |
||
| 39 | } |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Register the routes for products. |
||
| 43 | */ |
||
| 44 | public function register_routes() { |
||
| 45 | register_rest_route( |
||
| 46 | $this->namespace, |
||
| 47 | '/' . $this->rest_base, |
||
| 48 | array( |
||
| 49 | 'args' => array( |
||
| 50 | 'product_id' => array( |
||
| 51 | 'description' => __( 'Unique identifier for the variable product.', 'woocommerce' ), |
||
| 52 | 'type' => 'integer', |
||
| 53 | ), |
||
| 54 | ), |
||
| 55 | array( |
||
| 56 | 'methods' => \WP_REST_Server::READABLE, |
||
| 57 | 'callback' => array( $this, 'get_items' ), |
||
| 58 | 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
||
| 59 | 'args' => $this->get_collection_params(), |
||
| 60 | ), |
||
| 61 | array( |
||
| 62 | 'methods' => \WP_REST_Server::CREATABLE, |
||
| 63 | 'callback' => array( $this, 'create_item' ), |
||
| 64 | 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
||
| 65 | 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::CREATABLE ), |
||
| 66 | ), |
||
| 67 | 'schema' => array( $this, 'get_public_item_schema' ), |
||
| 68 | ), |
||
| 69 | true |
||
| 70 | ); |
||
| 71 | register_rest_route( |
||
| 72 | $this->namespace, |
||
| 73 | '/' . $this->rest_base . '/(?P<id>[\d]+)', |
||
| 74 | array( |
||
| 75 | 'args' => array( |
||
| 76 | 'product_id' => array( |
||
| 77 | 'description' => __( 'Unique identifier for the variable product.', 'woocommerce' ), |
||
| 78 | 'type' => 'integer', |
||
| 79 | ), |
||
| 80 | 'id' => array( |
||
| 81 | 'description' => __( 'Unique identifier for the variation.', 'woocommerce' ), |
||
| 82 | 'type' => 'integer', |
||
| 83 | ), |
||
| 84 | ), |
||
| 85 | array( |
||
| 86 | 'methods' => \WP_REST_Server::READABLE, |
||
| 87 | 'callback' => array( $this, 'get_item' ), |
||
| 88 | 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
||
| 89 | 'args' => array( |
||
| 90 | 'context' => $this->get_context_param( |
||
| 91 | array( |
||
| 92 | 'default' => 'view', |
||
| 93 | ) |
||
| 94 | ), |
||
| 95 | ), |
||
| 96 | ), |
||
| 97 | array( |
||
| 98 | 'methods' => \WP_REST_Server::EDITABLE, |
||
| 99 | 'callback' => array( $this, 'update_item' ), |
||
| 100 | 'permission_callback' => array( $this, 'update_item_permissions_check' ), |
||
| 101 | 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
||
| 102 | ), |
||
| 103 | array( |
||
| 104 | 'methods' => \WP_REST_Server::DELETABLE, |
||
| 105 | 'callback' => array( $this, 'delete_item' ), |
||
| 106 | 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
||
| 107 | 'args' => array( |
||
| 108 | 'force' => array( |
||
| 109 | 'default' => false, |
||
| 110 | 'type' => 'boolean', |
||
| 111 | 'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ), |
||
| 112 | ), |
||
| 113 | ), |
||
| 114 | ), |
||
| 115 | 'schema' => array( $this, 'get_public_item_schema' ), |
||
| 116 | ), |
||
| 117 | true |
||
| 118 | ); |
||
| 119 | register_rest_route( |
||
| 120 | $this->namespace, |
||
| 121 | '/' . $this->rest_base . '/batch', |
||
| 122 | array( |
||
| 123 | 'args' => array( |
||
| 124 | 'product_id' => array( |
||
| 125 | 'description' => __( 'Unique identifier for the variable product.', 'woocommerce' ), |
||
| 126 | 'type' => 'integer', |
||
| 127 | ), |
||
| 128 | ), |
||
| 129 | array( |
||
| 130 | 'methods' => \WP_REST_Server::EDITABLE, |
||
| 131 | 'callback' => array( $this, 'batch_items' ), |
||
| 132 | 'permission_callback' => array( $this, 'batch_items_permissions_check' ), |
||
| 133 | 'args' => $this->get_endpoint_args_for_item_schema( \WP_REST_Server::EDITABLE ), |
||
| 134 | ), |
||
| 135 | 'schema' => array( $this, 'get_public_batch_schema' ), |
||
| 136 | ), |
||
| 137 | true |
||
| 138 | ); |
||
| 139 | } |
||
| 140 | |||
| 141 | /** |
||
| 142 | * Get object. |
||
| 143 | * |
||
| 144 | * @since 3.0.0 |
||
| 145 | * @param int $id Object ID. |
||
| 146 | * @return \WC_Data|bool |
||
| 147 | */ |
||
| 148 | protected function get_object( $id ) { |
||
| 150 | } |
||
| 151 | |||
| 152 | /** |
||
| 153 | * Check if a given request has access to update an item. |
||
| 154 | * |
||
| 155 | * @param \WP_REST_Request $request Full details about the request. |
||
| 156 | * @return \WP_Error|boolean |
||
| 157 | */ |
||
| 158 | public function update_item_permissions_check( $request ) { |
||
| 159 | $object = $this->get_object( (int) $request['id'] ); |
||
| 160 | |||
| 161 | if ( $object && 0 !== $object->get_id() && ! wc_rest_check_post_permissions( $this->post_type, 'edit', $object->get_id() ) ) { |
||
| 162 | return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you are not allowed to edit this resource.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
||
| 163 | } |
||
| 164 | |||
| 165 | // Check if variation belongs to the correct parent product. |
||
| 166 | if ( $object && 0 !== $object->get_parent_id() && absint( $request['product_id'] ) !== $object->get_parent_id() ) { |
||
| 167 | return new \WP_Error( 'woocommerce_rest_cannot_edit', __( 'Parent product does not match current variation.', 'woocommerce' ), array( 'status' => rest_authorization_required_code() ) ); |
||
| 168 | } |
||
| 169 | |||
| 170 | return true; |
||
| 171 | } |
||
| 172 | |||
| 173 | /** |
||
| 174 | * Prepare a single variation output for response. |
||
| 175 | * |
||
| 176 | * @param \WC_Data $object Object data. |
||
| 177 | * @param \WP_REST_Request $request Request object. |
||
| 178 | * @return \WP_REST_Response |
||
| 179 | */ |
||
| 180 | public function prepare_object_for_response( $object, $request ) { |
||
| 181 | $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
||
| 182 | $data = array( |
||
| 183 | 'id' => $object->get_id(), |
||
| 184 | 'name' => $object->get_name( $context ), |
||
|
|
|||
| 185 | 'type' => $object->get_type(), |
||
| 186 | 'parent_id' => $object->get_parent_id( $context ), |
||
| 187 | 'date_created' => wc_rest_prepare_date_response( $object->get_date_created(), false ), |
||
| 188 | 'date_created_gmt' => wc_rest_prepare_date_response( $object->get_date_created() ), |
||
| 189 | 'date_modified' => wc_rest_prepare_date_response( $object->get_date_modified(), false ), |
||
| 190 | 'date_modified_gmt' => wc_rest_prepare_date_response( $object->get_date_modified() ), |
||
| 191 | 'description' => wc_format_content( $object->get_description() ), |
||
| 192 | 'permalink' => $object->get_permalink(), |
||
| 193 | 'sku' => $object->get_sku(), |
||
| 194 | 'price' => $object->get_price(), |
||
| 195 | 'regular_price' => $object->get_regular_price(), |
||
| 196 | 'sale_price' => $object->get_sale_price(), |
||
| 197 | 'date_on_sale_from' => wc_rest_prepare_date_response( $object->get_date_on_sale_from(), false ), |
||
| 198 | 'date_on_sale_from_gmt' => wc_rest_prepare_date_response( $object->get_date_on_sale_from() ), |
||
| 199 | 'date_on_sale_to' => wc_rest_prepare_date_response( $object->get_date_on_sale_to(), false ), |
||
| 200 | 'date_on_sale_to_gmt' => wc_rest_prepare_date_response( $object->get_date_on_sale_to() ), |
||
| 201 | 'on_sale' => $object->is_on_sale(), |
||
| 202 | 'status' => $object->get_status(), |
||
| 203 | 'purchasable' => $object->is_purchasable(), |
||
| 204 | 'virtual' => $object->is_virtual(), |
||
| 205 | 'downloadable' => $object->is_downloadable(), |
||
| 206 | 'downloads' => $this->get_downloads( $object ), |
||
| 207 | 'download_limit' => '' !== $object->get_download_limit() ? (int) $object->get_download_limit() : -1, |
||
| 208 | 'download_expiry' => '' !== $object->get_download_expiry() ? (int) $object->get_download_expiry() : -1, |
||
| 209 | 'tax_status' => $object->get_tax_status(), |
||
| 210 | 'tax_class' => $object->get_tax_class(), |
||
| 211 | 'manage_stock' => $object->managing_stock(), |
||
| 212 | 'stock_quantity' => $object->get_stock_quantity(), |
||
| 213 | 'stock_status' => $object->get_stock_status(), |
||
| 214 | 'backorders' => $object->get_backorders(), |
||
| 215 | 'backorders_allowed' => $object->backorders_allowed(), |
||
| 216 | 'backordered' => $object->is_on_backorder(), |
||
| 217 | 'weight' => $object->get_weight(), |
||
| 218 | 'dimensions' => array( |
||
| 219 | 'length' => $object->get_length(), |
||
| 220 | 'width' => $object->get_width(), |
||
| 221 | 'height' => $object->get_height(), |
||
| 222 | ), |
||
| 223 | 'shipping_class' => $object->get_shipping_class(), |
||
| 224 | 'shipping_class_id' => $object->get_shipping_class_id(), |
||
| 225 | 'image' => $this->get_image( $object ), |
||
| 226 | 'attributes' => $this->get_attributes( $object ), |
||
| 227 | 'menu_order' => $object->get_menu_order(), |
||
| 228 | 'meta_data' => $object->get_meta_data(), |
||
| 229 | ); |
||
| 230 | |||
| 231 | $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
||
| 232 | $data = $this->add_additional_fields_to_object( $data, $request ); |
||
| 233 | $data = $this->filter_response_by_context( $data, $context ); |
||
| 234 | $response = rest_ensure_response( $data ); |
||
| 235 | $response->add_links( $this->prepare_links( $object, $request ) ); |
||
| 236 | |||
| 237 | /** |
||
| 238 | * Filter the data for a response. |
||
| 239 | * |
||
| 240 | * The dynamic portion of the hook name, $this->post_type, |
||
| 241 | * refers to object type being prepared for the response. |
||
| 242 | * |
||
| 243 | * @param \WP_REST_Response $response The response object. |
||
| 244 | * @param \WC_Data $object Object data. |
||
| 245 | * @param \WP_REST_Request $request Request object. |
||
| 246 | */ |
||
| 247 | return apply_filters( "woocommerce_rest_prepare_{$this->post_type}_object", $response, $object, $request ); |
||
| 248 | } |
||
| 249 | |||
| 250 | /** |
||
| 251 | * Get the image for a product variation. |
||
| 252 | * |
||
| 253 | * @param \WC_Product_Variation $variation Variation data. |
||
| 254 | * @return array |
||
| 255 | */ |
||
| 256 | protected function get_image( $variation ) { |
||
| 282 | ); |
||
| 283 | } |
||
| 284 | } |
||
| 285 | |||
| 286 | /** |
||
| 287 | * Set variation image. |
||
| 288 | * |
||
| 289 | * @throws \WC_REST_Exception REST API exceptions. |
||
| 290 | * |
||
| 291 | * @param \WC_Product_Variation $variation Variation instance. |
||
| 292 | * @param array $image Image data. |
||
| 293 | * @return \WC_Product_Variation |
||
| 294 | */ |
||
| 295 | protected function set_variation_image( $variation, $image ) { |
||
| 333 | } |
||
| 334 | |||
| 335 | /** |
||
| 336 | * Prepare objects query. |
||
| 337 | * |
||
| 338 | * @since 3.0.0 |
||
| 339 | * @param \WP_REST_Request $request Full details about the request. |
||
| 340 | * @return array |
||
| 341 | */ |
||
| 342 | protected function prepare_objects_query( $request ) { |
||
| 343 | $args = parent::prepare_objects_query( $request ); |
||
| 344 | |||
| 345 | // Set post_status. |
||
| 346 | $args['post_status'] = $request['status']; |
||
| 347 | |||
| 348 | // Set custom args to handle later during clauses. |
||
| 349 | $custom_keys = array( |
||
| 350 | 'sku', |
||
| 351 | 'min_price', |
||
| 352 | 'max_price', |
||
| 353 | 'stock_status', |
||
| 354 | 'low_in_stock', |
||
| 355 | ); |
||
| 356 | foreach ( $custom_keys as $key ) { |
||
| 357 | if ( ! empty( $request[ $key ] ) ) { |
||
| 358 | $args[ $key ] = $request[ $key ]; |
||
| 359 | } |
||
| 360 | } |
||
| 361 | |||
| 362 | // Filter by tax class. |
||
| 363 | if ( ! empty( $request['tax_class'] ) ) { |
||
| 364 | $args['meta_query'] = $this->add_meta_query( // WPCS: slow query ok. |
||
| 365 | $args, |
||
| 366 | array( |
||
| 367 | 'key' => '_tax_class', |
||
| 368 | 'value' => 'standard' !== $request['tax_class'] ? $request['tax_class'] : '', |
||
| 369 | ) |
||
| 370 | ); |
||
| 371 | } |
||
| 372 | |||
| 373 | // Filter by on sale products. |
||
| 374 | if ( is_bool( $request['on_sale'] ) ) { |
||
| 375 | $on_sale_key = $request['on_sale'] ? 'post__in' : 'post__not_in'; |
||
| 376 | $on_sale_ids = wc_get_product_ids_on_sale(); |
||
| 377 | |||
| 378 | // Use 0 when there's no on sale products to avoid return all products. |
||
| 379 | $on_sale_ids = empty( $on_sale_ids ) ? array( 0 ) : $on_sale_ids; |
||
| 380 | |||
| 381 | $args[ $on_sale_key ] += $on_sale_ids; |
||
| 382 | } |
||
| 383 | |||
| 384 | // Force the post_type argument, since it's not a user input variable. |
||
| 385 | if ( ! empty( $request['sku'] ) ) { |
||
| 386 | $args['post_type'] = array( 'product', 'product_variation' ); |
||
| 387 | } else { |
||
| 388 | $args['post_type'] = $this->post_type; |
||
| 389 | } |
||
| 390 | |||
| 391 | $args['post_parent'] = $request['product_id']; |
||
| 392 | |||
| 393 | if ( ! empty( $request['search'] ) ) { |
||
| 394 | $args['search'] = $request['search']; |
||
| 395 | unset( $args['s'] ); |
||
| 396 | } |
||
| 397 | |||
| 398 | return $args; |
||
| 399 | } |
||
| 400 | |||
| 401 | /** |
||
| 402 | * Prepare a single variation for create or update. |
||
| 403 | * |
||
| 404 | * @param \WP_REST_Request $request Request object. |
||
| 405 | * @param bool $creating If is creating a new object. |
||
| 406 | * @return \WP_Error|\WC_Data |
||
| 407 | */ |
||
| 408 | protected function prepare_object_for_database( $request, $creating = false ) { |
||
| 608 | } |
||
| 609 | |||
| 610 | /** |
||
| 611 | * Clear caches here so in sync with any new variations. |
||
| 612 | * |
||
| 613 | * @param \WC_Data $object Object data. |
||
| 614 | */ |
||
| 615 | public function clear_transients( $object ) { |
||
| 616 | wc_delete_product_transients( $object->get_parent_id() ); |
||
| 617 | wp_cache_delete( 'product-' . $object->get_parent_id(), 'products' ); |
||
| 618 | } |
||
| 619 | |||
| 620 | /** |
||
| 621 | * Delete a variation. |
||
| 622 | * |
||
| 623 | * @param \WP_REST_Request $request Full details about the request. |
||
| 624 | * |
||
| 625 | * @return bool|\WP_Error|\WP_REST_Response |
||
| 626 | */ |
||
| 627 | public function delete_item( $request ) { |
||
| 725 | } |
||
| 726 | |||
| 727 | /** |
||
| 728 | * Get batch of items from requst. |
||
| 729 | * |
||
| 730 | * @param \WP_REST_Request $request Full details about the request. |
||
| 731 | * @param string $batch_type Batch type; one of create, update, delete. |
||
| 732 | * @return array |
||
| 733 | */ |
||
| 734 | protected function get_batch_of_items_from_request( $request, $batch_type ) { |
||
| 735 | $params = $request->get_params(); |
||
| 736 | $url_params = $request->get_url_params(); |
||
| 737 | $product_id = $url_params['product_id']; |
||
| 738 | |||
| 739 | if ( ! isset( $params[ $batch_type ] ) ) { |
||
| 740 | return array(); |
||
| 741 | } |
||
| 742 | |||
| 743 | $items = array_filter( $params[ $batch_type ] ); |
||
| 744 | |||
| 745 | if ( 'update' === $batch_type || 'create' === $batch_type ) { |
||
| 746 | foreach ( $items as $key => $item ) { |
||
| 747 | $items[ $key ] = array_merge( |
||
| 748 | array( |
||
| 749 | 'product_id' => $product_id, |
||
| 750 | ), |
||
| 751 | $item |
||
| 752 | ); |
||
| 753 | } |
||
| 754 | } |
||
| 755 | |||
| 756 | return array_filter( $items ); |
||
| 757 | } |
||
| 758 | |||
| 759 | /** |
||
| 760 | * Prepare links for the request. |
||
| 761 | * |
||
| 762 | * @param \WC_Data $object Object data. |
||
| 763 | * @param \WP_REST_Request $request Request object. |
||
| 764 | * @return array Links for the given post. |
||
| 765 | */ |
||
| 766 | protected function prepare_links( $object, $request ) { |
||
| 781 | } |
||
| 782 | |||
| 783 | /** |
||
| 784 | * Get the Variation's schema, conforming to JSON Schema. |
||
| 785 | * |
||
| 786 | * @return array |
||
| 787 | */ |
||
| 788 | public function get_item_schema() { |
||
| 789 | $weight_unit = get_option( 'woocommerce_weight_unit' ); |
||
| 790 | $dimension_unit = get_option( 'woocommerce_dimension_unit' ); |
||
| 791 | $schema = array( |
||
| 792 | '$schema' => 'http://json-schema.org/draft-04/schema#', |
||
| 793 | 'title' => $this->post_type, |
||
| 794 | 'type' => 'object', |
||
| 795 | 'properties' => array( |
||
| 796 | 'id' => array( |
||
| 797 | 'description' => __( 'Unique identifier for the resource.', 'woocommerce' ), |
||
| 798 | 'type' => 'integer', |
||
| 799 | 'context' => array( 'view', 'edit' ), |
||
| 800 | 'readonly' => true, |
||
| 801 | ), |
||
| 802 | 'name' => array( |
||
| 803 | 'description' => __( 'Product parent name.', 'woocommerce' ), |
||
| 804 | 'type' => 'string', |
||
| 805 | 'context' => array( 'view', 'edit' ), |
||
| 806 | ), |
||
| 807 | 'type' => array( |
||
| 808 | 'description' => __( 'Product type.', 'woocommerce' ), |
||
| 809 | 'type' => 'string', |
||
| 810 | 'default' => 'variation', |
||
| 811 | 'enum' => array( 'variation' ), |
||
| 812 | 'context' => array( 'view', 'edit' ), |
||
| 813 | ), |
||
| 814 | 'parent_id' => array( |
||
| 815 | 'description' => __( 'Product parent ID.', 'woocommerce' ), |
||
| 816 | 'type' => 'integer', |
||
| 817 | 'context' => array( 'view', 'edit' ), |
||
| 818 | ), |
||
| 819 | 'date_created' => array( |
||
| 820 | 'description' => __( "The date the variation was created, in the site's timezone.", 'woocommerce' ), |
||
| 821 | 'type' => 'date-time', |
||
| 822 | 'context' => array( 'view', 'edit' ), |
||
| 823 | 'readonly' => true, |
||
| 824 | ), |
||
| 825 | 'date_modified' => array( |
||
| 826 | 'description' => __( "The date the variation was last modified, in the site's timezone.", 'woocommerce' ), |
||
| 827 | 'type' => 'date-time', |
||
| 828 | 'context' => array( 'view', 'edit' ), |
||
| 829 | 'readonly' => true, |
||
| 830 | ), |
||
| 831 | 'description' => array( |
||
| 832 | 'description' => __( 'Variation description.', 'woocommerce' ), |
||
| 833 | 'type' => 'string', |
||
| 834 | 'context' => array( 'view', 'edit' ), |
||
| 835 | ), |
||
| 836 | 'permalink' => array( |
||
| 837 | 'description' => __( 'Variation URL.', 'woocommerce' ), |
||
| 838 | 'type' => 'string', |
||
| 839 | 'format' => 'uri', |
||
| 840 | 'context' => array( 'view', 'edit' ), |
||
| 841 | 'readonly' => true, |
||
| 842 | ), |
||
| 843 | 'sku' => array( |
||
| 844 | 'description' => __( 'Unique identifier.', 'woocommerce' ), |
||
| 845 | 'type' => 'string', |
||
| 846 | 'context' => array( 'view', 'edit' ), |
||
| 847 | ), |
||
| 848 | 'price' => array( |
||
| 849 | 'description' => __( 'Current variation price.', 'woocommerce' ), |
||
| 850 | 'type' => 'string', |
||
| 851 | 'context' => array( 'view', 'edit' ), |
||
| 852 | 'readonly' => true, |
||
| 853 | ), |
||
| 854 | 'regular_price' => array( |
||
| 855 | 'description' => __( 'Variation regular price.', 'woocommerce' ), |
||
| 856 | 'type' => 'string', |
||
| 857 | 'context' => array( 'view', 'edit' ), |
||
| 858 | ), |
||
| 859 | 'sale_price' => array( |
||
| 860 | 'description' => __( 'Variation sale price.', 'woocommerce' ), |
||
| 861 | 'type' => 'string', |
||
| 862 | 'context' => array( 'view', 'edit' ), |
||
| 863 | ), |
||
| 864 | 'date_on_sale_from' => array( |
||
| 865 | 'description' => __( "Start date of sale price, in the site's timezone.", 'woocommerce' ), |
||
| 866 | 'type' => 'date-time', |
||
| 867 | 'context' => array( 'view', 'edit' ), |
||
| 868 | ), |
||
| 869 | 'date_on_sale_from_gmt' => array( |
||
| 870 | 'description' => __( 'Start date of sale price, as GMT.', 'woocommerce' ), |
||
| 871 | 'type' => 'date-time', |
||
| 872 | 'context' => array( 'view', 'edit' ), |
||
| 873 | ), |
||
| 874 | 'date_on_sale_to' => array( |
||
| 875 | 'description' => __( "End date of sale price, in the site's timezone.", 'woocommerce' ), |
||
| 876 | 'type' => 'date-time', |
||
| 877 | 'context' => array( 'view', 'edit' ), |
||
| 878 | ), |
||
| 879 | 'date_on_sale_to_gmt' => array( |
||
| 880 | 'description' => __( "End date of sale price, in the site's timezone.", 'woocommerce' ), |
||
| 881 | 'type' => 'date-time', |
||
| 882 | 'context' => array( 'view', 'edit' ), |
||
| 883 | ), |
||
| 884 | 'on_sale' => array( |
||
| 885 | 'description' => __( 'Shows if the variation is on sale.', 'woocommerce' ), |
||
| 886 | 'type' => 'boolean', |
||
| 887 | 'context' => array( 'view', 'edit' ), |
||
| 888 | 'readonly' => true, |
||
| 889 | ), |
||
| 890 | 'status' => array( |
||
| 891 | 'description' => __( 'Variation status.', 'woocommerce' ), |
||
| 892 | 'type' => 'string', |
||
| 893 | 'default' => 'publish', |
||
| 894 | 'enum' => array_keys( get_post_statuses() ), |
||
| 895 | 'context' => array( 'view', 'edit' ), |
||
| 896 | ), |
||
| 897 | 'purchasable' => array( |
||
| 898 | 'description' => __( 'Shows if the variation can be bought.', 'woocommerce' ), |
||
| 899 | 'type' => 'boolean', |
||
| 900 | 'context' => array( 'view', 'edit' ), |
||
| 901 | 'readonly' => true, |
||
| 902 | ), |
||
| 903 | 'virtual' => array( |
||
| 904 | 'description' => __( 'If the variation is virtual.', 'woocommerce' ), |
||
| 905 | 'type' => 'boolean', |
||
| 906 | 'default' => false, |
||
| 907 | 'context' => array( 'view', 'edit' ), |
||
| 908 | ), |
||
| 909 | 'downloadable' => array( |
||
| 910 | 'description' => __( 'If the variation is downloadable.', 'woocommerce' ), |
||
| 911 | 'type' => 'boolean', |
||
| 912 | 'default' => false, |
||
| 913 | 'context' => array( 'view', 'edit' ), |
||
| 914 | ), |
||
| 915 | 'downloads' => array( |
||
| 916 | 'description' => __( 'List of downloadable files.', 'woocommerce' ), |
||
| 917 | 'type' => 'array', |
||
| 918 | 'context' => array( 'view', 'edit' ), |
||
| 919 | 'items' => array( |
||
| 920 | 'type' => 'object', |
||
| 921 | 'properties' => array( |
||
| 922 | 'id' => array( |
||
| 923 | 'description' => __( 'File ID.', 'woocommerce' ), |
||
| 924 | 'type' => 'string', |
||
| 925 | 'context' => array( 'view', 'edit' ), |
||
| 926 | ), |
||
| 927 | 'name' => array( |
||
| 928 | 'description' => __( 'File name.', 'woocommerce' ), |
||
| 929 | 'type' => 'string', |
||
| 930 | 'context' => array( 'view', 'edit' ), |
||
| 931 | ), |
||
| 932 | 'file' => array( |
||
| 933 | 'description' => __( 'File URL.', 'woocommerce' ), |
||
| 934 | 'type' => 'string', |
||
| 935 | 'context' => array( 'view', 'edit' ), |
||
| 936 | ), |
||
| 937 | ), |
||
| 938 | ), |
||
| 939 | ), |
||
| 940 | 'download_limit' => array( |
||
| 941 | 'description' => __( 'Number of times downloadable files can be downloaded after purchase.', 'woocommerce' ), |
||
| 942 | 'type' => 'integer', |
||
| 943 | 'default' => -1, |
||
| 944 | 'context' => array( 'view', 'edit' ), |
||
| 945 | ), |
||
| 946 | 'download_expiry' => array( |
||
| 947 | 'description' => __( 'Number of days until access to downloadable files expires.', 'woocommerce' ), |
||
| 948 | 'type' => 'integer', |
||
| 949 | 'default' => -1, |
||
| 950 | 'context' => array( 'view', 'edit' ), |
||
| 951 | ), |
||
| 952 | 'tax_status' => array( |
||
| 953 | 'description' => __( 'Tax status.', 'woocommerce' ), |
||
| 954 | 'type' => 'string', |
||
| 955 | 'default' => 'taxable', |
||
| 956 | 'enum' => array( 'taxable', 'shipping', 'none' ), |
||
| 957 | 'context' => array( 'view', 'edit' ), |
||
| 958 | ), |
||
| 959 | 'tax_class' => array( |
||
| 960 | 'description' => __( 'Tax class.', 'woocommerce' ), |
||
| 961 | 'type' => 'string', |
||
| 962 | 'context' => array( 'view', 'edit' ), |
||
| 963 | ), |
||
| 964 | 'manage_stock' => array( |
||
| 965 | 'description' => __( 'Stock management at variation level.', 'woocommerce' ), |
||
| 966 | 'type' => 'boolean', |
||
| 967 | 'default' => false, |
||
| 968 | 'context' => array( 'view', 'edit' ), |
||
| 969 | ), |
||
| 970 | 'stock_quantity' => array( |
||
| 971 | 'description' => __( 'Stock quantity.', 'woocommerce' ), |
||
| 972 | 'type' => 'integer', |
||
| 973 | 'context' => array( 'view', 'edit' ), |
||
| 974 | ), |
||
| 975 | 'stock_status' => array( |
||
| 976 | 'description' => __( 'Controls the stock status of the product.', 'woocommerce' ), |
||
| 977 | 'type' => 'string', |
||
| 978 | 'default' => 'instock', |
||
| 979 | 'enum' => array_keys( wc_get_product_stock_status_options() ), |
||
| 980 | 'context' => array( 'view', 'edit' ), |
||
| 981 | ), |
||
| 982 | 'backorders' => array( |
||
| 983 | 'description' => __( 'If managing stock, this controls if backorders are allowed.', 'woocommerce' ), |
||
| 984 | 'type' => 'string', |
||
| 985 | 'default' => 'no', |
||
| 986 | 'enum' => array( 'no', 'notify', 'yes' ), |
||
| 987 | 'context' => array( 'view', 'edit' ), |
||
| 988 | ), |
||
| 989 | 'backorders_allowed' => array( |
||
| 990 | 'description' => __( 'Shows if backorders are allowed.', 'woocommerce' ), |
||
| 991 | 'type' => 'boolean', |
||
| 992 | 'context' => array( 'view', 'edit' ), |
||
| 993 | 'readonly' => true, |
||
| 994 | ), |
||
| 995 | 'backordered' => array( |
||
| 996 | 'description' => __( 'Shows if the variation is on backordered.', 'woocommerce' ), |
||
| 997 | 'type' => 'boolean', |
||
| 998 | 'context' => array( 'view', 'edit' ), |
||
| 999 | 'readonly' => true, |
||
| 1000 | ), |
||
| 1001 | 'weight' => array( |
||
| 1002 | /* translators: %s: weight unit */ |
||
| 1003 | 'description' => sprintf( __( 'Variation weight (%s).', 'woocommerce' ), $weight_unit ), |
||
| 1004 | 'type' => 'string', |
||
| 1005 | 'context' => array( 'view', 'edit' ), |
||
| 1006 | ), |
||
| 1007 | 'dimensions' => array( |
||
| 1008 | 'description' => __( 'Variation dimensions.', 'woocommerce' ), |
||
| 1009 | 'type' => 'object', |
||
| 1010 | 'context' => array( 'view', 'edit' ), |
||
| 1011 | 'properties' => array( |
||
| 1012 | 'length' => array( |
||
| 1013 | /* translators: %s: dimension unit */ |
||
| 1014 | 'description' => sprintf( __( 'Variation length (%s).', 'woocommerce' ), $dimension_unit ), |
||
| 1015 | 'type' => 'string', |
||
| 1016 | 'context' => array( 'view', 'edit' ), |
||
| 1017 | ), |
||
| 1018 | 'width' => array( |
||
| 1019 | /* translators: %s: dimension unit */ |
||
| 1020 | 'description' => sprintf( __( 'Variation width (%s).', 'woocommerce' ), $dimension_unit ), |
||
| 1021 | 'type' => 'string', |
||
| 1022 | 'context' => array( 'view', 'edit' ), |
||
| 1023 | ), |
||
| 1024 | 'height' => array( |
||
| 1025 | /* translators: %s: dimension unit */ |
||
| 1026 | 'description' => sprintf( __( 'Variation height (%s).', 'woocommerce' ), $dimension_unit ), |
||
| 1027 | 'type' => 'string', |
||
| 1028 | 'context' => array( 'view', 'edit' ), |
||
| 1029 | ), |
||
| 1030 | ), |
||
| 1031 | ), |
||
| 1032 | 'shipping_class' => array( |
||
| 1033 | 'description' => __( 'Shipping class slug.', 'woocommerce' ), |
||
| 1034 | 'type' => 'string', |
||
| 1035 | 'context' => array( 'view', 'edit' ), |
||
| 1036 | ), |
||
| 1037 | 'shipping_class_id' => array( |
||
| 1038 | 'description' => __( 'Shipping class ID.', 'woocommerce' ), |
||
| 1039 | 'type' => 'string', |
||
| 1040 | 'context' => array( 'view', 'edit' ), |
||
| 1041 | 'readonly' => true, |
||
| 1042 | ), |
||
| 1043 | 'image' => array( |
||
| 1044 | 'description' => __( 'Variation image data.', 'woocommerce' ), |
||
| 1045 | 'type' => 'object', |
||
| 1046 | 'context' => array( 'view', 'edit' ), |
||
| 1047 | 'properties' => array( |
||
| 1048 | 'id' => array( |
||
| 1049 | 'description' => __( 'Image ID.', 'woocommerce' ), |
||
| 1050 | 'type' => 'integer', |
||
| 1051 | 'context' => array( 'view', 'edit' ), |
||
| 1052 | ), |
||
| 1053 | 'date_created' => array( |
||
| 1054 | 'description' => __( "The date the image was created, in the site's timezone.", 'woocommerce' ), |
||
| 1055 | 'type' => 'date-time', |
||
| 1056 | 'context' => array( 'view', 'edit' ), |
||
| 1057 | 'readonly' => true, |
||
| 1058 | ), |
||
| 1059 | 'date_created_gmt' => array( |
||
| 1060 | 'description' => __( 'The date the image was created, as GMT.', 'woocommerce' ), |
||
| 1061 | 'type' => 'date-time', |
||
| 1062 | 'context' => array( 'view', 'edit' ), |
||
| 1063 | 'readonly' => true, |
||
| 1064 | ), |
||
| 1065 | 'date_modified' => array( |
||
| 1066 | 'description' => __( "The date the image was last modified, in the site's timezone.", 'woocommerce' ), |
||
| 1067 | 'type' => 'date-time', |
||
| 1068 | 'context' => array( 'view', 'edit' ), |
||
| 1069 | 'readonly' => true, |
||
| 1070 | ), |
||
| 1071 | 'date_modified_gmt' => array( |
||
| 1072 | 'description' => __( 'The date the image was last modified, as GMT.', 'woocommerce' ), |
||
| 1073 | 'type' => 'date-time', |
||
| 1074 | 'context' => array( 'view', 'edit' ), |
||
| 1075 | 'readonly' => true, |
||
| 1076 | ), |
||
| 1077 | 'src' => array( |
||
| 1078 | 'description' => __( 'Image URL.', 'woocommerce' ), |
||
| 1079 | 'type' => 'string', |
||
| 1080 | 'format' => 'uri', |
||
| 1081 | 'context' => array( 'view', 'edit' ), |
||
| 1082 | ), |
||
| 1083 | 'name' => array( |
||
| 1084 | 'description' => __( 'Image name.', 'woocommerce' ), |
||
| 1085 | 'type' => 'string', |
||
| 1086 | 'context' => array( 'view', 'edit' ), |
||
| 1087 | ), |
||
| 1088 | 'alt' => array( |
||
| 1089 | 'description' => __( 'Image alternative text.', 'woocommerce' ), |
||
| 1090 | 'type' => 'string', |
||
| 1091 | 'context' => array( 'view', 'edit' ), |
||
| 1092 | ), |
||
| 1093 | ), |
||
| 1094 | ), |
||
| 1095 | 'attributes' => array( |
||
| 1096 | 'description' => __( 'List of attributes.', 'woocommerce' ), |
||
| 1097 | 'type' => 'array', |
||
| 1098 | 'context' => array( 'view', 'edit' ), |
||
| 1099 | 'items' => array( |
||
| 1100 | 'type' => 'object', |
||
| 1101 | 'properties' => array( |
||
| 1102 | 'id' => array( |
||
| 1103 | 'description' => __( 'Attribute ID.', 'woocommerce' ), |
||
| 1104 | 'type' => 'integer', |
||
| 1105 | 'context' => array( 'view', 'edit' ), |
||
| 1106 | ), |
||
| 1107 | 'name' => array( |
||
| 1108 | 'description' => __( 'Attribute name.', 'woocommerce' ), |
||
| 1109 | 'type' => 'string', |
||
| 1110 | 'context' => array( 'view', 'edit' ), |
||
| 1111 | ), |
||
| 1112 | 'option' => array( |
||
| 1113 | 'description' => __( 'Selected attribute term name.', 'woocommerce' ), |
||
| 1114 | 'type' => 'string', |
||
| 1115 | 'context' => array( 'view', 'edit' ), |
||
| 1116 | ), |
||
| 1117 | ), |
||
| 1118 | ), |
||
| 1119 | ), |
||
| 1120 | 'menu_order' => array( |
||
| 1121 | 'description' => __( 'Menu order, used to custom sort products.', 'woocommerce' ), |
||
| 1122 | 'type' => 'integer', |
||
| 1123 | 'context' => array( 'view', 'edit' ), |
||
| 1124 | ), |
||
| 1125 | 'meta_data' => array( |
||
| 1126 | 'description' => __( 'Meta data.', 'woocommerce' ), |
||
| 1127 | 'type' => 'array', |
||
| 1128 | 'context' => array( 'view', 'edit' ), |
||
| 1129 | 'items' => array( |
||
| 1130 | 'type' => 'object', |
||
| 1131 | 'properties' => array( |
||
| 1132 | 'id' => array( |
||
| 1133 | 'description' => __( 'Meta ID.', 'woocommerce' ), |
||
| 1134 | 'type' => 'integer', |
||
| 1135 | 'context' => array( 'view', 'edit' ), |
||
| 1136 | 'readonly' => true, |
||
| 1137 | ), |
||
| 1138 | 'key' => array( |
||
| 1139 | 'description' => __( 'Meta key.', 'woocommerce' ), |
||
| 1140 | 'type' => 'string', |
||
| 1141 | 'context' => array( 'view', 'edit' ), |
||
| 1142 | ), |
||
| 1143 | 'value' => array( |
||
| 1144 | 'description' => __( 'Meta value.', 'woocommerce' ), |
||
| 1145 | 'type' => 'mixed', |
||
| 1146 | 'context' => array( 'view', 'edit' ), |
||
| 1147 | ), |
||
| 1148 | ), |
||
| 1149 | ), |
||
| 1150 | ), |
||
| 1151 | ), |
||
| 1152 | ); |
||
| 1153 | return $this->add_additional_fields_schema( $schema ); |
||
| 1154 | } |
||
| 1155 | |||
| 1156 | /** |
||
| 1157 | * Get the query params for collections of attachments. |
||
| 1158 | * |
||
| 1159 | * @return array |
||
| 1160 | */ |
||
| 1161 | public function get_collection_params() { |
||
| 1190 | } |
||
| 1191 | } |
||
| 1192 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.