| 1 | <?php |
| 2 | |
| 3 | require_once __DIR__ . "/../lib/php/ejecutaServicio.php"; |
| 4 | require_once __DIR__ . "/../lib/php/select.php"; |
| 5 | require_once __DIR__ . "/../lib/php/devuelveJson.php"; |
| 6 | require_once __DIR__ . "/Bd.php"; |
| 7 | require_once __DIR__ . "/TABLA_PRODUCTO.php"; |
| 8 | |
| 9 | ejecutaServicio(function () { |
| 10 | |
| 11 | $pdo = Bd::pdo(); |
| 12 | |
| 13 | $lista = select(pdo: $pdo, from: PRODUCTO, orderBy: PROD_NOMBRE); |
| 14 | |
| 15 | $render = ""; |
| 16 | foreach ($lista as $modelo) { |
| 17 | $encodeId = urlencode($modelo[PROD_ID]); |
| 18 | $id = htmlentities($encodeId); |
| 19 | $nombre = htmlentities($modelo[PROD_NOMBRE]); |
| 20 | $precio = htmlentities("$" . number_format($modelo[PROD_PRECIO], 2)); |
| 21 | $existencias = htmlentities(number_format($modelo[PROD_EXISTENCIAS], 2)); |
| 22 | $render .= |
| 23 | "<dt>$nombre</dt> |
| 24 | <dd> |
| 25 | <a href='agrega.html?id=$id'>Agregar al carrito</a> |
| 26 | </dd> |
| 27 | <dd> |
| 28 | <dl> |
| 29 | <dt>Precio</dt> |
| 30 | <dd>$precio</dd> |
| 31 | <dt>Existencias</dt> |
| 32 | <dd>$existencias</dd> |
| 33 | </dl> |
| 34 | </dd>"; |
| 35 | } |
| 36 | devuelveJson(["lista" => ["innerHTML" => $render]]); |
| 37 | }); |
| 38 | |