Commit c4cdf7e4f94bc84a9861e7d67cc9ec1440f703a7
1 parent
d96878c5
commit before grand update
Showing
1 changed file
with
40 additions
and
1 deletions
Show diff stats
controllers/VariantController.php
... | ... | @@ -13,7 +13,8 @@ |
13 | 13 | use yii\web\Controller; |
14 | 14 | use yii\web\NotFoundHttpException; |
15 | 15 | use yii\filters\VerbFilter; |
16 | - | |
16 | + use yii\web\Response; | |
17 | + | |
17 | 18 | /** |
18 | 19 | * VartiantController implements the CRUD actions for ProductVariant model. |
19 | 20 | */ |
... | ... | @@ -306,4 +307,42 @@ |
306 | 307 | throw new NotFoundHttpException('The requested page does not exist.'); |
307 | 308 | } |
308 | 309 | } |
310 | + | |
311 | + public function actionList($q = null, $id = null) | |
312 | + { | |
313 | + \Yii::$app->response->format = Response::FORMAT_JSON; | |
314 | + $out = [ | |
315 | + 'results' => [ | |
316 | + 'id' => '', | |
317 | + 'text' => '', | |
318 | + ], | |
319 | + ]; | |
320 | + if (!is_null($q)) { | |
321 | + $out[ 'results' ] = ProductVariant::find() | |
322 | + ->select( | |
323 | + [ | |
324 | + 'product_variant.id as id', | |
325 | + 'product_variant.sku as text', | |
326 | + ] | |
327 | + ) | |
328 | + ->where( | |
329 | + [ | |
330 | + 'like', | |
331 | + 'product_variant.sku', | |
332 | + $q, | |
333 | + ] | |
334 | + ) | |
335 | + ->andFilterWhere( | |
336 | + [ | |
337 | + '!=', | |
338 | + 'product_variant.id', | |
339 | + $id, | |
340 | + ] | |
341 | + ) | |
342 | + ->limit(20) | |
343 | + ->asArray() | |
344 | + ->all(); | |
345 | + } | |
346 | + return $out; | |
347 | + } | |
309 | 348 | } | ... | ... |