-
Notifications
You must be signed in to change notification settings - Fork 1
/
addcart.php
60 lines (59 loc) · 2.04 KB
/
addcart.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
<?php
session_start();
require "config.php";
require "models/db.php";
require "models/product.php";
require "models/manufacture.php";
require "models/protype.php";
require "models/cart.php";
require "models/user.php";
$product = new Product();
$manu = new Manufacture();
$type = new Protype();
$cart = new Cart();
$user = new User();
if (isset($_SESSION['user'])) {
# code...
if (isset($_GET['id'])) {
# code...
$id = $_GET['id'];
$sl = $_POST['qty'];
if (isset($_SESSION['cart'][$id])) {
# code...
$qty = $_SESSION['cart'][$id] + 1;
} else {
$qty = $sl;
}
$_SESSION['cart'][$id] = $qty;
# code...
$check = $user->check($_SESSION['user']);
foreach ($check as $values) {
foreach ($_SESSION['cart'] as $key => $qty) {
$getProductById = $product->getProductById($id);
foreach ($getProductById as $value) {
if ($key == $value['id']) {
if ($checkProduct_id = $cart->checkProduct_id($key)) {
if ($cart->UpdateQty($qty + $sl - 1, $key)) {
# code...
header("location:viewcart.php");
}
} else {
# code...
if ($cart->addCart($values['user_id'], $key, $value['price'], $qty)) {
// header("location:checkout.php");
echo "<script>alert('Đã thêm vào giỏ hàng')</script>";
header("location:viewcart.php");
//echo "them tc";
} else {
# code...
echo "them khong tc";
}
}
}
}
}
}
}
} else {
header('location:login/index.php');
}