PageSourceSearch

https://www.gantuning.ru/modules/kr_checkout/js/kr_checkout.js

js gantuning.ru collected 2026-10-07 23:02:32 UTC 16,429 bytes, 439 lines download raw bytes

1$(document).ready(function() {
2	
3	window.folderPath = window.folderPath || '';
4	
5	KR_Checkout.init();
6	$('#strana').change(function(){
7	
8	/*
9		if( $(this).val() == 177 ){
10			$('[data-payment="68"]').show()
11			$('[data-payment="68"]').trigger('click')
12		} else {
13			$('[data-payment="68"]').hide()
14			$('[data-payment="61"]').trigger('click')
15		}
16	*/
17
18	})
19});
20
21var KR_CheckoutClass = function() {
22	var self = this;
23	
24	this.init = function() {
25		console.log($(".kr_checkout_country option:selected").val());
26		/* Вешаем маску на номер телефона */
27		if(parseInt($(".kr_checkout_country option:selected").val())==177) {
28
29			// $('.zapolniFormuGAGT_inputs[name=customer_phone]').mask("8(9?99) 999-99-99");
30			$('input[name=customer_phone]').mask('+7 (999) 999-99-99');
31
32			$('input[name=customer_phone]').on('focus', function(e){
33				if(parseInt($(".kr_checkout_country option:selected").val())==177 && ($(e.currentTarget).val() == '' || $(e.currentTarget).val() == '+')){
34					$(e.currentTarget).val('+7');
35					$('input[name="customer_phone"]').addClass('is-invalid');
36				}
37			});
38		}
39		$('input[name=customer_phone]').on('keyup', function(){
40
41			if (!self.checkPhone()){
42				$('input[name="customer_phone"]').addClass('is-invalid');
43			}
44			else
45				$('input[name="customer_phone"]').removeClass('is-invalid');
46			
47		});
48		
49		
50		//Оферта
51		
52		
53		
54		$('input[name=customer_mail]').on('keyup', function(){
55			
56			var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
57			
58			
59			if ( !re.test($(this).val())  )
60				$('input[name="customer_mail"]').addClass('is-invalid');
61			else
62				$('input[name="customer_mail"]').removeClass('is-invalid');
63			
64		});
65		
66				//$('.zapolniFormuGAGT_inputs[name=customer_phone]').attr("placeholder","8(__) ___-____");
67		if($('.kr_checkout').length > 0) {
68			$('.kr_checkout_country').change(function() {
69				self.countryChange(this);
70			});
71
72			// $('.kr_checkout_city').keyup(function() {
73			// 	self.cityFind(this);
74			// });
75			
76			
77			
78			/*
79			Автокомплитер отключил пока
80			*/
81			$('input[name="customer_city"]').autocomplete({
82			  source: function( request, response ) {
83				$.ajax( {
84				  url: '/module/kr_checkout/ajax',
85				  dataType: 'json',
86				  data: {
87					task:'city_find',
88					term: request.term
89				  },
90				  success: function( data ) {
91					response( data );
92				  }
93				} );
94			  },
95			  minLength: 2
96			} );
97			
98			/*$('.kr_checkout_city').kladr({
99			    type: $.kladr.type.city,
100			    limit: 5
101			});*/
102
103			$('.kr_checkout_payment li').click(function() {
104				self.paymentSelect(this);
105				
106				//Для DE && COM вешаем на смену оплаты отсылку данных на сервер
107				if(
108					$(".kr_checkout.ordering").data("site_code") !== undefined && 
109					($(".kr_checkout.ordering").data("site_code") == "ES" ||
110					$(".kr_checkout.ordering").data("site_code") == "FR" ||
111					$(".kr_checkout.ordering").data("site_code") == "IT" ||
112					$(".kr_checkout.ordering").data("site_code") == "DE" || $(".kr_checkout.ordering").data("site_code") == "COM" || $(".kr_checkout.ordering").data("site_code") == "US" || $(".kr_checkout.ordering").data("site_code") == "UK" || $(".kr_checkout.ordering").data("site_code") == "RU")
113				){
114					KR_Cart.cartReload();
115				}
116				
117			});
118
119			$('.kr_checkout_delivery li').click(function() {
120				self.deliverySelect(this);
121				KR_Cart.cartReload();
122			});
123
124			$('.kr_checkout_order').click(function() {
125				self.orderMake();
126			});
127		}
128	}
129
130	this.checkPhone = function(){
131
132		var phone_obj = $('input[name="customer_phone"]');
133		var phone = phone_obj.val().match(/\d/g);
134		if (phone === null || phone === undefined) {
135			return false;
136		}
137		var phone_verify = phone[1] + phone[2];
138
139		if ( !phone_obj.val() || (parseInt($(".kr_checkout_country option:selected"))==177 &&
140			(
141				phone_obj.val().length != 18 ||
142				phone_obj.val()[4] == 7 ||
143				phone_verify == '88' ||
144				phone_verify == '89'
145			)))
146			return false
147		else
148			return true;
149	}
150
151	this.paymentSelect = function(EL) {
152		$('.kr_checkout_payment li').removeClass('active');
153		$(EL).addClass('active');
154	}
155	
156	this.deliverySelect = function(EL) {
157		$('.kr_checkout_delivery li').removeClass('active');
158		$(EL).addClass('active');
159	}
160		
161	this.countryChange = function(EL) {
162		
163		var country = $(EL).val();
164		$('input[name="customer_city"]').val('');
165		$.ajax({
166			url: '/module/kr_checkout/ajax',
167			method: 'POST',
168			data:{task:'country_change', country:country},
169			dataType: 'json'
170		}).done(function(answer) {
171			if(answer.status == 'ok') {
172				/* При смене страны сбрасываем маску */
173				$('input[name=customer_phone]').unmask();
174				/* Отрубаем КЛАДР */
175				$('input[name="customer_city"]').autocomplete( "disable" );;
176				//$('.zapolniFormuGAGT_inputs[name=customer_phone]').attr("placeholder", $('.zapolniFormuGAGT_inputs[name=customer_phone]').data("placeholder"));
177				if ( country == 177 )/* Если поставили снова "Россия", то маску возвращаем и включаем КЛАДР*/{
178					//$('.zapolniFormuGAGT_inputs[name=customer_phone]').attr("placeholder","8(__) ___-____");			
179					// $('.zapolniFormuGAGT_inputs[name=customer_phone]').mask("8(9?99) 999-99-99");
180					$('input[name=customer_phone]').mask('+7 (999) 999-99-99');
181				
182					$('input[name="customer_city"]').autocomplete( "enable" );
183			
184
185				}
186				
187				//Для != DE && != COM устанавливаем paypal
188				if(
189					$(".kr_checkout.ordering").data("site_code") !== undefined && 
190					($(".kr_checkout.ordering").data("site_code") == "FR" ||$(".kr_checkout.ordering").data("site_code") == "IT" || $(".kr_checkout.ordering").data("site_code") == "ES" ||  $(".kr_checkout.ordering").data("site_code") == "US" || $(".kr_checkout.ordering").data("site_code") == "UK")
191				){
192					$('.kr_checkout_payment li[data-payment=61]').trigger("click");
193					$('.kr_checkout_delivery li.active a').trigger('click');
194				}
195				else if ( $(".kr_checkout.ordering").data("site_code") == "COM" || $(".kr_checkout.ordering").data("site_code") == "DE" ){
196					//DE и COM просто обновляем корзину
197					KR_Cart.cartReload();
198				}
199				//RU оставляем все как было
200				else{
201					
202					if( $(this).val() == 177 ){
203						$('[data-payment="68"]').show()
204						$('[data-payment="68"]').trigger('click')
205					} else {
206						$('[data-payment="68"]').hide()
207						$('[data-payment="61"]').trigger('click')
208					}
209					KR_Cart.cartReload();
210				}
211			}
212		});
213	}
214
215	this.cityFind = function(EL) {
216		/*
217		var query = $(EL).val();
218		$.ajax({
219			url: '/module/kr_checkout/ajax',
220			method: 'POST',
221			data:{task:'city_find', query:query},
222			dataType: 'json'
223		}).done(function(answer) {
224			if(answer.status == 'ok') {
225
226			}
227		});
228		*/
229	}
230	
231	this.orderMake = function () {
232		var customer = {};
233		customer.name = $('.kr_checkout_customer input[name="customer_name"]').val();
234		customer.phone = $('.kr_checkout_customer input[name="customer_phone"]').val().replace('+7 ','8');
235		customer.mail = $('.kr_checkout_customer input[name="customer_mail"]').val();
236		customer.country = $('.kr_checkout_customer .kr_checkout_country option:selected').val();
237		customer.city = $('.kr_checkout_customer input[name="customer_city"]').val();
238		customer.street = $('.kr_checkout_customer input[name="customer_street"]').val();
239		
240		if ( !customer.name )
241			$('.kr_checkout_customer input[name="customer_name"]').addClass('is-invalid');
242		else if ( customer.name && $('.kr_checkout_customer input[name="customer_name"]').hasClass('is-invalid')  )
243			$('.kr_checkout_customer input[name="customer_name"]').removeClass('is-invalid');
244
245		if ( !customer.phone || !self.checkPhone()){
246			$('.kr_checkout_customer input[name="customer_phone"]').addClass('is-invalid');
247			customer.phone = false;
248		}
249		else if ( customer.phone && $('.kr_checkout_customer input[name="customer_phone"]').hasClass('is-invalid')  )
250			$('.kr_checkout_customer input[name="customer_phone"]').removeClass('is-invalid');
251		
252		if ( !customer.mail )
253			$('.kr_checkout_customer input[name="customer_mail"]').addClass('is-invalid');
254		else if ( customer.mail && $('.kr_checkout_customer input[name="customer_mail"]').hasClass('is-invalid')  )
255			$('.kr_checkout_customer input[name="customer_mail"]').removeClass('is-invalid');
256		
257		if ( !customer.city )
258			$('.kr_checkout_customer input[name="customer_city"]').addClass('is-invalid');
259		else if ( customer.city && $('.kr_checkout_customer input[name="customer_city"]').hasClass('is-invalid')  )
260			$('.kr_checkout_customer input[name="customer_city"]').removeClass('is-invalid');
261		
262		if ( !customer.street )
263			$('.kr_checkout_customer input[name="customer_street"]').addClass('is-invalid');
264		else if ( customer.street && $('.kr_checkout_customer input[name="customer_street"]').hasClass('is-invalid')  )
265			$('.kr_checkout_customer input[name="customer_street"]').removeClass('is-invalid');
266		
267		var main_fields = (customer.name && customer.phone && customer.mail && customer.city && customer.street) ? true : false;
268		
269		
270		//FOR DE && COM
271		var oferta = true;
272		var dop_fields_de = true;
273		if(
274			$(".kr_checkout.ordering").data("site_code") !== undefined && 
275			(
276			$(".kr_checkout.ordering").data("site_code") == "ES" ||
277			$(".kr_checkout.ordering").data("site_code") == "FR" ||
278			$(".kr_checkout.ordering").data("site_code") == "IT" ||
279			$(".kr_checkout.ordering").data("site_code") == "DE" ||
280			$(".kr_checkout.ordering").data("site_code") == "COM" ||
281			$(".kr_checkout.ordering").data("site_code") == "US" ||
282			$(".kr_checkout.ordering").data("site_code") == "UK")
283		){
284			customer.surname = $('.kr_checkout_customer input[name="customer_surname"]').val();
285			customer.firma = $('.kr_checkout_customer input[name="customer_firma"]').val();
286			customer.post = $('.kr_checkout_customer input[name="customer_post"]').val();
287			var oferta = false;
288			var dop_fields_de = false;
289			
290			if ( !customer.surname )
291				$('.kr_checkout_customer input[name="customer_surname"]').addClass('is-invalid');
292			else if ( customer.surname && $('.kr_checkout_customer input[name="customer_surname"]').hasClass('is-invalid')  )
293				$('.kr_checkout_customer input[name="customer_surname"]').removeClass('is-invalid');
294			
295			if ( !customer.post )
296				$('.kr_checkout_customer input[name="customer_post"]').addClass('is-invalid');
297			else if ( customer.post && $('.kr_checkout_customer input[name="customer_post"]').hasClass('is-invalid')  )
298				$('.kr_checkout_customer input[name="customer_post"]').removeClass('is-invalid');
299			
300			if(customer.surname && customer.post)
301				dop_fields_de = true;
302			
303			//oferta
304			if($(".js-agree-oferta:checked").length == 2) {
305				var oferta = true;
306				$('.js-agree-oferta').removeClass('is-invalid');
307			}
308			else {
309				$('.js-agree-oferta:not(:checked)').addClass('is-invalid');
310			}
311		}
312
313		let delivery_method = false;
314		if ( $('.kr_checkout_delivery').length ){
315			delivery_method = $('.kr_checkout_delivery .l.active').data().delivery;
316
317		}
318
319		if(main_fields && dop_fields_de && oferta) {
320			var payment_block = $('.kr_checkout_payment li.active');
321			if(payment_block.length > 0) {
322				var payment_module = payment_block.data('payment');
323				var payment_module_code = payment_block.data('payment_module_code');
324				$('body').append('<div id="preloader"><div id="spinner"><img src="/themes/gantuning/assets/img/general/preloader/preloader.gif" alt=""></div></div>');
325				$.ajax({
326					url: '/module/kr_checkout/ajax',
327					method: 'POST',
328					data:{task:'order_make', customer:customer, payment:payment_module, payment_module_code:payment_module_code, delivery_method:delivery_method},
329					dataType: 'json'
330				}).done(function(answer) {
331					if(answer.status == 'ok') {
332						
333						$('.kr_checkout_customer input[name="customer_name"]').removeClass('error');
334						$('.kr_checkout_customer input[name="customer_phone"]').removeClass('error');
335						$('.kr_checkout_customer input[name="customer_mail"]').removeClass('error');
336
337						if(answer.payment_form) {
338							
339							$('#preloader').remove();
340							$('.kr_checkout').replaceWith(answer.payment_form);
341							var checkout_block = $('.kr_checkout').offset();
342							$('html, body').scrollTop(checkout_block.top - 50);			
343							setTimeout(function() {
344								$('#buyGAGT').click();
345							}, 2000);
346						}
347						else {
348							if(answer.ref !== undefined && answer.ref=='gdd2'){
349								//window.location.href = '/thankyou'+answer.status.utm_source_ref+'/';
350								window.location.href = '/thankyou2gdd/';
351							}
352							else if(answer.ref !== undefined && answer.ref=='gdd'){
353								//window.location.href = '/thankyou'+answer.status.utm_source_ref+'/';
354								window.location.href = '/thankyougdd/';
355							}
356							else{
357								if ($(".kr_checkout.ordering").data("site_code") == "RU" && payment_module_code == 'tinkoff') {// Tinkoff рассрочка
358												let products = answer.result.products;
359												let items = [];
360												$.each(products, function (index, value) {
361													items[index] = {
362														name: value.name2, 
363														price: value.price, 
364														quantity: value.quantity
365													};
366												});
367												items.push({
368													name: 'Доставка', 
369													price: answer.result.shipping, 
370													quantity: 1
371												});
372
373												tinkoff.createLink(
374													{
375														sum: answer.result.total,
376														items: items,
377														promoCode: 'installment_0_0_6_10,2',
378														shopId: 'e136dfea-0bf9-40de-942f-0891da6491ec',
379														showcaseId: 'a376d8a9-d352-45e3-9eb2-cda9441d5868',
380														values: {
381															contact: {
382															  fio: {
383																lastName: $("input[name='customer_name']").val(),
384																firstName: ' '
385															  },
386															  mobilePhone: $( "input[name='customer_phone']" ).val(),
387															  email: $( "input[name='customer_mail']" ).val()
388															}
389														}
390													}
391													).then((r) => {// запускаем аналитику страницы "Спасибо" без перехода на неё и редирект на страницу Тинькофф
vendor: 425 bytes, lines 391-397
391
392														(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
393														(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
394														m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
395														})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
396												  
397														ga('create', '
397UA-96263089-1
vendor: 68 bytes, lines 397-400
397', 'auto');
398														ga('send', 'pageview');
399
400														
400$(location).attr('href', r);
401													})
402
403								} else {
404									window.location.href = window.folderPath  + '/thankyou/';
405								}
406							}
407						}
408					}
409					else if ( answer.status == 'error' ){
410						$('#preloader').remove();
411						answer.error.forEach(function(item, i, arr) {
412							if ( item.indexOf("firstname") != -1 )
413								$('.kr_checkout_customer input[name="customer_name"]').addClass('error');
414							
415							if ( item.indexOf("phone") != -1 )
416								$('.kr_checkout_customer input[name="customer_phone"]').addClass('error');
417							
418							if ( item.indexOf("email") != -1 )
419								$('.kr_checkout_customer input[name="customer_mail"]').addClass('error');
420							
421							
422						});
423					} 
424				});
425			}
426			else {
427				var customer_block = $('.kr_checkout_payment').offset();
428				$('html, body').scrollTop(customer_block.top - 50);				
429			}
430		}
431		else if( ! main_fields || ! dop_fields_de) {
432			var customer_block = $('.kr_checkout_customer').offset();
433			$('html, body').scrollTop(customer_block.top - 50);
434		}
435		
436	}
437	
438}
439var KR_Checkout = new KR_CheckoutClass();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.