Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- # highlight_file(__FILE__);
- # ini_set('display_errors', 1);
- # error_reporting(E_ALL);
- require_once('includes/Funcoes.php');
- if(!isset($_SESSION)) session_start();
- /**
- * Começando o carrinho
- */
- if (!isset($_SESSION['venda'])) {
- $_SESSION['venda'] = array();
- }
- if(isset($_GET['par'])){
- $produtos = $_GET['par'];
- if(!isset($_SESSION['venda'][$produtos])){
- $_SESSION['venda'][$produtos] = 1;
- } else {
- $_SESSION['venda'][$produtos] += 1;
- }
- }
- if(isset($_GET['del'])){
- $Excluir = $_GET['del'];
- if($Excluir > 0){
- $_SESSION['venda'][$Excluir] -= 1;
- } else {
- unset($_SESSION['venda'][$Excluir]);
- }
- }
- ?>
- <?php echo "<pre>"; print_r($_SESSION['venda']); echo "</pre>"; ?>
- <!DOCTYPE html>
- <html lang="pt">
- <head>
- <meta charset="UTF-8">
- <title>Carrinho de Compras</title>
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
- <script src="https://code.jquery.com/jquery-1.12.1.min.js"></script>
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
- <script src="assets/js/scripts.js"></script>
- <link rel="stylesheet" href="assets/css/estilos.css">
- </head>
- <body>
- <div class="container">
- <div class="row">
- <div class="col-md-12">
- <h1><a href="http://sirleiicristina.com.br">Loja de Bikinis</a></h1>
- </div>
- </div>
- <div class="row">
- <?php foreach ($query as $dados) { ?>
- <div class="col-md-3">
- <div class="row">
- <div class="onebyone col-md-12">
- <div class="total">
- <p class="titulo"><?php echo $dados['nome']; ?></p>
- <p class="titulo">R$<?php echo number_format($dados['preco'], 2, ".", ","); ?></p>
- <a href="index.php?par=<?php echo $dados['ID']; ?>">
- <strong>Adicionar ao carrinho</strong>
- </a>
- </div>
- <img class="imagem" src="<?php echo $dados['imagem']; ?>">
- </div>
- </div>
- </div>
- <?php } ?>
- </div>
- <div class="row">
- <div class="col-md-12">
- <h2>Checkout</h2>
- </div>
- </div>
- <table class="table table-striped table-bordered">
- <thead>
- <tr>
- <th>Produto</th>
- <th>Preço</th>
- <th>Quantidade</th>
- <th>Subtotal</th>
- <th>Ações</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <?php $Total = 0; ?>
- <?php foreach($_SESSION['venda'] as $Prod => $Quantidade) { ?>
- <?php $sql = "SELECT * FROM produtos WHERE ID = '$Prod'";
- $prods = $mysqli->query($sql);
- $smtm = $prods->fetch_assoc();
- $subtotal = $smtm['preco'] * $Quantidade; ?>
- <td><?php echo $smtm['nome']; ?></td>
- <td>R$<?php echo $smtm['preco']; ?></td>
- <td><?php echo $Quantidade; ?></td>
- <td><?php echo number_format($subtotal, 2, ".", ","); ?></td>
- <td><a href="index.php?del=<?php echo $smtm['ID']; ?>">Excluir</a></td>
- </tr>
- <?php $Total += $smtm['preco'] * $Quantidade; ?>
- <?php } ?>
- <tr>
- <td colspan="5"></td>
- </tr>
- <tr>
- <td colspan="4"></td>
- <td>Total: R$<?php echo number_format($Total, 2, ".", ","); ?></td>
- </tr>
- <tr>
- <td></td>
- <td></td>
- <td></td>
- <td></td>
- <td>
- <form action="" method="POST" style="margin:0">
- <input type="hidden" name="Total" value="<?php echo $Total; ?>">
- <input type="submit" name="enviar" onclick="return confirm('Tem certeza que deseja finalizar este pedido?');" value="Finalizar Pedido" class="btn btn-success btn-block">
- </form>
- </td>
- </tr>
- </tbody>
- </table>
- </div>
- </body>
- </html>
- <?php
- if (isset($_POST['enviar'])) {
- $Total = $_POST['Total'];
- $SqlInserirVenda = $mysqli->query("INSERT INTO vendas VALUES ('', $Total)");
- $IdVenda = $mysqli->insert_id;
- foreach ($_SESSION['venda'] as $ProdInsert => $Qtd) {
- $SqlInsertItens = $mysqli->query("INSERT INTO itensvendas VALUES ('', '$IdVenda', '$ProdInsert', '$Qtd')");
- }
- unset($_SESSION['venda']); session_destroy();
- echo "
- <META HTTP-EQUIV=REFRESH CONTENT = '0;URL=http://sirleiicristina.com.br'>
- <script type=\"text/javascript\">
- alert(\"A compra foi efetivada com sucesso.\");
- </script>
- ";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment