João Vitor Pinheiro 0 Posted June 9, 2019 Report Share Posted June 9, 2019 Gostaria de poder editar o valor da quantidade dentro do meu carrinho, pois so consigo aumentar mais um se eu for no index e adicionar novamente o mesmo produto,não consigo implementar algo que altere o valor da quantidade ja dentro do carrinho, se alguem puder ajudar eu agradeço muito, aqui está o codigo do meu carrinho: < <?php session_start(); if (!isset( $_SESSION['itens'] ) ) : $_SESSION['itens'] = array(); endif; if ( isset( $_GET['add'] ) && $_GET['add'] == "carrinho" ) : $idProduto = $_GET['id']; if (!isset ($_SESSION['itens'][$idProduto])): $_SESSION['itens'][$idProduto] = 1; else: $_SESSION['itens'][$idProduto] +=1; endif; endif; if ( count( $_SESSION['itens'] ) == 0 ) : echo ' <h1>Carrinho vazio</h1>'; else: $_SESSION['dados'] =array(); $conexao = new PDO ('mysql:host=localhost;dbname=meusprodutos',"root", ""); ?> <table > <thead> <th>Nome</th> <th>Preço</th> <th>Quantidade</th> <th>Subtotal</th> <th>Opções</th> </thead> <tbody> <?php $totalcarrinho = 0; foreach ( $_SESSION['itens'] as $idProduto => $quantidade ) : $select = $conexao->prepare("SELECT * FROM produtos WHERE id=?"); $select ->bindParam(1, $idProduto); $select ->execute(); $produtos = $select->fetchAll(); $total = $quantidade * $produtos[0]["preco"]; if(count( $_SESSION['itens'] ) == 0 ) : $totalcarrinho = 0; else: $tempcarrinho = $totalcarrinho; $totalcarrinho = $tempcarrinho + $total; endif; ?> <tr> <td><div align="center" style="font-size:20px; font-family: verdana"> <font color="black"><?=$produtos[0]["nome"]?></font> </div></td> <td><?=number_format( $produtos[0]["preco"], 2, ", ", "." )?></td> <td><div align="center"> <?=$quantidade?> </div></td> <td><?=number_format( $total, 2, ",", "." )?></td> <td><a href="remover.php?remover=carrinho&id=<?=$idProduto?>">Remover</a></td> </tr> <?php array_push($_SESSION['dados'], array ('id_produto' => $produtos[0]["nome"], 'quantidade' => $quantidade, 'preco' => $produtos[0]["preco"], 'total' => $total ) ); endforeach; ?> </tbody> </table> <table> <td><div align='center' style='font-size:25px;font-family:Verdana'>Total <?=number_format( $totalcarrinho, 2, ",", "." )?></div></td> </table> <?php echo '<a href="finalizar.php">Finalizar pedido</a>'; endif; ?> > Link to post Share on other sites
M6 153 Posted June 11, 2019 Report Share Posted June 11, 2019 Esse código não se percebe nada. Se queres que alguém te ajude a perceber o código, formata-o como deve ser. 10 REM Generation 48K! 20 INPUT "URL:", A$ 30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50 40 PRINT "404 Not Found" 50 PRINT "./M6 @ Portugal a Programar." Link to post Share on other sites
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now