Subversion Repositories SmartDukaan

Rev

Rev 32639 | Rev 33790 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
23343 ashik.ali 1
$(function() {
24202 amit.gupta 2
	callback = function(value) {
24203 amit.gupta 3
		removeItemFromLocalStorage(giftItemId);
28339 tejbeer 4
		if (isNaN(value)) {
24202 amit.gupta 5
			bootbox("No of watches should be a number. Set '0' specifically");
6
			return;
28339 tejbeer 7
		} else {
24202 amit.gupta 8
			loadCart("main-content", value);
9
		}
10
	}
27754 amit.gupta 11
	$(document).on('click', ".cart_icon_header", function() {
28339 tejbeer 12
		if (typeof hasGift == "undefined") {
25738 amit.gupta 13
			hasGift = false;
14
		}
28339 tejbeer 15
		if (hasGift) {
16
			bootBoxObj = {
17
				size: "medium",
18
				title: "Add Number of Watch as Gift",
19
				callback: callback,
20
				inputType: 'number'
21
			};
22
 
24202 amit.gupta 23
			bootbox.prompt(bootBoxObj);
24
		} else {
28339 tejbeer 25
			loadCart('main-content', 0);
24202 amit.gupta 26
		}
23343 ashik.ali 27
	});
28339 tejbeer 28
 
29
 
27754 amit.gupta 30
	$(document).on('click', ".cart-checkout", function() {
23343 ashik.ali 31
		checkout("main-content");
32
	});
28339 tejbeer 33
 
27754 amit.gupta 34
	$(document).on('click', ".add-bag-submit", function() {
28339 tejbeer 35
		added = false;
23405 amit.gupta 36
		$('#catalogModalBody').hide();
27658 tejbeer 37
		var itemId = $(this).closest('tr').attr('data');
28339 tejbeer 38
 
39
		var poItemId = $(this).closest('tr').find("#poItemId").val();
40
 
32639 ranu 41
 
28339 tejbeer 42
		var poId = $(this).closest('tr').find("#poId").val();
43
 
32639 ranu 44
 
23343 ashik.ali 45
		$("#bagModel .itemId").val(itemId);
32639 ranu 46
 
23343 ashik.ali 47
		$("#bagModel .quantity").val(0);
32639 ranu 48
 
28339 tejbeer 49
		doGetAjaxRequestHandler(context + "/checkItemAvailability/?itemId=" + itemId, function(response) {
23347 ashik.ali 50
			var obj = JSON.parse(response);
32639 ranu 51
 
23347 ashik.ali 52
			$(".modal-body h4.bagModalProductInfo.modelHeaderCustom > span").text(obj.displayName);
32639 ranu 53
 
23347 ashik.ali 54
			$(".modal-body h4.bagModalAvailability.modelHeaderCustom > span").text(obj.availability);
23405 amit.gupta 55
			inputEle = [];
32639 ranu 56
 
57
			if ("earlyImeis" in obj && obj.earlyImeis.length > 0) {
58
 
59
				for (var i in obj.earlyImeis) {
23405 amit.gupta 60
					inputEle.push('<span class="input-group-addon">');
28339 tejbeer 61
					inputEle.push('<input type="checkbox" aria-label="..." name="interest" value="' + obj.earlyImeis[i] + '" id="' + obj.earlyImeis[i] + '"/>');
62
					inputEle.push('<label for="' + obj.earlyImeis[i] + '">' + obj.earlyImeis[i] + '</label>');
23405 amit.gupta 63
					inputEle.push('</span>');
28339 tejbeer 64
					if (i % 3 == 2) {
23967 amit.gupta 65
						inputEle.push('</br>');
66
					}
23405 amit.gupta 67
				}
30366 amit.gupta 68
				$(".modal-body h4.bagModalEarlyImeis.modelHeaderCustom > span").html(inputEle.join(''));
24440 amit.gupta 69
				$(".modal-body h4.bagModalEarlyImeis.modelHeaderCustom").show();
70
				$(".modal-body h4.bagModalQuantity.modelHeaderCustom").hide();
23405 amit.gupta 71
			} else {
32639 ranu 72
				$(".modal-body h4.bagModalEarlyImeis.modelHeaderCustom > span").html("");
24440 amit.gupta 73
				$(".modal-body h4.bagModalEarlyImeis.modelHeaderCustom").hide();
74
				$(".modal-body h4.bagModalQuantity.modelHeaderCustom").show();
32639 ranu 75
			}
23405 amit.gupta 76
 
23347 ashik.ali 77
			$("#bagModel .availability").val(obj.availability);
28339 tejbeer 78
 
79
			$("#bagModel .poitemId").val(poItemId);
80
			$("#bagModel .poId").val(poId);
81
 
23405 amit.gupta 82
			$('#catalogModalBody').show();
23347 ashik.ali 83
		});
23343 ashik.ali 84
	});
28339 tejbeer 85
 
24202 amit.gupta 86
	// addToBagButton
28339 tejbeer 87
 
27754 amit.gupta 88
	$(document).on('click', "#addToBagButton", function() {
23343 ashik.ali 89
		var itemId = $("#bagModel .itemId").val();
28339 tejbeer 90
		var poitemId = $("#bagModel .poitemId").val();
91
		var poId = $("#bagModel .poId").val();
92
		console.log(poitemId)
93
		console.log(poId)
94
 
23343 ashik.ali 95
		var tempAvailability = $("#bagModel .availability").val();
96
		var quantity = $("#bagModel .quantity").val();
24440 amit.gupta 97
		imeiCount = $('h4.bagModalEarlyImeis').find('input').length;
28339 tejbeer 98
		if (imeiCount > 0) {
24440 amit.gupta 99
			quantity = $('h4.bagModalEarlyImeis').find('input:checked').length;
28339 tejbeer 100
			if (quantity == 0) {
23405 amit.gupta 101
				alert("Please check one of the imei(s)");
102
				return;
103
			}
28339 tejbeer 104
		} else if (!quantity || parseInt(quantity) <= 0 || isNaN(parseInt(quantity)) || quantity.indexOf('.') != -1) {
23343 ashik.ali 105
			alert("Please enter valid quantity");
106
			return;
107
		}
28339 tejbeer 108
 
109
		doGetAjaxRequestHandler(context + "/checkItemAvailability/?itemId=" + itemId, function(response) {
23500 ashik.ali 110
			var obj = JSON.parse(response);
111
			console.log(obj);
28339 tejbeer 112
			if (obj.availability < parseInt(quantity) || obj.availability == 0) {
23500 ashik.ali 113
				alert("You don't have enough inventory of this item");
114
				return;
115
			}
28339 tejbeer 116
			var obj = { 'itemId': obj.itemId, 'displayName': obj.displayName, 'quantity': parseInt(quantity), 'iconUrl': obj.iconUrl, 'poItemId': poitemId, 'poId': poId };
117
			if (imeiCount > 0) {
23500 ashik.ali 118
				obj['imeis'] = [];
28339 tejbeer 119
				$('h4.bagModalEarlyImeis').find('input:checked').each(function(index, ele) {
23500 ashik.ali 120
					obj['imeis'].push(ele.value);
121
				});
122
			}
123
			console.log(obj);
124
			addItemInLocalStorage(obj);
32639 ranu 125
			//alert("Item added to bag successfully");
126
			showToast("Item, Item added to bag successfully!");
23500 ashik.ali 127
			$('#bagModel').modal('hide');
28339 tejbeer 128
 
129
		});
130
 
23343 ashik.ali 131
	});
28339 tejbeer 132
 
32639 ranu 133
	// add to bag with cart page
134
 
135
	$(document).on('click', "#addToBagButtonwithCart", function () {
136
		var itemId = $("#bagModel .itemId").val();
137
		var poitemId = $("#bagModel .poitemId").val();
138
		var poId = $("#bagModel .poId").val();
139
		console.log(poitemId)
140
		console.log(poId)
141
 
142
		var tempAvailability = $("#bagModel .availability").val();
143
		var quantity = $("#bagModel .quantity").val();
144
		imeiCount = $('h4.bagModalEarlyImeis').find('input').length;
145
		if (imeiCount > 0) {
146
			quantity = $('h4.bagModalEarlyImeis').find('input:checked').length;
147
			if (quantity == 0) {
148
				alert("Please check one of the imei(s)");
149
				return;
150
			}
151
		} else if (!quantity || parseInt(quantity) <= 0 || isNaN(parseInt(quantity)) || quantity.indexOf('.') != -1) {
152
			alert("Please enter valid quantity");
153
			return;
154
		}
155
 
156
		doGetAjaxRequestHandler(context + "/checkItemAvailability/?itemId=" + itemId, function (response) {
157
			var obj = JSON.parse(response);
158
			console.log(obj);
159
			if (obj.availability < parseInt(quantity) || obj.availability == 0) {
160
				alert("You don't have enough inventory of this item");
161
				return;
162
			}
163
			var obj = {
164
				'itemId': obj.itemId,
165
				'displayName': obj.displayName,
166
				'quantity': parseInt(quantity),
167
				'iconUrl': obj.iconUrl,
168
				'poItemId': poitemId,
169
				'poId': poId
170
			};
171
			if (imeiCount > 0) {
172
				obj['imeis'] = [];
173
				$('h4.bagModalEarlyImeis').find('input:checked').each(function (index, ele) {
174
					obj['imeis'].push(ele.value);
175
				});
176
			}
177
			console.log(obj);
178
			addItemInLocalStorage(obj);
179
			//alert("Item added to bag successfully");
180
			showToast("Item, Item added to bag successfully!");
181
			$('#bagModel').modal('hide');
182
			// Trigger the click event for the cart icon
183
			$(".cart_icon_header").trigger('click');
184
 
185
		});
186
 
187
	});
188
 
32653 ranu 189
	// direct go billing page skip checkout page
190
	$(document).on('click', "#addToBagButtonwithBillingpage", function () {
191
		var itemId = $("#bagModel .itemId").val();
192
		var poitemId = $("#bagModel .poitemId").val();
193
		var poId = $("#bagModel .poId").val();
194
		console.log(poitemId)
195
		console.log(poId)
196
 
197
		var tempAvailability = $("#bagModel .availability").val();
198
		var quantity = $("#bagModel .quantity").val();
199
		imeiCount = $('h4.bagModalEarlyImeis').find('input').length;
200
		if (imeiCount > 0) {
201
			quantity = $('h4.bagModalEarlyImeis').find('input:checked').length;
202
			if (quantity == 0) {
203
				alert("Please check one of the imei(s)");
204
				return;
205
			}
206
		} else if (!quantity || parseInt(quantity) <= 0 || isNaN(parseInt(quantity)) || quantity.indexOf('.') != -1) {
207
			alert("Please enter valid quantity");
208
			return;
209
		}
210
 
211
		doGetAjaxRequestHandler(context + "/checkItemAvailability/?itemId=" + itemId, function (response) {
212
			var obj = JSON.parse(response);
213
			console.log(obj);
214
			if (obj.availability < parseInt(quantity) || obj.availability == 0) {
215
				alert("You don't have enough inventory of this item");
216
				return;
217
			}
218
			var obj = {
219
				'itemId': obj.itemId,
220
				'displayName': obj.displayName,
221
				'quantity': parseInt(quantity),
222
				'iconUrl': obj.iconUrl,
223
				'poItemId': poitemId,
224
				'poId': poId
225
			};
226
			if (imeiCount > 0) {
227
				obj['imeis'] = [];
228
				$('h4.bagModalEarlyImeis').find('input:checked').each(function (index, ele) {
229
					obj['imeis'].push(ele.value);
230
				});
231
			}
232
			console.log(obj);
233
			addItemInLocalStorage(obj);
234
			//alert("Item added to bag successfully");
235
			showToast("Item, Item added to bag successfully!");
236
			$('#bagModel').modal('hide');
237
			// Trigger the click event for the cart icon
238
			$(".cart-checkout").trigger('click');
239
 
240
		});
241
 
242
	});
243
 
28339 tejbeer 244
	$(document).on('click', ".cart-trash", function() {
23343 ashik.ali 245
		var itemId = $(this).attr('data');
246
		removeItemFromLocalStorage(itemId);
247
		$('div[itemId="' + itemId + '"]').remove();
28339 tejbeer 248
		if ($('#cart-details').html().trim() == "") {
23343 ashik.ali 249
			$('#cart-details-empty').show();
250
			$('#cart-checkout').hide();
251
		}
252
	});
28339 tejbeer 253
 
254
 
30596 tejbeer 255
	$(document).on('click', ".web-offer-submit", function() {
256
		let catalogId = $(this).data("catalogid");
257
		console.log(catalogId)
258
 
259
		doGetAjaxRequestHandler(context + "/getWebOfferByCatalogId?catalogItemId="
260
			+ catalogId, function(response) {
261
 
262
				$('#todayOfferModal .modal-content').html(response);
263
 
264
			});
265
 
266
	});
267
 
268
 
28339 tejbeer 269
	$(document).on('click', ".bill-now", function() {
26263 amit.gupta 270
		emptyBag();
28339 tejbeer 271
 
26263 amit.gupta 272
		var itemId = $(this).data('itemid');
273
		var imei = $(this).data('imei');
28339 tejbeer 274
		var bagObj = { itemId: itemId, displayName: "", quantity: 1, imeis: [imei] }
26263 amit.gupta 275
		addItemInLocalStorage(bagObj);
276
		checkout('main-content');
277
	});
28339 tejbeer 278
 
27754 amit.gupta 279
	$(document).on('change', ".cart-qty", function() {
23343 ashik.ali 280
		var itemId = $(this).attr('data');
281
		var maxQty = $(this).attr('max');
282
		var qty = $(this).val();
28339 tejbeer 283
		if (!qty) {
23343 ashik.ali 284
			qty = 0;
285
		}
28339 tejbeer 286
		if (parseInt(qty) < 0) {
23343 ashik.ali 287
			alert("Invalid quantity");
288
			$(this).val(0);
289
			qty = 0;
290
		}
28339 tejbeer 291
		if (parseInt(qty) > parseInt(maxQty)) {
292
			alert("You don't have availability of " + qty);
23343 ashik.ali 293
			$(this).val(maxQty);
294
			qty = maxQty;
295
		}
296
		changeQuantityInLocalStorage(itemId, qty);
297
	});
298
});
299
 
300
 
26263 amit.gupta 301
function emptyBag() {
302
	delete localStorage.getItem("bag");
303
}
23343 ashik.ali 304
 
28339 tejbeer 305
function addItemInLocalStorage(bagObj) {
306
	if (localStorage.getItem("bag") != null) {
23343 ashik.ali 307
		var bag = JSON.parse(localStorage.getItem("bag"));
308
		bag[bagObj.itemId] = bagObj
28339 tejbeer 309
		localStorage.setItem("bag", JSON.stringify(bag));
23343 ashik.ali 310
		bag = localStorage.getItem("bag")
311
		$("#cart_bar").find('span').text(Object.keys(JSON.parse(bag)).length);
312
	}
28339 tejbeer 313
	else {
23343 ashik.ali 314
		var tempObj = {};
315
		tempObj[bagObj.itemId] = bagObj
28339 tejbeer 316
		localStorage.setItem("bag", JSON.stringify(tempObj));
23343 ashik.ali 317
		var bag = localStorage.getItem("bag")
318
		$("#cart_bar").find('span').text(Object.keys(JSON.parse(bag)).length);
319
	}
320
}
321
 
322
 
28339 tejbeer 323
function changeQuantityInLocalStorage(itemId, newQuantity) {
23343 ashik.ali 324
	var bag = JSON.parse(localStorage.getItem("bag"));
28339 tejbeer 325
	if (typeof bag[itemId] == "undefined") {
24202 amit.gupta 326
		bag[itemId] = {};
28339 tejbeer 327
		bag[itemId].itemId = itemId;
24202 amit.gupta 328
		bag[itemId].displayName = "SmartDukaan Gift Watch";
24203 amit.gupta 329
		bag[itemId].iconUrl = "";
330
		delete bag["giftQty"];
28339 tejbeer 331
 
24202 amit.gupta 332
	}
23343 ashik.ali 333
	bag[itemId].quantity = newQuantity;
28339 tejbeer 334
	localStorage.setItem("bag", JSON.stringify(bag));
23343 ashik.ali 335
}
336
 
28339 tejbeer 337
function removeItemFromLocalStorage(itemId) {
338
	if (localStorage.getItem("bag") != null) {
23343 ashik.ali 339
		var bag = JSON.parse(localStorage.getItem("bag"));
340
		delete bag[itemId];
28339 tejbeer 341
		localStorage.setItem("bag", JSON.stringify(bag));
23343 ashik.ali 342
		$("#cart_bar").find('span').text(Object.keys(bag).length);
343
	}
344
}
345
 
24202 amit.gupta 346
function addGiftQty(giftQty) {
28339 tejbeer 347
	if (localStorage.getItem("bag") != null) {
24202 amit.gupta 348
		var bag = JSON.parse(localStorage.getItem("bag"));
349
		bag["giftQty"] = giftQty;
28339 tejbeer 350
		localStorage.setItem("bag", JSON.stringify(bag));
24202 amit.gupta 351
	}
352
}
24207 amit.gupta 353
function removeGiftQty() {
28339 tejbeer 354
	if (localStorage.getItem("bag") != null) {
24207 amit.gupta 355
		var bag = JSON.parse(localStorage.getItem("bag"));
356
		delete bag["giftQty"];
28339 tejbeer 357
		localStorage.setItem("bag", JSON.stringify(bag));
24207 amit.gupta 358
	}
359
}
24202 amit.gupta 360
 
24440 amit.gupta 361
function saveBag(bagObj) {
362
	localStorage.setItem("bag", JSON.stringify(bagObj));
363
}
364
 
28339 tejbeer 365
function emptyBag() {
366
	localStorage.setItem("bag", JSON.stringify({}));
23343 ashik.ali 367
	$("#cart_bar").find('span').text(0);
368
}
369
 
28339 tejbeer 370
function loadCart(domId, giftQty) {
24202 amit.gupta 371
	addGiftQty(giftQty);
23343 ashik.ali 372
	var params = {
28339 tejbeer 373
		"cartData": localStorage.getItem("bag")
374
	}
375
	doPostAjaxRequestWithParamsHandler(context + "/cart", params, function(response) {
23343 ashik.ali 376
		$('#' + domId).html(response);
24207 amit.gupta 377
		removeGiftQty();
23343 ashik.ali 378
	});
379
}
380
 
28339 tejbeer 381
function checkout(domId) {
23343 ashik.ali 382
	var params = {
28339 tejbeer 383
		"cartData": localStorage.getItem("bag")
384
	}
28382 tejbeer 385
 
386
 
387
	bootbox.alert({
388
		title: "<div class = 'disclosurehindata'> <img src='resources/images/alert-icon.png' style='width:10%'></div>",
389
		message: "<div class = 'disclosurehindata'> <img src='resources/images/activation-alert.png' style='width:100%'> </div>"
390
		,
391
		buttons: {
392
			ok: {
393
				label: 'Agree',
394
				className: 'btn-success'
395
			},
396
 
397
		},
398
		callback: function() {
399
			doPostAjaxRequestWithParamsHandler(context + "/validate-cart", params, function(response) {
400
				$('#' + domId).html(response);
401
				var obj = JSON.parse(response);
402
				redirectCart(obj.redirectUrl, obj.params, "main-content");
403
				$('#main-content').html(response);
404
			});
405
 
406
		}
23343 ashik.ali 407
	});
28382 tejbeer 408
 
23343 ashik.ali 409
}
410
 
26817 amit.gupta 411
//On checkout we are also setting imeis why?
28339 tejbeer 412
function redirectCart(url, cartData, domId) {
23500 ashik.ali 413
	var params = {
28339 tejbeer 414
		"cartData": cartData
23500 ashik.ali 415
	}
28339 tejbeer 416
	doPostAjaxRequestWithParamsHandler(context + url, params, function(response) {
417
		$('#' + domId).html(response);
418
		cartData = JSON.parse(cartData);
419
		for (itemId in cartData) {
420
			if ('imeis' in cartData[itemId]) {
421
				$('#order-details').find('input[name="serialNumber"][itemId="' + itemId + '"]').each(function(i, e) {
422
					if ($(e).attr("itemtype") == "SERIALIZED") {
423
						e.value = cartData[itemId].imeis[i];
424
					} else {
425
						cartData[itemId].imeis = [];
426
 
427
					}
428
				});
429
			}
430
		}
431
		saveBag(cartData);
432
		window.dispatchEvent(new Event('resize'));
433
	});
23343 ashik.ali 434
}