Order.php
1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
namespace ACA\WC\Export\Strategy;
use AC;
use AC\ListTable;
use ACA\WC\ListTable\Orders;
use ACP\Export\Strategy;
use Automattic;
use Automattic\WooCommerce\Internal\DataStores\Orders\OrdersTableQuery;
class Order extends Strategy
{
/**
* @var string
*/
private $order_type;
public function __construct(AC\ListScreen $list_screen, $order_type = 'shop_order')
{
parent::__construct($list_screen);
$this->order_type = $order_type;
}
public function get_total_items(): int
{
return $this->get_list_table()->get_total_items();
}
protected function ajax_export(): void
{
ob_start();
add_filter('woocommerce_order_list_table_prepare_items_query_args', [$this, 'catch_posts'], 1000);
add_filter('woocommerce_orders_table_query_clauses', [$this, 'alter_clauses'], 100, 2);
}
public function alter_clauses($clauses, OrdersTableQuery $query): array
{
$ids = $this->get_requested_ids();
if ($ids) {
$column = $query->get_table_name('orders') . '.ID';
$ids = array_map('absint', $ids);
$clauses['where'] .= sprintf(' AND %s IN( %s )', $column, implode(',', $ids));
}
return $clauses;
}
public function catch_posts($args): void
{
ob_get_clean();
$args['return'] = 'ids';
$args['type'] = $this->order_type;
$args['page'] = $this->get_export_counter() + 1;
$args['limit'] = $this->get_num_items_per_iteration();
$orders = wc_get_orders($args);
$this->export($orders->orders);
}
protected function get_list_table(): ListTable
{
return new Orders(
wc_get_container()->get(Automattic\WooCommerce\Internal\Admin\Orders\ListTable::class)
);
}
}