PHP - Conservar objeto ticket en sesion para agregar productos

 
Vista:
sin imagen de perfil
Val: 62
Ha aumentado su posición en 4 puestos en PHP (en relación al último mes)
Gráfica de PHP

Conservar objeto ticket en sesion para agregar productos

Publicado por giuli (74 intervenciones) el 28/07/2018 17:42:09
en mi aplicacion quiero crear un ticket con productos.

Entonces pense crear un objeto ticket en el index de ticket(uso MVC).

1
2
3
4
5
6
7
8
9
10
11
<?php
session_start();
include_once ("/../../../models/claseTicket.php");
 
date_default_timezone_set("America/Argentina/Buenos_Aires");
 $time=time();
 $fecha = date("d/m/y  (H:i:s)",$time);
 echo date("d/m/y  (H:i:s)",$time);
 $ticket = new Ticket($fecha,$time);
$_SESSION['ticket']=$ticket;
 ?>

Para luego usarlo en un php que llamo desde ajax:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
header('Content-Type: application/json');
include ("../../models/claseTicket.php");
session_start();
//$objTicket=$_SESSION['ticket'];
if(isset($_SESSION['ticket'])==true){
    if (isset($_POST['accion'])){
   if ($_POST['accion']="listar"){
 
 
       $arrayarticulos[]=$ticket->listarArt();
 
    echo json_encode($arrayarticulos);
 
   }else if ($_POST['accion']="agregar"){
    $id = $_POST['id'];
    $precio = $_POST['precio'];
    $cant=$_POST['cantidad'];
    $nom=$_POST['nombre'];
 
    $objTicket->agregaDetalle(new detalleTicket($id,$precio,$cant,$nom));
 
   }
}   }

Este es mi ajax:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
$(document).ready(function() {
listarDetalle();
 
});
function listarDetalle(){
     var accion="listar";
    $.ajax({
 
            type: "POST",
            url: "../gestionweb/includes/php/procesoDetalle.php",
            data: { "accion":accion},
            dataType:'json',
 
            error: function(){
                alert("error petición ajax");
            },
 
            success: function(data){
                console.log(data);
 
 
               for (var i = 0; i < data.length; i++) {
          alert('fdsfgds')
                var newRow =
                    "<tr>" +
                    "<td>" + data[i].idp + "</td>" +
                    "<td>" + data[i].nombre + "</td>"
                    "<td>" + data[i].marca + "</td>" +
                    "<td>" + data[i].cantidad + "</td>" +
                    "<td><input type='radio' id='"+data[i].idproducto+"' name='seleccion'/></td>"+
                    "</tr>";
                $(newRow).appendTo("#ticket tbody");
 
 
 
 
 
 
 
        } }
 
}).fail( function( jqXHR, textStatus, errorThrown ) {
 
  if (jqXHR.status === 0) {
 
    alert('Not connect: Verify Network.');
 
  } else if (jqXHR.status == 404) {
 
    alert('Requested page not found [404]');
 
  } else if (jqXHR.status == 500) {
 
    alert('Internal Server Error [500].');
 
  } else if (textStatus === 'parsererror') {
 
    alert('Requested JSON parse failed.');
 
  } else if (textStatus === 'timeout') {
 
    alert('Time out error.');
 
  } else if (textStatus === 'abort') {
 
    alert('Ajax request aborted.');
 
  } else {
 
    alert('Uncaught Error: ' + jqXHR.responseText);
 
  }
 
});;
 
};

Pero no me muestra nada...ninguno de los articulos. Es decir tengo una ventana de agregar productos y un boton terminado que redirige al index donde se ejecuta listardetalle
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder