-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathOrderBuilder.php
90 lines (76 loc) · 1.79 KB
/
OrderBuilder.php
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
declare(strict_types=1);
namespace Corcel\WooCommerce\Model\Builder;
use Corcel\Model\Builder\PostBuilder;
class OrderBuilder extends PostBuilder
{
/**
* Scope a query to only cancelled orders.
*/
public function cancelled(): PostBuilder
{
return $this->status('cancelled');
}
/**
* Scope a query to only completed orders.
*/
public function completed(): PostBuilder
{
return $this->status('completed');
}
/**
* Scope a query to only failed orders.
*/
public function failed(): PostBuilder
{
return $this->status('failed');
}
/**
* Scope a query to only on hold orders.
*/
public function onHold(): PostBuilder
{
return $this->status('on-hold');
}
/**
* Scope a query to only pending orders.
*/
public function pending(): PostBuilder
{
return $this->status('pending');
}
/**
* Scope a query to only processing orders.
*/
public function processing(): PostBuilder
{
return $this->status('processing');
}
/**
* Scope a query to only refunded orders.
*/
public function refunded(): PostBuilder
{
return $this->status('refunded');
}
/**
* Scope a query to orders with given status.
*/
public function status($status): PostBuilder
{
$status = substr($status, 0, 3) === 'wc-' ? substr($status, 3) : $status;
$builtin = [
'cancelled',
'completed',
'failed',
'on-hold',
'pending',
'processing',
'refunded',
];
if (in_array($status, $builtin)) {
$status = 'wc-'.$status;
}
return parent::status($status);
}
}