Beispiel #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Productos::find();
     $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;
     }
     $query->andFilterWhere(['id' => $this->id, 'precio' => $this->precio, 'categoria' => $this->categoria, 'activa' => $this->activa]);
     $query->andFilterWhere(['like', 'nombre', $this->nombre])->andFilterWhere(['like', 'descripcion_corta', $this->descripcion_corta])->andFilterWhere(['like', 'descripcion_larga', $this->descripcion_larga])->andFilterWhere(['like', 'tipo', $this->tipo])->andFilterWhere(['like', 'condiciones', $this->condiciones])->andFilterWhere(['like', 'ubicacion', $this->ubicacion]);
     return $dataProvider;
 }
Beispiel #2
0
 public function actionGenerarcupon($id)
 {
     $cupon = new Cupones();
     $request = Yii::$app->request;
     $cupon->idusuario = \Yii::$app->user->identity->id;
     $cupon->idproducto = $id;
     $hoy = date('Y-m-d');
     $cupon->fecha = $hoy;
     $producto = Productos::findOne($id);
     $producto->vendidos += 1;
     $cupon->save();
     $producto->update();
     $Models = Stock::findOne($id);
     if ($Models != null) {
         $Models->stock--;
         if ($Models == 0) {
             $producto = Productos::findOne($id);
             $producto->activo = 0;
         }
         $Models->save();
     }
     return $this->redirect(['view', 'id' => $cupon->id]);
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getIdproducto0()
 {
     return $this->hasOne(Productos::className(), ['id' => 'idproducto']);
 }
 public function actionActivacion()
 {
     $request = Yii::$app->request;
     $producto = Productos::find()->where(['id' => $request->get('id')])->one();
     if ($producto->activa == 0) {
         $producto->activa = 1;
         $producto->update();
     } else {
         $producto->activa = 0;
         $producto->update();
     }
     return $this->redirect(['view', 'id' => $producto->id]);
 }
 /**
  * Finds the Productos model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Productos the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Productos::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Beispiel #6
0
 public function actionSearch()
 {
     $this->layout = "frontoffice";
     $parametro = Yii::$app->request->post('nombre');
     $lista = Productos::find()->where(['like', 'nombre', $parametro])->orWhere(['like', 'descripcion_corta', $parametro])->andWhere(['activa' => true])->all();
     return $this->render('search', ["model" => $lista]);
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getProductos()
 {
     return $this->hasMany(Productos::className(), ['idcategoria' => 'id']);
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getIdproductos()
 {
     return $this->hasMany(Productos::className(), ['id' => 'idproducto'])->viaTable('producto_tienda', ['idcomercio' => 'id']);
 }