@@ -103,25 +103,7 @@ protected function get()
103
103
{
104
104
try {
105
105
$ results = WooCommerce::all ($ this ->endpoint , $ this ->options );
106
-
107
- if (empty ($ this ->where )) {
108
- return $ results ;
109
- }
110
- $ filteredResults = [];
111
- foreach ($ this ->where as $ key => $ where ) {
112
- foreach ($ results as $ result ) {
113
- $ name = $ where ['name ' ];
114
- $ name = $ result ->$ name ;
115
- $ operator = ($ where ['operator ' ] == '= ' ) ? $ where ['operator ' ].'= ' : $ where ['operator ' ];
116
- $ value = $ where ['value ' ];
117
- $ condition = "' $ name' $ operator ' $ value' " ;
118
- if (eval ("return $ condition; " )) {
119
- $ filteredResults [] = $ result ;
120
- }
121
- }
122
- }
123
-
124
- return $ filteredResults ;
106
+ return $ results ;
125
107
} catch (\Exception $ ex ) {
126
108
throw new \Exception ($ ex ->getMessage (), 1 );
127
109
}
@@ -170,25 +152,60 @@ protected function options($parameters)
170
152
*/
171
153
protected function where (...$ parameters )
172
154
{
173
- if (count ($ parameters ) == 3 ) {
174
- $ where = [
175
- 'name ' => $ parameters [0 ],
176
- 'operator ' => $ parameters [1 ],
177
- 'value ' => $ parameters [2 ],
178
- ];
179
- $ this ->where [] = $ where ;
180
- }
181
-
182
- if (count ($ parameters ) == 2 ) {
183
- $ this ->options [$ parameters [0 ]] = $ parameters [1 ];
155
+ if (count ($ parameters ) < 2 || count ($ parameters ) > 3 ) {
156
+ throw new \Exception ("Too many arguments. You can pass minimum 2 and maximum 3 paramneters " );
184
157
}
185
-
186
- if (count ($ parameters ) == 1 ) {
187
- foreach ($ parameters as $ parameter ) {
188
- foreach ($ parameter as $ key => $ value ) {
189
- $ this ->options [$ key ] = $ value ;
190
- }
191
- }
158
+ $ field = $ parameters [0 ];
159
+ $ value = count ($ parameters ) == 3 ? $ parameters [2 ] : $ parameters [1 ];
160
+
161
+ switch ($ field ) {
162
+ case 'name ' :
163
+ case 'title ' :
164
+ case 'description ' :
165
+ $ this ->options ['search ' ] = $ value ;
166
+ break ;
167
+ case 'sku ' :
168
+ $ this ->options ['sku ' ] = $ value ;
169
+ break ;
170
+ case 'type ' :
171
+ $ this ->options ['type ' ] = $ value ;
172
+ break ;
173
+ case 'category ' :
174
+ $ this ->options ['category ' ] = $ value ;
175
+ break ;
176
+ case 'tag ' :
177
+ $ this ->options ['tag ' ] = $ value ;
178
+ break ;
179
+ case 'after ' :
180
+ $ this ->options ['after ' ] = $ value ;
181
+ break ;
182
+ case 'before ' :
183
+ $ this ->options ['before ' ] = $ value ;
184
+ break ;
185
+ case 'attribute ' :
186
+ $ this ->options ['attribute ' ] = $ value ;
187
+ break ;
188
+ case 'attribute_term ' :
189
+ $ this ->options ['attribute_term ' ] = $ value ;
190
+ break ;
191
+ case 'in_stock ' :
192
+ $ this ->options ['in_stock ' ] = $ value ;
193
+ break ;
194
+ case 'featured ' :
195
+ $ this ->options ['featured ' ] = $ value ;
196
+ break ;
197
+ case 'min_price ' :
198
+ $ this ->options ['min_price ' ] = $ value ;
199
+ break ;
200
+ case 'max_price ' :
201
+ $ this ->options ['max_price ' ] = $ value ;
202
+ break ;
203
+ case 'shipping_class ' :
204
+ $ this ->options ['shipping_class ' ] = $ value ;
205
+ break ;
206
+ case 'tax_class ' :
207
+ $ this ->options ['tax_class ' ] = $ value ;
208
+ break ;
192
209
}
193
210
194
211
return $ this ;
0 commit comments