Skip to content

Commit 6eb92fe

Browse files
committed
Fixed sub modules and added collection.
1 parent a88a56a commit 6eb92fe

File tree

15 files changed

+519
-215
lines changed

15 files changed

+519
-215
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@
5959
"Term": "Codexshaper\\WooCommerce\\Models\\Term",
6060
"Variation": "Codexshaper\\WooCommerce\\Models\\Variation",
6161
"Webhook": "Codexshaper\\WooCommerce\\Facades\\Webhook",
62-
"WooCommerce": "Codexshaper\\WooCommerce\\Facades\\WooCommerce"
62+
"WooCommerce": "Codexshaper\\WooCommerce\\Facades\\WooCommerce",
63+
"Query": "Codexshaper\\WooCommerce\\Facades\\Query"
6364
}
6465
}
6566
}

src/Facades/Query.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Codexshaper\WooCommerce\Facades;
4+
5+
use Illuminate\Support\Facades\Facade;
6+
7+
class Query extends Facade
8+
{
9+
/**
10+
* Get the registered name of the component.
11+
*
12+
* @return string
13+
*/
14+
protected static function getFacadeAccessor()
15+
{
16+
return 'Codexshaper\WooCommerce\Query';
17+
}
18+
}

src/Models/Attribute.php

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

33
namespace Codexshaper\WooCommerce\Models;
44

5+
use Codexshaper\WooCommerce\Facades\Query;
56
use Codexshaper\WooCommerce\Traits\QueryBuilderTrait;
67

78
class Attribute extends BaseModel
@@ -20,9 +21,9 @@ class Attribute extends BaseModel
2021
*/
2122
protected function getTerms($attribute_id, $options = [])
2223
{
23-
$this->endpoint = "products/attributes/{$attribute_id}/terms";
24-
25-
return self::all($options);
24+
return Query::init()
25+
->setEndpoint("products/attributes/{$attribute_id}/terms")
26+
->all($options);
2627
}
2728

2829
/**
@@ -36,9 +37,9 @@ protected function getTerms($attribute_id, $options = [])
3637
*/
3738
protected function getTerm($attribute_id, $term_id, $options = [])
3839
{
39-
$this->endpoint = "products/attributes/{$attribute_id}/terms";
40-
41-
return self::find($term_id, $options);
40+
return Query::init()
41+
->setEndpoint("products/attributes/{$attribute_id}/terms")
42+
->find($term_id, $options);
4243
}
4344

4445
/**
@@ -51,9 +52,9 @@ protected function getTerm($attribute_id, $term_id, $options = [])
5152
*/
5253
protected function addTerm($attribute_id, $data)
5354
{
54-
$this->endpoint = "products/attributes/{$attribute_id}/terms";
55-
56-
return self::create($data);
55+
return Query::init()
56+
->setEndpoint("products/attributes/{$attribute_id}/terms")
57+
->create($data);
5758
}
5859

5960
/**
@@ -67,9 +68,9 @@ protected function addTerm($attribute_id, $data)
6768
*/
6869
protected function updateTerm($attribute_id, $term_id, $data)
6970
{
70-
$this->endpoint = "products/attributes/{$attribute_id}/terms";
71-
72-
return self::update($term_id, $data);
71+
return Query::init()
72+
->setEndpoint("products/attributes/{$attribute_id}/terms")
73+
->update($term_id, $data);
7374
}
7475

7576
/**
@@ -83,9 +84,9 @@ protected function updateTerm($attribute_id, $term_id, $data)
8384
*/
8485
protected function deleteTerm($attribute_id, $term_id, $options = [])
8586
{
86-
$this->endpoint = "products/attributes/{$attribute_id}/terms";
87-
88-
return self::delete($term_id, $options);
87+
return Query::init()
88+
->setEndpoint("products/attributes/{$attribute_id}/terms")
89+
->delete($term_id, $options);
8990
}
9091

9192
/**
@@ -98,8 +99,8 @@ protected function deleteTerm($attribute_id, $term_id, $options = [])
9899
*/
99100
protected function batchTerm($attribute_id, $data)
100101
{
101-
$this->endpoint = "products/attributes/{$attribute_id}/terms";
102-
103-
return self::batch($data);
102+
$return Query::init()
103+
->setEndpoint("products/attributes/{$attribute_id}/terms")
104+
->batch($data);
104105
}
105106
}

src/Models/Customer.php

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

33
namespace Codexshaper\WooCommerce\Models;
44

5+
use Codexshaper\WooCommerce\Facades\Query;
56
use Codexshaper\WooCommerce\Traits\QueryBuilderTrait;
67

78
class Customer extends BaseModel
@@ -10,10 +11,17 @@ class Customer extends BaseModel
1011

1112
protected $endpoint = 'customers';
1213

14+
/**
15+
* Download.
16+
*
17+
* @param int $id
18+
*
19+
* @return object
20+
*/
1321
protected function downloads($id)
1422
{
15-
$this->endpoint = "customers/{$id}/downloads";
16-
17-
return self::all();
23+
return Query::init()
24+
->setEndpoint("customers/{$id}/downloads")
25+
->all($options);
1826
}
1927
}

src/Models/Note.php

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

33
namespace Codexshaper\WooCommerce\Models;
44

5+
use Codexshaper\WooCommerce\Facades\Query;
56
use Codexshaper\WooCommerce\Traits\QueryBuilderTrait;
67

78
class Note extends BaseModel
@@ -20,9 +21,9 @@ class Note extends BaseModel
2021
*/
2122
protected function all($order_id, $options = [])
2223
{
23-
$this->endpoint = "orders/{$order_id}/notes";
24-
25-
return self::all($options);
24+
return Query::init()
25+
->setEndpoint("orders/{$order_id}/notes")
26+
->all($options);
2627
}
2728

2829
/**
@@ -36,9 +37,9 @@ protected function all($order_id, $options = [])
3637
*/
3738
protected function find($order_id, $note_id, $options = [])
3839
{
39-
$this->endpoint = "orders/{$order_id}/notes";
40-
41-
return self::find($note_id, $options);
40+
return Query::init()
41+
->setEndpoint("orders/{$order_id}/notes")
42+
->find($note_id, $options);
4243
}
4344

4445
/**
@@ -51,9 +52,9 @@ protected function find($order_id, $note_id, $options = [])
5152
*/
5253
protected function create($order_id, $data)
5354
{
54-
$this->endpoint = "orders/{$order_id}/notes";
55-
56-
return self::create($data);
55+
return Query::init()
56+
->setEndpoint("orders/{$order_id}/notes")
57+
->create($data);
5758
}
5859

5960
/**
@@ -67,16 +68,19 @@ protected function create($order_id, $data)
6768
*/
6869
protected function delete($order_id, $note_id, $options = [])
6970
{
70-
$this->endpoint = "orders/{$order_id}/notes";
71-
72-
return self::delete($note_id, $options);
71+
return Query::init()
72+
->setEndpoint("orders/{$order_id}/notes")
73+
->delete($note_id, $options);
7374
}
7475

7576
/**
7677
* Paginate results.
7778
*
79+
*
80+
* @param int $order_id
7881
* @param int $per_page
7982
* @param int $current_page
83+
* @param array $options
8084
*
8185
* @return array
8286
*/
@@ -86,32 +90,36 @@ protected function paginate(
8690
$current_page = 1,
8791
$options = []
8892
) {
89-
$this->endpoint = "orders/{$order_id}/notes";
90-
91-
return self::paginate($per_page, $current_page, $options);
93+
return Query::init()
94+
->setEndpoint("orders/{$order_id}/notes")
95+
->paginate($per_page, $current_page, $options);
9296
}
9397

9498
/**
9599
* Count all results.
96100
*
101+
* @param int $order_id
102+
*
97103
* @return int
98104
*/
99105
protected function count($order_id)
100106
{
101-
$this->endpoint = "orders/{$order_id}/notes";
102-
103-
return self::count();
107+
return Query::init()
108+
->setEndpoint("orders/{$order_id}/notes")
109+
->count();
104110
}
105111

106112
/**
107113
* Store data.
108114
*
115+
* @param int $order_id
116+
*
109117
* @return array
110118
*/
111119
public function save($order_id)
112120
{
113-
$this->endpoint = "orders/{$order_id}/notes";
114-
115-
return self::save();
121+
return Query::init()
122+
->setEndpoint("orders/{$order_id}/notes")
123+
->save();
116124
}
117125
}

0 commit comments

Comments
 (0)