Example #1
0
 public function actionVerproducto($id)
 {
     $this->layout = 'frontoffice';
     $model = $this->findModel($id);
     $temporal = Temporales::findOne($id);
     if ($temporal != null) {
         return $this->render('verProducto', ['temporal' => $temporal, 'model' => $model]);
     } else {
         $stock = Stock::findOne($id);
         if ($stock != null) {
             return $this->render('verProducto', ['stock' => $stock, 'model' => $model]);
         }
     }
     return $this->render('verProducto', ['model' => $this->findModel($id)]);
 }
Example #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]);
 }
Example #3
0
 /**
  * Finds the Stock model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Stock the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Stock::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }