You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

81 lines
1.9 KiB

<?php
namespace api\controllers;
use api\logic\Helper;
use backend\modules\shop\models\ars\Cart;
use Throwable;
use Yii;
/**
* @author iron
* @email weiriron@gmail.com
*/
class CartController extends CommonController
{
public $modelClass = 'backend\modules\shop\models\ars\Cart';
public $className = 'api\logic\CartLogic';
public function actions()
{
$action = parent::actions();
unset($action['index']);
unset($action['delete']);
$action['options'] = [
'class' => 'yii\rest\OptionsAction',
'collectionOptions' => ['DELETE', 'PUT', 'OPTIONS']
];
return $action;
}
/**
* @return object
* @throws yii\base\InvalidConfigException
*/
public function actionIndex()
{
$query = Cart::find()->where(['user_id' => Yii::$app->user->getId()]);
return Helper::index($query);
}
/**
* @return bool
* @throws Throwable
* @throws Yii\base\InvalidConfigException
* @throws Yii\db\StaleObjectException
* @throws yii\base\Exception
* @throws yii\web\BadRequestHttpException
* @throws yii\web\NotFoundHttpException
* @throws yii\web\ServerErrorHttpException
*/
public function actionUpdate()
{
return $this->object->update();
}
/**
* @return null|Cart
* @throws yii\base\Exception
* @throws yii\web\BadRequestHttpException
* @throws yii\web\NotFoundHttpException
* @throws yii\web\ServerErrorHttpException
*/
public function actionCreate()
{
return $this->object->create();
}
/**
* @throws Yii\db\StaleObjectException
* @throws Throwable
* @throws yii\web\BadRequestHttpException
* @throws yii\web\NotFoundHttpException
* @throws yii\web\ServerErrorHttpException
*/
public function actionDelete()
{
return $this->object->delete();
}
}