WooCommerce Code Reference

ShopperListItems extends AbstractRoute
in package
Uses ShopperListsNonceCheck

GET / POST on /shopper-lists/{slug}/items.

GET returns the items in a list. POST saves an item to the list either from an existing cart line or from direct item payload fields.

Table of Contents

IDENTIFIER  = 'shopper-list-items'
Route identifier.
SCHEMA_TYPE  = 'shopper-list-item'
Schema identifier this route uses.
SCHEMA_VERSION  = 1
The routes schema version.
$namespace  : string
Route namespace.
$schema  : AbstractSchema
Schema class instance.
$schema_controller  : SchemaController
Schema Controller instance.
__construct()  : mixed
Constructor.
get_args()  : array<string|int, mixed>
Get method arguments for this REST route.
get_collection_params()  : array<string|int, mixed>
Retrieves the query params for the collections.
get_item_schema()  : array<string|int, mixed>
Get item schema properties.
get_namespace()  : string
Get the namespace for this route.
get_path()  : string
Get the path of this REST route.
get_path_regex()  : string
Get the path regex for this REST route.
get_response()  : WP_REST_Response
Get the route response based on the type of request.
prepare_item_for_response()  : WP_REST_Response
Prepare a single item for response.
set_namespace()  : mixed
Set the namespace for this route.
error_to_response()  : WP_REST_Response
Converts an error to a response object. Based on \WP_REST_Server.
get_context_param()  : array<string|int, mixed>
Retrieves the context param.
get_response_by_request_method()  : WP_REST_Response
Get the route response based on the type of request.
get_route_delete_response()  : WP_REST_Response
Get route response for DELETE requests.
get_route_error_response()  : WP_Error
Get route response when something went wrong.
get_route_error_response_from_object()  : WP_Error
Get route response when something went wrong and the supplied error is a WP_Error. This currently only happens when an item in the cart is out of stock, partially out of stock, can only be bought individually, or when the item is not purchasable.
get_route_post_response()  : WP_REST_Response
Add an item to the requested list from cart_item_key or direct product payload fields.
get_route_response()  : WP_REST_Response
Return the items in the requested list.
get_route_update_response()  : WP_REST_Response
Get route response for PUT requests.
prepare_links()  : array<string|int, mixed>
Prepare links for the request.
prepare_response_for_collection()  : array<string|int, mixed>|mixed
Prepares a response for insertion into a collection.
prime_product_caches_for_items()  : void
Prime post caches before the per-item product lookup loop in the schema.
resolve_item_payload()  : array{0: int, 1: array, 2: int}
Resolve the POST input into a uniform payload (product lookup id, variation, quantity).

Constants

Properties

Methods

get_collection_params()

Retrieves the query params for the collections.

public get_collection_params() : array<string|int, mixed>
Return values
array<string|int, mixed>Query parameters for the collection.

get_response()

Get the route response based on the type of request.

public get_response(WP_REST_Request $request) : WP_REST_Response
Parameters
$request : WP_REST_Request

Request object.

Return values
WP_REST_Response

prepare_item_for_response()

Prepare a single item for response.

public prepare_item_for_response(mixed $item, WP_REST_Request $request) : WP_REST_Response
Parameters
$item : mixed

Item to format to schema.

$request : WP_REST_Request

Request object.

Return values
WP_REST_Response$response Response data.

set_namespace()

Set the namespace for this route.

public set_namespace(string $namespace) : mixed
Parameters
$namespace : string

Given namespace.

Return values
mixed

error_to_response()

Converts an error to a response object. Based on \WP_REST_Server.

protected error_to_response(WP_Error $error) : WP_REST_Response
Parameters
$error : WP_Error

WP_Error instance.

Return values
WP_REST_ResponseList of associative arrays with code and message keys.

get_context_param()

Retrieves the context param.

protected get_context_param([array<string|int, mixed> $args = array() ]) : array<string|int, mixed>

Ensures consistent descriptions between endpoints, and populates enum from schema.

Parameters
$args : array<string|int, mixed> = array()

Optional. Additional arguments for context parameter. Default empty array.

Return values
array<string|int, mixed>Context parameter details.

get_response_by_request_method()

Get the route response based on the type of request.

protected get_response_by_request_method(WP_REST_Request $request) : WP_REST_Response
Parameters
$request : WP_REST_Request

Request object.

Return values
WP_REST_Response

get_route_delete_response()

Get route response for DELETE requests.

protected get_route_delete_response(WP_REST_Request $request) : WP_REST_Response

When implemented, should return a \WP_REST_Response.

Parameters
$request : WP_REST_Request

Request object.

Tags
throws
RouteException

On error.

Return values
WP_REST_Response

get_route_error_response()

Get route response when something went wrong.

protected get_route_error_response(string $error_code, string $error_message[, int $http_status_code = 500 ][, array<string|int, mixed> $additional_data = [] ]) : WP_Error
Parameters
$error_code : string

String based error code.

$error_message : string

User facing error message.

$http_status_code : int = 500

HTTP status. Defaults to 500.

$additional_data : array<string|int, mixed> = []

Extra data (key value pairs) to expose in the error response.

Return values
WP_ErrorWP Error object.

get_route_error_response_from_object()

Get route response when something went wrong and the supplied error is a WP_Error. This currently only happens when an item in the cart is out of stock, partially out of stock, can only be bought individually, or when the item is not purchasable.

protected get_route_error_response_from_object(WP_Error $error_object[, int $http_status_code = 500 ][, array<string|int, mixed> $additional_data = [] ]) : WP_Error
Parameters
$error_object : WP_Error

The WP_Error object containing the error.

$http_status_code : int = 500

HTTP status. Defaults to 500.

$additional_data : array<string|int, mixed> = []

Extra data (key value pairs) to expose in the error response.

Return values
WP_ErrorWP Error object.

get_route_post_response()

Add an item to the requested list from cart_item_key or direct product payload fields.

protected get_route_post_response(WP_REST_Request $request) : WP_REST_Response
Parameters
$request : WP_REST_Request

Request object.

Tags
throws
RouteException

On validation failure.

phpstan-param

\WP_REST_Request<array<string, mixed>> $request

Return values
WP_REST_Response

get_route_response()

Return the items in the requested list.

protected get_route_response(WP_REST_Request $request) : WP_REST_Response
Parameters
$request : WP_REST_Request

Request object.

Tags
throws
RouteException

When the list doesn't exist.

phpstan-param

\WP_REST_Request<array<string, mixed>> $request

Return values
WP_REST_Response

get_route_update_response()

Get route response for PUT requests.

protected get_route_update_response(WP_REST_Request $request) : WP_REST_Response

When implemented, should return a \WP_REST_Response.

Parameters
$request : WP_REST_Request

Request object.

Tags
throws
RouteException

On error.

Return values
WP_REST_Response

Prepare links for the request.

protected prepare_links(mixed $item, WP_REST_Request $request) : array<string|int, mixed>
Parameters
$item : mixed

Item to prepare.

$request : WP_REST_Request

Request object.

Return values
array<string|int, mixed>

prepare_response_for_collection()

Prepares a response for insertion into a collection.

protected prepare_response_for_collection(WP_REST_Response $response) : array<string|int, mixed>|mixed
Parameters
$response : WP_REST_Response

Response object.

Return values
array<string|int, mixed>|mixedResponse data, ready for insertion into collection data.

prime_product_caches_for_items()

Prime post caches before the per-item product lookup loop in the schema.

private prime_product_caches_for_items(array<string|int, ShopperListItem$items) : void
Parameters
$items : array<string|int, ShopperListItem>

Items.

Return values
void

resolve_item_payload()

Resolve the POST input into a uniform payload (product lookup id, variation, quantity).

private resolve_item_payload(WP_REST_Request $request) : array{0: int, 1: array, 2: int}

Accepts either an existing cart_item_key, or direct product_id/variation_id/variation.

Parameters
$request : WP_REST_Request

Request object.

Tags
throws
RouteException

When neither a cart_item_key nor a product_id is supplied, or the cart_item_key is unknown.

phpstan-param

\WP_REST_Request<array<string, mixed>> $request

Return values
array{0: int, 1: array, 2: int}`[ lookup_id, variation, quantity ]`.