WordPress at Your Fingertips
function is not described

Automattic\WooCommerce\Blocks\StoreApi\Routes

CartAddItem::get_route_post_response() protected WC 1.0

Handle the request and return a valid response for this endpoint.

{} It's a method of the class: CartAddItem{}

No Hooks.

Return

\WP_REST_Response.

Usage

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

Code of CartAddItem::get_route_post_response() WC 5.8.0

protected function get_route_post_response( \WP_REST_Request $request ) {
	// Do not allow key to be specified during creation.
	if ( ! empty( $request['key'] ) ) {
		throw new RouteException( 'woocommerce_rest_cart_item_exists', __( 'Cannot create an existing cart item.', 'woocommerce' ), 400 );
	}

	$cart   = $this->cart_controller->get_cart_instance();
	$result = $this->cart_controller->add_to_cart(
		[
			'id'        => $request['id'],
			'quantity'  => $request['quantity'],
			'variation' => $request['variation'],
		]
	);

	$response = rest_ensure_response( $this->schema->get_item_response( $cart ) );
	$response->set_status( 201 );
	return $response;
}