-
Notifications
You must be signed in to change notification settings - Fork 0
/
cart.html
204 lines (153 loc) · 6.28 KB
/
cart.html
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
---
layout: null
title: Highland Park Furniture Co.
description: Custom Furniture Handmade in Calgary Alberta
sitemap:
priority: 1.0
lastmod: 2020-08-02
changefreq: weekly
---
<!DOCTYPE HTML>
<html>
<head>
{% include head.html %}
</head>
<body class="is-loading">
<!-- Wrapper -->
<div id="wrapper" class="fade-in">
<!-- Header -->
<header id="header">
<img src="{{"/images/logothin.svg" | absolute_url }}" alt="" class="svg"/>
</header>
<!-- Nav -->
<nav id="nav">
{% include nav.html %}
</nav>
<!-- Main -->
<div id="main">
<div class="container">
<div class="card mb-4 shadow-sm">
<div class="card-header">
<h2>Cart</h2>
</div>
<div class="card-body">
<table class="table">
<tbody class="cart">
</tbody>
<tfoot>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td class="text-right">Total: <strong class="total"></strong></td>
<td></td>
</tfoot>
</table>
<//button class="btn btn-outline-warning mr-2" onClick="cartLS.destroy()"Destroy//button>
<//button class="btn btn-outline-warning mr-2" onClick="cartLS.list()"Checkout//button>
</div>
<div style="margin-left: 50vw" >
<button class="button" id="checkout-button-stripe" role="link" type="button">
Proceed to Checkout
</button></div>
<div id="error-message"></div>
</div>
</div>
<!-- Footer -->
<footer>
<ul class="actions">
<li><a href="{{ "/process/" | absolute_url }}" class="button">Our Process</a></li>
</ul>
</footer>
</div>
</div>
<!-- Footer -->
{% include foot.html %}
<!-- Scripts -->
{% include scripts-main.html %}
<//script src="{{ "/assets/js/products.js" | absolute_url }}"><//script>
<script>
function renderCart(items) {
const $cart = document.querySelector(".cart")
const $total = document.querySelector(".total")
$cart.innerHTML = items.map((item) => `
<tr>
<td>${item.name}</td>
<td></td>
<td>${item.quantity}</td>
<td style="width: 60px;">
<button type="button"
onClick="cartLS.quantity('${item.id}',1)">+</button>
</td>
<td style="width: 60px;">
<button type="button"
onClick="cartLS.quantity('${item.id}',-1)">−</button>
</td>
<td class="text-right">$${item.price}</td>
<td class="text-right"><Button class="btn btn-primary" onClick="cartLS.remove('${item.id}')">Delete</Button></td>
</tr>`).join("")
$total.innerHTML = "$" + cartLS.total()
}
renderCart(cartLS.list())
cartLS.onChange(renderCart)
</script>
<script>
(function() {
var stripe = Stripe('pk_test_51MJl9YG47Qvg6QA2wzGrgHhhNBB1G3ztgu19d6EaaMkjWuGfHrOf4M6dYM8MpTBOSPtXQ9yiAIcZs5LjHIhiAcUg00ep05RmNz');
var checkoutButton = document.getElementById('checkout-button-stripe');
//var cartlength = localStorage.length;
//console.log(cartlength);
var stripeout = localStorage.getItem("__cart");
var stripeoutString = {cartitem: JSON.parse(localStorage.getItem("__cart"))};
var cartlength = stripeoutString.cartitem.length;
console.log(stripeoutString.cartitem);
console.log(cartlength);
if (cartlength >= 1) var stripeout0 = {price: stripeoutString.cartitem[0].id, quantity: stripeoutString.cartitem[0].quantity};
if (cartlength >= 2) var stripeout1 = {price: stripeoutString.cartitem[1].id, quantity: stripeoutString.cartitem[1].quantity};
if (cartlength >= 3) var stripeout2 = "{price: '" + stripeoutString.cartitem[2].id + "', quantity: " + stripeoutString.cartitem[2].quantity + "}";
if (cartlength >= 4) var stripeout3 = "{price: '" + stripeoutString.cartitem[3].id + "', quantity: " + stripeoutString.cartitem[3].quantity + "}";
if (cartlength >= 5) var stripeout4 = "{price: '" + stripeoutString.cartitem[4].id + "', quantity: " + stripeoutString.cartitem[4].quantity + "}";
if (cartlength >= 6) var stripeout5 = "{price: '" + stripeoutString.cartitem[5].id + "', quantity: " + stripeoutString.cartitem[5].quantity + "}";
if (cartlength >= 7) var stripeout6 = "{price: '" + stripeoutString.cartitem[6].id + "', quantity: " + stripeoutString.cartitem[6].quantity + "}";
checkoutButton.addEventListener('mouseover', function checkoutprep() {
const stripeintent = [];
stripeintent[0]= stripeout0;
stripeintent[1]= stripeout1 ?? null;
stripeintent[2]= stripeout2 ?? null;
stripeintent[3]= stripeout3 ?? null;
stripeintent[4]= stripeout4 ?? null;
stripeintent[5]= stripeout5 ?? null;
stripeintent[6]= stripeout6 ?? null;
//console.log(stripeintent);
const stripeexport = stripeintent.filter(notNull);
function notNull(value) {
return value != null;
};
console.log(stripeexport);
checkoutButton.addEventListener('click', function () {
/*
* When the customer clicks on the button, redirect
* them to Checkout.
*/
//stripe.redirectToCheckout({lineItems: [{price: 'price_1MXfzXG47Qvg6QA2AfHSOQE3', quantity: 1}, {price: 'price_1MYDxlG47Qvg6QA2GxxzUwBG', quantity: 1}], mode: 'payment',
//stripe.redirectToCheckout({lineItems: "[" + stripeout0 + ", " + stripeout1 + "]", mode: 'payment',
stripe.redirectToCheckout({lineItems: stripeexport, mode: 'payment',
successUrl: window.location.protocol + '//highlandparkfurniture.ca/success',
cancelUrl: window.location.protocol + '//highlandparkfurniture.ca/cancelled',
})
.then(function (result) {
if (result.error) {
/*
* If `redirectToCheckout` fails due to a browser or network
* error, display the localized error message to your customer.
*/
var displayError = document.getElementById('error-message');
displayError.textContent = result.error.message;
}
});
});
})})();
</script>
</body>
</html>