Skip to content

Commit cd88cd5

Browse files
committed
Added pagination for sub modules.
1 parent ef8e029 commit cd88cd5

File tree

11 files changed

+296
-128
lines changed

11 files changed

+296
-128
lines changed

src/Models/BaseModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ public function __call($method, $parameters)
4747

4848
public static function __callStatic($method, $parameters)
4949
{
50-
return (new static() )->$method(...$parameters);
50+
return (new static())->$method(...$parameters);
5151
}
5252
}

src/Models/Note.php

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Codexshaper\WooCommerce\Models;
44

5-
use Codexshaper\WooCommerce\Facades\WooCommerce;
65
use Codexshaper\WooCommerce\Traits\QueryBuilderTrait;
76

87
class Note extends BaseModel
@@ -21,7 +20,9 @@ class Note extends BaseModel
2120
*/
2221
protected function all($order_id, $options = [])
2322
{
24-
return WooCommerce::all("orders/{$order_id}/notes", $options);
23+
$this->endpoint = "orders/{$order_id}/notes";
24+
25+
return self::all($options);
2526
}
2627

2728
/**
@@ -35,7 +36,9 @@ protected function all($order_id, $options = [])
3536
*/
3637
protected function find($order_id, $note_id, $options = [])
3738
{
38-
return WooCommerce::find("orders/{$order_id}/notes/{$note_id}", $options);
39+
$this->endpoint = "orders/{$order_id}/notes";
40+
41+
return self::find($note_id, $options);
3942
}
4043

4144
/**
@@ -48,7 +51,9 @@ protected function find($order_id, $note_id, $options = [])
4851
*/
4952
protected function create($order_id, $data)
5053
{
51-
return WooCommerce::create("orders/{$order_id}/notes", $data);
54+
$this->endpoint = "orders/{$order_id}/notes";
55+
56+
return self::create($data);
5257
}
5358

5459
/**
@@ -62,6 +67,51 @@ protected function create($order_id, $data)
6267
*/
6368
protected function delete($order_id, $note_id, $options = [])
6469
{
65-
return WooCommerce::delete("orders/{$order_id}/notes/{$note_id}", $options);
70+
$this->endpoint = "orders/{$order_id}/notes";
71+
72+
return self::delete($note_id, $options);
73+
}
74+
75+
/**
76+
* Paginate results.
77+
*
78+
* @param int $per_page
79+
* @param int $current_page
80+
*
81+
* @return array
82+
*/
83+
protected function paginate(
84+
$order_id,
85+
$per_page = 10,
86+
$current_page = 1,
87+
$options = []
88+
) {
89+
$this->endpoint = "orders/{$order_id}/notes";
90+
91+
return self::paginate($per_page, $current_page, $options);
92+
}
93+
94+
/**
95+
* Count all results.
96+
*
97+
* @return int
98+
*/
99+
protected function count($order_id)
100+
{
101+
$this->endpoint = "orders/{$order_id}/notes";
102+
103+
return self::count();
104+
}
105+
106+
/**
107+
* Store data.
108+
*
109+
* @return array
110+
*/
111+
public function save($order_id)
112+
{
113+
$this->endpoint = "orders/{$order_id}/notes";
114+
115+
return self::save();
66116
}
67117
}

src/Models/Order.php

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Codexshaper\WooCommerce\Models;
44

5-
use Codexshaper\WooCommerce\Facades\WooCommerce;
65
use Codexshaper\WooCommerce\Traits\QueryBuilderTrait;
76

87
class Order extends BaseModel
@@ -17,22 +16,30 @@ class Order extends BaseModel
1716

1817
protected function notes($order_id, $options = [])
1918
{
20-
return WooCommerce::all("orders/{$order_id}/notes", $options);
19+
$this->endpoint = "orders/{$order_id}/notes";
20+
21+
return self::all($options);
2122
}
2223

23-
protected function note($order_id, $note_id)
24+
protected function note($order_id, $note_id, $options = [])
2425
{
25-
return WooCommerce::find("orders/{$order_id}/notes/{$note_id}");
26+
$this->endpoint = "orders/{$order_id}/notes";
27+
28+
return self::find($note_id, $options);
2629
}
2730

2831
protected function createNote($order_id, $data = [])
2932
{
30-
return WooCommerce::create("orders/{$order_id}/notes", $data);
33+
$this->endpoint = "orders/{$order_id}/notes";
34+
35+
return self::create($data);
3136
}
3237

3338
protected function deleteNote($order_id, $note_id, $options = [])
3439
{
35-
return WooCommerce::delete("orders/{$order_id}/notes/{$note_id}", $options);
40+
$this->endpoint = "orders/{$order_id}/notes";
41+
42+
return self::delete($note_id, $options);
3643
}
3744

3845
/*
@@ -41,21 +48,29 @@ protected function deleteNote($order_id, $note_id, $options = [])
4148

4249
protected function refunds($order_id, $options = [])
4350
{
44-
return WooCommerce::all("orders/{$order_id}/refunds", $options);
51+
$this->endpoint = "orders/{$order_id}/refunds";
52+
53+
return self::all($options);
4554
}
4655

47-
protected function refund($order_id, $refund_id)
56+
protected function refund($order_id, $refund_id, $options = [])
4857
{
49-
return WooCommerce::find("orders/{$order_id}/refunds/{$refund_id}");
58+
$this->endpoint = "orders/{$order_id}/refunds";
59+
60+
return self::find($refund_id, $options);
5061
}
5162

5263
protected function createRefund($order_id, $data = [])
5364
{
54-
return WooCommerce::create("orders/{$order_id}/refunds", $data);
65+
$this->endpoint = "orders/{$order_id}/refunds";
66+
67+
return self::create($data);
5568
}
5669

5770
protected function deleteRefund($order_id, $refund_id, $options = [])
5871
{
59-
return WooCommerce::delete("orders/{$order_id}/refunds/{$refund_id}", $options);
72+
$this->endpoint = "orders/{$order_id}/refunds";
73+
74+
return self::delete($refund_id, $options);
6075
}
6176
}

src/Models/Refund.php

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Codexshaper\WooCommerce\Models;
44

5-
use Codexshaper\WooCommerce\Facades\WooCommerce;
65
use Codexshaper\WooCommerce\Traits\QueryBuilderTrait;
76

87
class Refund extends BaseModel
@@ -21,7 +20,9 @@ class Refund extends BaseModel
2120
*/
2221
protected function all($order_id, $options = [])
2322
{
24-
return WooCommerce::all("orders/{$order_id}/refunds", $options);
23+
$this->endpoint = "orders/{$order_id}/refunds";
24+
25+
return self::all($options);
2526
}
2627

2728
/**
@@ -35,7 +36,9 @@ protected function all($order_id, $options = [])
3536
*/
3637
protected function find($order_id, $refund_id, $options = [])
3738
{
38-
return WooCommerce::find("orders/{$order_id}/refunds/{$refund_id}", $options);
39+
$this->endpoint = "orders/{$order_id}/refunds";
40+
41+
return self::find($refund_id, $options);
3942
}
4043

4144
/**
@@ -48,7 +51,9 @@ protected function find($order_id, $refund_id, $options = [])
4851
*/
4952
protected function create($order_id, $data)
5053
{
51-
return WooCommerce::create("orders/{$order_id}/refunds", $data);
54+
$this->endpoint = "orders/{$order_id}/refunds";
55+
56+
return self::create($data);
5257
}
5358

5459
/**
@@ -62,6 +67,51 @@ protected function create($order_id, $data)
6267
*/
6368
protected function delete($order_id, $refund_id, $options = [])
6469
{
65-
return WooCommerce::delete("orders/{$order_id}/refunds/{$refund_id}", $options);
70+
$this->endpoint = "orders/{$order_id}/refunds";
71+
72+
return self::delete($refund_id, $options);
73+
}
74+
75+
/**
76+
* Paginate results.
77+
*
78+
* @param int $per_page
79+
* @param int $current_page
80+
*
81+
* @return array
82+
*/
83+
protected function paginate(
84+
$order_id,
85+
$per_page = 10,
86+
$current_page = 1,
87+
$options = []
88+
) {
89+
$this->endpoint = "orders/{$order_id}/refunds";
90+
91+
return self::paginate($per_page, $current_page, $options);
92+
}
93+
94+
/**
95+
* Count all results.
96+
*
97+
* @return int
98+
*/
99+
protected function count($order_id)
100+
{
101+
$this->endpoint = "orders/{$order_id}/refunds";
102+
103+
return self::count();
104+
}
105+
106+
/**
107+
* Store data.
108+
*
109+
* @return array
110+
*/
111+
public function save($order_id)
112+
{
113+
$this->endpoint = "orders/{$order_id}/refunds";
114+
115+
return self::save();
66116
}
67117
}

src/Models/Setting.php

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,6 @@ class Setting extends BaseModel
1111

1212
protected $endpoint = 'settings';
1313

14-
/**
15-
* Retrieve all Items.
16-
*
17-
* @param array $options
18-
*
19-
* @return array
20-
*/
21-
protected function all($options = [])
22-
{
23-
return WooCommerce::all($this->endpoint, $options);
24-
}
25-
2614
/**
2715
* Retrieve option.
2816
*
@@ -34,7 +22,9 @@ protected function all($options = [])
3422
*/
3523
protected function option($group_id, $id, $options = [])
3624
{
37-
return WooCommerce::find("settings/{$group_id}/{$id}", $options);
25+
$this->endpoint = "settings/{$group_id}";
26+
27+
return self::find($id, $options);
3828
}
3929

4030
/**
@@ -47,7 +37,7 @@ protected function option($group_id, $id, $options = [])
4737
*/
4838
protected function options($id, $options = [])
4939
{
50-
return WooCommerce::find("settings/{$id}", $options);
40+
return self::find($id, $options);
5141
}
5242

5343
/**
@@ -61,7 +51,9 @@ protected function options($id, $options = [])
6151
*/
6252
protected function update($group_id, $id, $data)
6353
{
64-
return WooCommerce::update("settings/{$group_id}/{$id}", $data);
54+
$this->endpoint = "settings/{$group_id}";
55+
56+
return self::update($id, $data);
6557
}
6658

6759
/**
@@ -73,6 +65,8 @@ protected function update($group_id, $id, $data)
7365
*/
7466
protected function batch($id, $data)
7567
{
76-
return WooCommerce::create("settings/{$id}/batch", $data);
68+
$this->endpoint = "settings/{$id}";
69+
70+
return self::batch($data);
7771
}
7872
}

src/Models/ShippingMethod.php

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,11 @@
22

33
namespace Codexshaper\WooCommerce\Models;
44

5-
use Codexshaper\WooCommerce\Facades\WooCommerce;
65
use Codexshaper\WooCommerce\Traits\QueryBuilderTrait;
76

87
class ShippingMethod extends BaseModel
98
{
109
use QueryBuilderTrait;
1110

1211
protected $endpoint = 'shipping_methods';
13-
14-
/**
15-
* Retrieve all Items.
16-
*
17-
* @param array $options
18-
*
19-
* @return array
20-
*/
21-
protected function all($options = [])
22-
{
23-
return WooCommerce::all($this->endpoint, $options);
24-
}
25-
26-
/**
27-
* Retrieve single Item.
28-
*
29-
* @param int $id
30-
* @param array $options
31-
*
32-
* @return object
33-
*/
34-
protected function find($id, $options = [])
35-
{
36-
return WooCommerce::find("{$this->endpoint}/{$id}", $options);
37-
}
3812
}

0 commit comments

Comments
 (0)