-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.html
181 lines (176 loc) · 6.66 KB
/
search.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
{% extends 'shop/basic.html' %}
{% block title%} Search Results - My Awesome Cart{% endblock %}
{% block css %}
.col-md-3
{
display: inline-block;
margin-left:-4px;
}
.carousel-indicators .active {
background-color: blue;
}
.col-md-3 img{
width: 170px;
height: 200px;
}
body .carousel-indicator li{
background-color: blue;
}
body .carousel-indicators{
bottom: -40px;
}
.carousel-indicators li {
background-color: #7270fc;
}
body .carousel-control-prev-icon,
body .carousel-control-next-icon{
background-color: blue;
}
.carousel-control-prev,
.carousel-control-next{
top: auto;
bottom: auto;
padding-top: 222px;
}
body .no-padding{
padding-left: 0,
padding-right: 0;
}
{% endblock %}
{% block body %}
{% load static %}
<div class="container">
<!--Slideshow starts here -->
{% for product, range, nSlides in allProds %}
<h5 class="my-4">Flash Sale On {{product.0.category}} - Recommended Items</h5>
<div class="row">
<div id="demo{{forloop.counter}}" class="col carousel slide my-3" data-ride="carousel">
<ul class="carousel-indicators">
<li data-target="#demo{{forloop.counter}}" data-slide-to="0" class="active"></li>
{% for i in range %}
<li data-target="#demo{{forloop.parentloop.counter}}" data-slide-to="{{i}}"></li>
{% endfor %}
</ul>
<div class="container carousel-inner no-padding">
<div class="carousel-item active">
{% for i in product %}
<div class="col-xs-3 col-sm-3 col-md-3">
<div class="card align-items-center" style="width: 18rem;">
<img src='/media/{{i.image}}' class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title" id="namepr{{i.id}}">{{i.product_name}}</h5>
<p class="card-text">{{i.desc|slice:"0:53"}}...</p>
<h6 class="card-title" >Price: <span id="pricepr{{i.id}}">{{i.price}}</span></h6>
<span id="divpr{{i.id}}" class="divpr">
<button id="pr{{i.id}}" class="btn btn-primary cart">Add To Cart</button>
</span>
<a href="/shop/products/{{i.id}}"><button id="qv{{i.id}}" class="btn btn-primary cart">QuickView</button></a>
</div>
</div>
</div>
{% if forloop.counter|divisibleby:4 and forloop.counter > 0 and not forloop.last %}
</div>
<div class="carousel-item">
{% endif %}
{% endfor %}
</div>
</div>
</div>
<!-- left and right controls for the slide -->
<a class="carousel-control-prev" href="#demo{{forloop.counter}}" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#demo{{forloop.counter}}" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
{% endfor %}
</div>
{% endblock %}
{% block js %}
<script>
{% if msg|length != 0 %}
alert('{{msg}}');
window.location.href = "/"
{% endif %}
// Find out the cart items from localStorage
if (localStorage.getItem('cart') == null) {
var cart = {};
} else {
cart = JSON.parse(localStorage.getItem('cart'));
updateCart(cart);
}
// If the add to cart button is clicked, add/increment the item
//$('.cart').click(function() {
$('.divpr').on('click', 'button.cart', function(){
var idstr = this.id.toString();
if (cart[idstr] != undefined) {
qty = cart[idstr][0] + 1;
} else {
qty = 1;
name = document.getElementById('name'+idstr).innerHTML;
price = document.getElementById('price'+idstr).innerHTML;
cart[idstr] = [qty, name, parseInt(price)];
}
updateCart(cart);
});
//Add Popover to cart
$('#popcart').popover();
updatePopover(cart);
function updatePopover(cart) {
console.log('We are inside updatePopover');
var popStr = "";
popStr = popStr + "<h5> Cart for your items in my shopping cart </h5><div class='mx-2 my-2'>";
var i = 1;
for (var item in cart) {
popStr = popStr + "<b>" + i + "</b>. ";
popStr = popStr + document.getElementById('name' + item).innerHTML.slice(0, 19) + "... Qty: " + cart[item][0] + '<br>';
i = i + 1;
}
popStr = popStr + "</div> <a href='/shop/checkout'><button class='btn btn-primary' id ='checkout'>Checkout</button></a> <button class='btn btn-primary' onclick='clearCart()' id ='clearCart'>Clear Cart</button> "
console.log(popStr);
document.getElementById('popcart').setAttribute('data-content', popStr);
$('#popcart').popover('show');
}
function clearCart() {
cart = JSON.parse(localStorage.getItem('cart'));
for (var item in cart) {
document.getElementById('div' + item).innerHTML = '<button id="' + item + '" class="btn btn-primary cart">Add To Cart</button>'
}
localStorage.clear();
cart = {};
updateCart(cart);
}
function updateCart(cart) {
var sum = 0;
for (var item in cart) {
sum = sum + cart[item][0];
document.getElementById('div' + item).innerHTML = "<button id='minus" + item + "' class='btn btn-primary minus'>-</button> <span id='val" + item + "''>" + cart[item][0] + "</span> <button id='plus" + item + "' class='btn btn-primary plus'> + </button>";
}
localStorage.setItem('cart', JSON.stringify(cart));
document.getElementById('cart').innerHTML = sum;
console.log(cart);
updatePopover(cart);
}
// If plus or minus button is clicked, change the cart as well as the display value
$('.divpr').on("click", "button.minus", function() {
a = this.id.slice(7, );
cart['pr' + a][0] = cart['pr' + a][0] - 1;
cart['pr' + a][0] = Math.max(0, cart['pr' + a][0]);
if (cart['pr' + a][0] == 0){
document.getElementById('divpr' + a).innerHTML = '<button id="pr'+a+'" class="btn btn-primary cart">Add to Cart</button>';
delete cart['pr'+a];
}
else{
document.getElementById('valpr' + a).innerHTML = cart['pr' + a][0];
}
updateCart(cart);
});
$('.divpr').on("click", "button.plus", function() {
a = this.id.slice(6, );
cart['pr' + a][0] = cart['pr' + a][0] + 1;
document.getElementById('valpr' + a).innerHTML = cart['pr' + a][0];
updateCart(cart);
});
</script>
{% endblock %}