Skip to content

Commit 53c3479

Browse files
committed
Added options and custom query
1 parent c1a5af6 commit 53c3479

File tree

3 files changed

+98
-52
lines changed

3 files changed

+98
-52
lines changed

src/Models/Customer.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,33 @@
66

77
class Customer
88
{
9-
public function all()
9+
public function all($options = [])
1010
{
11-
return WooCommerce::all('customers');
11+
return WooCommerce::all('customers', $options);
1212
}
1313

14-
public function find($id)
14+
public function find($id, $options = [])
1515
{
16-
return WooCommerce::find('customers/'.$id);
16+
return WooCommerce::find("customers/{$id}", $options);
1717
}
1818

19-
public function create( $data ) {
20-
return WooCommerce::create('customers', $data);
19+
public function create($data)
20+
{
21+
return WooCommerce::create('customers', $data);
2122
}
2223

23-
public function update( $id, $data ) {
24-
return WooCommerce::update('customers/'.$id, $data);
24+
public function update($id, $data)
25+
{
26+
return WooCommerce::update("customers/{$id}", $data);
2527
}
2628

27-
public function delete( $id, $options=[] ) {
28-
return WooCommerce::delete('customers/'.$id, $options);
29+
public function delete($id, $options = [])
30+
{
31+
return WooCommerce::delete("customers/{$id}", $options);
2932
}
3033

31-
public function batch( $data ) {
32-
return WooCommerce::create('customers/batch', $options);
34+
public function batch($data)
35+
{
36+
return WooCommerce::create('customers/batch', $options);
3337
}
3438
}

src/Models/Order.php

Lines changed: 66 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,76 +6,114 @@
66

77
class Order
88
{
9+
protected $options = [];
10+
protected $results = [];
911

10-
public function all()
12+
public function all($options = [])
1113
{
12-
return WooCommerce::all('orders');
14+
return WooCommerce::all('orders', $options);
1315
}
1416

15-
public function find($id)
17+
public function find($id, $options = [])
1618
{
17-
return WooCommerce::find("orders/{$id}");
19+
return WooCommerce::find("orders/{$id}", $options);
1820
}
1921

20-
public function create( $data ) {
21-
return WooCommerce::create('orders', $data);
22+
public function create($data)
23+
{
24+
return WooCommerce::create('orders', $data);
2225
}
2326

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);
2630
}
2731

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);
3035
}
3136

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);
3440
}
3541

3642
/*
3743
* Note
3844
*/
3945

40-
public function notes( $order_id )
46+
public function notes($order_id, $options = [])
4147
{
42-
return WooCommerce::all("orders/{$order_id}/notes");
48+
return WooCommerce::all("orders/{$order_id}/notes", $options);
4349
}
4450

45-
public function note( $order_id, $note_id )
51+
public function note($order_id, $note_id)
4652
{
47-
return WooCommerce::create("orders/{$order_id}/notes/{$note_id}");
53+
return WooCommerce::create("orders/{$order_id}/notes/{$note_id}");
4854
}
4955

50-
public function createNote( $order_id )
56+
public function createNote($order_id)
5157
{
52-
return WooCommerce::create("orders/{$order_id}/notes");
58+
return WooCommerce::create("orders/{$order_id}/notes");
5359
}
5460

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);
5764
}
5865

5966
/*
6067
* Refund
6168
*/
6269

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)
6481
{
65-
return WooCommerce::all("orders/{$order_id}/refunds");
82+
return WooCommerce::create("orders/{$order_id}/refunds");
6683
}
6784

68-
public function refund( $order_id, $refund_id )
85+
public function deleteRefund($order_id, $refund_id, $options = [])
6986
{
70-
return WooCommerce::create("orders/{$order_id}/refunds/{$refund_id}");
87+
return WooCommerce::delete("orders/{$order_id}/refunds/{$refund_id}", $options);
7188
}
7289

73-
public function createRefund( $order_id )
90+
/* Custom Query */
91+
public function where(...$parameters)
7492
{
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;
76107
}
77108

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];
80118
}
81119
}

src/Models/Product.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,33 @@
66

77
class Product
88
{
9-
public function all()
9+
public function all($options = [])
1010
{
11-
return WooCommerce::all('products');
11+
return WooCommerce::all('products', $options);
1212
}
1313

14-
public function find($id)
14+
public function find($id, $options = [])
1515
{
16-
return WooCommerce::find('products/'.$id);
16+
return WooCommerce::find("products/{$id}", $options);
1717
}
1818

19-
public function create( $data ) {
20-
return WooCommerce::create('products', $data);
19+
public function create($data)
20+
{
21+
return WooCommerce::create('products', $data);
2122
}
2223

23-
public function update( $id, $data ) {
24-
return WooCommerce::update('products/'.$id, $data);
24+
public function update($id, $data)
25+
{
26+
return WooCommerce::update("products/{$id}", $data);
2527
}
2628

27-
public function delete( $id, $options=[] ) {
28-
return WooCommerce::delete('products/'.$id, $options);
29+
public function delete($id, $options = [])
30+
{
31+
return WooCommerce::delete("products/{$id}", $options);
2932
}
3033

31-
public function batch( $data ) {
32-
return WooCommerce::create('products/batch', $options);
34+
public function batch($data)
35+
{
36+
return WooCommerce::create('products/batch', $options);
3337
}
3438
}

0 commit comments

Comments
 (0)