-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProduct_Details.html
More file actions
167 lines (153 loc) · 7.29 KB
/
Product_Details.html
File metadata and controls
167 lines (153 loc) · 7.29 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<!-- This file has been downloaded from bootdey.com @bootdey on twitter -->
<!-- All snippets are MIT license http://bootdey.com/license -->
<title>ZincAPI Product Details Example</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/js/bootstrap.bundle.min.js"></script>
<link href="./loading.css" rel="stylesheet">
</head>
<body>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<div class="loading">Loading…</div>
<div class="container content">
<div class="card">
<div class="card-body">
<h3 id="title" class="card-title">Rounded Chair</h3>
<h6 class="card-subtitle">By <span id="brand"></span></h6>
<div class="row">
<div class="col-lg-5 col-md-5 col-sm-6">
<div class="white-box text-center">
<div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
<div id="images" class="carousel-inner">
</div>
<a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
</div>
<div class="col-lg-7 col-md-7 col-sm-6">
<h4 class="box-title mt-5">Product description</h4>
<ul id="description"></ul>
<h2 class="mt-5">
$<span id="price">1.00</span>
</h2>
<button class="btn btn-dark btn-rounded mr-1" data-toggle="tooltip" title="" data-original-title="Add to cart">
<i class="fa fa-shopping-cart"></i>
</button>
<button class="btn btn-primary btn-rounded">Buy Now</button>
</div>
</div>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
<h3 class="box-title mt-5">Product Details</h3>
<div class="table-responsive table-sm">
<table class="table table-striped table-product">
<tbody id="specifics">
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split('&');
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split('=');
if (decodeURIComponent(pair[0]) == variable) {
return decodeURIComponent(pair[1]);
}
}
return null;
}
async function getProductDetails(productId) {
const headers = new Headers();
if(localStorage.getItem('ct')){
const clientToken = localStorage.getItem('ct')
headers.set('Authorization', 'Basic ' + btoa(clientToken + ":")); //this is how you authenticate using your client token
} else {
headers.set('Authorization', 'Basic ' + btoa("demouser:superdupersecret")); //demo auth
}
const response = await fetch(`https://api.zinc.io/v1/products/${productId}?retailer=amazon&max_age=3600`, { headers });
const json = await response.json();
console.log('product details', json);
return json;
}
function updateProductDetailsUI(details) {
if(details.status === "failed"){
alert(`${details.code}: ${details.message}`);
return;
}
$(".loading").fadeOut(500)
$("#title").text(details.title)
$("#brand").text(details.brand)
$("#stars").text(details.stars)
$("#reviewCount").text(details.review_count)
for (const image of details.images) {
$("#images").append(`<div class="carousel-item"><img id="image" class="d-block w-100" src="${image}"></div>`)
}
$('#images div:first-child').addClass('active');
for (const bullet of details.feature_bullets || []) {
$("#description").append(`<li>${bullet}</li>`)
}
$("#price").text((details.price / 100).toFixed(2)) //price is always in cents
for (const epid of details.epids) {
$("#specifics").append(`<tr><td width="390">${epid.type}</td><td>${epid.value}</td></tr>`)
}
for (const detail of details.product_details) {
if (detail.indexOf(":") === -1) continue;
$("#specifics").append(`<tr><td width="390">${detail.slice(0, detail.indexOf(':'))}</td><td>${detail.slice(detail.indexOf(':') + 1)}</td></tr>`)
}
}
//get data and update ui
const productDetailsPromise = getProductDetails(getQueryVariable('pid')||'B07VQ69WP5');
document.addEventListener("DOMContentLoaded", async () => updateProductDetailsUI(await productDetailsPromise))
</script>
<style type="text/css">
body {
background-color: #edf1f5;
margin-top: 20px;
}
.card {
margin-bottom: 30px;
}
.card {
position: relative;
display: flex;
flex-direction: column;
min-width: 0;
word-wrap: break-word;
background-color: #fff;
background-clip: border-box;
border: 0 solid transparent;
border-radius: 0;
}
.card .card-subtitle {
font-weight: 300;
margin-bottom: 10px;
color: #8898aa;
}
.table-product.table-striped tbody tr:nth-of-type(odd) {
background-color: #f3f8fa !important
}
.table-product td {
border-top: 0px solid #dee2e6 !important;
color: #728299 !important;
}
</style>
</body>
</html>