Subversion Repositories SmartDukaan

Rev

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

Rev 14952 Rev 14969
Line 14... Line 14...
14
	}
14
	}
15
}
15
}
16
 
16
 
17
$(function(){	
17
$(function(){	
18
	if($('.scroll > .card').length>0) {
18
	if($('.scroll > .card').length>0) {
19
		setTimeout(function(){ document.location.reload(); }, 1000*10*60);
19
		setTimeout(function(){ document.location.reload(); }, 1000*15*60);
20
		$('.scroll').jscroll({
20
		$('.scroll').jscroll({
21
			loadingHtml: '<center><img src="/img/ajax-loader.gif" alt="Loading" /></center>',
21
			loadingHtml: '<center><img src="/img/ajax-loader.gif" alt="Loading" /></center>',
22
		    autoTriggerUntil: 3,
22
		    autoTriggerUntil: 3,
23
		    padding: 20,
23
		    padding: 20,
24
		});
24
		});
Line 33... Line 33...
33
			calls.push(temp);
33
			calls.push(temp);
34
		});
34
		});
35
		calls = sortByKey(calls,'sort');		
35
		calls = sortByKey(calls,'sort');		
36
		for(var i in calls){
36
		for(var i in calls){
37
			fetchLivePrice(calls[i]['val'])
37
			fetchLivePrice(calls[i]['val'])
38
		}		
38
		}				
39
	};
39
	};
40
	function sortByKey(array, key) {
40
	function sortByKey(array, key) {
41
	    return array.sort(function(a, b) {
41
	    return array.sort(function(a, b) {
42
	        var x = a[key]; var y = b[key];
42
	        var x = a[key]; var y = b[key];
43
	        return ((x < y) ? -1 : ((x > y) ? 1 : 0));
43
	        return ((x < y) ? -1 : ((x > y) ? 1 : 0));
44
	    });
44
	    });
45
	};
45
	};
46
	function fetchLivePrice(obj){		
46
	function fetchLivePrice(obj){		
-
 
47
		ga('send', 'event', 'liveprice', 'fetch', $(obj).data('bundle_id'));
47
		var that = obj;	
48
		var that = obj;	
48
		var inStock = false;		
49
		var inStock = false;		
49
		var req = $.ajax({
50
		var req = $.ajax({
50
			url: '/store_products/getliveprice/'+$(that).data('bundle_id')+'/'+$(that).data('id'),
51
			url: '/store_products/getliveprice/'+$(that).data('bundle_id')+'/'+$(that).data('id'),
51
			// Tell jQuery we're expecting JSONP
52
			// Tell jQuery we're expecting JSONP
Line 104... Line 105...
104
							$('#bestprice').html(globalminprice).siblings('.cashbackamount').html(globalmincashback);
105
							$('#bestprice').html(globalminprice).siblings('.cashbackamount').html(globalmincashback);
105
							$('#beststorelink').data('id',globalminsku).data('source',globalminsource).data('price',globalminprice).data('url',globalminurl).removeClass('hidden');
106
							$('#beststorelink').data('id',globalminsku).data('source',globalminsource).data('price',globalminprice).data('url',globalminurl).removeClass('hidden');
106
							$('#bestpricecontainer').removeClass('hidden');
107
							$('#bestpricecontainer').removeClass('hidden');
107
						} 
108
						} 
108
					} else{
109
					} else{
-
 
110
						ga('send', 'event', 'liveprice', 'outofstock', response.products[0]._id);
109
						outOfStockCount++;
111
						outOfStockCount++;
110
						$(that).parent().parent().remove();	
112
						$(that).parent().parent().remove();	
111
					}
113
					}
112
					if(!response.products[0].available_price){
114
					if(!response.products[0].available_price){
113
						// outOfStockCount++;
115
						// outOfStockCount++;
114
						// $(that).parent().parent().remove();	
116
						// $(that).parent().parent().remove();	
115
						var btn = $("<a class='tryagainforliveprice btn btn-xs btn-warning' title='Try Again'>Try Again</a>");
117
						var btn = $("<a class='tryagainforliveprice btn btn-xs btn-warning' title='Try Again'>Try Again</a>");
116
						$(that).html(btn);
118
						$(that).html(btn);
-
 
119
						ga('send', 'event', 'liveprice', 'failed', response.products[0]._id);
117
					}
120
					}					
118
				} else{
121
				} else{
119
					// outOfStockCount++;
122
					// outOfStockCount++;
120
					// $(that).parent().parent().remove();
123
					// $(that).parent().parent().remove();
121
					var btn = $("<a class='tryagainforliveprice btn btn-xs btn-warning' title='Try Again'>Try Again</a>");
124
					var btn = $("<a class='tryagainforliveprice btn btn-xs btn-warning' title='Try Again'>Try Again</a>");
122
					$(that).html(btn);
125
					$(that).html(btn);
-
 
126
					ga('send', 'event', 'liveprice', 'failure', response.products[0]._id);
123
				}
127
				}
124
				checkForOutStocks(outOfStockCount);
128
				checkForOutStocks(outOfStockCount);
125
			},
129
			},
126
			error: function(request, status, err) {
130
			error: function(request, status, err) {
127
				//console.log(status+' '+err+' '+request);
131
				//console.log(status+' '+err+' '+request);
128
            	// if (status == "timeout") {
132
            	// if (status == "timeout") {
129
            		var btn = $("<a class='tryagainforliveprice btn btn-xs btn-warning' title='Try Again'>Try Again</a>");
133
            		var btn = $("<a class='tryagainforliveprice btn btn-xs btn-warning' title='Try Again'>Try Again</a>");
130
					$(that).html(btn);
134
					$(that).html(btn);
-
 
135
					ga('send', 'event', 'liveprice', 'error', response.products[0]._id);
131
				// } else {
136
				// } else {
132
					// $(that).parent().parent().remove();
137
					// $(that).parent().parent().remove();
133
				// }
138
				// }
134
			}
139
			}
135
		});
140
		});
136
		livePriceCalls.push(req);
141
		livePriceCalls.push(req);
137
	};
142
	};
138
	function checkForOutStocks(count){
143
	function checkForOutStocks(count){
139
		if(count>=livePriceCalls.length){
144
		if(count>=livePriceCalls.length){
140
			$('#bestpricecontainer').html('<h4>Out of stock</h4>').removeClass('hidden');	
145
			$('#bestpricecontainer').html('<h4>Out of stock</h4>').removeClass('hidden');	
141
		}
146
		}		
142
	};
147
	};
143
	$(document).on('click','.showless',function(){
148
	$(document).on('click','.showless',function(){
144
		$(this).addClass('hidden').siblings('.varnts').hide();
149
		$(this).addClass('hidden').siblings('.varnts').hide();
145
		$(this).parent().find('.variants',0).removeClass('hidden').addClass('justshow');
150
		$(this).parent().find('.variants',0).removeClass('hidden').addClass('justshow');
146
	});
151
	});