Problemas com carrinho de compras

21/05/2018

0

PHP

Bom dia, amigos!! Não costumo ficar pedindo nada nos foruns, mas estou a uma semana tentando adequar meu carrinho de compras que está funcionando mas agora tenho que colocar produtos com numeração e sem numeração. Aí é o problema nada que tentei está funcionando. Vou colocar a rotina abaixo:
detalhe_produto.php
<?php
///////////////////////////////
$query7 = "SELECT * FROM produto WHERE id=$lista";
$result7 = $conexao->prepare( $query7 )or die( ''''''''''''''''Falha na instrução SQL: '''''''''''''''' . mysql_error() );
$result7->execute();
$contar = $result7->rowCount();
if ( $contar > 0 ) {
///////////////////////////////
while($mostra7 = $result7->FETCH(PDO::FETCH_OBJ)){  
	$id=$mostra7->id;
	$cat_id=$mostra7->cat_id;
	$nome7=$mostra7->nome;
	$imagem7=$mostra7->imagem;
	$desc=$mostra7->descricao;
	$med17=$mostra7->med1;
	$preco7=$mostra7->preco;
	$disp=$mostra7->disp;
	$grade=$mostra7->grade;
?>
<div class="col-md-8 products-single">
	<div class="col-md-5 grid-single">
		<div class="flexslider">
			<div class="slides">
				<div class="thumb-image"> <img src="imagens/<?php echo $imagem7 ?>" data-imagezoom="true" class="img-responsive" alt=""/> </div>
			</div>
		</div>
		<!-- FlexSlider -->
		<script src="js/imagezoom.js"></script>

	</div>
	<div class="col-md-7 single-text">
	<form action="cart.php" method="get">
		<input type="hidden" name="acao" value="add">
		<input type="hidden" name="id" value="<?php echo $id ?>">
		<div class="details-left-info simpleCart_shelfItem">
			<h2><?php echo $nome7 ?></h2>
			<p class="availability">Disponível?: <span class="color"><?php if($disp="S"){ echo ''''''''''''''''Sim''''''''''''''''; }else{ echo ''''''''''''''''Não''''''''''''''''; } ?></span>
			</p>
			<div class="price_single">
			<?php 
			if ($grade=="S"){
			?>
				<span class="">Escolha o tamanho e o preço</span><br>
				<?php
				$query8 = "SELECT * FROM numeracao WHERE disp=''''''''''''''''S''''''''''''''''"; 
				$result8 = $conexao->prepare( $query8 )or die( ''''''''''''''''Falha na instrução SQL: '''''''''''''''' . mysql_error() );
				$result8->execute();
				while ($mostra8 = $result8->FETCH(PDO::FETCH_OBJ)){
				$id8=$mostra8->id_numero;
				$id_produto=$mostra8->id_produto;
				$numero8=$mostra8->numero;
				$preco8=$mostra8->preco;
				$altura8=$mostra8->altura;
				$largura8=$mostra8->largura;
				$comprimento8=$mostra8->comprimento;
				?>
				<div class="col-sm-3" style="font-size: 14px">
				<input type="radio" name="dados" value="<?php echo $id_produto.''''''''''''''''-''''''''''''''''.$numero8.''''''''''''''''-''''''''''''''''.$preco8.''''''''''''''''-''''''''''''''''.$altura8.''''''''''''''''-''''''''''''''''.$largura8.''''''''''''''''-''''''''''''''''.$comprimento8 ?>" required>
				<span class="actual item_price"><font color="#ff0000"><?php echo $numero8 ?></font> <br> R$ <?php echo number_format( $preco8, 2, '''''''''''''''','''''''''''''''', ''''''''''''''''.'''''''''''''''' )?>
				</span>
				</div>
				<?php
				}
				}else{
				?>
				<input type="hidden" name="dados" value="0">
					<span class="actual item_price">R$ <?php echo number_format( $preco7, 2, '''''''''''''''','''''''''''''''', ''''''''''''''''.'''''''''''''''' )?></span>
				<?php
				}
				?>
				</div>
				<div class="clearfix"> </div>
				<div class="col-lg-12"> </div>
				<h3>Descrição</h3>
				<div class="quick_desc"><?php echo $desc ?></div>
				<?php 
				if ($med17=="0"){
					echo " ";
				}else{
				?>
				<div><?php echo $med17 ?></div>
				<?php }?>
				<div class="clearfix"> </div>
				<div class="single-but item_add">
				<input type="submit" class="btn btn-danger btn-lg" value="Incluir no carrinho">
				<!--<a class="btn btn-danger btn-lg" href="cart.php?acao=add&id=<?php //echo $id ?>" class="card-link"><i class="fa fa-shopping-basket"></i> Incluir no carrinho</a>-->			
				</div>
		</div>
	</form>
	</div>
	<div class="clearfix"></div>
</div>
<?php 
} 
	
} else {
	echo ''''''''''''''''<div class="alert alert-danger col-md-12">
                      <button type="button" class="close" data-dismiss="alert">×</button>
                      <strong>Aviso!</strong> Não há dados cadastrados em nosso banco de dados ou a página não existe.
                </div>'''''''''''''''';
}
?>
Luiz Paulo

Luiz Paulo

Responder

Posts

21/05/2018

Luiz Paulo

Segue o código cart.php
<?php
session_start();
error_reporting(0);
include( "admin/conecta/conexao.php" );
//////////////////////////////////////////////
if ( !isset( $_SESSION[ 'carrinho' ] ) ) {
	$_SESSION[ 'carrinho' ] = array();
//////////////////////////////////////////////
}
if(isset($_GET['dados'])){
//////////////////////////////////////////////
	$_SESSION[ 'dados' ] = $_GET[ 'dados' ];
//////////////////////////////////////////////
				$dados_fim = " ";
				$numeroT = " ";
				$precoT = " ";
				$alturaT = " ";
				$larguraT = " ";
				$comprimentoT = " ";
				$dados=$_SESSION[ 'dados' ];
				/*echo $dados;*/
				$dados_fim = explode('-', $dados);
				$idprodutoT = $dados_fim[0];
				$numeroT = $dados_fim[1];
				$precoT = $dados_fim[2];
				$alturaT = $dados_fim[3];
				$larguraT = $dados_fim[4];
				$comprimentoT = $dados_fim[5];

/*}else{
	$_SESSION[ 'dados' ] =" ";*/
}

//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;
		} else {
			$_SESSION[ 'carrinho' ][ $id ] += 1;
		}
	}
	//SUBTRAI DO CARRINHO
	if ( $_GET[ 'acao' ] == 'sub' ) {
		$id = intval( $_GET[ 'id' ] );
		if ( !isset( $_SESSION[ 'carrinho' ][ $id ] ) ) {
			$_SESSION[ 'carrinho' ][ $id ] = 1;
		} else {
			$_SESSION[ 'carrinho' ][ $id ] -= 1;
		}
		if ( $_SESSION[ 'carrinho' ][ $id ] == 0 ) {
			unset( $_SESSION[ 'carrinho' ][ $id ] );
			session_destroy();
		}
	}
	//REMOVER CARRINHO
	if ( $_GET[ 'acao' ] == 'del' ) {
		$id = intval( $_GET[ 'id' ] );
		if ( isset( $_SESSION[ 'carrinho' ][ $id ] ) ) {
			unset( $_SESSION[ 'carrinho' ][ $id ] );
			session_destroy();
		}
	}
	//REFRESH CARRINHO
	if ( $_GET[ 'acao' ] == 'ref' ) {}

}

?>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>CASA BELA PRESENTES</title>
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<script type="applijegleryion/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script>
	<link href="css/bootstrap.css" rel='stylesheet' type='text/css'/>
	<!-- Custom Theme files -->
	<link href="css/style.css" rel='stylesheet' type='text/css'/>
	<script src="js/jquery-1.11.1.min.js"></script>
	<script src="js/bootstrap.min.js"></script>
	<!-- start menu -->
	<link href="css/megamenu.css" rel="stylesheet" type="text/css" media="all"/>
	<script type="text/javascript" src="js/megamenu.js"></script>
	<script>
		$( document ).ready( function () {
			$( ".megamenu" ).megamenu();
		} );
	</script>
	<script src="js/menu_jquery.js"></script>
	<script src="js/simpleCart.min.js">
	</script>
	<!--web-fonts-->
	<link href="css/font-awesome.min.css" rel="stylesheet" type="text/css">
	<link href='//fonts.googleapis.com/css?family=Open+Sans:400,300,400italic,300italic,600,700' rel='stylesheet' type='text/css'>
	<link href='//fonts.googleapis.com/css?family=Roboto+Slab:300,400,700' rel='stylesheet' type='text/css'>
	<!--//web-fonts-->
	<script src="js/scripts.js" type="text/javascript"></script>
	<script src="js/modernizr.custom.js"></script>
	<script type="text/javascript" src="js/move-top.js"></script>
	<script type="text/javascript" src="js/easing.js"></script>
	<!--/script-->
	<script type="text/javascript">
		jQuery( document ).ready( function ( $ ) {
			$( ".scroll" ).click( function ( event ) {
				event.preventDefault();
				$( 'html,body' ).animate( {
					scrollTop: $( this.hash ).offset().top
				}, 900 );
			} );
		} );
	</script>
</head>

<body>
	<!--start-home-->
	<?php include('menu.php') ?>
	<!--start-content-->
	<div class="container">
		<div class="card mt-5">
			<div class="card-body" align="center" style="background-color: gainsboro; padding: 20px">
				<h3 class="card-title" style="padding: 10PX">MEU PEDIDO</h3>
				<div class="btn btn-default" style="font-size: 18px; font-weight: bold; padding: 0 45px"><a href="index.php">Ver mais Produtos</a>
				</div>
			</div>
		</div>
		<!-------------------------------------------->
		<div class=" table-responsive">
			<table class="table table-strip">
				<thead>
					<tr>
						<th>Produto</th>
						<th> </th>
						<th> </th>
						<th width="17%">Quantidade</th>
						<th width="8%">Preço</th>
						<th width="8%">Subtotal</th>
						<th width="3%"></th>
					</tr>
				</thead>
				<tbody>
				<?php
				echo $idprodutoT;
				echo $numeroT;
				echo $precoT;
				echo $alturaT;
				echo $larguraT;
				echo $comprimentoT;
				if ( count( $_SESSION[ 'carrinho' ] ) == 0 ) {
						?>
					<div class="card mt-5">
						<div class="card-body" align="center" style="background-color: mintcream; padding: 20px">
							<h4 class="card-title">Sua Cesta de Pedidos está vazia!!</h4>
						</div>
					</div>
					<?php

					} else {
					
						$total = 0;
						foreach ( $_SESSION[ 'carrinho' ] as $id => $qtd ) {
							$sql = "SELECT id,nome,imagem,preco  FROM produto WHERE id= '$id'";
							$stmt = $conexao->prepare( $sql );
							$stmt->execute();
							$linha = $stmt->FETCH( PDO::FETCH_OBJ );
							/////////////////////////////////////////////
							if ($id = $idprodutoT){
							$id = $linha->id;
							$imagem = $linha->imagem;
							$nome = $linha->nome;
							$preco = number_format( $precoT, 2, ',', '.' );
							$sub = number_format( $precoT * $qtd, 2, ',', '.' );
							$total += $precoT * $qtd;								
							}else{
							/////////////////////////////////////////////
							$id = $linha->id;
							$imagem = $linha->imagem;
							$nome = $linha->nome;
							$preco = number_format( $linha->preco, 2, ',', '.' );
							$sub = number_format( $linha->preco * $qtd, 2, ',', '.' );
							$total += $linha->preco * $qtd;
							}
							?>
					<tr style="font-size: 14px" align="center">
						<td><img src="imagens/<?php echo $imagem ?>" width="126"/>
						</td>
						<td>
							<?php echo $nome ?>
						</td>
						<td> </td>
						<td><span class="qtd">
							<span class="qtd_val"><?php echo $qtd ?></span>
							<a class="itens_val" href="cart.php?acao=sub&id=<?php echo $id ?>"><i class="fa fa-minus-square aria-hidden="true"></i> Excluir</a>
							<a class="itens_val" href="cart.php?acao=add&id=<?php echo $id ?>"><i class="fa fa-minus-square aria-hidden="true"></i> Incluir</a>
							</span>
						</td>
						<td>R$
							<?php echo $preco ?>
						</td>
						<td>R$
							<?php echo $sub ?>
						</td>
						<td><a href="cart.php?acao=del&id=<?php echo $id ?>&dados=<?php echo $dados ?>" class="btn btn-danger"><i class="fa fa-trash" aria-hidden="true"></i> Remover Item</a>
						</td>
					</tr>
					<?php }?>
					<tr>
						<td colspan="4" class="text-right"><b>Total: </b>
						</td>
						<td>R$
							<?php echo number_format($total, 2, ',', '.')?>
						</td>
						<td colspan="2"></td>
					</tr>
				</tbody>
			</table>
			<a class="btn btn-info" href="index.php"><i class="fa fa-shopping-basket aria-hidden="true"></i> Continuar Comprando</a>
			<a href="cart.php?acao=ref" data-rel="collapse" class="btn btn-primary"><i class="fa fa-refresh" aria-hidden="true"></i> Atualizar</a>
			<a href="checkout.php" class="btn btn-success"><i class="fa fa-shopping-cart" aria-hidden="true"></i> Finalizar</a>
			<?php 
}
 ?>
		</div>
	</div>
	<?php include('base.php') ?>
</body>
</html>
Responder

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar