Automattic\WooCommerce\StoreApi\Routes\V1
CartItems::get_route_post_response
Creates one item from the collection.
Метод класса: CartItems{}
Хуков нет.
Возвращает
\WP_REST_Response.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->get_route_post_response( $request );
- $request(WP_REST_Request) (обязательный)
- Request object.
Код CartItems::get_route_post_response() CartItems::get route post response WC 11.0.1
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 );
}
$result = $this->cart_controller->add_to_cart(
[
'id' => $request['id'],
'quantity' => $request['quantity'],
'variation' => $request['variation'],
]
);
$response = rest_ensure_response( $this->prepare_item_for_response( $this->cart_controller->get_cart_item( $result ), $request ) );
$response->set_status( 201 );
return $response;
}