|
6 | 6 |
|
7 | 7 | class Order |
8 | 8 | { |
| 9 | + protected $options = []; |
| 10 | + protected $results = []; |
9 | 11 |
|
10 | | - public function all() |
| 12 | + public function all($options = []) |
11 | 13 | { |
12 | | - return WooCommerce::all('orders'); |
| 14 | + return WooCommerce::all('orders', $options); |
13 | 15 | } |
14 | 16 |
|
15 | | - public function find($id) |
| 17 | + public function find($id, $options = []) |
16 | 18 | { |
17 | | - return WooCommerce::find("orders/{$id}"); |
| 19 | + return WooCommerce::find("orders/{$id}", $options); |
18 | 20 | } |
19 | 21 |
|
20 | | - public function create( $data ) { |
21 | | - return WooCommerce::create('orders', $data); |
| 22 | + public function create($data) |
| 23 | + { |
| 24 | + return WooCommerce::create('orders', $data); |
22 | 25 | } |
23 | 26 |
|
24 | | - public function update( $id, $data ) { |
25 | | - return WooCommerce::update("orders/{$id}", $data); |
| 27 | + public function update($id, $data) |
| 28 | + { |
| 29 | + return WooCommerce::update("orders/{$id}", $data); |
26 | 30 | } |
27 | 31 |
|
28 | | - public function delete( $id, $options=[] ) { |
29 | | - return WooCommerce::delete("orders/{$id}", $options); |
| 32 | + public function delete($id, $options = []) |
| 33 | + { |
| 34 | + return WooCommerce::delete("orders/{$id}", $options); |
30 | 35 | } |
31 | 36 |
|
32 | | - public function batch( $data ) { |
33 | | - return WooCommerce::create('orders/batch', $options); |
| 37 | + public function batch($data) |
| 38 | + { |
| 39 | + return WooCommerce::create('orders/batch', $data); |
34 | 40 | } |
35 | 41 |
|
36 | 42 | /* |
37 | 43 | * Note |
38 | 44 | */ |
39 | 45 |
|
40 | | - public function notes( $order_id ) |
| 46 | + public function notes($order_id, $options = []) |
41 | 47 | { |
42 | | - return WooCommerce::all("orders/{$order_id}/notes"); |
| 48 | + return WooCommerce::all("orders/{$order_id}/notes", $options); |
43 | 49 | } |
44 | 50 |
|
45 | | - public function note( $order_id, $note_id ) |
| 51 | + public function note($order_id, $note_id) |
46 | 52 | { |
47 | | - return WooCommerce::create("orders/{$order_id}/notes/{$note_id}"); |
| 53 | + return WooCommerce::create("orders/{$order_id}/notes/{$note_id}"); |
48 | 54 | } |
49 | 55 |
|
50 | | - public function createNote( $order_id ) |
| 56 | + public function createNote($order_id) |
51 | 57 | { |
52 | | - return WooCommerce::create("orders/{$order_id}/notes"); |
| 58 | + return WooCommerce::create("orders/{$order_id}/notes"); |
53 | 59 | } |
54 | 60 |
|
55 | | - public function deleteNote( $order_id, $note_id, $options = [] ) { |
56 | | - return WooCommerce::delete("orders/{$order_id}/notes/{$note_id}", $options); |
| 61 | + public function deleteNote($order_id, $note_id, $options = []) |
| 62 | + { |
| 63 | + return WooCommerce::delete("orders/{$order_id}/notes/{$note_id}", $options); |
57 | 64 | } |
58 | 65 |
|
59 | 66 | /* |
60 | 67 | * Refund |
61 | 68 | */ |
62 | 69 |
|
63 | | - public function refunds( $order_id ) |
| 70 | + public function refunds($order_id, $options = []) |
| 71 | + { |
| 72 | + return WooCommerce::all("orders/{$order_id}/refunds", $options); |
| 73 | + } |
| 74 | + |
| 75 | + public function refund($order_id, $refund_id) |
| 76 | + { |
| 77 | + return WooCommerce::create("orders/{$order_id}/refunds/{$refund_id}"); |
| 78 | + } |
| 79 | + |
| 80 | + public function createRefund($order_id) |
64 | 81 | { |
65 | | - return WooCommerce::all("orders/{$order_id}/refunds"); |
| 82 | + return WooCommerce::create("orders/{$order_id}/refunds"); |
66 | 83 | } |
67 | 84 |
|
68 | | - public function refund( $order_id, $refund_id ) |
| 85 | + public function deleteRefund($order_id, $refund_id, $options = []) |
69 | 86 | { |
70 | | - return WooCommerce::create("orders/{$order_id}/refunds/{$refund_id}"); |
| 87 | + return WooCommerce::delete("orders/{$order_id}/refunds/{$refund_id}", $options); |
71 | 88 | } |
72 | 89 |
|
73 | | - public function createRefund( $order_id ) |
| 90 | + /* Custom Query */ |
| 91 | + public function where(...$parameters) |
74 | 92 | { |
75 | | - return WooCommerce::create("orders/{$order_id}/refunds"); |
| 93 | + if (count($parameters) == 2) { |
| 94 | + $this->options[$parameters[0]] = $parameters[1]; |
| 95 | + } |
| 96 | + |
| 97 | + if (count($parameters) == 1) { |
| 98 | + |
| 99 | + foreach ($parameters as $parameter) { |
| 100 | + |
| 101 | + foreach ($parameter as $key => $value) { |
| 102 | + $this->options[$key] = $value; |
| 103 | + } |
| 104 | + } |
| 105 | + } |
| 106 | + return $this; |
76 | 107 | } |
77 | 108 |
|
78 | | - public function deleteRefund( $order_id, $refund_id, $options = [] ) { |
79 | | - return WooCommerce::delete("orders/{$order_id}/refunds/{$refund_id}", $options); |
| 109 | + public function get() |
| 110 | + { |
| 111 | + return WooCommerce::all('orders', $this->options); |
| 112 | + } |
| 113 | + |
| 114 | + public function first() |
| 115 | + { |
| 116 | + $order = $this->get()[0]; |
| 117 | + return ['order' => $order]; |
80 | 118 | } |
81 | 119 | } |
0 commit comments