Changeset 3490345
- Timestamp:
- 03/24/2026 08:19:20 PM (4 days ago)
- Location:
- routeapp/trunk
- Files:
-
- 5 edited
-
admin/class-routeapp-order-recover.php (modified) (5 diffs)
-
includes/class-routeapp-cron-schedules.php (modified) (6 diffs)
-
public/js/routeapp-public-pbc.js (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
-
routeapp.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
routeapp/trunk/admin/class-routeapp-order-recover.php
r3490342 r3490345 100 100 */ 101 101 private function getOrdersBatch($batchSize, $offset, $recoverTo, $recoverFrom) { 102 $args = [103 'limit' =>$batchSize,104 'offset' =>$offset,105 'date_created' => '>=' . $recoverFrom,106 'date_created' => '<=' . $recoverTo,107 ];108 109 return wc_get_orders( $args);102 $args = array( 103 'limit' => (int) $batchSize, 104 'offset' => (int) $offset, 105 'type' => 'shop_order', 106 'date_created' => $recoverFrom . '...' . $recoverTo, 107 ); 108 109 return wc_get_orders( $args ); 110 110 } 111 111 … … 131 131 public function massiveOrderSave($orders) { 132 132 foreach ($orders as $order) { 133 Routeapp_Cron_Schedules::updateOrderStatusMetaIfNeeded( $order, false ); 133 134 $order->save(); 134 135 } … … 143 144 public function updateOrderPostMeta($orders) { 144 145 foreach ($orders as $order) { 145 if (!get_post_meta( $order->get_id(), '_routeapp_order_id')) { 146 Routeapp_Cron_Schedules::updateOrderStatusMetaIfNeeded( $order ); 147 148 $has_route_meta = method_exists( $order, 'get_meta' ) 149 ? $order->get_meta( '_routeapp_order_id' ) 150 : get_post_meta( $order->get_id(), '_routeapp_order_id', true ); 151 if ( ! $has_route_meta ) { 146 152 //check if order exists on Route side 147 153 $getOrderResponse = Routeapp_API_Client::getInstance()->get_order($order->get_id()); … … 156 162 /** 157 163 * Get the count of orders based on the specified date range. 158 * 159 * @param string $from Starting date for the orders. 160 * @param string $to Ending date for the orders. 164 * Supports both High-performance order storage (HPOS) and WordPress posts storage (legacy). 165 * 166 * @param string $from Starting date for the orders (YYYY-MM-DD). 167 * @param string $to Ending date for the orders (YYYY-MM-DD). 161 168 * @return int The count of orders. 162 169 */ … … 164 171 global $wpdb; 165 172 166 $query = " 167 SELECT COUNT(1) 173 $from_date = $from . ' 00:00:00'; 174 $to_date = $to . ' 23:59:59'; 175 176 if ( $this->is_hpos_enabled() ) { 177 // High-performance order storage: query wc_orders table 178 $orders_table = $wpdb->prefix . 'wc_orders'; 179 $from_gmt = get_gmt_from_date( $from_date ); 180 $to_gmt = get_gmt_from_date( $to_date ); 181 182 $query = $wpdb->prepare( 183 "SELECT COUNT(1) 184 FROM {$orders_table} AS orders 185 WHERE orders.type = 'shop_order' 186 AND orders.status NOT IN ( 'wc-auto-draft', 'auto-draft', 'trash' ) 187 AND orders.date_created_gmt >= %s 188 AND orders.date_created_gmt <= %s", 189 $from_gmt, 190 $to_gmt 191 ); 192 } else { 193 // WordPress posts storage (legacy): query wp_posts 194 $query = $wpdb->prepare( 195 "SELECT COUNT(1) 168 196 FROM {$wpdb->posts} AS posts 169 WHERE posts.post_type = 'shop_order_placehold' 197 WHERE posts.post_type = 'shop_order' 198 AND posts.post_status NOT IN ( 'wc-auto-draft', 'auto-draft', 'trash' ) 170 199 AND posts.post_date >= %s 171 AND posts.post_date <= %s 172 "; 173 174 $prepared_query = $wpdb->prepare($query, $from, $to); 175 $order_count = $wpdb->get_var($prepared_query); 176 177 return $order_count; 200 AND posts.post_date <= %s", 201 $from_date, 202 $to_date 203 ); 204 } 205 206 return (int) $wpdb->get_var( $query ); 207 } 208 209 /** 210 * Check if High-performance order storage (HPOS) is enabled. 211 * 212 * @return bool True if HPOS is enabled, false otherwise. 213 */ 214 private function is_hpos_enabled() { 215 if ( ! class_exists( 'Automattic\WooCommerce\Utilities\OrderUtil' ) ) { 216 return false; 217 } 218 return \Automattic\WooCommerce\Utilities\OrderUtil::custom_orders_table_usage_is_enabled(); 178 219 } 179 220 -
routeapp/trunk/includes/class-routeapp-cron-schedules.php
r3102499 r3490345 308 308 309 309 /** 310 * Update order status meta (_routeapp_included_order_statuses, _routeapp_cancel_order_statuses) 311 * only if they don't exist or are different from current options. 312 * 313 * @param \WC_Order $order The order to update. 314 * @param bool $auto_save If true (default), saves the order when HPOS and meta changed. 315 * Set to false when the caller will save the order (e.g. massiveOrderSave). 316 * @return void 317 */ 318 public static function updateOrderStatusMetaIfNeeded( $order, $auto_save = true ) { 319 if ( ! $order ) { 320 return; 321 } 322 $routeapp_public = self::get_route_public_instance(); 323 if ( ! $routeapp_public ) { 324 return; 325 } 326 $is_hpos = class_exists( 'Automattic\WooCommerce\Utilities\OrderUtil' ) 327 && OrderUtil::custom_orders_table_usage_is_enabled(); 328 $acceptedOrderStatuses = get_option( 'routeapp_included_order_statuses' ) ? get_option( 'routeapp_included_order_statuses' ) : array(); 329 $acceptedCanceledStatuses = get_option( 'routeapp_cancel_order_statuses' ) ? get_option( 'routeapp_cancel_order_statuses' ) : array(); 330 331 $updated = false; 332 $updated |= $routeapp_public->updateRouteOrderMetaData( $order, $is_hpos, '_routeapp_included_order_statuses', $acceptedOrderStatuses ); 333 $updated |= $routeapp_public->updateRouteOrderMetaData( $order, $is_hpos, '_routeapp_cancel_order_statuses', $acceptedCanceledStatuses ); 334 335 if ( $updated && $is_hpos && $auto_save ) { 336 $order->save(); 337 } 338 } 339 340 /** 310 341 * Update order post_meta with route order data 311 342 * … … 319 350 $routeCharge = $routeOrder['insured_status'] == 'insured_selected' ? $routeOrder['paid_to_insure'] : ''; 320 351 $protected = !empty($routeCharge) ? 1 : 0; 352 $acceptedOrderStatuses = get_option( 'routeapp_included_order_statuses' ) ? get_option( 'routeapp_included_order_statuses' ) : array(); 353 $acceptedCanceledStatuses = get_option( 'routeapp_cancel_order_statuses' ) ? get_option( 'routeapp_cancel_order_statuses' ) : array(); 354 321 355 if ( class_exists('Automattic\WooCommerce\Utilities\OrderUtil') 322 && OrderUtil::custom_orders_table_usage_is_enabled() ) {356 && OrderUtil::custom_orders_table_usage_is_enabled() ) { 323 357 // HPOS usage is enabled. 324 $order->update_meta_data( '_routeapp_order_id',$routeOrder['id'] );325 $order->update_meta_data( '_routeapp_route_charge', $routeCharge );326 $order->update_meta_data( '_routeapp_route_protection', $protected );327 358 $order->update_meta_data( '_routeapp_order_id', $routeOrder['id'] ); 359 $order->update_meta_data( '_routeapp_route_charge', $routeCharge ); 360 $order->update_meta_data( '_routeapp_route_protection', $protected ); 361 self::updateOrderStatusMetaIfNeeded( $order, false ); 328 362 $order->save(); 329 363 } else { … … 332 366 update_post_meta( $order->get_id(), '_routeapp_route_charge', $routeCharge ); 333 367 update_post_meta( $order->get_id(), '_routeapp_route_protection', $protected ); 368 self::updateOrderStatusMetaIfNeeded( $order ); 334 369 } 335 370 } … … 367 402 $routeCharge = $body->insured_status == 'insured_selected' ? $body->paid_to_insure : ''; 368 403 $protected = !empty($routeCharge) ? 1 : 0; 404 $acceptedOrderStatuses = get_option( 'routeapp_included_order_statuses' ) ? get_option( 'routeapp_included_order_statuses' ) : array(); 405 $acceptedCanceledStatuses = get_option( 'routeapp_cancel_order_statuses' ) ? get_option( 'routeapp_cancel_order_statuses' ) : array(); 406 369 407 if ( class_exists('Automattic\WooCommerce\Utilities\OrderUtil') 370 && OrderUtil::custom_orders_table_usage_is_enabled() ) {408 && OrderUtil::custom_orders_table_usage_is_enabled() ) { 371 409 // HPOS usage is enabled. 372 410 $order->update_meta_data('_routeapp_order_id', $body->id ); 373 411 $order->update_meta_data('_routeapp_route_charge', $routeCharge ); 374 412 $order->update_meta_data('_routeapp_route_protection', $protected ); 375 413 self::updateOrderStatusMetaIfNeeded( $order, false ); 376 414 $order->save(); 377 415 } else { … … 380 418 update_post_meta( $order->get_id(), '_routeapp_route_charge', $routeCharge ); 381 419 update_post_meta( $order->get_id(), '_routeapp_route_protection', $protected ); 420 self::updateOrderStatusMetaIfNeeded( $order ); 382 421 } 383 422 } … … 414 453 415 454 $args = array( 416 'post_type' => 'shop_order',417 'posts_per_page' => -1,418 'post_status' => array_merge($acceptedOrderStatuses, $acceptedCanceledStatuses),419 'date_created' => '>=' . $after,420 'meta_query' => array(421 array(422 'key' => 'routeapp_shipment_tracking_number',423 'value' => '',424 'compare' => '!='425 ),426 array(427 'key' => 'routeapp_shipment_cron_api_called',428 'compare' => 'NOT EXISTS'429 ),430 )455 'post_type' => 'shop_order', 456 'posts_per_page' => -1, 457 'post_status' => array_merge($acceptedOrderStatuses, $acceptedCanceledStatuses), 458 'date_created' => '>=' . $after, 459 'meta_query' => array( 460 array( 461 'key' => 'routeapp_shipment_tracking_number', 462 'value' => '', 463 'compare' => '!=' 464 ), 465 array( 466 'key' => 'routeapp_shipment_cron_api_called', 467 'compare' => 'NOT EXISTS' 468 ), 469 ) 431 470 ); 432 471 -
routeapp/trunk/public/js/routeapp-public-pbc.js
r3490342 r3490345 67 67 */ 68 68 function triggerBlocksCheckoutCartUpdate() { 69 if (isBlocksCheckoutAvailable()) { 70 try { 71 wc.blocksCheckout.extensionCartUpdate({ 72 namespace: 'route-widget-integration', 73 data: { 74 checkbox: RouteConfig.checkbox === Route.Coverage.ActiveByDefault 75 } 76 }).then(function() { 77 // Cart update successful - the frontend will automatically refresh 78 }).catch(function(error) { 79 console.error('Route widget: Cart update failed:', error); 80 // Fallback to traditional checkout update 81 triggerCheckoutUpdate(); 82 }); 83 } catch (error) { 84 console.error('Route widget: Error triggering blocks checkout update:', error); 85 // Fallback to traditional checkout update 69 if (!isBlocksCheckoutAvailable()) { 70 triggerCheckoutUpdate(); 71 return; 72 } 73 74 try { 75 wc.blocksCheckout.extensionCartUpdate({ 76 namespace: 'route-widget-integration', 77 data: { 78 checkbox: RouteConfig.checkbox === Route.Coverage.ActiveByDefault 79 } 80 }).catch(function(error) { 81 console.error('Route widget: Cart update failed:', error); 82 }).finally(function() { 86 83 triggerCheckoutUpdate(); 87 } 88 } else{89 // Fallback to traditional checkout update if blocks checkout is not available84 }); 85 } catch (error) { 86 console.error('Route widget: Error triggering blocks checkout update:', error); 90 87 triggerCheckoutUpdate(); 91 88 } … … 102 99 }, 103 100 success: function () { 104 if (RouteConfig.is_cart_page) { 101 if (isBlocksCheckoutAvailable()) { 102 triggerBlocksCheckoutCartUpdate(); 103 } else if (RouteConfig.is_cart_page) { 105 104 triggerCartUpdate(); 106 105 } else { 107 // Use blocks checkout update if available, otherwise fallback to traditional 108 if (isBlocksCheckoutAvailable()) { 109 triggerBlocksCheckoutCartUpdate(); 110 } else { 111 triggerCheckoutUpdate(); 112 } 106 triggerCheckoutUpdate(); 113 107 } 114 108 -
routeapp/trunk/readme.txt
r3490342 r3490345 6 6 Requires at least: 4.0 7 7 Tested up to: 6.7.1 8 Stable tag: 2.3. 08 Stable tag: 2.3.3 9 9 Requires PHP: 5.6 10 10 License: GPLv2 or later … … 106 106 107 107 == Changelog == 108 109 = 2.3.3 = 110 * Update order sync with the latest order sync status 111 112 = 2.3.2 = 113 * Fix order sync compatibility with HPOS and legacy storage 114 115 = 2.3.1 = 116 * Fix checkout order summary not updating when Route protection is toggled on blocks-based checkout 108 117 109 118 = 2.3.0 = -
routeapp/trunk/routeapp.php
r3490342 r3490345 10 10 * Plugin URI: https://route.com/for-merchants/ 11 11 * Description: Route allows shoppers to insure their orders with one-click during checkout, adding a layer of 3rd party trust while improving the customer shopping experience. 12 * Version: 2.3. 012 * Version: 2.3.3 13 13 * Author: Route 14 14 * Author URI: https://route.com/ … … 26 26 * Currently plugin version. 27 27 */ 28 define( 'ROUTEAPP_VERSION', '2.3. 0' );28 define( 'ROUTEAPP_VERSION', '2.3.3' ); 29 29 30 30 /**
Note: See TracChangeset
for help on using the changeset viewer.