diff --git a/plugins/woocommerce-blocks/src/Installer.php b/plugins/woocommerce-blocks/src/Installer.php index 17e9186a60e..553ed61af54 100644 --- a/plugins/woocommerce-blocks/src/Installer.php +++ b/plugins/woocommerce-blocks/src/Installer.php @@ -58,8 +58,8 @@ class Installer { `order_id` bigint(20) NOT NULL, `product_id` bigint(20) NOT NULL, `stock_quantity` double NOT NULL DEFAULT 0, - `timestamp` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - `expires` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `timestamp` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + `expires` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY (`order_id`, `product_id`) ) $collate; " diff --git a/plugins/woocommerce-blocks/src/StoreApi/Utilities/ReserveStock.php b/plugins/woocommerce-blocks/src/StoreApi/Utilities/ReserveStock.php index 72242f615ea..c3c172ec84e 100644 --- a/plugins/woocommerce-blocks/src/StoreApi/Utilities/ReserveStock.php +++ b/plugins/woocommerce-blocks/src/StoreApi/Utilities/ReserveStock.php @@ -162,9 +162,10 @@ final class ReserveStock { $result = $wpdb->query( $wpdb->prepare( " - REPLACE INTO {$wpdb->wc_reserved_stock} ( order_id, product_id, stock_quantity, expires ) - SELECT %d, %d, %d, ( NOW() + INTERVAL %d MINUTE ) from DUAL + INSERT INTO {$wpdb->wc_reserved_stock} ( `order_id`, `product_id`, `stock_quantity`, `timestamp`, `expires` ) + SELECT %d, %d, %d, NOW(), ( NOW() + INTERVAL %d MINUTE ) FROM DUAL WHERE ( $query_for_stock FOR UPDATE ) - ( $query_for_reserved_stock FOR UPDATE ) >= %d + ON DUPLICATE KEY UPDATE `expires` = VALUES( `expires` ) ", $order->get_id(), $product_id,