PageSourceSearch

https://xn--32-jlcd4bwh9e.xn--p1ai/g/templates/shop2/2.130.2/130-13/js/shop_bonuses.js

js xn--32-jlcd4bwh9e.xn--p1ai collected 2026-09-30 03:09:42 UTC 6,987 bytes, 243 lines download raw bytes

1/*Купон*/
2
3shop2.queue.coupon = function () {
4	shop2.on('afterCartAddCoupon, afterCartRemoveCoupon', function () {
5		document.location.reload();
6	});
7
8	$('.coupon-btn').on('click', function (e) {
9		var coupon = $('#coupon'),
10			code = coupon.val();
11
12		e.preventDefault();
13
14		if (code) {
15			shop2.cart.addCoupon(code);
16		} else {
17			shop2.msg('Введите код купона', $(this));
18		}
19
20	});
21
22
23	$('.coupon-delete').on('click', function (e) {
24		var $this = $(this),
25			code = $this.data('code');
26
27		e.preventDefault();
28
29		if (code) {
30			shop2.cart.removeCoupon(code);
31		}
32	});
33};
34
35/*Купон*/
36
37/*Бонусы*/
38
39shop2.cart.applyBonusPoint = function (bonus_points, func) {
40
41	shop2.trigger('beforeCartApplyBonus');
42
43	$.getJSON(
44		'/-/x-api/v1/public/?method=cart/applyBonusPoints', {
45			param: {
46				hash: shop2.hash.cart,
47				bonus_points: bonus_points
48			}
49		},
50		function (d, status) {
51			shop2.fire('afterCartApplyBonusPoints', func, d, status);
52			shop2.trigger('afterCartApplyBonusPoints', d, status);
53		}
54	);
55
56	return false;
57};
58
59shop2.cart.removeBonusPoint = function (func) {
60
61	shop2.trigger('beforeCartRemoveCartBonusPoints');
62
63	$.getJSON(
64		'/-/x-api/v1/public/?method=cart/RemoveBonusPoints', {
65			param: {
66				hash: shop2.hash.cart
67			}
68		},
69		function (d, status) {
70			shop2.fire('afterCartRemoveCartBonusPoints', func, d, status);
71			shop2.trigger('afterCartRemoveCartBonusPoints', d, status);
72		}
73	);
74};
75
76shop2.queue.bonus = function () {
77
78	shop2.on('afterCartApplyBonusPoints, afterCartRemoveCartBonusPoints', function () {
79		document.location.reload();
80	});
81
82	$('.bonus-apply').on('click', function (e) {
83		var bonus = $('#bonus-points'),
84			points = Number(bonus.val()),
85			bonus_user = Number($('.bonus-amount').data('bonus-amount'));
86
87		switch (true) {
88			case points == "":
89
90				e.preventDefault();
91				
92				shop2.msg('Введите значение', $(this));
93
94				break;
95				
96			case points > bonus_user:
97			
98				shop2.msg('Вам доступно только '+bonus_user+' бонусов', $(this));
99			
100				break;
101				
102			case bonus_user >= points:
103
104				shop2.cart.applyBonusPoint(points);
105
106				break;
107		};
108	});
109
110	$('.bonus-delete').on('click', function (e) {
111		shop2.cart.removeBonusPoint();
112	});
113	
114	$('.cart-bonuses__title label').on('click', function(e){
115		e.preventDefault();
116        var $check = $(':checkbox', this);
117        $check.prop('checked', !$check.prop('checked'));
118        
119		$('.cart-bonuses__container').toggleClass('show_bonuses');
120		
121		if (!$check.prop('checked') && $('.cart-total__item.bonus_item').length) {
122			shop2.cart.removeBonusPoint();
123		};
124	});
125
126	$.fn.inputFilter = function (inputFilter) {
127		return this.on("input keydown keyup mousedown mouseup select contextmenu drop", function () {
128			if (inputFilter(this.value)) {
129				this.oldValue = this.value;
130				this.oldSelectionStart = this.selectionStart;
131				this.oldSelectionEnd = this.selectionEnd;
132			} else if (this.hasOwnProperty("oldValue")) {
133				this.value = this.oldValue;
134				this.setSelectionRange(this.oldSelectionStart, this.oldSelectionEnd);
135			}
136		});
137	};
138
139	$("#bonus-points").inputFilter(function (value) {
140		return /^\d*$/.test(value);
141	});
142};
143
144/*Бонусы*/
145
146
147$(function(){
148	
149	$(document).off('click.getPromoLink').off('click.promoPagelist');
150			
151	var gr_promo_info = {};
152
153    $(document).on('click', '.get-promo-link', function (e) {
154	    e.preventDefault();
155	    var ver_id = $(this).data('ver-id'),
156	        cmd = $(this).data('cmd'),
157	        hash = shop2.apiHash.getPromoProducts,
158	        is_main = $(this).data('is-main'),
159	        kind_id = $(this).data('kind-id'),
160	        discount_id = $(this).data('discount-id');
161	        
162	    gr_promo_title = $(this).text(),
163        gr_promo_desc =  $(this).parents('.promo-action').find('.promo-action__text').html();
164        
165	    $.ajax({
166	        url: '/-/shop2-api/?ver_id=' + ver_id + '&cmd=' + cmd + '&hash=' + hash + '&kind_id=' + kind_id + '&discount_id=' + discount_id + '&is_main=' + is_main,
167	        type: 'POST',
168	        dataType: 'json',
169	        data: {},
170	        success: function (res) {
171	            shop2.alert(res.data, 'Закрыть', 'promo-products-list');
172	
173	            setTimeout(function () {
174	            	$('.promo-header__title').html(gr_promo_title);
175	            	if (!gr_promo_desc) {
176	            		$('.promo-header__desc').hide();
177	            	};
178	            	$('.promo-header__desc').html(gr_promo_desc);
179	            	
180	            	if (!$('.promo-products-list .shop-pagelist').length) {
181	            		$('.promo-products-list .product-list.list .product-item:last-child').css('border-bottom', 'none');
182	            	};
183	            	
184	            	$('.promo-products-list').click().addClass('custom-scroll scroll-width-thin scroll');
185	            	$('.promo-products-list .product-item').each(function() {
186						var $flags = $(this).find('.product-flags');
187						var $flagsContainer = $(this).find('.product-item__bottom-left');
188	
189						$flags.prependTo($flagsContainer);
190					});
191	            
192	                $('.product-list .gr_images_lazy_load').each(function () {
193	                    $(this).attr('src', $(this).attr('data-src'));
194	                });
195	                
196	                shop2_gr.methods.amountInit();
197	            }, 100);
198	        }
199	    });
200	    
201	    return gr_promo_info = {
202	    	gr_promo_title: gr_promo_title,
203	    	gr_promo_desc: gr_promo_desc
204	    }
205	});
206	
207	$(document).on('click', '.promo-products-list li', function (e) {
208	    e.preventDefault();
209	    var url = $(this).find('a').attr('href');
210	    
211	    $.ajax({
212	        url: url,
213	        type: 'POST',
214	        dataType: 'json',
215	        data: {},
216	        success: function (res) {
217	            shop2.alert(res.data, 'Закрыть', 'promo-products-list');
218	            
219	            setTimeout(function () {
220	            	$('.promo-header__title').html(gr_promo_info.gr_promo_title);
221	            	if (!gr_promo_info.gr_promo_desc) {
222	            		$('.promo-header__desc').hide();
223	            	};
224	            	$('.promo-header__desc').html(gr_promo_info.gr_promo_desc);
225	            	
226	            	$('.promo-products-list').click().addClass('custom-scroll scroll-width-thin scroll');
227	            	$('.promo-products-list .product-item').each(function() {
228						var $flags = $(this).find('.product-flags');
229						var $flagsContainer = $(this).find('.product-item__bottom-left');
230	
231						$flags.prependTo($flagsContainer);
232					});
233	            
234	                $('.product-list .gr_images_lazy_load').each(function () {
235	                    $(this).attr('src', $(this).attr('data-src'));
236	                });
237	                shop2_gr.methods.amountInit();
238	            }, 100);
239	        }
240	    });
241	});
242		
243});

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.