/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Carropedido::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(['idCarroPedido' => $this->idCarroPedido, 'pedido_idPedido' => $this->pedido_idPedido, 'producto_idProducto' => $this->producto_idProducto, 'cantidad' => $this->cantidad]);
     return $dataProvider;
 }
Exemple #2
0
 public function actionSaveItemsPedido()
 {
     $idPedido = $_POST['idPedido'];
     $data = $_POST['data'];
     $borrados = $_POST['borrados'];
     $lista_productos_a_borrar = json_decode($borrados, true);
     $lista_productos_seleccionados = json_decode($data, true);
     foreach (array_values($lista_productos_a_borrar) as $idProducto) {
         $carropedido = Carropedido::find()->where(['pedido_idPedido' => $idPedido, 'producto_idProducto' => $idProducto]);
         if ($carropedido->exists()) {
             $carropedido->one()->delete();
         }
     }
     foreach ($lista_productos_seleccionados as $producto) {
         $idProducto = $producto['idProducto'];
         $carropedido = Carropedido::find()->where(['pedido_idPedido' => $idPedido, 'producto_idProducto' => $idProducto]);
         if ($carropedido->exists()) {
             $carropedido = $carropedido->one();
             $carropedido->cantidad = $producto['cantidad'];
         } else {
             $carropedido = new Carropedido();
             $carropedido->pedido_idPedido = $idPedido;
             $carropedido->producto_idProducto = $idProducto;
             $carropedido->cantidad = $producto['cantidad'];
         }
         $carropedido->save();
     }
 }
Exemple #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCarropedidos()
 {
     return $this->hasMany(Carropedido::className(), ['pedido_idPedido' => 'idPedido']);
 }
 /**
  * Finds the Carropedido model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $idCarroPedido
  * @param integer $pedido_idPedido
  * @param integer $producto_idProducto
  * @return Carropedido the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($idCarroPedido, $pedido_idPedido, $producto_idProducto)
 {
     if (($model = Carropedido::findOne(['idCarroPedido' => $idCarroPedido, 'pedido_idPedido' => $pedido_idPedido, 'producto_idProducto' => $producto_idProducto])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }