Inheritance: extends yii\db\ActiveRecord
Exemplo n.º 1
0
 public function actionDelete()
 {
     $goodsId = (int) Yii::$app->request->post('goodsId');
     $output = ['status' => 'no'];
     Yii::$app->response->format = Response::FORMAT_JSON;
     $model = CartGoods::findOne(['goods_id' => $goodsId, 'user_id' => Yii::$app->user->id]);
     if ($model) {
         if (!$model->delete()) {
             return $output;
         }
     }
     $output['status'] = 'ok';
     return $output;
 }
Exemplo n.º 2
0
 public function actionDelete($id)
 {
     $output = ['status' => 'fail', 'data' => []];
     $model = CartGoods::findOne(['goods_id' => $id, 'user_id' => Yii::$app->user->id]);
     if ($model) {
         if (!$model->delete()) {
             return $output;
         }
     }
     $output['status'] = 'success';
     return $output;
 }
Exemplo n.º 3
0
 /**
  * 清空购物车商品
  * 
  * @param string $storeId
  * @return integer the number of rows deleted
  */
 public function clearCartGoods($storeId = null)
 {
     $condition = ['user_id' => $this->id];
     if ($storeId !== null) {
         $condition['store_id'] = $storeId;
     }
     return CartGoods::deleteAll($condition);
 }