-
Notifications
You must be signed in to change notification settings - Fork 0
/
product.php
122 lines (109 loc) · 4.35 KB
/
product.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
<?php include 'includes/session.php'; ?>
<?php
$conn = $pdo->open();
$slug = $_GET['product'];
try{
$stmt = $conn->prepare("SELECT *, products.name AS prodname, category.name AS catname, products.id AS prodid FROM products LEFT JOIN category ON category.id=products.category_id WHERE slug = :slug");
$stmt->execute(['slug' => $slug]);
$product = $stmt->fetch();
}
catch(PDOException $e){
echo "There is some problem in connection: " . $e->getMessage();
}
//page view
$now = date('Y-m-d');
if($product['date_view'] == $now){
$stmt = $conn->prepare("UPDATE products SET counter=counter+1 WHERE id=:id");
$stmt->execute(['id'=>$product['prodid']]);
}
else{
$stmt = $conn->prepare("UPDATE products SET counter=1, date_view=:now WHERE id=:id");
$stmt->execute(['id'=>$product['prodid'], 'now'=>$now]);
}
?>
<?php include 'includes/header.php'; ?>
<body class="hold-transition skin-blue layout-top-nav">
<script>
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = 'https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.12';
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<div class="wrapper">
<?php include 'includes/navbar.php'; ?>
<div class="content-wrapper">
<div class="container">
<!-- Main content -->
<section class="content">
<div class="row">
<div class="col-sm-9">
<div class="callout" id="callout" style="display:none">
<button type="button" class="close"><span aria-hidden="true">×</span></button>
<span class="message"></span>
</div>
<div class="row">
<div class="col-sm-6">
<img src="<?php echo (!empty($product['photo'])) ? 'images/'.$product['photo'] : 'images/noimage.jpg'; ?>" width="100%" class="zoom" data-magnify-src="images/large-<?php echo $product['photo']; ?>">
<br><br>
<form class="form-inline" id="productForm">
<div class="form-group">
<div class="input-group col-sm-5">
<span class="input-group-btn">
<button type="button" id="minus" class="btn btn-default btn-flat btn-lg"><i class="fa fa-minus"></i></button>
</span>
<input type="text" name="quantity" id="quantity" class="form-control input-lg" value="1">
<span class="input-group-btn">
<button type="button" id="add" class="btn btn-default btn-flat btn-lg"><i class="fa fa-plus"></i>
</button>
</span>
<input type="hidden" value="<?php echo $product['prodid']; ?>" name="id">
</div>
<button type="submit" class="btn btn-primary btn-lg btn-flat"><i class="fa fa-shopping-cart"></i> Add to Cart</button>
</div>
</form>
</div>
<div class="col-sm-6">
<h1 class="page-header"><?php echo $product['prodname']; ?></h1>
<h3><b>$ <?php echo number_format($product['price'], 2); ?></b></h3>
<p><b>Category:</b> <a href="category.php?category=<?php echo $product['cat_slug']; ?>"><?php echo $product['catname']; ?></a></p>
<p><b>Description:</b></p>
<p><?php echo $product['description']; ?></p>
</div>
</div>
<br>
<!-- <div class="fb-comments" data-href="http://localhost/ecommerce/product.php?product=<?php echo $slug; ?>" data-numposts="10" width="100%"></div> -->
</div>
<!-- <div class="col-sm-3">
<?php include 'includes/sidebar.php'; ?>
</div> -->
</div>
</section>
</div>
</div>
<?php $pdo->close(); ?>
<?php include 'includes/footer.php'; ?>
</div>
<?php include 'includes/scripts.php'; ?>
<script>
$(function(){
$('#add').click(function(e){
e.preventDefault();
var quantity = $('#quantity').val();
quantity++;
$('#quantity').val(quantity);
});
$('#minus').click(function(e){
e.preventDefault();
var quantity = $('#quantity').val();
if(quantity > 1){
quantity--;
}
$('#quantity').val(quantity);
});
});
</script>
</body>
</html>