/** * @throws CHttpException */ public function actionAdd() { if (!Yii::app()->getRequest()->getIsPostRequest() || !Yii::app()->getRequest()->getIsAjaxRequest()) { throw new CHttpException(404); } $productId = (int) Yii::app()->getRequest()->getPost('id'); if (!$productId) { throw new CHttpException(404); } if ($this->favorite->add($productId)) { Yii::app()->ajax->raw(['result' => true, 'data' => Yii::t('FavoriteModule.favorite', 'Success added!'), 'count' => $this->favorite->count()]); } Yii::app()->ajax->raw(['message' => Yii::t('FavoriteModule.favorite', 'Error =('), 'result' => false, 'count' => $this->favorite->count()]); }