Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- if(!isset($_SESSION['carrinho'])){
- $_SESSION['carrinho'] = array();
- }
- // Adiciona produto
- if(isset($_GET['acao'])){
- //Adicionar carrinho
- if($_GET['acao'] == 'add'){
- $id = intval ($_GET['id']);
- if(!isset($_SESSION['carrinho'][$id])){
- $_SESSION['carrinho'][$id] = 1;
- }
- }
- //Remover carrinho
- if($_GET['acao'] == 'del'){
- $id = intval ($_GET['id']);
- if(isset($_SESSION['carrinho'][$id])){
- unset($_SESSION['carrinho'][$id]);
- }
- }
- //alterar quantidade
- if($_GET['acao'] == 'up'){
- if (is_array($_POST['prod'])){
- foreach($_POST['prod'] as $id => $qtd){
- $id = intval ($id);
- $qtd = intval ($qtd);
- if (!empty($qtd) || $qtd <> 0){
- $_SESSION['carrinho'][$id] = $qtd;
- }else{
- unset($_SESSION['carrinho'][$id]);
- }
- }
- }
- }
- }
- ?>
- <?php
- include ("verifica.php");
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <?php
- include "../admin/ligacao.php";
- ?>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>loja</title>
- <style type="text/css">
- <!--
- @import url(../css.css);
- -->
- </style>
- </head>
- <body>
- <div id="conteudo">
- <b class="titulo">Carrinho de Compras</b>
- <div id="texto">
- <table border="0px" style="text-align:center">
- <tr><td colspan="6" style="text-align:right"><a href="categoria1.php" class="formulario" style="text-decoration:none;"> Continuar as compras </a></td>
- </tr>
- <tr height="5px"></tr>
- <tr>
- </tr>
- <tr>
- <td width="200"><b>Nome do Produto</b></td>
- <td width="80"><b>Imagem</b></td>
- <td width="79"><b>Quantidade</b></td>
- <td width="75"><b>Preço</b></td>
- <td width="90"><b>Subtotal</b></td>
- <td width="64"><b>Acções</b></td>
- </tr>
- <form action="?acao=up" method="post">
- <?php
- if (count($_SESSION['carrinho'])== 0){
- echo '<tr> <td colspan="5"> Não há produtos no carrinho </td></tr>';
- }else{
- foreach ($_SESSION['carrinho'] as $id => $qtd){
- $sql = "SELECT * FROM produtos WHERE id= '$id'";
- $sql = mysql_query($sql) or die (mysql_error());
- $linha = mysql_fetch_assoc($sql);
- $nome_produto = $linha['nome_produto'];
- $imagem = $linha['imagem'];
- $preco = number_format ($linha ['preco'], 2, ',', '');
- $sub = number_format ($linha ['preco'] * $qtd, 2, ',', '');
- $total += $sub;
- echo '<tr>
- <td> '.$nome_produto.' </td>
- <td><img src="../imagens/'.$imagem.'" style="max-width:60px; max-height:60px;" border="0px" /> </td>
- <td> <input type="text" size="3" name="prod['.$id.']" value="'.$qtd.'" style="text-align:center"/> </td>
- <td> '.$preco.' €</td>
- <td> '.$sub.' € </td>
- <td> <a href="?acao=del&id='.$id.'"><span class="formulario"> Apagar</span> </a> </td>
- </tr>';
- }
- $total = number_format ($total, 2, ',', '');
- echo '<tr></tr><tr>
- <td colspan ="3"></td>
- <td><b>Total</b></td>
- <td> '.$total.' € </td>
- </tr><tr height="5px"></tr>';
- }
- ?>
- <tr>
- <td colspan="4"></td>
- <td colspan="2"><input type="submit" value="Actualizar Encomenda" class="formulario" style="text-align:right" /></td>
- </tr>
- <tr height="5px">
- </tr>
- <tr>
- <td colspan="4"></td>
- <td colspan="2"> <a href="finalizar_encomenda.php"><span class="formulario">Finalizar a encomenda</span></a></td>
- </tr>
- <tr height="15px">
- </tr>
- </form>
- </table>
- </div><!--fim div texto-->
- </div> <!--fim div conteudo-->
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment