From b32e9649e8e64d394fa097c602533a6e342a04a7 Mon Sep 17 00:00:00 2001 From: Aunshon Date: Thu, 30 Nov 2023 11:26:34 +0600 Subject: [PATCH] Fix: WCFM withdraw plugin select switch case (#14) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix: wcvendors withdraw plugin select switch case * Fix: wcvendors withdraw plugin select switch case * Fix: wcvendors withdraw plugin select switch case * ⚡️Fix: exclude dokan orders, migrate wcfm orders only. * ⚡️Fix: exclude dokan orders, migrate wcfm orders only. * ⚡️Fix: exclude dokan orders, migrate wcfm orders only. * ⚡️Fix: exclude dokan orders, migrate wcfm orders only. * ⚡️Fix: exclude dokan orders, migrate wcfm orders only. * ⚡️Fix: exclude dokan orders, migrate wcfm orders only. * ⚡️HPOS support * add paged parameter in get_items in processor and in other classes that extended it. --- includes/Processors/Order.php | 45 ++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/includes/Processors/Order.php b/includes/Processors/Order.php index 21d9978..91a3aaf 100644 --- a/includes/Processors/Order.php +++ b/includes/Processors/Order.php @@ -27,7 +27,18 @@ class Order extends Processor { * @return integer */ public static function get_total( $plugin ) { - return (int) dokan()->order->all( [ 'return' => 'count', 'parent' => 0, ] ); + global $wpdb; + + switch ( $plugin ) { + case 'wcfmmarketplace': + $total = (int) $wpdb->get_var( "SELECT COUNT( DISTINCT order_id ) FROM {$wpdb->prefix}wcfm_marketplace_orders" ); + break; + + default: + $total = 0; + } + + return $total; } /** @@ -41,14 +52,30 @@ public static function get_total( $plugin ) { */ public static function get_items( $plugin, $number, $offset, $paged ) { global $wpdb; - $args = array( - 'order' => 'ASC', - 'paged' => $paged, - 'limit' => $number, - 'parent' => 0, - ); - - $orders = dokan()->order->all( $args ); + + switch ( $plugin ) { + case 'wcfmmarketplace': + $orders = []; + $wcfm_orders = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT order_id FROM {$wpdb->prefix}wcfm_marketplace_orders LIMIT %d OFFSET %d", $number, $offset ), ARRAY_A ); + $wcfm_orders = array_map( + function ( $item ) { + return $item['order_id']; + }, + $wcfm_orders + ); + + if ( ! empty( $wcfm_orders ) ) { + $orders = dokan()->order->all( + [ + 'include' => $wcfm_orders, + ] + ); + } + break; + + default: + $orders = []; + } if ( empty( $orders ) ) { self::throw_error();