Exemple #1
0
 public function actionItemsPedidos($idPedido)
 {
     $contenido_pedido = Carropedido::findAll(['pedido_idPedido' => $idPedido]);
     $id_productos = array_map(function ($o) {
         return $o->producto_idProducto;
     }, $contenido_pedido);
     $productos = Producto::find()->where(['IN', 'idProducto', $id_productos])->all();
     $items = array_map(function ($u) use($idPedido) {
         $temp = Carropedido::findOne(['pedido_idPedido' => $idPedido, 'producto_idProducto' => $u->idProducto]);
         if (empty($temp)) {
             $cantidad = 0;
         } else {
             $cantidad = $temp->cantidad;
         }
         $row['idProducto'] = $u->idProducto;
         $row['codigo'] = $u->codigo;
         $row['nombre'] = $u->producto;
         $row['precio'] = $u->precio;
         $row['embalaje'] = $u->embalajeIdEmbalaje->nombre;
         $row['cantidad'] = $cantidad;
         return $row;
     }, $productos);
     return Json::encode($items);
 }
 /**
  * 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.');
     }
 }