Subversion Repositories SmartDukaan

Rev

Rev 14430 | Rev 14434 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 14430 Rev 14432
Line 1... Line 1...
1
var livePriceCalls = [];
1
var livePriceCalls = [];
-
 
2
var outOfStockCount = 0;
2
$(function(){	
3
$(function(){	
3
	if($('.scroll > .card').length>0) {
4
	if($('.scroll > .card').length>0) {
4
		setTimeout(function(){ document.location.reload(); }, 1000*60*35);
5
		setTimeout(function(){ document.location.reload(); }, 1000*60*35);
5
		$('.scroll').jscroll({
6
		$('.scroll').jscroll({
6
			loadingHtml: '<center><img src="/img/ajax-loader.gif" alt="Loading" /></center>',
7
			loadingHtml: '<center><img src="/img/ajax-loader.gif" alt="Loading" /></center>',
Line 17... Line 18...
17
			calls.push(temp);
18
			calls.push(temp);
18
		});
19
		});
19
		calls = sortByKey(calls,'sort');		
20
		calls = sortByKey(calls,'sort');		
20
		for(var i in calls){
21
		for(var i in calls){
21
			fetchLivePrice(calls[i]['val'])
22
			fetchLivePrice(calls[i]['val'])
22
		}
23
		}		
23
	};
24
	};
24
	function sortByKey(array, key) {
25
	function sortByKey(array, key) {
25
	    return array.sort(function(a, b) {
26
	    return array.sort(function(a, b) {
26
	        var x = a[key]; var y = b[key];
27
	        var x = a[key]; var y = b[key];
27
	        return ((x < y) ? -1 : ((x > y) ? 1 : 0));
28
	        return ((x < y) ? -1 : ((x > y) ? 1 : 0));
28
	    });
29
	    });
29
	};
30
	};
30
	function fetchLivePrice(obj){
31
	function fetchLivePrice(obj){		
31
		// console.log(obj);
32
		var that = obj;	
32
		var inStock = false;
33
		var inStock = false;		
33
		var that = obj;			
-
 
34
		var req = $.ajax({
34
		var req = $.ajax({
35
			url: '/store_products/getliveprice/'+$(that).data('bundle_id')+'/'+$(that).data('id'),
35
			url: '/store_products/getliveprice/'+$(that).data('bundle_id')+'/'+$(that).data('id'),
36
			// Tell jQuery we're expecting JSONP
36
			// Tell jQuery we're expecting JSONP
37
			dataType: "json",
37
			dataType: "json",
38
			// Tell YQL what we want and that we want JSON			
38
			// Tell YQL what we want and that we want JSON			
Line 75... Line 75...
75
						// console.log(globalminprice+' '+globalminsku);
75
						// console.log(globalminprice+' '+globalminsku);
76
						if(globalminprice != 9999999) {
76
						if(globalminprice != 9999999) {
77
							$('#bestprice').html(globalminprice);
77
							$('#bestprice').html(globalminprice);
78
							$('#beststorelink').data('id',globalminsku).removeClass('hidden');
78
							$('#beststorelink').data('id',globalminsku).removeClass('hidden');
79
							$('#bestpricecontainer').removeClass('hidden');
79
							$('#bestpricecontainer').removeClass('hidden');
80
						}
80
						} 
81
					} else{
81
					} else{
-
 
82
						outOfStockCount++;
82
						$(that).parent().parent().remove();	
83
						$(that).parent().parent().remove();	
83
					}
84
					}
84
					if(!response.products[0].available_price){
85
					if(!response.products[0].available_price){
-
 
86
						outOfStockCount++;
85
						$(that).parent().parent().remove();	
87
						$(that).parent().parent().remove();	
86
					}
88
					}
87
				} else{
89
				} else{
-
 
90
					outOfStockCount++;
88
					$(that).parent().parent().remove();
91
					$(that).parent().parent().remove();
89
				}
92
				}
-
 
93
				checkForOutStocks(outOfStockCount);
90
			},
94
			},
91
			error: function(request, status, err) {
95
			error: function(request, status, err) {
92
				//console.log(status+' '+err+' '+request);
96
				//console.log(status+' '+err+' '+request);
93
            	// if (status == "timeout") {
97
            	// if (status == "timeout") {
94
            		var btn = $("<a class='tryagainforliveprice btn btn-xs btn-warning' title='Try Again'>Try Again</a>");
98
            		var btn = $("<a class='tryagainforliveprice btn btn-xs btn-warning' title='Try Again'>Try Again</a>");
Line 98... Line 102...
98
				// }
102
				// }
99
			}
103
			}
100
		});
104
		});
101
		livePriceCalls.push(req);
105
		livePriceCalls.push(req);
102
	};
106
	};
-
 
107
	function checkForOutStocks(count){
-
 
108
		if(count>=livePriceCalls.length){
-
 
109
			$('#bestpricecontainer').html('<h4>Out of stock</h4>').removeClass('hidden');	
-
 
110
		}
-
 
111
	};
103
	$(document).on('click','.variants',function(){
112
	$(document).on('click','.variants',function(){
104
		$('.storeproductinfo').empty();
113
		$('.storeproductinfo').empty();
105
		var variants = $(this).data('variants');	
114
		var variants = $(this).data('variants');	
106
		$('#variantscount').html(variants.length);
115
		$('#variantscount').html(variants.length);
107
		for(var i in variants){
116
		for(var i in variants){
Line 178... Line 187...
178
				if(response.success && response.type=='redirect'){
187
				if(response.success && response.type=='redirect'){
179
					document.location = response.url;
188
					document.location = response.url;
180
				}
189
				}
181
			}
190
			}
182
		});
191
		});
183
		ga('send', 'event', 'product', 'click', $(this).data('id'));
192
		ga('send', 'event', 'product', 'click', $(this).data('url'));
184
	});
193
	});
185
	$('.jscroll-inner').on('click','.likedeal',function(e){	
194
	$('.jscroll-inner').on('click','.likedeal',function(e){	
186
		var that = $(this);
195
		var that = $(this);
187
		if($(that).hasClass('active')){
196
		if($(that).hasClass('active')){
188
			//User has already liked it,so remove like
197
			//User has already liked it,so remove like