Skip to content

Commit

Permalink
Merge branch 'fix/wcfm-order-issues' into feat/yithmultivendor-to-dokan
Browse files Browse the repository at this point in the history
# Conflicts:
#	includes/Processors/Order.php
  • Loading branch information
Aunshon committed Aug 28, 2023
2 parents 5333644 + 9e16525 commit a0e9566
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions includes/Processors/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,26 @@ 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;

case 'yithvendors':

Check failure on line 38 in includes/Processors/Order.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

There must be a comment when fall-through is intentional in a non-empty case body
$total = (int) dokan()->order->all(
[
'return' => 'count',
'parent' => 0,
]
);

default:
$total = 0;
}

return $total;
}

/**
Expand All @@ -41,14 +60,37 @@ public static function get_total( $plugin ) {
* @throws \Exception
*/
public static function get_items( $plugin, $number, $offset ) {
global $wpdb;
$args = array(
'order' => 'ASC',
'paged' => $offset + 1,
'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();
Expand Down

0 comments on commit a0e9566

Please sign in to comment.