Automattic\WooCommerce\StoreApi\Routes\V1

ShopperListItems::get_route_responseprotectedWC 1.0

Return the items in the requested list.

Method of the class: ShopperListItems{}

No Hooks.

Returns

\WP_REST_Response.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_route_response( $request );
$request(WP_REST_Request) (required)
Request object.

ShopperListItems::get_route_response() code WC 10.9.1

protected function get_route_response( \WP_REST_Request $request ) {
	$list = ShopperList::get_by_slug( (string) $request['slug'] );
	if ( ! $list ) {
		throw new RouteException( 'woocommerce_rest_shopper_list_not_found', esc_html__( 'Your saved list isn\'t available right now.', 'woocommerce' ), 404 );
	}

	$items = array_values( $list->get_items() );
	$this->prime_product_caches_for_items( $items );

	$response = array();
	foreach ( $items as $item ) {
		$response[] = $this->prepare_response_for_collection( $this->prepare_item_for_response( $item, $request ) );
	}

	return rest_ensure_response( $response );
}