/**
  * 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();
     }
 }
 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;
     }
 }
 /**
  * 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;
 }