PageSourceSearch

https://www.maxbakery.ru/assets/js/minicart.js?50

js maxbakery.ru collected 2026-10-04 09:33:53 UTC 35,927 bytes, 1,100 lines download raw bytes

1$(function () {
2	var cart = simpleCart;
3
4	window.mobilesite = !!document.location.href.match(/spisok-product_mobile|cart_mobile.php/);
5	window.c2500 = 0;
6
7	$.fn.toggleClick = function () {
8		var methods = arguments, // store the passed arguments for future reference
9			count = methods.length; // cache the number of methods 
10		//use return this to maintain jQuery chainability
11		return this.each(function (i, item) {
12			// for each element you bind to
13			var index = 0; // create a local counter for that element
14			$(item).click(function () { // bind a click handler to that element
15				return methods[index++ % count].apply(this, arguments); // that when called will apply the 'index'th method to that element
16				// the index % count means that we constrain our iterator between 0 and (count-1)
17			});
18		});
19	};
20
21	$.get("/assets/js/jquery.mousewheel.js", function () {
22		$(window).mousewheel(function (event, delta) {
23			if (window.isOverP) {
24				$("div.simpleCart_items").scrollTop(parseFloat($("div.simpleCart_items").scrollTop()) - delta * 20);
25				return false;
26			}
27		});
28	});
29
30	$(".cartInfo").addClass('closed');
31
32	$("input#address1275, input#address1274").change(function () {
33		manageDelivery($(this).val());
34	});
35
36	$("input#address1274").click();
37
38
39
40
41	function manageDelivery(zone) {
42
43		totalGoods = simpleCart.total();
44
45		if (totalGoods > 5000) {
46			$("div.order__item:contains('Доставка') div.order__price").text("0 ₽");
47		} else {
48			$("div.order__item:contains('Доставка') div.order__price").text("500 ₽");
49		}
50
51		if (totalGoods >= 3000) {
52			$("#cartSubmit1btn").removeAttr("disabled").show();
53			$("#go-order, #ord-wrapper").show();
54			$("#go-menu").hide();
55
56		} else {
57			$("#cartSubmit1btn").hide().attr("disabled");
58			$("#go-order, #ord-wrapper").hide();
59			$("#go-menu").show();
60		}
61
62
63		return 0;
64
65		//zone = 300;
66
67		//return 0;
68
69		//    mskPrice = price: g[2865]['price'],
70		//    mskObl = price: g[2866]['price'];
71
72		//        console.log('item0', simpleCart.items());
73
74		//        if (simpleCart.find({uid: 2865}).length)  simpleCart.find({uid: 2865})[0].remove();
75		//        if (simpleCart.find({uid: 2866}).length)  simpleCart.find({uid: 2866})[0].remove();       
76
77
78		//console.log('manage delivery zone=', zone);
79
80		var totalGoods = 0;
81		simpleCart.each(function (item) {
82			if (!item.get('delivery')) totalGoods += parseFloat(item.get('price')) * parseFloat(item.get('quantity'));
83		});
84		//console.log('totalGoods', totalGoods);
85
86
87		$("#cartSubmit1btn").toggle(!simpleCart.find({ uid: 2897 }).length);
88
89		if (totalGoods < 2500 && !simpleCart.find({ uid: 2897 }).length && totalGoods > 1) {
90
91			//console.log('less 2500, adding delivery');
92			simpleCart.add({
93				uid: 2897,
94				name: g[2897]['name'],
95				price: g[2897]['price'],
96				quantity: 1,
97				//		image: g[2897]['image'],
98				image: 'none.jpg',
99				delivery: 1,
100				sort_order: 10000,
101				ingredients: g[2897]['ingredients']
102			});
103			//console.log('c2500 2', window.c2500);
104			//simpleCart.update();   	    
105
106			if (simpleCart.find({ uid: 2866 }).length) simpleCart.find({ uid: 2866 })[0].remove();
107			if (simpleCart.find({ uid: 2865 }).length) simpleCart.find({ uid: 2865 })[0].remove();
108			$("#cartSubmit1btn").attr("disabled", "true");
109			$("#ord-wrapper, #go-order").hide();
110			$("#go-menu").show();
111
112		}
113
114		if (totalGoods >= 2500) {
115
116			$("#cartSubmit1btn").removeAttr("disabled").show();
117			$("#go-order, #ord-wrapper").show();
118			$("#go-menu").hide();
119
120		}
121
122		if (zone == '1274' && totalGoods < 4000 && totalGoods >= 2500 && !simpleCart.find({ uid: 2865 }).length) {
123			//console.log('msk less 4000, adding delivery');
124			res = simpleCart.add({
125				uid: 2865,
126				name: g[2865]['name'],
127				price: g[2865]['price'],
128				quantity: 1,
129				image: g[2865]['image'],
130				delivery: 1,
131				sort_order: 10000,
132				ingredients: g[2865]['ingredients']
133			});
134			//console.log('res', res);
135			if (simpleCart.find({ uid: 2897 }).length) simpleCart.find({ uid: 2897 })[0].remove();
136			//simpleCart.update();   
137
138		}
139
140		if (zone == '1274' && totalGoods >= 4000 && simpleCart.find({ uid: 2865 }).length) {
141			//console.log('delivery 1274 removing');
142			if (simpleCart.find({ uid: 2866 }).length) simpleCart.find({ uid: 2866 })[0].remove();
143			if (simpleCart.find({ uid: 2865 }).length) simpleCart.find({ uid: 2865 })[0].remove();
144			if (simpleCart.find({ uid: 2897 }).length) simpleCart.find({ uid: 2897 })[0].remove();
145		}
146
147		if (zone == '1274' && simpleCart.find({ uid: 2866 }).length) {
148			//console.log('delivery 1274 removing');
149			simpleCart.find({ uid: 2866 })[0].remove();
150		}
151
152
153		if (zone == '1275' && simpleCart.find({ uid: 2865 }).length) {
154			//console.log('delivery 1274 removing');
155			simpleCart.find({ uid: 2865 })[0].remove();
156		}
157
158		if (zone == '1275' && totalGoods < 4000 && simpleCart.total() > 2500 && !simpleCart.find({ uid: 2866 }).length) {
159			//console.log('msk less 3000, adding delivery');
160			res = simpleCart.add({
161				uid: 2866,
162				name: g[2866]['name'],
163				price: g[2866]['price'],
164				quantity: 1,
165				image: g[2866]['image'],
166				delivery: 1,
167				sort_order: 10000,
168				ingredients: g[2866]['ingredients']
169			});
170
171			//console.log('res', res);
172			if (simpleCart.find({ uid: 2897 }).length) simpleCart.find({ uid: 2897 })[0].remove();
173
174			//simpleCart.update();   
175
176		}
177
178		if (zone == '1275' && totalGoods >= 4000 && simpleCart.find({ uid: 2866 }).length) {
179			//console.log('delivery 1275 removing');
180			if (simpleCart.find({ uid: 2866 }).length) simpleCart.find({ uid: 2866 })[0].remove();
181			if (simpleCart.find({ uid: 2865 }).length) simpleCart.find({ uid: 2865 })[0].remove();
182			if (simpleCart.find({ uid: 2897 }).length) simpleCart.find({ uid: 2897 })[0].remove();
183
184		}
185
186		if (simpleCart.items().length == 1 && (simpleCart.items()[0].get('uid') == 2866 || simpleCart.items()[0].get('uid') == 2865)) {
187			//console.log('cart empty, removing all delivery items');
188			if (simpleCart.find({ uid: 2865 }).length) simpleCart.find({ uid: 2865 })[0].remove();
189			if (simpleCart.find({ uid: 2866 }).length) simpleCart.find({ uid: 2866 })[0].remove();
190			if (simpleCart.find({ uid: 2897 }).length) simpleCart.find({ uid: 2897 })[0].remove();
191
192
193
194		}
195
196
197
198	}
199
200
201
202
203	$(document).on("click", ".cartInfo", function () {
204		if (simpleCart.items().length) {
205			if ($(this).hasClass('closed')) {
206				$("#cartPopover").slideDown(200);
207				//				$("#cartPopover").fadeIn(500);
208				$(".cartInfo").removeClass('closed').addClass('open');
209			} else {
210				$("#cartPopover").slideUp(200);
211				$(".cartInfo").removeClass('open').addClass('closed');
212			}
213		}
214	});
215
216
217	/*
218
219	$(".cart2").bind({
220		'mouseenter': function () {
221			$("#cartPopover").slideDown(10);
222			$(".cartInfo").removeClass('closed').addClass('open');
223			window.isOverP = 1;
224			$("body").addClass("noscroll2");
225
226		},
227		'mouseleave': function () {
228			$("#cartPopover").slideUp(10);
229			$(".cartInfo").removeClass('open').addClass('closed');
230			window.isOverP = 0;
231			$("body").removeClass("noscroll2");
232
233		}
234	});
235	
236	*/
237
238	$(document).on("click", "[data-name='item_increment_basket']", function () {
239
240		//console.log('increment');
241		uid = $(this).data('uid');
242		item1 = simpleCart.find({ uid: uid })[0];
243		ca = parseFloat(item1.get('ca'));
244		unit = item1.get('unit');
245		qty = parseFloat(item1.quantity() * ca);
246		//y = qty.toFixed(1);
247		//console.log('qty0', qty, 'ca', ca, 'unit', unit);	    
248
249		qty = parseFloat(qty + ca);
250		qty = parseFloat(qty.toFixed(1));
251		//console.log('new qty1', qty);	    
252
253		item1.quantity(Math.round(qty / ca));
254		$("[data-name='qty'][data-uid='" + uid + "']").text(qty + "  " + unit);
255		item1.quantity(Math.round(qty / ca));
256		simpleCart.update();
257
258	});
259
260
261	$(document).on("click", "[data-name='item_decrement_basket']", function () {
262
263		//console.log('increment');
264		uid = $(this).data('uid');
265		item1 = simpleCart.find({ uid: uid })[0];
266
267		//console.log('item', item1);
268
269		ca = parseFloat(item1.get('ca'));
270		unit = item1.get('unit');
271		qty = parseFloat(item1.quantity() * ca);
272		qty = qty.toFixed(1);
273
274		//console.log('qty0', qty, 'ca', ca, 'unit', unit);	    
275
276		qty = qty - ca || parseFloat(qty);
277
278		//console.log('new qty', qty);	    
279
280		item1.quantity(Math.round(qty / ca));
281		qty = parseFloat(qty.toFixed(1));
282		console.log('qty pf', qty);
283		$("[data-name='qty'][data-uid='" + uid + "']").text(qty + "  " + unit);
284		item1.quantity(Math.round(qty / ca));
285		simpleCart.update();
286
287	});
288
289
290	$(document).on("click", "span.btn--del", function () {
291		let $_this = $(this).parents(".item-name"),
292				itemId = $(this).parents(".itemRow").attr('id').replace(/cartItem_/, ''),
293				id = simpleCart.find({ id: itemId })[0].get("uid"),
294				name = $_this.find(".title").text().trim(),
295				position = $_this.index('.order__table .itemRow') + 1,
296				quantity = parseFloat($_this.find(".btn--quantity span[data-name='qty']").text().trim()),
297				price = simpleCart.find({ id: itemId })[0].get("price");
298				category = simpleCart.find({ id: itemId })[0].get("category");
299				list = simpleCart.find({ id: itemId })[0].get("list");
300
301		console.log('item', simpleCart.find({ id: itemId }), 'itemId', itemId);
302		simpleCart.find({ id: itemId })[0].remove();
303
304		// ecommerce - Удаление товара из корзины YM
305		window.ymDataLayer = window.ymDataLayer || [];
306		window.ymDataLayer.push({
307			"ecommerce": {
308				"currencyCode": "RUB",
309				"remove": {
310					"products": [
311						{
312							"id": id,
313							"name": name,
314							"category": category,
315							"quantity": quantity,
316							"list": list,
317							"position": position
318						}
319					]
320				}
321			}
322		});
323
324		// ecommerce - Удаление товара из корзины GA
325		window.dataLayer = window.dataLayer || [];
326		window.dataLayer.push({
327			'event': 'remove_from_cart',
328			'ecommerce': {
329				'items': [{
330					'item_name': name,
331					'item_id': id,
332					'price': price,
333					'item_brand': 'MaxBakery',
334					'item_category': category,
335					'item_list_name': list,
336					'index': position,
337					'quantity': quantity
338				}]
339			}
340		});
341
342	});
343
344	if (document.location.href.match(/order.php|cart.php|order3|cart_mobile.php|orde111r.php|page_1481656785_3105.html|page14773196594259.php/)) {
345		cart({
346			cartColumns: [{
347				view: 'remove',
348				text: "Remove",
349				label: false
350			}, {
351				attr: "image",
352				label: false,
353				view: function (item, column) {
354					if (item.get('composite')) return false;
355					return document.location.href.match(/cart_mobile.php/) ? (item.get('image') ? '<span class="img-box"><span class="img-cont"><span><img src="' + item.get('image') + '" alt=""></span></span></span><span class="rubr"></span>' : '') : (item.get('image') ? '<a class="link-img cat-item cboxElement1" href="' + item.get('href').replace("popup", "product") + '"><span class="img-box"><span class="img-cont"><span><img src="' + item.get('image') + '" alt=""></span></span></span><span class="rubr"></span></a>' : '');
356				}
357			}, {
358				view: function (item, column) {
359					aHTML = '<a class="cat-item cboxElement1" href="' + item.get('href').replace("popup", "product") + '">' + item.get('name') + '</a>';
360					cHTML = '<span class="cat-item cboxElement1">' + item.get('name') + '</span>';
361					return document.location.href.match(/cart_mobile.php/) ? '<div class="name">' + item.get('name') + '</div><div class="subname">' + item.get('anons') + '</div>' : ('<div class="name">' + (item.get('composite') ? cHTML : aHTML) + '</div><div class="subname">' + item.get('anons') + '</div>');
362				},
363				attr: "name",
364				label: "Наименование/состав"
365			}, //			{ attr: "quantity", label: "Количество", view: "input"},
366			{
367				attr: "calories",
368				label: "Калорийность",
369				view: function (item, column) {
370					if (item.get('composite')) return false;
371					return item.get('calories') ? Math.floor(item.get('calories')) + ' kcal' : '';
372				}
373			}, {
374				view: function (item, column) {
375					if (item.get('composite')) return false;
376					if (item.get('uid')) {
377						price = simpleCart.FIcfg[item.get('uid')] && simpleCart.FIcfg[item.get('uid')]['price'] ? simpleCart.FIcfg[item.get('uid')]['price'] : item.get('price');
378					} else price = item.get('price1') ? item.get('price1') : item.get('price');
379					if (item.get('price1') && item.get('price2') && item.quantity() >= 2) {
380						var p1 = parseFloat(item.get('price1')),
381							p2 = parseFloat(item.get('price2'));
382						discount = p1 - p2;
383						discountText = "<img src='/images/percent.png' title='Цена по акции - скидка " + discount + " руб. на второе блюдо' />";
384
385
386					} else {
387						discountText = '';
388					}
389					return (item.get('price1') && item.get('price2') && item.quantity() >= 2 ? "<div class='cartprice2'>За второе блюдо: <span>" + p2 + " руб.</span></div>" : '') + (item.get('price1') ? item.get('price1') : item.get('price')) + " руб. " + " x<input type='text' class='input-text simpleCart_input' value='" + item.get('quantity') + "' />";
390				},
391				attr: "quantity",
392				label: "Количество"
393			}, {
394				attr: "total",
395				label: "Сумма",
396				view: "currency"
397			}
398			],
399			cartStyle: document.location.href.match(/cart_mobile.php/) ? "div" : "table"
400		});
401		simpleCart.currency({
402			code: "RUR",
403			name: "RUR",
404			symbol: ""
405		});
406	} else {
407		cart({
408			cartColumns: [
409				//A custom cart column for putting the quantity and increment and decrement items in one div for easier styling.
410				{
411					attr: "image",
412					label: false,
413					view: function (item, column) {
414						if (item.get('composite')) return false;
415						//return item.get('image') ? '<img src="' + item.get('image') + '">' : '';
416						if (item.get('sku')) return '<img src="/assets/img/goods_new/' + item.get('sku') + '.jpg"/>'
417					}
418				}, {
419					attr: "name",
420					label: false,
421					view: function (item, column) {
422						if (item.get('composite')) return false;
423						item_price = item.get('price') * item.get('quantity');
424						item_price = item_price.toFixed(2);
425						//item_pquantity = item.get('quantity')
426
427
428						if (item.get('delivery')) {
429
430
431							return "<div class='product__shop-info'>" +
432								"<div class='product__price'>" +
433								//цена
434								"<span class='product__user-price'><span data-name='item_price_basket' data-uid='" + item.get('uid') + "'>" +
435								"<span class='product__delivery-name'>" + (item.get('uid') == 2897 ? 'Доставка невозможна' : (item.get('name') + "</span>" + (item.get('uid') == '2866' ? '' : (item_price + "</span> рублей</span>")))) +
436								"<p class='product__desc'>" + item.get('ingredients') + "</p>" +
437								"</div>";
438
439
440
441						}
442
443						/*else return "<div class='product__shop-info'>" +
444							"<a href=" + item.get('href') + " class='title title--light'>" + item.get('name') + "</a>" +
445							"<p class='product__desc'>" + item.get('ingredients') + "</p></div>" +
446							"<div class='product__user-info'>" +
447							//удаляло
448							"<span class='btn btn--del'>Удалить<svg width='11' height='10'><use xlink:href='#cross'></use></svg></span>" +
449							//добавляло
450							"<span class='btn btn--quantity'>" +
451							"<span class='minus' data-name='item_decrement_basket' data-uid=" + item.get('uid') +"></span>" +
452							"<span data-name='qty' data-uid=" + item.get('uid') + ">" + parseFloat((item.get('quantity') * item.get('ca')).toFixed(1)) + " " + item.get("unit") + ".</span>" +
453							"<span class='plus' data-name='item_increment_basket' data-uid=" + item.get('uid') + "></span>" +
454							"</span></div>"+
455							"<div class='product__price'>" +
456								//цена
457							"<span class='product__shop-price'>" + (item.get('price') / item.get('ca')).toFixed(2) + "&#8381; <sup>/ " + item.get("unit") + ".</sup></span>" +
458								//сумма
459							"<span class='product__user-price'><span data-name='item_price_basket' data-uid='" + item.get('uid') + "'>" + item_price + "</span> &#8381;</span>" +
460							"</div>";
461					}*/
462
463						else return "<div class='product__shop-info'>" +
464							"<a href=" + item.get('href') + " class='title title--light'>" + item.get('name') + "</a>" +
465							"<p class='product__desc'>" + item.get('ingredients') + "</p></div>" +
466							"<div class='product__user-info'>" +
467
468
469							"<div class='product__price'>" +
470							//цена
471							"<span class='product__shop-price'>" + (item.get('price') / item.get('ca')).toFixed(2) + "<span class='cur'>&#8381;</span> <sup>/ " + item.get("unit") + ".</sup></span>" +
472
473							"<span class='btn btn--quantity'>" +
474							"<span class='minus' data-name='item_decrement_basket' data-uid=" + item.get('uid') + "></span>" +
475							"<span data-name='qty' data-uid=" + item.get('uid') + ">" + parseFloat((item.get('quantity') * item.get('ca')).toFixed(1)) + " " + item.get("unit") + ".</span>" +
476							"<span class='plus' data-name='item_increment_basket' data-uid=" + item.get('uid') + "></span>" +
477							"</span>" +
478							//сумма
479							"<span class='product__user-price'><span data-name='item_price_basket' data-uid='" + item.get('uid') + "'>" + item_price + "</span> <span class='cur'>&#8381;</span></span>" +
480							//удаляло
481							"<span class='btn btn--del'>Удалить<svg width='11' height='10'><use xlink:href='#cross'></use></svg></span>" +
482							"</div></div>";
483					}
484				}/*,{
485//				    view: function(item, column) {
486					view: 'remove',
487					text: '<div class="product__user-info"></div>',
488					label: false
489//					return item.get('composite') ? '' : "<img src='/images/minicart_remove.png' />";
490//				    },
491//				    attr: 'remove'
492				}, {
493					view: function (item, column) {
494						if (item.get('composite')) return false;
495						return "<span class='btn btn--quantity'>" +
496						"<span class='minus'></span>" +
497						"<span>" + item.get('quantity') + " шт.</span>" +
498						"<span class='plus'></span>" +
499						"</span></div>";
500					},
501					attr: 'custom'
502				}, //Name of the item //Subtotal of that row (quantity of that item * the price)
503				{
504					view: 'currency',
505					attr: "total",
506					label: false
507				}
508				/*
509			{  view: function(item, column) { 
510
511				if (item.get('composite')) return false;
512				if (item.get('uid')) {
513					price = simpleCart.FIcfg[item.get('uid')]['price'] ? simpleCart.FIcfg[item.get('uid')]['price'] : item.get('price');
514				}
515				else 	price = item.get('price');
516				//return	Math.ceil(price) + "руб."; 
517				return	price + "руб."; 
518
519
520			   }, attr: "custom", label: false},
521*/
522			],
523			cartStyle: 'div',
524			minicart: true
525		});
526		cart['minicart'] = 1;
527		simpleCart.currency({
528			code: "RUR",
529			name: "RUR",
530			symbol: ""
531		});
532	}
533	var itemType = ['susi', 'roll'];
534	simpleCart.extend({
535		/*
536	catFIcfg: { 
537	"susi": {
538		"sous":10,
539		},
540
541
542	"roll":	{
543			"sous":10,
544		"palki":10
545		},
546
547
548	61:	{
549			"sous":10,
550		"palki":10
551		}
552	},
553	
554/*	
555
556	FIcfg: {
557			"sous": {
558			uid: 'sous',
559			name: "Соус",
560			price: "10",
561			anons: 'Соус',
562			uid: 200
563		},
564
565			"palki": {
566			 uid: 'palki',
567			 name: 'Палочки',
568			 price: 0,
569			 size: "Small" ,
570			 quantity: 1,
571			 anons: 'Приборы для еды',
572			 category: 'FI',
573			 sort_order: 3,
574			 uid: 500
575		},
576
577
578	},
579
580*/
581		catFIcfg: {
582			10047: {
583				332: 10,
584				328: 10,
585				329: 10,
586				432: 10
587			},
588			10048: {
589				329: 2,
590				328: 2,
591				332: 3,
592				432: 3
593			}
594		},
595		FIcfg: {
596			/*
597						329: {
598							token: "Vasabi",
599							name: "Васаби",
600							price: "20",
601							price1: "20",
602							anons: "",
603							uid: 329
604						},
605						328: {
606							token: "Imbir-marinovannyj",
607							name: "Имбирь маринованный",
608							price: "20",
609							price1: "20",
610							anons: "",
611							uid: 328
612						},
613						332: {
614							token: "Sous-Soevyj",
615							name: "Соус Соевый",
616							price: "20",
617							price1: "20",
618							anons: "",
619							uid: 332
620						},
621						432: {
622							token: "Palki",
623							name: "Палочки",
624							price: "0.00",
625							anons: "Палочки",
626							uid: 432,
627							image: '/images/palochki_dlia_edy.jpg'
628						}
629			*/
630		},
631
632		SETFIcfg: {
633			100164: {
634				328: 1,
635				329: 2
636
637			}
638		},
639
640		FIcrosscfg: {
641			3000: [100, 200, 300],
642			6000: [110, 220, 320],
643			9000: [120, 230, 330]
644		},
645
646		checkFIState: function () {
647			var itemCategoryCount = simpleCart.getItemCategoryCount(),
648				FIupdated = [];
649
650			for (category in itemCategoryCount) {
651				for (FIuid in simpleCart.catFIcfg[category]) {
652					if (category && simpleCart.catFIcfg[category] && itemCategoryCount[category]) {
653						var v = 0;
654						simpleCart.each(function (item) {
655							if (item.get('category') == category)
656								v += Math.ceil(item.quantity() / simpleCart.catFIcfg[category][FIuid]);
656 // Math.ceil потому что 1 товар кладется сразу, так что инкремент фри товаров идет на N+1 материнких товаров
657							if (simpleCart.SETFIcfg[item.get('uid')] && simpleCart.SETFIcfg[item.get('uid')][FIuid]) {
658								v += simpleCart.SETFIcfg[item.get('uid')][FIuid]; // сеты
659							}
660						});
661						FIupdated.push(FIuid);
662						simpleCart.updateFIState(FIuid, v);
663					}
664				}
665			}
666
667			for (FIuid in simpleCart.FIcfg) {
668				if ($.inArray(FIuid, FIupdated) == -1) {
669					if (simpleCart.find({ uid: FIuid }).length)
670						simpleCart.find({ uid: FIuid })[0].price(simpleCart.FIcfg[FIuid]['price']);
671				}
672			}
673
674			simpleCart.update();
675
676		},
677
678		updateFIState: function (uid, quantity) {
679			var FItems = simpleCart.find({ uid: uid });
680			if (FItems.length) {
681				var FItem = FItems[0],
682					FIquantity = FItem.quantity();
683				if ((iq = parseFloat(quantity) - parseFloat(FIquantity)) > -1) {
684					var c = Math.abs(iq) >= 1 ? Math.abs(iq) : 0;
685					FItem.price((c * simpleCart.FIcfg[uid]['price']) / FIquantity);
686					FItem.quantity(Math.ceil(parseFloat(FIquantity + iq)));
687				} else {
688					FItem.price((
689						simpleCart.FIcfg[uid]['price'] * (FIquantity - Math.ceil(quantity))) / FIquantity
690					);
691				}
692			} else if (quantity > 1 || !FItems.length) {
693				var tq = FItems.length ? Math.floor(quantity) + 1 : 1;
694				simpleCart.addFI(uid, tq, 0); // если нет фритоваров и добавили хоть 1 материнский товар, добавляем фри товар
695			}
696		},
697
698		getItemCategoryCount: function () {
699			var itemCategoryCount = {};
700			simpleCart.each(function (item) {
701				var itemCategory = item.get('category');
702				var itemQuantity = item.quantity();
703				if (itemCategoryCount[itemCategory]) {
704					itemCategoryCount[itemCategory] += itemQuantity;
705				} else {
706					itemCategoryCount[itemCategory] = itemQuantity;
707				}
708			});
709			return itemCategoryCount;
710		},
711		addFI: function (uid, quantity, price) {
712			p = parseFloat(price) || 0;
713			//console.log ('addFI q=' + quantity + 'price=' + p + " uid=" + uid);
714			simpleCart.add({
715				uid: uid,
716				token: simpleCart.FIcfg[uid]['token'],
717				name: simpleCart.FIcfg[uid]['name'],
718				price: p,
719				price1: simpleCart.FIcfg[uid]['price1'],
720				size: "Small",
721				quantity: quantity,
722				anons: simpleCart.FIcfg[uid]['anons'],
723				//	     category: 'sous',	
724				sort_order: 2,
725				image: simpleCart.FIcfg[uid]['image']
726			});
727		}
728	});
729	simpleCart.ready(function () {
730		simpleCart.bind('load', function () {
731
732			setSelectItemQuantity();
733
734			if (typeof (applyDiscountCard) != 'undefined' && localStorage.getItem('discountCardNumber')) applyDiscountCard(localStorage.getItem('discountCardNumber'));
735			if (typeof (updateCartCSS) != 'undefined') updateCartCSS();
736
737			simpleCart.bind("beforeAdd", function (item, isNew) {
738				if (!item.get('uid')) item.set("category", "sushi");
739			});
740
741			console.log('load');
742
743			simpleCart.bind("beforeRemove", function (item) {
744				//			        setSelectItemQuantity();
745			});
746
747			$(".in-cart").show(200);
748
749			simpleCart.bind("update", function () {
750				//				console.log('upd');
751
752				//$(".simpleCart_quantity_2").text(simpleCart.items().length-1 > 0 ? simpleCart.items().length-1 : 0);
753				$(".simpleCart_quantity_2").text(simpleCart.items().length);
754
755				manageDelivery($("input[name='user_f_42']:checked").val() || 1274);
756
757				removeOrphanItems();
758
759				$("a[href*='/product']").each(function () { $(this).data('href', $(this).attr('href').replace('product', 'popup')); });
760
761				if (simpleCart.items().length == 1 && simpleCart.find({ uid: 2897 }).length) {
762					simpleCart.find({ uid: 2897 })[0].remove();
763				}
764
765				if (!simpleCart.items().length && document.location.href.match(/cart.php|cart_mobile.php|cart/)) {
766					$("div.simpleCart_items").replaceWith('<div class="empty-block"><div class="empty-block__title">Ваша корзина пока пуста</div><a href="/catalog/" class="btn btn--gold-narrow ">Перейти в каталог</a></div>');
767					//$(".warning-msg").hide();
768					$("a#cleanCartBtn1, [name='cart-no1'], [name='cart-no2']").remove();
769					//$("#cartSubmit1btn").attr("disabled", "true");
770					$("#cartSubmit1btn").hide();
771
772				}
773
774				if (document.location.href.match(/cart.php/)) {
775					initColorBox();
776				}
777				if (document.location.href.match(/order.php|order_mobile.php/)) {
778					orderFillTextArea();
779				}
780
781				if (typeof (processFils) != 'undefined') processFils(); // enable this to process
782
783				$('#user_f_45').val(simpleCart.grandTotal());
784
785				//if (typeof (applyDiscountCard)!= 'undefined' && localStorage.getItem('discountCardNumber')) applyDiscountCard(localStorage.getItem('discountCardNumber'));
786
787
788				if (simpleCart.items().length == 1 && simpleCart.find({ uid: 2897 }).length) {
789					simpleCart.find({ uid: 2897 })[0].remove();
790				}
791
792
793
794
795			});
796			simpleCart.bind("afterAdd", function (item, isNew) {
797				//console.log('afteradd');
798				if (typeof (applyDiscountCard) != 'undefined' && localStorage.getItem('discountCardNumber')) applyDiscountCard(localStorage.getItem('discountCardNumber'));
799				//    				if (typeof (processFils) != 'undefined') processFils();
800			});
801
802			simpleCart.bind("afterSave", function (item, isNew) {
803				if (!simpleCart.items().length) {
804					$("#cartPopover").hide();
805					$(".cart-trigger").hide();
806				} else {
807					$(".cart-trigger").show();
808				}
809
810				//	simpleCart.checkFIState();
811			});
812
813			simpleCart.bind("beforeSave", function (item, isNew) {
814				//    				if (typeof (processFils) != 'undefined') processFils();
815
816				///				    console.log('feforesave');
817				//if (typeof (applyDiscountCard)!= 'undefined' && localStorage.getItem('discountCardNumber')) applyDiscountCard(localStorage.getItem('discountCardNumber'));
818				//	simpleCart.checkFIState();
819			});
820		});
821	});
822
823
824
825});
826
827
828function removeOrphanItems() {
829	var containers = [];
830	$.each(simpleCart.items(), function (i, item) {
831		if (item.get('composite') && !simpleCart.find({ uid: item.get('parentuid') }).length) { item.remove(); }
832	});
833
834	if (simpleCart.find({ uid: "1011" }).length) simpleCart.find({ uid: "1011" })[0].remove();
835	if (simpleCart.find({ iiko_id: "bd1fddb6-0c6e-44a1-bc7f-a3d450efbdfe" }).length) simpleCart.find({ iiko_id: "bd1fddb6-0c6e-44a1-bc7f-a3d450efbdfe" })[0].remove();
836	if (simpleCart.find({ iiko_id: "6dc0c5d8-7b5e-4ddb-8be6-0766da4b4882" }).length) simpleCart.find({ iiko_id: "6dc0c5d8-7b5e-4ddb-8be6-0766da4b4882" })[0].remove();
837
838
839
840}
841
842function setSelectItemQuantity() {
843	$("li[name='select-item-li0']").text(0)
844	simpleCart.each(function (item) {
845		if (window.mobilesite) {
846			$("select#select-item-" + item.get('uid')).val(item.quantity());
847		}
848		else {
849			$("li[name='select-item-li0']", $("ul#select-item-" + (item.get('uid2') || item.get('uid')))).text(item.quantity());
850		}
851	});
852}
853
854function applyPromoCode(promocode) {
855	var promoGoodsInBasket = 0,
856		promocodeApplied = 0,
857		promocodeCorrect = 0,
858		promises = [],
859		dfd = $.Deferred(),
860		lastItem = $.Deferred();
861
862	$.each(simpleCart.items(), function (i, item) {
863		if (item.get('promo')) { return 1; }
864		//	console.log('item', item);
865		$.ajax({
866			url: item.get('href').replace(/product|popup/, 'product-data-promo-multiple').replace(/.html/, ''), type: "GET", dataType: "json", async: false,
867			success: function (data) {
868				//console.log('s0', data);		
869				if (data['promo-ids']) {
870					$.each(data['promo-ids'], function (i, promoid) {
871						$.ajax({
872							url: '/promo-check.php', data: { id: promoid, promocode: promocode }, type: "GET", dataType: "json", async: false,
873							success: function (promocheck) {
874								//    				    console.log('pc0', promocheck, 'promocode' + promocode + ' id=' + item.get('uid'));
875								if (promocheck['success'] == 1) {
876									//console.log('success verification promocode ' + promocode, promocheck['success']);
877									$.ajax({
878										url: '/alltovar-tech2.php?p_f_2_temp_id=20&p_f_2_id=' + promoid, type: "GET", dataType: "json", async: false,
879										success: function (promodata) {
880											//				    		    console.log('pgetpromodata', promodata);
881											promodata = promodata[0];
882											if (!item.get('promo')) {
883												item.set('uid', promodata['uid']);
884												item.set('iiko_id', promodata['iiko_id']);
885												item.set('price', promodata['price']);
886												item.set('price1', promodata['price']);
887												item.set('name', item.get('name') + ' PROMO');
888												item.set('promo', true);
889												simpleCart.update();
890												$('#user_f_45').val(simpleCart.grandTotal());
891											}
892											promocodeApplied = 1;
893											console.log('pca0', promocodeApplied);
894											promocodeCorrect = 1;
895										}
896									});
897								}
898							}
899						});
900						promoGoodsInBasket = 1;
901					});
902				}
903			}
904		});
905	});
906
907	/*    
908		console.log('promises0', promises);
909		$.when.apply($, promises).done(function() {
910			//console.log ('da0', discountApplied, num.toString().length, 'dfd', dfd);
911			//console.log('promises1', promises, 'pca1', promocodeApplied);
912	
913			dfd.resolve({
914				promocodeApplied: promocodeApplied, 
915				promoGoodsInBasket: promoGoodsInBasket,
916				promocodeCorrect: promocodeCorrect
917			});
918			
919			
920		});
921	
922	*/
923
924	//console.log ('pca5 promocodeapplied', promocodeApplied, 'pgib=' + promoGoodsInBasket, 'pcc'+promocodeCorrect);
925	return { promocodeApplied: promocodeApplied, promocodeCorrect: promocodeCorrect, promoGoodsInBasket: promoGoodsInBasket };
926
927
928	//    return dfd;	
929
930
931}
932
933
934
935
936
937function applyDiscountCard(num) {
938	var specialGoodsInBasket = 0,
939		discountApplied = 0,
940		promises = [],
941		dfd = $.Deferred();
942	//console.log ('dfd0', dfd);
943	if (((num >= 1 && num < 904000) || (num >= 1000001 && num <= 1108000)) && num.toString().length == 7) {
944		//console.log ('card ok item price=', item.get('price'));
945		$.each(simpleCart.items(), function (i, e) {
946			var item = simpleCart.items()[i];
947			//if (item.get('composite')) return true;                      
948			promise = getItemInfo(item.get('uid2') || item.get('uid'));
949			promises.push(promise);
950			promise.done(function (data) {
951				itemInfo = data['itemInfo'];
952				flags = itemInfo['flags'];
953				item.set('flags', flags);
954
955				if (item.get('baseprice') != itemInfo['price']) {  // old item, updating price
956					item.set('baseprice', itemInfo['price']);
957					item.set('price1', itemInfo['price']);
958					item.price(itemInfo['price']);
959					item.set('discounted', 0);
960				}
961
962				if ((flags && $.inArray('offer', flags) != -1) || $.inArray(parseFloat(item.get('category')), [225, 233, 289, 859, 858, 374, 1237]) != -1) {
963					//console.log (item, 'NGE', item.get('flags'), 'cat', $.inArray(item.get('category'), [225, 233, 289]));
964					specialGoodsInBasket = 1;
965					return true;
966				}
967
968				if (item.get('uid')) {
969					if (!item.get('discounted')) {
970						price = item.get('price1') ? item.get('price1') : item.get('price');
971						discountPrice = price * 0.9
972						item.set('price1', discountPrice);
973						item.price(discountPrice);
974						item.set('discounted', 1);
975						item.set('baseprice', price);
976						simpleCart.update();
977						discountApplied = 1;
978					}
979					else {
980						discountApplied = 1;
981					}
982				}
983				//console.log ('da', discountApplied);
984			});
985		});
986
987	}
988
989	$.when.apply($, promises).done(function () {
990		//console.log ('da0', discountApplied, num.toString().length, 'dfd', dfd);
991		dfd.resolve({
992			discountApplied: discountApplied,
993			specialGoodsInBasket: specialGoodsInBasket
994		});
995		//    	processFils();
996	});
997
998	return dfd;
999
1000}
1001
1002
1003function removeDiscountCard(num) {
1004	localStorage.removeItem('discountCardNumber');
1005	$.each(simpleCart.items(), function (i, e) {
1006		var item = simpleCart.items()[i];
1007		if (item.get('uid') && item.get('discounted')) {
1008			baseprice = item.get('baseprice');
1009			//console.log (item, baseprice);
1010			item.set('price1', baseprice);
1011			item.price(baseprice);
1012			item.set('discounted', 0);
1013			//console.log ('p', item.price());
1014			simpleCart.update();
1015		}
1016	});
1017}
1018
1019
1020function getItemInfo(id) {
1021	var def = $.Deferred();
1022	$.getJSON('/alltovar-tech2.php?p_f_2_temp_id=20&p_f_2_id=' + id).done(function (data) {
1023		if (data) {
1024			def.resolve({
1025				itemInfo: data[0]
1026			});
1027		}
1028	});
1029
1030	return def;
1031}
1032
1033function processFils() {
1034
1035	return 0;
1036
1037	//    console.log('processfils');
1038	//    var fils = simpleCart.find({iiko_id: '3ed47998-14f1-483f-9745-84437e06533d'});
1039	var fils = simpleCart.find({ uid: '245' });
1040
1041	if (!fils.length) return 0;
1042	//    console.log('fils', fils);
1043
1044	var sum = 0,
1045		dfc = 0,    // count of filadelfiyas to set the promo 
1046		filprice = fils[0].get('price1'), // make me dynamic FIXME
1047		filpromoprice = 99, // make me dynamic FIXME;
1048		diff = filprice - filpromoprice;
1049
1050	//    console.log('filprice', filprice);	
1051	simpleCart.each(function (item) {
1052		sum += item.quantity() * (item.get('uid') == '245' ? filprice : item.get('price1'));
1053		//	sum += item.quantity() * (item.get('iiko_id') == '3ed47998-14f1-483f-9745-84437e06533d' ? filprice : item.get('price1'));
1054	});
1055
1056	//console.log('fils quantuty', fils.quantity());
1057	var fc = fils[0].quantity();
1058
1059	//item.get('iiko_id') == '3ed47998-14f1-483f-9745-84437e06533d'
1060	//    console.log('sum0', sum);
1061
1062	for (i = 0; i < fc; i++) {
1063		r = 700 * (dfc + 1);
1064		//	console.log('r', r);
1065		//	console.log('ok0 sum', sum, 'sum-diff', sum-diff);
1066
1067		if (sum - diff >= r) {  // считаем нужное кол-во промо товаров, определяем по границе 700р
1068			console.log('dfc increase');
1069			dfc++;
1070			sum = sum - diff;
1071		}
1072	};
1073
1074	console.log('dfc', dfc);
1075
1076
1077	if (fils.length) {
1078		fq = fils[0].get('quantity');
1079		fqd = fq - dfc;
1080		promoprice = (fqd * filprice + dfc * filpromoprice) / fq;
1081		console.log('fq', fq, 'promoprice', promoprice);
1082		if (dfc && fils[0].get('price') != promoprice) {
1083			fils[0].set('price', promoprice);
1084			fils[0].set('name', 'Маргарита + акция 99 руб.');
1085			fils[0].set('promo', 1);
1086			fils[0].set('dfc', dfc);
1087			simpleCart.update();
1088		}
1089
1090		if (!dfc && fils[0].get('price') != promoprice) {
1091			fils[0].set('price', promoprice);
1092			fils[0].set('name', 'Маргарита');
1093			fils[0].set('dfc', 0);
1094			fils[0].set('promo', 0);
1095			simpleCart.update();
1096		}
1097
1098	}
1099
1100}

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.