Validate order items on post, not on draft order creation (https://github.com/woocommerce/woocommerce-blocks/pull/3810)
This commit is contained in:
parent
77119d9a7e
commit
d90e212f74
|
@ -194,6 +194,14 @@ class Checkout extends AbstractRoute {
|
||||||
* @return WP_REST_Response
|
* @return WP_REST_Response
|
||||||
*/
|
*/
|
||||||
protected function get_route_post_response( WP_REST_Request $request ) {
|
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.
|
* Obtain Draft Order and process request data.
|
||||||
*
|
*
|
||||||
|
@ -340,15 +348,10 @@ class Checkout extends AbstractRoute {
|
||||||
* @throws RouteException On error.
|
* @throws RouteException On error.
|
||||||
*/
|
*/
|
||||||
private function create_or_update_draft_order() {
|
private function create_or_update_draft_order() {
|
||||||
$cart_controller = new CartController();
|
|
||||||
$order_controller = new OrderController();
|
$order_controller = new OrderController();
|
||||||
$reserve_stock = new ReserveStock();
|
$reserve_stock = new ReserveStock();
|
||||||
$this->order = $this->get_draft_order_id() ? wc_get_order( $this->get_draft_order_id() ) : null;
|
$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 ) ) {
|
if ( ! $this->is_valid_draft_order( $this->order ) ) {
|
||||||
$this->order = $order_controller->create_order_from_cart();
|
$this->order = $order_controller->create_order_from_cart();
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue