public function loadBasket($id) { $model = Basket::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'Запись не найдена.'); } if ($model->user_id !== Yii::app()->user->id) { $this->error403(); } return $model; }
public function addProduct() { if ($this->validate()) { $exist_basket = Yii::app()->db->createCommand()->select('*')->from('basket')->where('user_id = :user_id AND product_id = :product_id', array(':user_id' => Yii::app()->user->id, ':product_id' => $this->product_id))->queryRow(); if (!$exist_basket) { $this->user_id = Yii::app()->user->id; $this->date_create = time(); $this->price = $this->product->price; if ($this->save(false)) { return true; } else { return false; } } else { Basket::model()->findByPk($exist_basket['id'])->saveCounters(array('count' => $this->count)); return true; } } else { //return $this->errors; } }