Subversion Repositories SmartDukaan

Rev

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

Rev 19030 Rev 19163
Line 78... Line 78...
78
        var globalminsku;
78
        var globalminsku;
79
        var globalmincashback = '';     
79
        var globalmincashback = '';     
80
        var globalminoffer = '';        
80
        var globalminoffer = '';        
81
        var calls = [];
81
        var calls = [];
82
        var priceRange = "";
82
        var priceRange = "";
-
 
83
        var saholic_cash = "";
-
 
84
        var globalminpriceshow;
83
        $('.storeminprice').each(function(){
85
        $('.storeminprice').each(function(){
84
            var temp = {'sort':$(this).data('searchorder'),'val':$(this)};
86
            var temp = {'sort':$(this).data('searchorder'),'val':$(this)};
85
            calls.push(temp);
87
            calls.push(temp);
86
        });
88
        });
87
        calls = sortByKey(calls,'sort');        
89
        calls = sortByKey(calls,'sort');        
Line 110... Line 112...
110
        properties.product_name = String($('#bestpriceproductname').html());
112
        properties.product_name = String($('#bestpriceproductname').html());
111
        pma.send('products','livesprice','fetch',me,properties);
113
        pma.send('products','livesprice','fetch',me,properties);
112
        var that = obj; 
114
        var that = obj; 
113
        var inStock = false;        
115
        var inStock = false;        
114
        var priceToCompare = 0;
116
        var priceToCompare = 0;
-
 
117
        var priceToShow = 0;
115
        var req = $.ajax({
118
        var req = $.ajax({
116
            url: '/store_products/getliveprice/'+$(that).data('bundle_id')+'/'+$(that).data('id'),
119
            url: '/store_products/getliveprice/'+$(that).data('bundle_id')+'/'+$(that).data('id'),
117
            // Tell jQuery we're expecting JSONP
120
            // Tell jQuery we're expecting JSONP
118
            dataType: "json",
121
            dataType: "json",
119
            // Tell YQL what we want and that we want JSON          
122
            // Tell YQL what we want and that we want JSON          
Line 134... Line 137...
134
                        var variants = [];
137
                        var variants = [];
135
                        var j = 0;
138
                        var j = 0;
136
                        for(var i in response.products){                                
139
                        for(var i in response.products){                                
137
                            if(response.products[i].in_stock == 1){
140
                            if(response.products[i].in_stock == 1){
138
                                if(response.products[i].gross_price && response.products[i].gross_price > response.products[i].available_price) {
141
                                if(response.products[i].gross_price && response.products[i].gross_price > response.products[i].available_price) {
139
                                    priceToCompare = response.products[i].gross_price;
142
//                                    priceToCompare = response.products[i].gross_price;
-
 
143
                                	priceToCompare = response.products[i].netPriceAfterCashBack;
-
 
144
                                    priceToShow = response.products[i].gross_price;
140
                                }else{
145
                                }else{
141
                                    if (response.products[i].source_id == 4 && response.products[i].cheapestBulkPrice != 0) {
146
                                    if (response.products[i].source_id == 4 && response.products[i].cheapestBulkPrice != 0) {
142
                                                priceToCompare = response.products[i].cheapestBulkPrice;
147
                                                priceToCompare = response.products[i].cheapestBulkPrice;
143
                                                if(response.products[i].packQuantity>1){
148
                                                if(response.products[i].packQuantity>1){
144
                                                    priceRange =(Math.round((response.products[i].cheapestBulkPrice/response.products[i].packQuantity) * 100) / 100)    + " - "
149
                                                    priceRange =(Math.round((response.products[i].cheapestBulkPrice/response.products[i].packQuantity) * 100) / 100)    + " - "
145
                                                    + (Math.round((response.products[i].available_price/response.products[i].packQuantity) * 100) / 100) + " /- per unit";
150
                                                    + (Math.round((response.products[i].netPriceAfterCashBack/response.products[i].packQuantity) * 100) / 100) + " /- per unit";
146
                                                }
151
                                                }
147
                                                else{
152
                                                else{
148
                                                    priceRange = response.products[i].cheapestBulkPrice
153
                                                    priceRange = response.products[i].cheapestBulkPrice
149
                                                    + " - "
154
                                                    + " - "
150
                                                    + response.products[i].available_price;
155
                                                    + response.products[i].netPriceAfterCashBack;
151
                                                }
156
                                                }
152
                                                
157
                                                
153
 
158
 
154
                                    } else {
159
                                    } else {
-
 
160
                                        priceToCompare = response.products[i].netPriceAfterCashBack;
-
 
161
                                        priceToShow = response.products[i].available_price;
-
 
162
                                        if(response.products[i].source_id == 4 && response.products[i].showNetPrice == 1 && response.products[i].cash_back >0 && response.products[i].cash_back_type > 0){
-
 
163
                                        	priceToShow = response.products[i].netPriceAfterCashBack;
155
                                        priceToCompare = response.products[i].available_price;
164
                                        	saholic_cash = '<span style="font-size:10px;color:#555;">(</span><span style="font-size:10px;color:red;">&#8377;'+response.products[i].available_price+'</span> <span style="font-size:10px;color:#555;">less </span>';
-
 
165
                                        	if(response.products[i].cash_back_type == 2){
-
 
166
                                        		saholic_cash =  saholic_cash+'<span style="font-size:10px;color:green">&#8377;'+response.products[i].cash_back+'</span><span style="font-size:10px;color:#555;">)</span>';
-
 
167
                                        	}
-
 
168
                                        	if(response.products[i].cash_back_type == 1){
-
 
169
                                        		saholic_cash =  saholic_cash+'<span style="font-size:10px;color:green">'+response.products[i].cash_back+'%</span><span style="font-size:10px;color:#555;">)</span>';
-
 
170
                                        	}
-
 
171
                                        }
156
                                    }
172
                                    }
157
                                }
173
                                }
158
                                inStock = true;                             
174
                                inStock = true;                             
159
                                if(priceToCompare && priceToCompare <= globalminprice) {
175
                                if(priceToCompare && priceToCompare <= globalminprice) {
160
                                    if (typeof globalminsource != "undefined" && globalminsource==4 && priceToCompare==globalminprice){
176
                                    if (typeof globalminsource != "undefined" && globalminsource==4 && priceToCompare==globalminprice){
161
                                    } else {
177
                                    } else {
162
                                        globalminprice = Math.round(priceToCompare);
178
                                        globalminprice = Math.round(priceToCompare);
-
 
179
                                        globalminpriceshow = priceToShow;
163
                                        globalminsku = response.products[i]._id;
180
                                        globalminsku = response.products[i]._id;
164
                                        globalminsource = response.products[i].source_id;
181
                                        globalminsource = response.products[i].source_id;
165
                                        globalminurl = response.products[i].marketPlaceUrl;
182
                                        globalminurl = response.products[i].marketPlaceUrl;
166
                                        globalminoffer = response.products[i].offer;
183
                                        globalminoffer = response.products[i].offer;
-
 
184
                                        if(globalminsource == 4 && saholic_cash !=""){
-
 
185
                                        	globalmincashback = saholic_cash;
-
 
186
                                        }else{
167
                                        globalmincashback = getcashbackstring(response.products[i].cash_back_type,response.products[i].cash_back);
187
                                        	globalmincashback = getcashbackstring(response.products[i].cash_back_type,response.products[i].cash_back);
-
 
188
                                        }
-
 
189
                                        
168
                                    }
190
                                    }
169
                                }
191
                                }
170
                                if(typeof minprice == 'undefined' || priceToCompare < minprice) {
192
                                if(typeof minprice == 'undefined' || priceToCompare < minprice) {
171
                                    minprice = Math.round(priceToCompare);
193
//                                    minprice = Math.round(priceToCompare);
-
 
194
                                	minprice = Math.round(priceToShow);
172
                                    minpriceindex = j;
195
                                    minpriceindex = j;
173
                                }                               
196
                                }                               
174
                                if(response.products[i].tagline && response.products[i].tagline.length>0 && $('#productoneliner').html().length==0) { 
197
                                if(response.products[i].tagline && response.products[i].tagline.length>0 && $('#productoneliner').html().length==0) { 
175
                                    $('#productoneliner').html(response.products[i].tagline).removeClass('hidden').show();                                  
198
                                    $('#productoneliner').html(response.products[i].tagline).removeClass('hidden').show();                                  
176
                                }                               
199
                                }                               
Line 188... Line 211...
188
                    if(inStock){
211
                    if(inStock){
189
                        $(that).html(minprice).siblings('.cashbackamount').html(getcashbackstring(response.products[minpriceindex].cash_back_type,response.products[minpriceindex].cash_back)).parent().addClass('viewproduct');
212
                        $(that).html(minprice).siblings('.cashbackamount').html(getcashbackstring(response.products[minpriceindex].cash_back_type,response.products[minpriceindex].cash_back)).parent().addClass('viewproduct');
190
                        
213
                        
191
                        if($(that).parent().data('storename') == "Saholic")
214
                        if($(that).parent().data('storename') == "Saholic")
192
                        {
215
                        {
-
 
216
                        	if(saholic_cash !=""){
-
 
217
                        		$(that).html(minprice).siblings('.cashbackamount').html(saholic_cash);
-
 
218
                        	} 
193
                            if (priceRange != "") {
219
                            if (priceRange != "") {
194
                                        $(that).html(priceRange);
220
                                        $(that).html(priceRange);
195
                            }
221
                            }
196
                            var url = minpriceurl;
222
                            var url = minpriceurl;
197
                            var value = url.substring(url.lastIndexOf('-') + 1);
223
                            var value = url.substring(url.lastIndexOf('-') + 1);
Line 212... Line 238...
212
                        if(response.products[minpriceindex]['offer'].length>0){
238
                        if(response.products[minpriceindex]['offer'].length>0){
213
                            $('#itemoffer-'+$(that).data('id')).show().html(response.products[minpriceindex]['offer']);
239
                            $('#itemoffer-'+$(that).data('id')).show().html(response.products[minpriceindex]['offer']);
214
                        }
240
                        }
215
                        $('#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');
241
                        $('#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');
216
                        if(globalminprice != 9999999) {
242
                        if(globalminprice != 9999999) {
217
                            $('#bestprice').html(globalminprice).siblings('.cashbackamount').html(globalmincashback).siblings('.productoffer').html(globalminoffer);
243
                            $('#bestprice').html(globalminpriceshow).siblings('.cashbackamount').html(globalmincashback).siblings('.productoffer').html(globalminoffer);
218
                            $('#beststorelink').data('id',globalminsku).data('source',globalminsource).data('price',globalminprice).data('url',globalminurl).removeClass('hidden');
244
                            $('#beststorelink').data('id',globalminsku).data('source',globalminsource).data('price',globalminpriceshow).data('url',globalminurl).removeClass('hidden');
219
                            $('#bestpricecontainer').removeClass('hidden');
245
                            $('#bestpricecontainer').removeClass('hidden');
220
 
246
 
221
                            if(typeof globalminsource!= "undefined") {
247
                            if(typeof globalminsource!= "undefined") {
222
                                if (globalminsource==4){
248
                                if (globalminsource==4){
-
 
249
//                                	$('#bestprice').html(globalminprice);
223
                                    if (priceRange != "") {
250
                                    if (priceRange != "") {
224
                                                $('#bestprice').html(priceRange);
251
                                                $('#bestprice').html(priceRange);
225
                                    }
252
                                    }
226
                                    var value = globalminurl.substring(globalminurl.lastIndexOf('-') + 1);
253
                                    var value = globalminurl.substring(globalminurl.lastIndexOf('-') + 1);
227
                                    $('#beststorelink').attr('data-identifier', value);
254
                                    $('#beststorelink').attr('data-identifier', value);
Line 240... Line 267...
240
                        properties.product_name = String($('#bestpriceproductname').html());
267
                        properties.product_name = String($('#bestpriceproductname').html());
241
                        pma.send('products','liveprice','outofstock',me,properties);
268
                        pma.send('products','liveprice','outofstock',me,properties);
242
                        outOfStockCount++;
269
                        outOfStockCount++;
243
                        $(that).parent().parent().remove(); 
270
                        $(that).parent().parent().remove(); 
244
                    }
271
                    }
245
                    if(!response.products[0].available_price){
272
                    if(!response.products[minpriceindex].available_price){
246
                        // outOfStockCount++;
273
                        // outOfStockCount++;
247
                        // $(that).parent().parent().remove();  
274
                        // $(that).parent().parent().remove();  
248
                        var btn = $("<a class='tryagainforliveprice btn btn-xs btn-warning' title='Try Again'>Try Again</a>");
275
                        var btn = $("<a class='tryagainforliveprice btn btn-xs btn-warning' title='Try Again'>Try Again</a>");
249
                        $(that).html(btn);
276
                        $(that).html(btn);
250
                        // ga('send', 'event', 'liveprice', 'failed', response.products[0]._id);
277
                        // ga('send', 'event', 'liveprice', 'failed', response.products[0]._id);
Line 712... Line 739...
712
        $('.'+$(this).data('type')).removeClass('hidden');
739
        $('.'+$(this).data('type')).removeClass('hidden');
713
    });
740
    });
714
    $(document).on('click','.brandpreferences .brands',function(){
741
    $(document).on('click','.brandpreferences .brands',function(){
715
        $(this).parents('.row').siblings('.controls').find('.editcategorypreferences',0).click();
742
        $(this).parents('.row').siblings('.controls').find('.editcategorypreferences',0).click();
716
    });
743
    });
717
    $(document).on('click','.tryagainforliveprice',function(){      
744
    $(document).on('click','.tryagainforliveprice',function(e){   
-
 
745
    	e.stopPropagation();
718
        fetchLivePrice($(this).parent());
746
        fetchLivePrice($(this).parent());
719
        $(this).parent().html('Getting Live Prices');
747
        $(this).parent().html('Getting Live Prices');
720
    });
748
    });
721
    $(document).on('click','.alert > a',function(){     
749
    $(document).on('click','.alert > a',function(){     
722
        ga('send', 'event', 'notifications', 'click', $(this).html());
750
        ga('send', 'event', 'notifications', 'click', $(this).html());