/**
  * Deletes all user viewed products.
  *
  * @return \yii\web\Response
  * @throws NotFoundHttpException
  */
 public function actionClearList()
 {
     if (!Yii::$app->user->isGuest) {
         ViewedProduct::deleteAll(['user_id' => \Yii::$app->user->id]);
         return $this->redirect(['list']);
     } else {
         throw new NotFoundHttpException();
     }
 }
예제 #2
0
 public function run()
 {
     parent::run();
     $products = ViewedProduct::find()->where(['user_id' => \Yii::$app->user->id])->limit($this->num)->all();
     if (!empty($products)) {
         return $this->render('last-viewed-products', ['products' => $products]);
     } else {
         return false;
     }
 }
예제 #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ViewedProduct::find()->where(['user_id' => \Yii::$app->user->id]);
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id, 'product_id' => $this->product_id, 'user_id' => $this->user_id, 'creation_time' => $this->creation_time, 'update_time' => $this->update_time]);
     return $dataProvider;
 }