Validate order items on post, not on draft order creation (https://github.com/woocommerce/woocommerce-blocks/pull/3810)

This commit is contained in:
Mike Jolley 2021-02-09 12:43:45 +00:00 committed by GitHub
parent 77119d9a7e
commit d90e212f74
1 changed files with 8 additions and 5 deletions

View File

@ -194,6 +194,14 @@ class Checkout extends AbstractRoute {
* @return WP_REST_Response
*/
protected function get_route_post_response( WP_REST_Request $request ) {
/**
* Validate items etc are allowed in the order before the order is processed. This will fix violations and tell
* the customer.
*/
$cart_controller = new CartController();
$cart_controller->validate_cart_items();
$cart_controller->validate_cart_coupons();
/**
* Obtain Draft Order and process request data.
*
@ -340,15 +348,10 @@ class Checkout extends AbstractRoute {
* @throws RouteException On error.
*/
private function create_or_update_draft_order() {
$cart_controller = new CartController();
$order_controller = new OrderController();
$reserve_stock = new ReserveStock();
$this->order = $this->get_draft_order_id() ? wc_get_order( $this->get_draft_order_id() ) : null;
// Validate items etc are allowed in the order before it gets created.
$cart_controller->validate_cart_items();
$cart_controller->validate_cart_coupons();
if ( ! $this->is_valid_draft_order( $this->order ) ) {
$this->order = $order_controller->create_order_from_cart();
} else {