-
Notifications
You must be signed in to change notification settings - Fork 0
/
carrinho.php
167 lines (158 loc) · 6.08 KB
/
carrinho.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
require_once dirname(__FILE__) . "/src/utils/handleAuth.php";
handleAuth(true, "/");
require_once dirname(__FILE__) . "/src/models/Usuario.php";
require_once dirname(__FILE__) . "/src/models/Produto.php";
require_once dirname(__FILE__) . "/src/utils/getUsuarioUnserialize.php";
require_once dirname(__FILE__) . "/src/utils/getCarrinhoUnserialize.php";
$usuario = getUsuarioUnserialize();
$carrinho = getCarrinhoUnserialize();
$qntProdutosCarrinhos = 0;
if (!empty($carrinho)) {
$qntProdutosCarrinhos = count($carrinho);
}
if($qntProdutosCarrinhos == 0) {
header("Location: /");
}
?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ezcommerce</title>
<!-- STYLES -->
<link rel="stylesheet" href="/styles/global.css">
<link rel="stylesheet" href="/styles/pages/carrinho.css">
<link rel="stylesheet" href="/styles/tables/carrinho.css">
<link rel="stylesheet" href="/styles/btns/cta.css">
<link rel="stylesheet" href="/styles/btns/ghost.css">
<link rel="stylesheet" href="/styles/nav/nav.css">
<link rel="stylesheet" href="/styles/rodape/rodape.css">
<!-- Aqui utilizamos apenas o elemento input__container, mas acabamos importando todas as outras (Refatorar!) -->
<link rel="stylesheet" href="/styles/form/form.css">
<!-- SCRIPTS -->
<script src="/public/scripts/popupConfirmar.js" defer></script>
<script src="/public/scripts/precosCarrinho.js" defer></script>
</head>
<body>
<nav class="nav">
<header class="nav__header">
<?php if ($usuario) { ?>
<?php
$nomeCompleto = $usuario->getNome();
$nomes = explode(" ", $nomeCompleto);
$sobrenome = $nomes[count($nomes) - 1];
?>
<h1>Olá, <?= $sobrenome ?> </h1>
<a
class="nav__header__sair"
href="/src/actions/logout.php"
>
<img src="/public/log-out.svg" width="24px" alt="Ícone de logout">
<span>Sair</span>
</a>
<?php } else { ?>
<h1>Ezcommerce</h1>
<span>Achei fácil comprar</span>
<?php } ?>
</header>
<ul class="nav__header__btns">
<li class="nav__header__btn">
<a href="/">
<img src="/public/home.svg" alt="Ícone da página inicial">
<span>Inicial</span>
</a>
</li>
<?php if ($usuario) { ?>
<li class="nav__header__btn nav__header__btn--active">
<a href="/carrinho.php">
<img src="/public/cart.svg" alt="Ícone de carrinho">
<span>Carrinho (<?= $qntProdutosCarrinhos ?>)</span>
</a>
</li>
<li class="nav__header__btn">
<a href="/editarPerfil.php">
<img src="/public/user.svg" alt="Ícone do perfil do usuário">
<span>Editar perfil</span>
</a>
</li>
<?php } ?>
<li class="nav__header__btn">
<a href="/ajuda.php">
<img src="/public/help.svg" alt="Ícone de ajuda">
<span>Ajuda</span>
</a>
</li>
</ul>
<footer class="nav__bottom__logo">
<img src="/public/logo-ez-dark.svg" alt="Logo da Ezcommerce">
</footer>
</nav>
<main>
<header>
<h2>Seu carrinho<h2>
<a class="ghost" href="/">
<span>Mais produtos</span>
</a>
</header>
<table class="tableCarrinho">
<tr>
<th></th>
<th>Nome</th>
<th>Preço</th>
<th>Quantidade</th>
<th>Subtotal</th>
</tr>
<?php foreach ($carrinho as $produto) { ?>
<tr>
<td>
<?php
$msgRemoverProduto = "Deseja realmente remover esse produto?";
$produtoId = $produto->getId();
$actionRemoverProduto = "/src/actions/carrinho.php?id=$produtoId&acao=remover";
?>
<button onclick="popupConfirmar('<?= $msgRemoverProduto?>', '<?= $actionRemoverProduto ?>')">
<img src="/public/x.svg" alt="Remover" title="Remover"/>
</button>
</td>
<td><?= $produto->getNome(); ?></td>
<td>R$ <?= $produto->getValor(); ?></td>
<td>
<input
type="number"
value="1"
min="1"
/>
</td>
<td>R$ <?= $produto->getValor(); ?></td>
</tr>
<?php } ?>
</table>
<div>
<h3>Total a pagar: <b>R$13.0</b></h3>
<nav>
<a
href="#"
class="btnCTA"
disabled
>
Comprar (Em desenvolvimento)
</a>
<?php
$msgEsvaziar = "Deseja realmente esvaziar seu carrinho?";
$actionEsvaziar = "/src/actions/carrinho.php?acao=esvaziar";
?>
<button
onclick="popupConfirmar('<?= $msgEsvaziar?>', '<?= $actionEsvaziar ?>')"
class="ghost ghost--caution"
>
Esvaziar carrinho
</button>
</nav>
</div>
<?php require_once dirname(__FILE__) . "/src/components/rodape.php"; ?>
</main>
</body>
</html>