|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Codexshaper\WooCommerce\Models; |
|
4
|
|
|
|
|
5
|
|
|
use Codexshaper\WooCommerce\Facades\Query; |
|
6
|
|
|
use Codexshaper\WooCommerce\Traits\QueryBuilderTrait; |
|
7
|
|
|
|
|
8
|
|
|
class Attribute extends BaseModel |
|
9
|
|
|
{ |
|
10
|
|
|
use QueryBuilderTrait; |
|
11
|
|
|
|
|
12
|
|
|
protected $endpoint = 'products/attributes'; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Retrieve all Items. |
|
16
|
|
|
* |
|
17
|
|
|
* @param int $attribute_id |
|
18
|
|
|
* @param array $options |
|
19
|
|
|
* |
|
20
|
|
|
* @return array |
|
21
|
|
|
*/ |
|
22
|
|
|
protected function getTerms($attribute_id, $options = []) |
|
23
|
|
|
{ |
|
24
|
|
|
return Query::init() |
|
25
|
|
|
->setEndpoint("products/attributes/{$attribute_id}/terms") |
|
26
|
|
|
->all($options); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Retrieve single Item. |
|
31
|
|
|
* |
|
32
|
|
|
* @param int $attribute_id |
|
33
|
|
|
* @param int $term_id |
|
34
|
|
|
* @param array $options |
|
35
|
|
|
* |
|
36
|
|
|
* @return object |
|
37
|
|
|
*/ |
|
38
|
|
|
protected function getTerm($attribute_id, $term_id, $options = []) |
|
39
|
|
|
{ |
|
40
|
|
|
return Query::init() |
|
41
|
|
|
->setEndpoint("products/attributes/{$attribute_id}/terms") |
|
42
|
|
|
->find($term_id, $options); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Create new Item. |
|
47
|
|
|
* |
|
48
|
|
|
* @param int $attribute_id |
|
49
|
|
|
* @param array $data |
|
50
|
|
|
* |
|
51
|
|
|
* @return object |
|
52
|
|
|
*/ |
|
53
|
|
|
protected function addTerm($attribute_id, $data) |
|
54
|
|
|
{ |
|
55
|
|
|
return Query::init() |
|
56
|
|
|
->setEndpoint("products/attributes/{$attribute_id}/terms") |
|
57
|
|
|
->create($data); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Update Existing Item. |
|
62
|
|
|
* |
|
63
|
|
|
* @param int $attribute_id |
|
64
|
|
|
* @param int $term_id |
|
65
|
|
|
* @param array $data |
|
66
|
|
|
* |
|
67
|
|
|
* @return object |
|
68
|
|
|
*/ |
|
69
|
|
|
protected function updateTerm($attribute_id, $term_id, $data) |
|
70
|
|
|
{ |
|
71
|
|
|
return Query::init() |
|
72
|
|
|
->setEndpoint("products/attributes/{$attribute_id}/terms") |
|
73
|
|
|
->update($term_id, $data); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Destroy Item. |
|
78
|
|
|
* |
|
79
|
|
|
* @param int $attribute_id |
|
80
|
|
|
* @param int $term_id |
|
81
|
|
|
* @param array $options |
|
82
|
|
|
* |
|
83
|
|
|
* @return object |
|
84
|
|
|
*/ |
|
85
|
|
|
protected function deleteTerm($attribute_id, $term_id, $options = []) |
|
86
|
|
|
{ |
|
87
|
|
|
return Query::init() |
|
88
|
|
|
->setEndpoint("products/attributes/{$attribute_id}/terms") |
|
89
|
|
|
->delete($term_id, $options); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Batch Update. |
|
94
|
|
|
* |
|
95
|
|
|
* @param int $attribute_id |
|
96
|
|
|
* @param array $data |
|
97
|
|
|
* |
|
98
|
|
|
* @return object |
|
99
|
|
|
*/ |
|
100
|
|
|
protected function batchTerm($attribute_id, $data) |
|
101
|
|
|
{ |
|
102
|
|
|
return Query::init() |
|
103
|
|
|
->setEndpoint("products/attributes/{$attribute_id}/terms") |
|
104
|
|
|
->batch($data); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|