-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
879 lines (706 loc) · 29.7 KB
/
index.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Shopping Cart</title>
<!-- jQuery -->
<script src="https://code.jquery.com/jquery-3.6.1.min.js" integrity="sha256-o88AwQnZB+VDvE9tvIXrMQaPlFFSUTR+nldQm1LuPXQ=" crossorigin="anonymous"></script>
<!-- Bootstrap -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<!-- Font Awesome -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css" integrity="sha512-xh6O/CkQoPOWDdYTDqeRdPCVd1SpvCA9XXcUnZS2FmJNp1coAFzvtCN9BmamE+4aHK8yyUHUSCcJHgXloTyT2A==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<!-- Cart Tab styles -->
<style>
#aside_cartTab
{
position: fixed;
right: 0;
top: 50%;
margin-top: -64px;
border-radius: .25rem;
}
#cartTab
{
padding: 2em 1em;
text-align: center;
}
</style>
<!-- end Cart Tab styles -->
<script>
// shopping cart config on page load
/*
* ----------
* Initialize
*
* debug affects the checkout function. Set to true for on-page testing. Set to false to make the checkout button
* redirect the user to the checkout target URL
*
* checkout target url should be the base URL of where the browser will be forwarded (no params)
*
* funnelID come from CheckoutChamp CRM
*
* retainUrlParams passes incoming URL parameters to the checkout page
*
* suggested default cart status message is "You have 0 items in your cart"
*
* subtotal should be initialized to 0. i.e. user starts with no cost in cart
*
* coupon code and message are optional. If used both values must be text.
*
* totalQtyInCart is used to store/display the sum of all quantities of items in the cart
*
* ----------
* Cart Items
*
* keys must be unique. e.g. "Product1_PB" vs "Product1_HC". These labels are used in HTML attributes
*
* ids must be unique. e.g. the product ID in the CheckoutChamp CRM. These values are used in HTML attributes
*
* item name value should be unique
*
* item qty should be initialized to 0. i.e. user starts with no items in cart
*
* item's price value must be integer or decimal. Script handles formatting to display prices as USD in the Cart.
* HTML must be manually set up to match these values and formatting.
*
* imgSrc is the path to where the product image is hosted
*
* imgAlt is the alt text of that product's corresponding img element in the cart
*
* */
let Cart =
{
"debug": true,
// "debug": false,
"checkOutTarget": "https://secure-checkout.your-domain.com/",
"funnelID": "funnel-id", // e.g. "fid3-checkout"
"retainUrlParams": true,
"status": "You have 0 items in your cart",
"subtotal": 0,
"coupon": "TEST",
"couponMessage": "This is a test coupon",
"totalQtyInCart": 0,
"items":
{
"Product1_PB":
{
"id": 999,
"name": "Product 1 Paperback",
"qty": 0,
"price": 85,
"imgSrc": "images/imgPH1.png",
"imgAlt": "product 1 paperback"
},
"Product1_HC":
{
"id": 998,
"name": "Product 1 Hardcover",
"qty": 0,
"price": 100,
"imgSrc": "images/imgPH1.png",
"imgAlt": "product 1 hardcover"
},
"Product2":
{
"id": 876,
"name": "Product 2",
"qty": 0,
"price": 200,
"imgSrc": "images/imgPH2.png",
"imgAlt": "product 2"
},
"Product3":
{
"id": 765,
"name": "Product 3",
"qty": 0,
"price": 300,
"imgSrc": "images/imgPH3.png",
"imgAlt": "product 3"
},
}
};
// end shopping cart config on page load
</script>
</head>
<body>
<section>
<div class="container">
<div class="row">
<!-- Products UI -->
<div class="col-12">
<div class="row m-3">
<div class="col-6"><h2>Products</h2></div>
<div class="col-6 text-end">
<button class="btn btn-primary" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasRight" aria-controls="offcanvasRight"><i class="fa-solid fa-cart-shopping" style="margin-right:.3em"></i> Cart</button>
</div>
</div>
<!-- product 1 -->
<div class="row d-flex">
<hr />
<!-- col: product 1 image -->
<div class="col-3 mb-3">
<img src="images/imgPH1.png" alt="product 1 image" width="100%" />
</div>
<!-- end col: product 1 image -->
<!-- col: product 1 details -->
<div class="col-9 mb-3">
<h3>Product 1</h3>
<p>Lorem ipsum dolor sit amet.</p>
<form action="">
<!-- product 1 paperback -->
<div class="form-check">
<!-- input value needs to be the item's key name used in Cart JSON -->
<input class="form-check-input" type="radio" name="radio_product1" value="Product1_PB" id="radio_product1_PB" checked>
<label class="form-check-label" for="radio_product1_PB">
Paperback ($85)
</label>
</div>
<!-- product 1 hardcover -->
<div class="form-check">
<!-- input value needs to be the item's key name used in Cart JSON -->
<input class="form-check-input" type="radio" name="radio_product1" value="Product1_HC" id="radio_product1_HC">
<label class="form-check-label" for="radio_product1_HC">
Hardcover ($100)
</label>
</div>
<!-- string passed to addVariantToCart() needs to be name of radio group for this product -->
<button id="btn_addProduct1" type="button" onclick="addVariantToCart('radio_product1')" class="btn btn-primary w-25 mb-3"><i class="fa-solid fa-cart-shopping" style="margin-right:.3em"></i> Add to cart</button>
</form>
</div>
<!-- end col: product 1 details -->
<hr />
</div>
<!-- end product 1 -->
<!-- product 2 -->
<div class="row d-flex">
<!-- col: product 2 image -->
<div class="col-3 mb-3">
<img src="images/imgPH2.png" alt="product 2 image" width="100%" />
</div>
<!-- end col: product 2 image -->
<!-- col: product 2 details -->
<div class="col-9 mb-3">
<h3>Product 2</h3>
<p>Consectetur adipisicing elit. Aliquam cumque, error esse.</p>
<p>$200.00</p>
<!-- the text passed to addItemToCart() needs to match the item's key name used in Cart JSON -->
<button id="btn_addProduct2" type="button" onclick="addItemToCart('Product2')" class="btn btn-primary w-25 mb-3"><i class="fa-solid fa-cart-shopping" style="margin-right:.3em"></i> Add to cart</button>
</div>
<!-- end col: product 2 details -->
<hr />
</div>
<!-- end product 2 -->
<!-- product 3 -->
<div class="row d-flex">
<!-- col: product 3 image -->
<div class="col-3 mb-3">
<img src="images/imgPH3.png" alt="product 3 image" width="100%" />
</div>
<!-- end col: product 3 image -->
<!-- col: product 3 details -->
<div class="col-9 mb-3">
<h3>Product 3</h3>
<p>Facere facilis fugiat, in iste omnis quam reiciendis reprehenderit voluptatem?</p>
<p>$300.00</p>
<!-- the text passed to addItemToCart() needs to match the item's key name used in Cart JSON -->
<button id="btn_addProduct3" type="button" onclick="addItemToCart('Product3')" class="btn btn-primary w-25 mb-3"><i class="fa-solid fa-cart-shopping" style="margin-right:.3em"></i> Add to cart</button>
</div>
<!-- end col: product 3 details -->
<hr />
</div>
<!-- end product 3 -->
</div>
<!-- end Products UI -->
</div>
</div>
</section>
<!-- offCanvas side panel -->
<aside>
<div class="offcanvas offcanvas-end" data-bs-scroll="true" data-bs-backdrop="false" tabindex="-1" id="offcanvasRight" aria-labelledby="offcanvasRightLabel">
<div class="offcanvas-header">
<h5 id="offcanvasRightLabel">Cart</h5>
<button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<!-- Cart UI -->
<!-- cart status message -->
<p id="cartStatus"></p>
<!-- the shelf that displays in-cart items -->
<ul class="list-group" id="cartItems"></ul>
<!-- order financials -->
<div class="row mt-3">
<span id="couponMessage"></span>
<p><strong>Subtotal:</strong> <span id="subtotal"></span><br />
Tax, shipping, and/or discounts will be calculated at checkout.</p>
<button onclick="checkout()" id="btn_checkout" type="button" class="btn btn-success mb-2">Checkout</button>
<button onclick="clearCart()" id="btn_clearCart" type="button" class="btn btn-secondary">Clear Cart</button>
</div>
<!-- end order financials -->
<!-- debug: checkout message -->
<div class="row mt-3">
<span id="checkOutMessage"></span>
</div>
<!-- end debug: checkout message -->
<!-- end Cart UI -->
</div>
</div>
</aside>
<!-- end offCanvas side panel -->
<!-- cart tab -->
<aside id="aside_cartTab" class="btn-primary" data-bs-toggle="offcanvas" data-bs-target="#offcanvasRight" aria-controls="offcanvasRight">
<div id="cartTab">
<p id="cartTab_qty">0</p>
<i class="fa-solid fa-cart-shopping"></i>
</div>
</aside>
<!-- end cart tab -->
<script>
// ============
// on page load
$(document).ready(function(){
// ---------
// cart init
// write the default cart status message to the page
$("#cartStatus").text(Cart.status);
// write the default cart subtotal to the page
$("#subtotal").text(USD(Cart.subtotal));
// if Cart is using a coupon, write the configured coupon code and message to the page
if (Cart.coupon !== "")
{
$("#couponMessage").append("<p><strong>Coupon:</strong> " + Cart.coupon + " - " + Cart.couponMessage + "</p>");
}
// end cart init
// -------------
// -------------
// cart tab init
hideCartTab();
// end cart tab init
// -----------------
});
// end on page load
// ================
// ===========================
// fn: express a number in USD
// n - integer or decimal - the number that will be expressed as a price
function USD(n)
{
// currency formatter
let usd = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
// These options are needed for rounding to whole numbers if that's what you want.
//minimumFractionDigits: 0, // (this suffices for whole numbers, but will print 2500.10 as $2,500.1)
//maximumFractionDigits: 0, // (causes 2500.99 to be printed as $2,501)
});
// end currency formatter
// return n as USD currency format
return usd.format(n);
}
// end fn USD
// ==========
// ==================================
// fn: get count of items in the cart
function getCountOfCartItems()
{
let cartItems = $("#cartItems li");
return cartItems.length;
}
// end fn getCountOfCartItems
// ==========================
// ============================================
// fn: calculate the total qty of items in cart
function countTotalQtyOfCartItems()
{
// variable to count with
let count = 0;
// count each item
for (const item in Cart.items)
{
count += Cart.items[item].qty;
}
// return the count
return count;
}
// end fn countTotalQtyOfCartItems
// ===============================
// ==================================
// fn: get total qty of items in cart
function getTotalQtyOfCartItems()
{
return Cart.totalQtyInCart;
}
// end fn getTotalQtyOfCartItems
// =============================
// ======================================
// fn: set the total qty of items in cart
function setTotalQtyOfCartItems(num)
{
Cart.totalQtyInCart = num;
}
// end fn setTotalQtyOfCartItems
// =============================
// =======================================================================
// fn: update cart status message based on how many items are on the shelf
function updateCartStatus()
{
// get updated cart status text
let updatedStatusText = "You have " + getTotalQtyOfCartItems() + " items in your cart";
// assign updated text to UI and Cart
$("#cartStatus").text(updatedStatusText);
Cart.status = updatedStatusText;
}
// end fn updateCartStatus
// =======================
// ==========================
// fn: increase cart subtotal
// Product - JSON - the product that is being added to the shelf or having its quantity updated
function increaseSubtotal(Product)
{
Cart.subtotal += Product.price;
$("#subtotal").text(USD(Cart.subtotal));
}
// end fn increaseSubtotal
// =======================
// ==============================
// fn: place an item on the shelf
// Product - JSON - the product that will be added to the shelf
// shelf - JS object - reference to the HTML ul element that holds the shelf items
function placeItemOnShelf(Product, shelf)
{
// append list item to cart
let shelfItem =
"<li id=\"productRow_" + Product.id + "\" class=\"list-group-item container\"><div class=\"row\"><div class=\"col-3\"><img src=\"" + Product.imgSrc + "\" alt=\"" + Product.imgAlt + "\" width=\"100%\"></div><div class=\"col-6\"><p>" + Product.name + "</p>" + "<p>" + USD(Product.price) + "</p>" + "</div>" + "<div class=\"col-3\"><div class=\"input-group mb-3\"><input type=\"number\" name=\"qty_" + Product.id + "\" class=\"form-control\" value=\"1\" min=\"0\"><button id=\"btn_removeRow_" + Product.id + "\" class=\"btn btn-light btn-sm w-100\">Remove</button></div></div></div></li>";
shelf.append(shelfItem);
// update item qty
Product.qty++;
// update total qty in Cart
Cart.totalQtyInCart++;
// need to update subtotal
increaseSubtotal(Product);
// need to update cart status message
updateCartStatus()
// ----------------------------------------------
// bind functions to the shelf item we just added
// handle changes in product quantity
// remove item from shelf if qty is set to 0
$("input[name=qty_" + Product.id + "]").on("change", function()
{
handleQuantityChange(this, Product);
});
// handle button click to remove a row
$("#btn_removeRow_" + Product.id).on("click", function()
{
removeItemFromCart(Product);
});
// end bind functions to the shelf item we just added
// --------------------------------------------------
// update cart tab UI
cartTabUI();
}
// end fn placeItemOnShelf
// =======================
// ========================================================================
// fn: handle changes to the product quantity field of an item on the shelf
// thisInput - JS object - self reference to the input field that was changed
// Product - JSON - holds data that we need to make updates to
function handleQuantityChange(thisInput, Product)
{
// get the new qty
let newQty = parseInt($(thisInput).val());
// do not allow negative numbers in the Cart
if (newQty < 0) { newQty = 0; }
// ----------------------------------
// if qty was set to 0 or less than 0
// remove the item from the shelf
if (newQty === 0)
{
removeItemFromCart(Product);
cartTabUI();
}
// --------------------------------------
// else proceed to handle quantity change
else
{
// get the old qty from Cart JSON
let oldQty = Product.qty;
// get difference between quantities
let difference = newQty - oldQty;
// calculate dollar amount difference of quantities
let costDifference = Product.price * difference;
// set the new qty in the item's JSON
Product.qty = newQty;
// set the new total qty in Cart's JSON
setTotalQtyOfCartItems(countTotalQtyOfCartItems());
// update subtotal in Cart JSON
Cart.subtotal += costDifference;
// display new cart subtotal
$("#subtotal").text(USD(Cart.subtotal));
// update the cart status message
updateCartStatus();
// update the Cart tab UI
cartTabUI();
}
}
// end fn handleQuantityChange
// ===========================
// ====================================
// fn: add a single product to the cart
function addItemToCart(item)
{
// get item details from Cart.items
let Product = Cart.items[item];
// get html element that holds the shelf items
let shelf = $('#cartItems');
// ensure items in shelf are unique
// look for an existing shelf li with an id of "productRow_Product.id"
let hasRow = $("#productRow_" + Product.id);
// ---------------------------------------------------------------------------
// if the shelf already has a row for the product ID that we are trying to add
if (hasRow.length === 1)
{
// increase the displayed quantity for that row
let input = $("input[name=qty_" + Product.id + "]"); // get the input field element
let qty = parseInt(input.val()); // get the input field's value
qty++; // increment the value
input.val(qty); // set the new value to the input field
// increment the Product's qty in Cart JSON
Product.qty++;
// increment the total qty of items in the Cart
Cart.totalQtyInCart++;
// increase the cart subtotal
increaseSubtotal(Product);
// update the Cart status message
updateCartStatus();
// update the Cart tab UI
cartTabUI();
}
// --------------------------------
// else place the item on the shelf
else
{
placeItemOnShelf(Product, shelf);
cartTabUI();
}
// end ensure items in shelf are unique
}
// end fn addItemToCart
// ====================
// =============================================
// fn: add a product with variations to the cart
function addVariantToCart(radioName)
{
// get input from radio group
let selectedItem = $("input[name=" + radioName + "]:checked").val();
// add variant to the cart
addItemToCart(selectedItem);
}
// end fn addVariantToCart
// =======================
// =================================
// fn: clear all items from the cart
function clearCart()
{
// get the shelf that hold cart items
let cartShelf = $("#cartItems");
// get the items on the shelf
let cartItems = $("#cartItems li");
// slide the shelf items out of view
cartItems.fadeOut(800);
// wait for the animation before proceeding
setTimeout(function ()
{
// ---------------
// reset Cart JSON
// reset subtotal to 0
Cart.subtotal = 0;
// reset all product qty to 0
let productKeys = Object.keys(Cart.items);
productKeys.forEach(function(k){
Cart.items[k].qty = 0;
});
// reset total qty in Cart to 0
Cart.totalQtyInCart = 0;
// end reset Cart JSON
// -------------------
// remove all shelf items from page
cartShelf.empty();
// update subtotal displayed in Cart
$("#subtotal").text(USD(Cart.subtotal));
// update cart status message
updateCartStatus();
// update cart tab UI
$("#cartTab_qty").text("0");
hideCartTab();
}, 800);
}
// end function clearCart
// ======================
// =================================
// fn: remove an item from the shelf
function removeItemFromCart(Product)
{
// get the row from the cart
let shelfRow = $("li#productRow_" + Product.id);
// fade out the shelf row
shelfRow.fadeOut(800);
// wait for animation before proceeding
setTimeout(function ()
{
// remove the row from the cart
shelfRow.remove();
// get the old qty from Product
let oldQty = Product.qty;
// update the total qty of items in the Cart
let oldTotalQty = getTotalQtyOfCartItems();
setTotalQtyOfCartItems(oldTotalQty - oldQty);
// update the subtotal in Cart JSON
let costToRemove = oldQty * Product.price;
Cart.subtotal -= costToRemove;
// update the subtotal displayed on the page
$("#subtotal").text(USD(Cart.subtotal));
// update the qty in Cart JSON
Product.qty = 0;
// update cart status message
updateCartStatus();
// update cart tab UI
cartTabUI();
}, 800);
}
// end fn removeItemFromCart
// =========================
// ==========================
// fn: handle checkout button
function checkout()
{
// debug switch
switch (Cart.debug)
{
// ----------------------------------------
// debug is true. let's see what's going on
case true:
debug();
break;
// ------------------------------------------
// debug is false. send user to checkout page
case false:
handleCheckout();
}
// end debug switch
}
// end fn checkout
// ===============
// ==============
// fn: cart debug
function debug()
{
// write to the document
$("#checkOutMessage").append("<p>-- TEST --</p>");
$("#checkOutMessage").append("<p>Cart is in debug mode. See console for Cart details.</p>");
$("#checkOutMessage").append("<p>Target URL: <a href='" + getURLToCheckoutPage() + "' target='_blank'>" + getURLToCheckoutPage() + "</a></p>");
console.log(Cart);
}
// end fn debug
// ============
// ==================================
// fn: redirect user to checkout page
function sendToCheckout()
{
window.location = getURLToCheckoutPage();
}
// end function sendToCheckout
// ===========================
// ================================================
// fn: get redirect URL based on Cart JSON settings
// see https://konnektive.atlassian.net/wiki/spaces/CC/pages/1859555013/Redirect+external+funnel+to+Checkout+Champ+Checkout
function getURLToCheckoutPage()
{
// build redirect parameters
let params = Cart.funnelID + "?products=";
// determine which products to include in checkout
let productKeys = Object.keys(Cart.items);
productKeys.forEach(function(k){
let product = Cart.items[k];
if (product.qty > 0)
{
// add "productID:quantity;" to url params
params += product.id + ":" + product.qty + ";";
}
});
// remove the unnecessary ";" from the last product that was added to the params
params = params.slice(0, -1);
// include coupon code if being used
if (Cart.coupon !== "")
{
params += "&couponCode=" + Cart.coupon;
}
// include incoming URL params if Cart.retainUrlParams is true
if (Cart.retainUrlParams === true)
{
let searchParams = window.location.search;
let correctedSearchParams = searchParams.replace("?", "&");
params += correctedSearchParams;
}
// return checkout URL
return Cart.checkOutTarget + params;
}
// end fn getLinkToCheckoutPage
// ============================
// =================================
// fn: checkout if cart is not empty
function handleCheckout()
{
// if Cart's subtotal is greater than 0
if (Cart.subtotal > 0)
{
// send user to check out page
sendToCheckout()
}
// else warn user that they must have products in their cart to check out
else
{
alert("You must have products in your cart to checkout.");
}
}
// end fn handleCheckout
// =====================
// =====================
// fn: show the cart tab
function showCartTab()
{
$("#aside_cartTab").fadeIn(500);
}
// end fn showCartTab
// ==================
// =====================
// fn: hide the cart tab
function hideCartTab()
{
$("#aside_cartTab").hide();
}
// end fn hideCartTab
// ==================
// ===============================
// fn: perform cart tab UI actions
function cartTabUI()
{
// get count of items in the cart
let numItemsInCart = getTotalQtyOfCartItems();
// if 0 items in cart
if (numItemsInCart === 0)
{
hideCartTab();
}
// else show cart tab and update cart tab items count
else
{
showCartTab();
$("#cartTab_qty").text(numItemsInCart);
}
}
// end function cartTabUI
// ======================
</script>
</body>
</html>