-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProductDetails.html
775 lines (646 loc) · 40.3 KB
/
ProductDetails.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
<!DOCTYPE html>
<html>
<script>
document.onreadystatechange = function() {
if (document.readyState !== "complete") {
$("#loadMe").modal({
backdrop: "static", //remove ability to close modal with click
keyboard: false, //remove option to close with keyboard
show: true //Display loader!
});
}
};
</script>
<!-- Modal -->
<div class="modal fade" id="loadMe" tabindex="-1" role="dialog" aria-labelledby="loadMeLabel">
<div class="modal-dialog modal-sm modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-body text-center">
<div class="loader"></div>
<div class="loader-txt">
<p id="loadermsg">Loading please wait....</p>
</div>
</div>
</div>
</div>
</div>
<head>
<script>
function preloadFunc() {
if (localStorage.getItem("Username") === null) {
window.location.href = ("login.html");
}
}
window.onpaint = preloadFunc();
</script>
<title>Product Details</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<!-------CSS----------->
<link href="https://fonts.googleapis.com/css?family=Nunito:400,700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.11.2/css/all.css">
<link rel="stylesheet" href="md/css/bootstrap.min.css">
<link rel="stylesheet" href="md/css/mdb.min.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" type="text/css" href="jquery.toast.css">
<style type="text/css">
.loader {
position: relative;
text-align: center;
margin: 15px auto 35px auto;
z-index: 9999;
display: block;
width: 80px;
height: 80px;
border: 10px solid rgba(0, 0, 0, .3);
border-radius: 50%;
border-top-color: #21b30e;
animation: spin 1s ease-in-out infinite;
-webkit-animation: spin 1s ease-in-out infinite;
}
@keyframes spin {
to {
-webkit-transform: rotate(360deg);
}
}
@-webkit-keyframes spin {
to {
-webkit-transform: rotate(360deg);
}
}
/** MODAL STYLING **/
.modal-content {
border-radius: 0px;
box-shadow: 0 0 20px 8px rgba(0, 0, 0, 0.7);
}
.modal-backdrop.show {
opacity: 0.90;
}
.loader-txt {
p {
font-size: 13px;
color: #666;
small {
font-size: 11.5px;
color: #999;
}
}
}
</style>
</head>
<body>
<!-- navbar -->
<nav class="navbar navbar-expand-lg navbar-light white-color sticky-top " align="center" id="MainNavbar">
<a class="navbar-brand" href="#"><span><img src="images/logoTitle.png" id="brand"
class="d-inline-block align-center"></a>
<!-- Collapse button -->
<button class="navbar-toggler float-right ml-auto" type="button" data-toggle="collapse" data-target="#navMenu" aria-controls="#navMenu" aria-expanded="false" aria-label="Expand" id="toggleBtn">
<span class="navbar-toggler-icon black-text"></span>
</button>
<!-- cart and profile -->
<span>
<ul class="nav">
<li class="nav-item" onclick="expandcart()">
<a class="nav-link" data-target="#cartModal" data-toggle="modal"><i
class="fas fa-shopping-cart fa-lg "></i><span class="badge badge-danger white-text" id="cartCountBadge"></span></a>
</li>
<li class="nav-item dropdown">
<a class="nav-link " id="navbarDropdownMenuLink-4" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fas fa-user fa-lg"></i></a>
<div class="dropdown-menu dropdown-menu-right dropdown-info">
<a class="dropdown-item" href="profile.html">PROFILE</a>
<a class="dropdown-item" href="#" onclick="logout()">LOGOUT</a>
</div>
</li>
</ul>
</span>
<div class="collapse navbar-collapse" id="navMenu">
<ul class="nav navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="homepage.html">HOME</a>
</li>
<li class="nav-item">
<a class="nav-link" href="DisplayFilterWise.html">CATEGORIES </a>
</li>
</ul>
</div>
</nav>
<!-- navbar -->
<!-- modal for cart -->
<div class="modal fade" id="cartModal" tabindex="-1" role="dialog" aria-labelledby="cartModalTitle" aria-hidden="true">
<!-- Add .modal-dialog-centered to .modal-dialog to vertically center the modal -->
<div class="modal-dialog modal-xl modal-dialog-centered" role="document">
<div class="modal-content cart-modal-class">
<div class="modal-body">
<div class="container">
<!-- Section: Block Content -->
<section>
<div class="row " id="cart-row-header">
<div class="col-md-12 col-lg-12 text-center">
<h5 id="cart-header-title">YOUR CART</h5>
<span id="cart-close-icon" aria-hidden="true" type="button" class="close" data-dismiss="modal">×</span>
</div>
</div>
<hr>
</section>
<!-- Section: Block Content -->
<div class="cart-list" id="cartbody">
</div>
<div class="cart-footer">
<div class="cart-subtotal-div text-center">
<p id="cart-subtotal">Subtotal = Rs. 0</p>
</div>
<div class="cart-checkout-div d-flex d-inline justify-content-center">
<button id="continue-shopping-btn" data-dismiss="modal">Continue</button>
<button id="checkout-btn" onclick="window.location.href=('checkout.html');">Checkout</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Modal -->
<!-- main content -->
<div class="container-fluid px-lg-5 py-xs-2 ">
<div class="card py-lg-5 py-xs-2 detailCard">
<div class="row pt-0">
<div class="col-lg-4 col-md-12 col-sm-12 text-center p-4 mt-md-2 mt-lg-2 mt-5">
<div class="flex-fill text-center image-container mt-1">
<view class="zoom">
<img class="image-fluid" id="mainProductImage">
</view>
</div>
</div>
<div class="col-lg-8 col-sm-12 col-md-12">
<div class="flex-column py-4 px-4">
<div class="flex-fill text-center text-md-left">
<a>
<p class="main-product-name-class font-weight-bold pr-2" id="name"></p>
</a>
</div>
<div class="flex-fill text-center text-md-left">
<p class="main-category-class pr-2" id="catagory"></p>
</div>
<div class="flex-fill text-center text-md-left ">
<ul class="main-rating-layout list-unstyled list-inline" id="rating">
</ul>
</div>
<div class="d-flex">
<div class="flex-fill">
<p class="main-price-class mt-3" id="price"></p>
</div>
<div class="flex-fill text-right px-lg-5" style="margin-top: -6px;">
<button class="cart-btn-class mt-3" id="addToCartBtn" onclick="add()">Add to Cart
<i class="fas fa-cart-plus fa-md p-1"></i>
</button>
</div>
</div>
<hr class="mt-2 mr-md-4">
<p class="main-description-class pr-md-4 pr-sm-2" id="description"></p>
</div>
</div>
</div>
</div>
<div class="card px-4 pt-3 pb-4 mt-5 mb-5">
<p class="font-weight-bold mt-2" style="text-align: center; font-size: 22px;">Similar Products</p>
<div class="row" id="similarProducts">
</div>
</div>
</div>
<!-- feedback modal -->
<div class="modal fade" id="modalContactForm" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header text-center">
<h4 class="modal-title w-100 font-weight-bold" style="font-family: Nunito;color: green;">Write to us</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body mx-3">
<div class="md-form">
<textarea type="text" class=" form-control p-2" id="feedback" rows="4" placeholder="Your Message..." style="font-family: Nunito;"></textarea>
</div>
</div>
<div class="modal-footer d-flex justify-content-center">
<button id="feedbackSendBtn" onclick="feedback()">Send</button>
</div>
</div>
</div>
</div>
<!-- footer -->
<footer class="page-footer font-small unique-color-dark pt-4 z-depth-2">
<!-- Footer Links -->
<div class="container text-center text-md-left">
<!-- Grid row -->
<div class="row">
<!-- Grid column -->
<div class="col-md-4 mx-auto">
<img src="images/logoTitle2.png" class="footerLogo">
<p>AgriTech is a E-commerce platform for farmers, which serves farmers the tools and pesticides easily,quickly and at reasonable rates.</p>
</div>
<!-- Grid column -->
<hr class="clearfix w-100 d-md-none">
<!-- Grid column -->
<div class="col-md-2 mx-auto">
<!-- Links -->
<h5 class="text-uppercase mt-3 mb-4 footerLinkClass">Company</h5>
<ul class="list-unstyled">
<li>
<a href="about.html">About Us</a>
</li>
<!-- <li>
<a href="#!">Core Values</a>
</li>
<li>
<a href="#!">Careers</a>
</li>
<li>
<a href="#!">Sitemap</a>
</li> -->
</ul>
</div>
<!-- Grid column -->
<hr class="clearfix w-100 d-md-none">
<!-- Grid column -->
<div class="col-md-2 mx-auto">
<!-- Links -->
<h5 class=" text-uppercase mt-3 mb-4 footerLinkClass">Policy Info</h5>
<ul class="list-unstyled">
<li>
<a href="#!">Privacy Policy</a>
</li>
<!-- <li>
<a href="#!">Terms of Sale</a>
</li> -->
<li>
<a href="#!">Terms of Use</a>
</li>
<!-- <li>
<a href="#!">Report Abuse</a>
</li> -->
</ul>
</div>
<!-- Grid column -->
<hr class="clearfix w-100 d-md-none">
<!-- Grid column -->
<div class="col-md-2 mx-auto">
<!-- Links -->
<h5 class="text-uppercase mt-3 mb-4 footerLinkClass">help</h5>
<ul class="list-unstyled">
<li>
<a href="#!">FAQ</a>
</li>
<li>
<a href="" data-toggle="modal" data-target="#modalContactForm">Contact Us</a>
</li>
</ul>
</div>
<!-- Grid column -->
</div>
<!-- Grid row -->
</div>
<!-- Footer Links -->
<hr>
<!-- Social buttons -->
<ul class="list-unstyled list-inline text-center">
<li class="list-inline-item">
<a class="btn-floating btn-fb mx-1">
<i class="fab fa-facebook-f"> </i>
</a>
</li>
<li class="list-inline-item">
<a class="btn-floating btn-tw mx-1">
<i class="fab fa-twitter"> </i>
</a>
</li>
<li class="list-inline-item">
<a class="btn-floating btn-gplus mx-1">
<i class="fab fa-google-plus-g"> </i>
</a>
</li>
<li class="list-inline-item">
<a class="btn-floating btn-li mx-1">
<i class="fab fa-linkedin-in"> </i>
</a>
</li>
</ul>
<!-- Social buttons -->
<!-- Copyright -->
<div class="footer-copyright text-center py-3">© 2020 Copyright:
<a href="#">AgriTech</a>
</div>
<!-- Copyright -->
</footer>
<!-- js -->
<script type="text/javascript" src="md/js/jquery.min.js"></script>
<script type="text/javascript" src="md/js/popper.min.js"></script>
<script type="text/javascript" src="md/js/bootstrap.min.js"></script>
<script type="text/javascript" src="md/js/mdb.min.js"></script>
<script src="jquery.toast.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.6.1/firebase.js"></script>
<script>
// Your web app's Firebase configuration
var firebaseConfig = {
apiKey: "AIzaSyBw4RVlD1ZdnNNn4ow5hahtxPxBSpL_tpA",
authDomain: "website-e1c2c.firebaseapp.com",
databaseURL: "https://website-e1c2c.firebaseio.com",
projectId: "website-e1c2c",
storageBucket: "website-e1c2c.appspot.com",
messagingSenderId: "640557542653",
appId: "1:640557542653:web:215d1a31f7ace2f72fe294"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
</script>
<script>
var catagory = "Pesticide";
var cnt = 0;
var ordBy = "name";
window.onload = () => {
load_data(ordBy);
firebase.database().ref().child("Users").child(localStorage.getItem("Username")).child("cart").on("value", function(snapshot) {
var cartCnt = snapshot.numChildren();
document.getElementById("cartCountBadge").innerHTML = cartCnt;
if (cartCnt == 0) {
//document.getElementById("checkout-btn").style["backgroundcolor"]="black";
document.getElementById("checkout-btn").disabled = true;
document.getElementById("checkout-btn").style = "background-color:grey !important";
} else {
// document.getElementById("checkout-btn").style["backgroundcolor"]="green";
document.getElementById("checkout-btn").disabled = false;
document.getElementById("checkout-btn").style = "background-color:green !important";
}
});
//document.getElementById("myName").innerHTML=localStorage.getItem("Username");
};
/*firebase.database().ref().child("HomeImages").limitToLast(3).on('value', function(snapshot1) {
if (snapshot1.exists())
{
document.getElementById("carouselimages").innerHTML="";
snapshot1.forEach(function(childSnapshot) {
document.getElementById("carouselimages").innerHTML+="<div class='carousel-item active'><img class='d-block w-100 sliderImageClass' src="+childSnapshot.val().ImageUri+"></div>";
});
}
});*/
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m, key, value) {
vars[key] = decodeURIComponent(value);
});
return vars;
}
function load_data(orderBy) {
$("#loadMe").modal({
backdrop: "static", //remove ability to close modal with click
keyboard: false, //remove option to close with keyboard
show: true //Display loader!
});
firebase.database().ref().child("Posts").child(getUrlVars()["pname"]).on('value', function(snapshot1) {
if (snapshot1.exists()) {
var storageRef = firebase.storage().ref();
document.getElementById("name").innerHTML = (snapshot1.val().name).toUpperCase();
document.getElementById("price").innerHTML = "Rs." + snapshot1.val().price;
document.getElementById("description").innerHTML = snapshot1.val().description;
document.getElementById("catagory").innerHTML = snapshot1.val().catagory;
var tmp = "";
var count = parseInt(snapshot1.val().rating.avgrating);
for (var i = 0; i < 5; i++) {
if (i < count) {
tmp += "<i class='fas fa-star orange-text'></i>";
} else {
tmp += "<i class='fas fa-star grey-text'></i>";
}
}
document.getElementById("rating").innerHTML += tmp;
storageRef.child(snapshot1.val().image).getDownloadURL().then(function(url) {
document.getElementById("mainProductImage").src = url;
}).catch(function(error) {
console.log(error);
});
firebase.database().ref().child("Posts").orderByChild("catagory").equalTo(snapshot1.val().catagory).on('value', function(snapshot2) {
if (snapshot2.exists()) {
var cnt = 0,
cnt1 = 0,
cnt3 = 1;
var ele;
document.getElementById("similarProducts").innerHTML = "";
snapshot2.forEach(function(childSnapshot) {
if (cnt1 > 4)
return
if (snapshot1.val().name != childSnapshot.val().name) {
cnt1++;
var storageRef = firebase.storage().ref();
//document.getElementById("similarProducts").innerHTML
var tmp = "<div class='col align-items-center d-flex justify-content-center m-1' ><div class='card productCardClass px-3'><div class='text-center' onclick=nextProduct('" + encodeURIComponent(childSnapshot.val().name) + "')><view class='zoom'> <img id=imgcat" + cnt1 + " class='image-fluid productImage'></view> </div><div class='mt-1 text-center' onclick=nextProduct('" + encodeURIComponent(childSnapshot.val().name) + "')> <a><p class='product-name-class'>" + (childSnapshot.val().name).toUpperCase() + "</p> </a> </div> <div class='text-center' onclick=nextProduct('" + encodeURIComponent(childSnapshot.val().name) + "')> <a> <p class='categoryClass'>" + childSnapshot.val().catagory + "</p> </a></div><div class='text-center'><ul class='rating rating-layout'>";
var count = parseInt(childSnapshot.val().rating.avgrating);
for (var i = 0; i < 5; i++) {
if (i < count) {
tmp += "<i class='fas fa-star orange-text'></i>";
} else {
tmp += "<i class='fas fa-star grey-text'></i>";
}
}
$("#similarProducts").prepend(tmp + "</ul></div> <div class='text-left' onclick=nextProduct('" + encodeURIComponent(childSnapshot.val().name) + "')><p class='product-description-class'>" + (childSnapshot.val().description).substring(0, 100) + "...</p></div><div class='d-flex'><div class='flex-fill'><p class='priceClass'>Rs." + childSnapshot.val().price + "</p></div> <div class='flex-fill text-right'><i class='fas fa-cart-plus fa-lg addCartClass' onclick=addtocart('" + encodeURIComponent(childSnapshot.val().name) + "')></i> </div></div></div></div>");
// document.getElementById("productlist").innerHTML+="<div class='d-flex border-top p-1'><div class='flex-fill'> <div class='card-body'> <div class='row align-items-center'><div class='col-5 px-0 align-items-center justify-content-center text-center'> <a> <img src='3.jpg' class='img-fluid productImage3' id='otherProductImage'> </a></div> <div class='col-7'><p class='productNameClass3 '><a>Mahavir Neem</a></p><p class='productCategoryClass'>Cropicide</p> <h6 class='productDescriptionClass black-text'>Mahavir Neem Agro Neem Cake/Neem Powder for Plants/Neem Fertlizer - 5Kg </h6><ul class='rating list-unstyled list-inline'><i class='fas fa-star orange-text'></i><i class='fas fa-star orange-text'></i><i class='fas fa-star orange-text'></i><i class='fas fa-star orange-text'></i><i class='fas fa-star orange-text'></i></ul><h5 class='priceClass float-left black-text'>Rs.649</h5><span class='float-right'><a data-toggle='tooltip' data-placement='top' title='Add to Cart'> <i class='fas fa-cart-plus fa-lg d-block w-100 blue-text addCartClass'></i></a> </span></div> </div></div></div> <div class='border-right'></div><div class='flex-fill'> <div class='card-body'> <div class='row align-items-center'><div class='col-5 px-0 align-items-center justify-content-center text-center'> <a> <img src='3.jpg' class='img-fluid productImage3' id='otherProductImage'> </a></div> <div class='col-7'><p class='productNameClass3 '><a>Mahavir Neem</a></p><p class='productCategoryClass'>Cropicide</p> <h6 class='productDescriptionClass black-text'>Mahavir Neem Agro Neem Cake/Neem Powder for Plants/Neem Fertlizer - 5Kg </h6><ul class='rating list-unstyled list-inline'><i class='fas fa-star orange-text'></i><i class='fas fa-star orange-text'></i><i class='fas fa-star orange-text'></i><i class='fas fa-star orange-text'></i><i class='fas fa-star orange-text'></i></ul><h5 class='priceClass float-left black-text'>Rs.649</h5><span class='float-right'><a data-toggle='tooltip' data-placement='top' title='Add to Cart'> <i class='fas fa-cart-plus fa-lg d-block w-100 blue-text addCartClass'></i></a> </span></div> </div></div></div></div>";
//$("#productlist").prepend("<div class='col align-items-center d-flex justify-content-center mt-4' id='products'><div class='card align-items-center mb-2 productCardClass'><!---card---><div class='view overlay zoom'><img id=imgcat"+cnt1+" class='productImage' id='pImage1'></div><div class='card-body'><a href='' class='categoryClass'><h5 style='color:black;'>"+(childSnapshot.val().name).toUpperCase()+"</h5><h6>"+childSnapshot.val().catagory+"</h6></a><h6 class='productNameClass'><a href='' class='black-text'>"+(childSnapshot.val().description).substring(0,100)+"...</a></h6><ul class='rating list-unstyled list-inline'><i class='fas fa-star orange-text'></i><i class='fas fa-star orange-text'></i><i class='fas fa-star orange-text'></i><i class='fas fa-star orange-text'></i><i class='fas fa-star orange-text'></i></ul><h5 class='priceClass float-left black-text'>Rs."+childSnapshot.val().price+"</h5><span class='float-right'><a data-toggle='tooltip' data-placement='top' title='Add to Cart'><i class='fas fa-cart-plus fa-lg d-block w-100 blue-text addCartClass' onclick=addtocart('"+ encodeURIComponent(childSnapshot.val().name)+"')></i></a></span></div></div><!-- Card --></div>");
(function(pid) {
storageRef.child(childSnapshot.val().image).getDownloadURL().then(function(url) {
document.getElementById("imgcat" + pid).src = url;
}).catch(function(error) {
console.log(error);
});
})(cnt1);
}
});
}
setTimeout(function() {
$("#loadMe").modal("hide");
}, 1000);
});
}
});
}
function nextProduct(name) {
//localStorage.setItem("pname",name);
window.location.href = ("ProductDetails.html?pname=" + name);
}
function changeqty(name, qty) {
name = decodeURIComponent(name);
if (qty == 0)
qty = 1;
qty = parseInt(qty);
firebase.database().ref().child("Users").child(localStorage.getItem("Username")).child("cart").child(name).child("qty").set(qty);
}
function expandcart() {
firebase.database().ref().child("Users").child(localStorage.getItem("Username")).child("cart").orderByChild("name").on('value', function(snapshot1) {
var storageRef = firebase.storage().ref();
document.getElementById("cartbody").innerHTML = "";
if (snapshot1.exists()) {
var cnt = 0,
cnt1 = 0,
total = 0;
document.getElementById("cartbody").innerHTML = "";
snapshot1.forEach(function(childSnapshot) {
total += childSnapshot.val().price * childSnapshot.val().qty;
//document.getElementById("cartbody").innerHTML+="<!-- First row --><tr><th scope='row'><img id=img"+cnt+" alt='' class='img-fluid z-depth-0' style='height: 120px;'></th><td><h5 class='mt-3'><strong>"+childSnapshot.val().name+"</strong></h5><p class='text-muted'>"+childSnapshot.val().catagory+"</p></td><td></td><td>"+childSnapshot.val().price+"</td><td><input type='number' value='2' aria-label='Search' class='form-control' style='width: 100px'></td><td class='font-weight-bold'><strong>"+childSnapshot.val().price+"</strong></td><td><button type='button' class='btn btn-sm btn-primary' id=removebtn"+cnt+" data-toggle='tooltip' data-placement='top' title='Remove item' onclick=removeitem('"+ encodeURIComponent(childSnapshot.val().name)+"')>X</button></td></tr><!-- First row -->";
// $("#removebtn"+cnt).click(function(){
// firebase.database().ref().child("Users").child(localStorage.getItem("Username")).child("cart").child(childSnapshot.val().name).remove();
// });
cnt++;
document.getElementById("cartbody").innerHTML += "<div class='row cart-item-row' ><div class='col-lg-2 col-md-2 col-sm-12 text-center'><img id=img" + cnt + " class='cart-item-image img-fluid'></div><div class='col-lg-10 col-md-10 col-sm-12' style='padding-top: 24px'><div class='row'><div class='col-lg-8 col-md-8 col-sm-12 ' style='padding-bottom:2px;'><div class='text-center'> <div class='flex-column text-md-left'> <p class='cart-item-name-class px-4 '> <a>" + childSnapshot.val().name + " </a> </p> <p class='cart-category-class px-4'> <a>" + childSnapshot.val().catagory + "</a> </p></div></div></div><div class='col-lg-4 col-md-4 col-sm-12 text-center'><div class='row'><div class='col text-right'><p class='cart-item-price'>Rs." + childSnapshot.val().price + "</p></div><div class='col'><div class='row cart-item-quantity'><input type='button' id='minus' class='cart-item-quantity-button' value='-' onclick=changeqty('" + encodeURIComponent(childSnapshot.val().name) + "','" + (childSnapshot.val().qty - 1) + "')><input value=" + childSnapshot.val().qty + " pattern='\d*' onkeyup=changeqty('" + encodeURIComponent(childSnapshot.val().name) + "',this.value) class='text-center cart-item-quantity-input'><input type='button' id='plus' value='+' onclick=changeqty('" + encodeURIComponent(childSnapshot.val().name) + "','" + (parseInt(childSnapshot.val().qty) + 1) + "') class='cart-item-quantity-button'> </div></div></div></div></div> <div class='d-flex d-inline justify-content-center cart-item-remove-div'><p class='cart-item-remove-button'><a id=removebtn" + cnt + " onclick=removeitem('" + encodeURIComponent(childSnapshot.val().name) + "')>Remove Item <i class='far fa-trash-alt'></i></a></p></div></div></div><hr>";
(function(pid) {
storageRef.child(childSnapshot.val().image).getDownloadURL().then(function(url) {
document.getElementById("img" + pid).src = url;
}).catch(function(error) {
console.log(error);
});
})(cnt);
// storageRef.child(childSnapshot.val().image).getDownloadURL().then(function(url) {
// document.getElementById("img"+cnt).src=url;
// cnt++;
// });
});
document.getElementById("cart-subtotal").innerHTML = "Subtotal = Rs. " + total;
}
});
}
function removeitem(val) {
val = decodeURIComponent(val);
firebase.database().ref().child("Users").child(localStorage.getItem("Username")).child("cart").child(val).remove();
expandcart();
}
function add() {
addtocart(encodeURIComponent(getUrlVars()["pname"]));
}
function addtocart(item) {
$.toast({
text: "Success", // Text that is to be shown in the toast
heading: 'Item added in Cart !', // Optional heading to be shown on the toast
icon: 'success', // Type of toast icon
showHideTransition: 'fade', // fade, slide or plain
allowToastClose: true, // Boolean value true or false
hideAfter: 3000, // false to make it sticky or number representing the miliseconds as time after which toast needs to be hidden
stack: 5, // false if there should be only one toast at a time or a number representing the maximum number of toasts to be shown at a time
position: 'bottom-right', // bottom-left or bottom-right or bottom-center or top-left or top-right or top-center or mid-center or an object representing the left, right, top, bottom values
textAlign: 'left', // Text alignment i.e. left, right or center
loader: true, // Whether to show loader or not. True by default
loaderBg: '#9EC600', // Background color of the toast loader
beforeShow: function() {}, // will be triggered before the toast is shown
afterShown: function() {}, // will be triggered after the toat has been shown
beforeHide: function() {}, // will be triggered before the toast gets hidden
afterHidden: function() {} // will be triggered after the toast has been hidden
});
item = decodeURIComponent(item);
firebase.database().ref().child("Posts").child(item).once('value', function(snapshot1) {
var obj = {
name: snapshot1.val().name,
price: snapshot1.val().price,
image: snapshot1.val().image,
catagory: snapshot1.val().catagory,
seller: snapshot1.val().seller,
qty: 1
};
firebase.database().ref().child("Users").child(localStorage.getItem("Username")).child("cart").child(item).set(obj);
});
}
function addtocart(item) {
item = decodeURIComponent(item);
firebase.database().ref().child("Users").child(localStorage.getItem("Username")).child("cart").child(item).once("value", function(snapshot) {
if (snapshot.exists()) {
$.toast({
text: "Warning", // Text that is to be shown in the toast
heading: 'Item Already added in Cart !', // Optional heading to be shown on the toast
icon: 'warning', // Type of toast icon
showHideTransition: 'fade', // fade, slide or plain
allowToastClose: true, // Boolean value true or false
hideAfter: 3000, // false to make it sticky or number representing the miliseconds as time after which toast needs to be hidden
stack: 5, // false if there should be only one toast at a time or a number representing the maximum number of toasts to be shown at a time
position: 'bottom-right', // bottom-left or bottom-right or bottom-center or top-left or top-right or top-center or mid-center or an object representing the left, right, top, bottom values
textAlign: 'left', // Text alignment i.e. left, right or center
loader: true, // Whether to show loader or not. True by default
loaderBg: 'orange', // Background color of the toast loader
beforeShow: function() {}, // will be triggered before the toast is shown
afterShown: function() {}, // will be triggered after the toat has been shown
beforeHide: function() {}, // will be triggered before the toast gets hidden
afterHidden: function() {} // will be triggered after the toast has been hidden
});
} else {
$.toast({
text: "Success", // Text that is to be shown in the toast
heading: 'Item added in Cart !', // Optional heading to be shown on the toast
icon: 'success', // Type of toast icon
showHideTransition: 'fade', // fade, slide or plain
allowToastClose: true, // Boolean value true or false
hideAfter: 3000, // false to make it sticky or number representing the miliseconds as time after which toast needs to be hidden
stack: 5, // false if there should be only one toast at a time or a number representing the maximum number of toasts to be shown at a time
position: 'bottom-right', // bottom-left or bottom-right or bottom-center or top-left or top-right or top-center or mid-center or an object representing the left, right, top, bottom values
textAlign: 'left', // Text alignment i.e. left, right or center
loader: true, // Whether to show loader or not. True by default
loaderBg: '#9EC600', // Background color of the toast loader
beforeShow: function() {}, // will be triggered before the toast is shown
afterShown: function() {}, // will be triggered after the toat has been shown
beforeHide: function() {}, // will be triggered before the toast gets hidden
afterHidden: function() {} // will be triggered after the toast has been hidden
});
firebase.database().ref().child("Posts").child(item).once('value', function(snapshot1) {
var obj = {
name: snapshot1.val().name,
price: snapshot1.val().price,
image: snapshot1.val().image,
catagory: snapshot1.val().catagory,
seller: snapshot1.val().seller,
qty: 1
};
firebase.database().ref().child("Users").child(localStorage.getItem("Username")).child("cart").child(item).set(obj);
});
}
});
}
function feedback() {
if (document.getElementById("feedback").value == "") {
alert("Write something !");
return;
}
firebase.database().ref().child("Feedbacks").push({
Feedback: document.getElementById("feedback").value,
Name: localStorage.getItem("Username")
});
$("#modalContactForm").modal("hide");
$.toast({
text: "Success", // Text that is to be shown in the toast
heading: 'Thanks for your Feedback!', // Optional heading to be shown on the toast
icon: 'success', // Type of toast icon
showHideTransition: 'fade', // fade, slide or plain
allowToastClose: true, // Boolean value true or false
hideAfter: 3000, // false to make it sticky or number representing the miliseconds as time after which toast needs to be hidden
stack: 5, // false if there should be only one toast at a time or a number representing the maximum number of toasts to be shown at a time
position: 'bottom-right', // bottom-left or bottom-right or bottom-center or top-left or top-right or top-center or mid-center or an object representing the left, right, top, bottom values
textAlign: 'left', // Text alignment i.e. left, right or center
loader: true, // Whether to show loader or not. True by default
loaderBg: '#9EC600', // Background color of the toast loader
beforeShow: function() {}, // will be triggered before the toast is shown
afterShown: function() {}, // will be triggered after the toat has been shown
beforeHide: function() {}, // will be triggered before the toast gets hidden
afterHidden: function() {} // will be triggered after the toast has been hidden
});
document.getElementById("feedback").value = "";
}
function logout() {
localStorage.clear();
window.location.href = ("login.html");
}
firebase.database().ref().child("Users").child(localStorage.getItem("Username")).child("cart").orderByChild("name").on('value', function(snapshot1) {
if (parseInt(snapshot1.numChildren()) == 0) {
document.getElementById("cart-subtotal").innerHTML = "Subtotal = Rs. 0";
document.getElementById("cartbody").style = "background-image:url('images/emptycart.png');background-repeat: no-repeat;background-size:290px 250px ;background-position: center center; ";
} else {
document.getElementById("cartbody").style = "background-color:white;";
}
});
</script>
</body>
</html>