Subversion Repositories SmartDukaan

Rev

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

Rev 14579 Rev 14685
Line 38... Line 38...
38
			// Tell YQL what we want and that we want JSON			
38
			// Tell YQL what we want and that we want JSON			
39
			method: 'get',
39
			method: 'get',
40
			// timeout: 30000,
40
			// timeout: 30000,
41
			// Work with the response
41
			// Work with the response
42
			success: function( response ) {
42
			success: function( response ) {
-
 
43
				// console.log(response);
43
				if(response.success){
44
				if(response.success){
44
					var i = 0;	
45
					var i = 0;	
45
					var minpriceindex = 0;				
46
					var minpriceindex = 0;				
46
					if(response.products[i].in_stock == 1){inStock = true;}
47
					if(response.products[i].in_stock == 1){inStock = true;}
47
					var minprice = response.products[0]['available_price'];
48
					var minprice = response.products[0]['available_price'];
Line 49... Line 50...
49
					if(response.products.length>0){
50
					if(response.products.length>0){
50
						//More than one products in store
51
						//More than one products in store
51
						var variants = [];
52
						var variants = [];
52
						// var i = 0;
53
						// var i = 0;
53
						for(var i in response.products){	
54
						for(var i in response.products){	
54
							if(response.products[i].in_stock == 1){inStock = true;}						
55
							if(response.products[i].in_stock == 1){
-
 
56
								inStock = true;
55
							// console.log(response.products[i]);
57
								// console.log(response.products[i]);
56
							if(response.products[i].available_price && response.products[i].available_price < globalminprice) {
58
								if(response.products[i].available_price && response.products[i].available_price < globalminprice) {
57
								globalminprice = Math.round(response.products[i].available_price);
59
									globalminprice = Math.round(response.products[i].available_price);
58
								globalminsku = response.products[i]._id;
60
									globalminsku = response.products[i]._id;
-
 
61
									var globalminsource = response.products[i].source_id;
-
 
62
									var globalminurl = response.products[i].marketPlaceUrl;									
59
							}
63
								}
60
							if(response.products[i].available_price <= minprice) {
64
								if(response.products[i].available_price <= minprice) {
61
								minprice = Math.round(response.products[i].available_price);
65
									minprice = Math.round(response.products[i].available_price);
62
								minpriceindex = i;
66
									minpriceindex = i;
63
							} 
67
								} 
64
							variants.push({'available_price' : Math.round(response.products[i].available_price), 'url' : response.products[i].marketPlaceUrl,'source_product_name' : response.products[i].source_product_name,'id' : response.products[i]._id});
68
								variants.push({'source_id' : response.products[i].source_id, 'available_price' : Math.round(response.products[i].available_price), 'url' : response.products[i].marketPlaceUrl,'source_product_name' : response.products[i].source_product_name,'id' : response.products[i]._id});
-
 
69
							}						
65
						}
70
						}
66
						if(i>0){
71
						if(variants.length>1){
67
							var variantslink = $('<span class="variants">+ '+i+' Options</span>');
72
							var variantslink = $('<span class="variants">+ '+(variants.length-1)+' Options</span>');
68
							$(that).parent().append(variantslink);							
73
							$(that).parent().append(variantslink);							
69
							$(variantslink).data('variants',variants)
74
							$(variantslink).data('variants',variants)
70
						}
75
						}
71
					}
76
					}
72
					if(inStock){
77
					if(inStock){
73
						$(that).html(minprice);
78
						$(that).html(minprice);
-
 
79
						// console.log(response.products[minpriceindex]);
74
						$('#sku-'+$(that).data('id')).data('id',response.products[minpriceindex]['_id']).removeClass('hidden');
80
						$('#sku-'+$(that).data('id')).data('id',response.products[minpriceindex]['_id']).data('source',response.products[minpriceindex]['source_id']).data('price',response.products[minpriceindex]['available_price']).data('url',response.products[minpriceindex]['marketPlaceUrl']).removeClass('hidden');
75
						// console.log(globalminprice+' '+globalminsku);
81
						// console.log(globalminprice+' '+globalminsku);
76
						if(globalminprice != 9999999) {
82
						if(globalminprice != 9999999) {
77
							$('#bestprice').html(globalminprice);
83
							$('#bestprice').html(globalminprice);
78
							$('#beststorelink').data('id',globalminsku).removeClass('hidden');
84
							$('#beststorelink').data('id',globalminsku).data('source',globalminsource).data('price',globalminprice).data('url',globalminurl).removeClass('hidden');
79
							$('#bestpricecontainer').removeClass('hidden');
85
							$('#bestpricecontainer').removeClass('hidden');
80
						} 
86
						} 
81
					} else{
87
					} else{
82
						outOfStockCount++;
88
						outOfStockCount++;
83
						$(that).parent().parent().remove();	
89
						$(that).parent().parent().remove();	
Line 113... Line 119...
113
			$('#bestpricecontainer').html('<h4>Out of stock</h4>').removeClass('hidden');	
119
			$('#bestpricecontainer').html('<h4>Out of stock</h4>').removeClass('hidden');	
114
		}
120
		}
115
	};
121
	};
116
	$(document).on('click','.variants',function(){
122
	$(document).on('click','.variants',function(){
117
		$('.storeproductinfo').empty();
123
		$('.storeproductinfo').empty();
118
		var variants = $(this).data('variants');	
124
		var variants = $(this).data('variants');
-
 
125
		// console.log(variants);
119
		$('#variantscount').html(variants.length);
126
		$('#variantscount').html(variants.length);
120
		for(var i in variants){
127
		for(var i in variants){
121
			// console.log(variants[i]);
128
			// console.log(variants[i]);
122
			var row = $('<div class="row storeproductinfo"><div class="col-xs-7">'+variants[i].source_product_name+'</div><div class="col-xs-3">'+variants[i].available_price+'</div><div class="col-xs-2"><button class="btn btn-primary btn-xs viewproduct" type="button" data-id="'+variants[i].id+'">Buy</button></div></div>');
129
			// var row = $('<div class="row storeproductinfo"><div class="col-xs-7">'+variants[i].source_product_name+'</div><div class="col-xs-3">'+variants[i].available_price+'</div><div class="col-xs-2"><button class="btn btn-primary btn-xs viewproduct" type="button" data-id="'+variants[i].id+'">Buy</button></div></div>');
123
			$('#storeproducts').parent().append(row);
130
			// $('#storeproducts').parent().append(row);
-
 
131
			var row = $('<div class="clearfix"></div><div class="col-xs-4">&nbsp;</div><div class="col-xs-5"><span class="cashbackrupee"></span> <span>'+variants[i].available_price+'</span></div><div class="col-xs-3 viewproduct" data-source="'+variants[i].source_id+'" data-price="'+variants[i].available_price+'" data-url="'+variants[i].url+'" data-id="'+variants[i].id+'"><button type="button" class="btn-xs btn btn-success">BUY</button></div>');
-
 
132
			$(this).parent().parent().append(row);
124
		}
133
		}
125
		// console.log($(this).parent());
134
		// console.log($(this).parent());
126
		$('#storename').html($(this).parent().data('storename'));
135
		// $('#storename').html($(this).parent().data('storename'));
127
		$('#variantModal').modal();
136
		// $('#variantModal').modal();
128
	});
137
	});
129
	$('.categorytab').on('click','.categorytabcontrol.active',function(){
138
	$('.categorytab').on('click','.categorytabcontrol.active',function(){
130
		$(this).toggleClass('active');
139
		$(this).toggleClass('active');
131
		$('#preferences-'+$(this).data('id')).addClass('hidden');
140
		$('#preferences-'+$(this).data('id')).addClass('hidden');
132
		$(this).parent().parent().children().find('.savecategorypreferences',0).removeClass('savecategorypreferences').addClass('editcategorypreferences').html('Edit').removeClass('btn-success');
141
		$(this).parent().parent().children().find('.savecategorypreferences',0).removeClass('savecategorypreferences').addClass('editcategorypreferences').html('Edit').removeClass('btn-success');