Automattic\WooCommerce\StoreApi\Routes\V1
CartAddItem::get_route_post_response()
Handle the request and return a valid response for this endpoint.
{} Это метод класса: CartAddItem{}
Хуков нет.
Возвращает
\WP_REST_Response
.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->get_route_post_response( $request );
- $request(\WP_REST_Request) (обязательный)
- Request object.
Код CartAddItem::get_route_post_response() CartAddItem::get route post response WC 6.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; }