PageSourceSearch

https://tic.dubai.co.il/wp-content/themes/ticdubai/assets/js/product.js?ver=0.0.64

js dubai.co.il collected 2026-10-02 20:37:40 UTC 16,386 bytes, 463 lines download raw bytes

1function set_total_price() {
2
3	//console.log('set_total_price');
4		
5        var totalPrice = 0;
6        var ages = jQuery('.cart-item');
7
8        ages.toArray().forEach( function(age, id) {
9            var qty = jQuery(age).find('input').val();
10            var price = jQuery(age).find('.price').attr('data-price');
11
12            if( price !== undefined ){
13                totalPrice = parseInt( totalPrice ) + parseInt( qty ) * parseInt( price );
14            }
15		//console.log('set_total_price_age', qty, price, totalPrice);
16        });
17
18	//console.log('set_total_price_totalPrice', totalPrice);
19
20        jQuery('#totalPrice').html(`₪${totalPrice}`);
21
22	//console.log('set_total_price_totalPrice_defined', totalPrice);
23
24        var agesArray = [];
25
26        ages.toArray().forEach( function(age) {
27            var attributeName = jQuery(age).attr('data-attribute');
28            var value = jQuery(age).attr('data-value');
29            var qty = jQuery(age).find('input').val();
30            var price = jQuery(age).find('.price').attr('data-price');
31            agesArray.push( { [`attribute_${attributeName}`] : value, qty : qty, price : price } );
32        });
33
34        var hasAdults = false;
35        var hasChildren = false;
36
37        agesArray.forEach( function(item) {
38            if( parseInt( item.price ) > 0 && parseInt( item.qty ) > 0 ){
39                hasAdults = true;
40            }
41            if( parseInt( item.price ) === 0 && parseInt( item.qty ) > 0 ){
42                hasChildren = true;
43            }
44        });
45
46        if(hasChildren === true && hasAdults === false){
47            jQuery('#addToCart').addClass('disabled-btn error-cards');
48        } else {
49            jQuery('#addToCart').removeClass('disabled-btn error-cards');
50        }
51        if(hasChildren === false && hasAdults === false){
52            jQuery('#addToCart').addClass('disabled-btn error-cards');
53        }
54}
55
56
57jQuery(document).ready(function () {
58
59    var productID = jQuery('.calendar-block').attr('data-product');
60
61	/* Disable the add to cart button if no time selected, 'select' event doesn't work for some reason */
62	jQuery('#selectedTime').on('change', function() {
63		jQuery( '.current-time' ).text( jQuery( this ).val() );
64		if ( jQuery( this ).val() === '' ) {
65			jQuery( '#addToCart' ).addClass( 'disabled-btn error-time' );
66		} else {
67			jQuery( '#addToCart' ).removeClass( 'disabled-btn error-time' );
68		}
69	});
70
71    jQuery('.minus').click(function () {
72        var jQueryinput = jQuery(this).parent().find('input');
73	return cartItemMinusClicked(jQueryinput);
74    });
75    jQuery('.plus').click(function () {
76        var jQueryinput = jQuery(this).parent().find('input');
77	return cartItemPlusClicked(jQueryinput);
78    });
79
80    check_attributes( productID );
81
82    jQuery('.attributes-select').on('change', function() {
83        check_attributes( productID );
84    });
85
86    function check_attributes( product_id ){
87        var attributes = [];
88        var agesArray = [];
89        var selects = jQuery('.attributes-select');
90
91        selects.toArray().forEach( function(select) {
92            var selectedValue = jQuery(select).val();
93            var attributeName = jQuery(select).attr('data-attribute');
94            attributes.push( { [`attribute_${attributeName}`] : selectedValue } );
95        });
96
97        var ages = jQuery('.cart-item');
98
99        ages.toArray().forEach( function(age) {
100            var attributeName = jQuery(age).attr('data-attribute');
101            var value = jQuery(age).attr('data-value');
102            agesArray.push( { [`attribute_${attributeName}`] : value } );
103        });
104
105        var data = {
106            action: 'woocommerce_check_variation',
107            product_id: product_id,
108            attributes: attributes,
109            ages: agesArray
110        };
111
112        jQuery.ajax({
113            type: 'post',
114            url: '/wp-admin/admin-ajax.php',
115            data: data,
116            beforeSend: function (response) {
117                jQuery('.calendar-block').css({ filter: 'blur(1px)' });
118            },
119            complete: function (response) {
120		//
121            },
122            success: function (response) {
123                jQuery('.calendar-block').css({ filter: '' });
124
125		var res = JSON.parse(response);
126                var ages = jQuery('.cart-item');
127                var allNull = true;
128		var dateSettings = jQuery( res ).last()[0]['date_time_settings'];
129		if ( dateSettings ) {
130			/* Set the ticket section label */
131			jQuery( '.ticket-section .name' ).html( dateSettings['ticket_section_label'] );
132			/* This calendar code block moved from the start of the file since it needs to be by variation settings instead of per product */
133			if ( 'show' === dateSettings['date_calendar'] ) {
134				/* Display the calendar in case it was previously hidden */
135				jQuery( '.calendar-section' ).show();
136				/* Set the date field label */
137				jQuery( '.calendar-section .name' ).html( dateSettings['date_section_label'] );
138				/* Set the selected date field label */
139				jQuery( '.current-date-label' ).text( dateSettings['date_selected_date_label'] );
140				jQuery('#selectedDate').html('');
141				jQuery( '#selectedHour' ).text( '' );
142					
143				/* Convert disabled weekdays string to int */
144				var DisabledWeekdays = dateSettings['date_disabled_weekdays'].map( function (x) {
145					return parseInt( x, 10); 
146				});
147				jQuery('.calendar').pignoseCalendar({
148					initialize: false,
149					minDate: dateSettings['date_min_date'],
150					disabledDates: dateSettings['date_disabled_dates'],
151					disabledWeekdays: DisabledWeekdays,
152					disabledRanges: dateSettings['date_disabled_ranges'],
153				
154					init: function(context) {
155						var todayDate = new Date();
156						var formattedDate = todayDate.toISOString();
157						var fd = formattedDate.split('T');
158						var units = jQuery('.pignose-calendar-unit');
159						units.toArray().forEach( function(item) {
160							if(jQuery(item).attr('data-date') === fd[0]){
161								jQuery(item).addClass('custom-current-date');
162							}
163						});
164					},
165					select: function(date, context) {
166						if(date[0] && date[0]._i){
167							var dt = date[0]._i;
168							dt = dt.split('-');
169							var day = dt[2];
170							var month = dt[1];
171							var year = dt[0];
172							var formattedDate = `${day}.${month}.${year}`;
173							jQuery('#selectedDate').html(formattedDate);
174							jQuery('#addToCart').removeClass('disabled-btn error-date');
175						} else {
176							jQuery('#addToCart').addClass('disabled-btn error-date');
177							jQuery('#selectedDate').html('');
178						}
179					},
180					week: 0,
181					/* Can be moved to check-variations to be translatable */
182					weeks: [
183						'א',
184						'ב',
185						'ג',
186						'ד',
187						'ה',
188						'ו',
189						'ש'
190					],
191					monthsLong: [
192						'ינואר',
193						'פברואר',
194						'מרץ',
195						'אפריל',
196						'מאי',
197						'יוני',
198						'יולי',
199						'אוגוסט',
200						'ספטמבר',
201						'אוקטובר',
202						'נובמבר',
203						'דצמבר'
204					],
205					months: [
206						'ינואר',
207						'פברואר',
208						'מרץ',
209						'אפריל',
210						'מאי',
211						'יוני',
212						'יולי',
213						'אוגוסט',
214						'ספטמבר',
215						'אוקטובר',
216						'נובמבר',
217						'דצמבר'
218					]
219				});
220					} else {
221						jQuery( '.calendar-section' ).hide();
222						jQuery('#selectedDate').html('');
223						jQuery('#addToCart').removeClass('disabled-btn error-date');
224					}
225
226					/* Apply the per variations time settings */
227					var timeField = jQuery( '#selectedTime' );
228					if ( dateSettings['time_options'] ) {
229						/* Can be moved to check-variations to be translatable */
230						jQuery( '.current-time-label' ).text( 'שעת פעילות נבחרת: ' );
231						jQuery( '.current-time' ).text( '' );
232						timeField.empty();
233						jQuery.each( dateSettings['time_options'], function( key, value) { 
234							 timeField.append( jQuery( "<option></option>" ).attr( "value", value ).text( value ) );
235						});
236						jQuery( '#selectedTime_field' ).show();
237					} else {
238						jQuery( '#selectedTime_field' ).hide();
239						jQuery( '.current-time-label' ).text( '' );
240						/* Can be moved to check-variations to be translatable */
241						jQuery( '.current-time' ).text( 'בהתאם לשעות פעילות המקום' );
242						timeField.empty();
243						jQuery( '#addToCart' ).removeClass( 'disabled-btn error-time' );
244					}
245					if ( dateSettings['attr_term_description'] ) {
246						jQuery( '.selected-term-description' ).html( dateSettings['attr_term_description'] ).show();
247					} else {
248						jQuery( '.selected-term-description' ).html( '' ).hide();
249					}
250				} else {
251					jQuery( '.selected-term-description' ).html( '' ).hide();
252					jQuery( '.calendar-section' ).hide();
253					jQuery('#selectedDate').html('');
254					jQuery('#addToCart').removeClass('disabled-btn error-date');
255					jQuery( '#selectedTime_field' ).hide();
256					jQuery( '#selectedTime' ).empty();
257					jQuery( '#addToCart' ).removeClass( 'disabled-btn error-time' );
258				}
259
260			ages.toArray().forEach( function(age, id) {
261                    if(res[id].price === ''){
262                        jQuery(age).css({ display: 'none' });
263                        jQuery(age).find('input').val(0);
264                    } else {
265                        jQuery(age).css({ display: 'none' }).css({ display: 'flex' });
266                        jQuery(age).find('.price').html( `₪${res[id].price}` ).attr('data-price', res[id].price );
267                        jQuery(age).find('input').val(0); // 2024-04-30
268                    }
269
270                    if(parseInt( res[id].price ) > 0){
271                        allNull = false;
272                    }
273                });
274
275                if(allNull === true){
276                    jQuery('.cart-list').find('.added-text').remove();
277                    jQuery('.cart-list').find('.result').css({ display : 'none' });
278		    /* Can be moved to check-variations to be translatable */
279                    jQuery('.cart-list').append('<p class="added-text" style="font-weight: bold; color: #9b1e80;">שילוב זה אינו זמין, יש לבחור שילוב אחר לכרטיס</p>');
280                } else {
281                    jQuery('.cart-list').find('.result').css({ display : 'flex' });
282                    jQuery('.cart-list').find('.added-text').remove();
283                }
284		/* Currency be moved to check-variations to be translatable */
285                jQuery('#totalPrice').html(`₪0`); // 2024-04-30
286
287		cartItemAllowDisplayOfQuantityCheking();	
288            }, // success
289        });
290    }
291
292    jQuery('#addToCart').on('click', function () {
293        set_total_price();
294	jQuery('.addToCart-errors-list .addToCart-error').hide();
295
296	/* Add condition about field visibility since it can be hidden */
297        if( jQuery('#selectedDate').is( ':visible' ) && jQuery('#selectedDate').html() === '') {
298            	jQuery(this).addClass('disabled-btn error-date');
299		jQuery('.addToCart-errors-list .addToCart-error-date').show();	
300        }
301
302	/* Add error message if time field is visible but not selected */
303        if( jQuery('#selectedTime').is( ':visible' ) && jQuery('#selectedTime').val() === '') {
304            jQuery(this).addClass('disabled-btn error-time');
305			jQuery('.addToCart-errors-list .addToCart-error-time').show();	
306        }
307	
308	if(jQuery('#addToCart').hasClass('error-cards')){
309		jQuery('.addToCart-errors-list .addToCart-error-cards').show();
310        }
311	if(jQuery('#addToCart').hasClass('error-date')){
312                jQuery('.addToCart-errors-list .addToCart-error-date').show();
313        }
314
315	/* Add condition about add to cart button have error-time class */
316	if(jQuery('#addToCart').hasClass('error-cards') || jQuery('#addToCart').hasClass('error-date') || jQuery('#addToCart').hasClass('error-time') ||  jQuery('#addToCart').hasClass('disabled-btn')) {
317            return false;
318        }
319
320        add_to_cart();
321        jQuery(this).addClass('button-loading');
322
323    });
324
325    function add_to_cart() {
326        if(jQuery('#addToCart').hasClass('button-loading')){
327            return false;
328        }
329
330        var attributes = [];
331        var agesArray = [];
332        var selects = jQuery('.attributes-select');
333        var selectedDate = jQuery('#selectedDate').html();
334
335        selects.toArray().forEach( function(select) {
336            var selectedValue = jQuery(select).val();
337            var attributeName = jQuery(select).attr('data-attribute');
338            attributes.push( { [`attribute_${attributeName}`] : selectedValue } );
339        });
340
341        var ages = jQuery('.cart-item');
342
343        ages.toArray().forEach( function(age) {
344            var attributeName = jQuery(age).attr('data-attribute');
345            var value = jQuery(age).attr('data-value');
346            var qty = jQuery(age).find('input').val();
347            var price = jQuery(age).find('.price').attr('data-price');
348            agesArray.push( { [`attribute_${attributeName}`] : value, qty : qty, price : price } );
349        });
350        var data = {
351            action: 'woocommerce_ajax_add_to_cart',
352            product_id: productID,
353            attributes: attributes,
354            ages: agesArray,
355            date: selectedDate,
356			/* Send also the selected time value */
357			time: jQuery( '#selectedTime' ).val(),
358        };
359
360        jQuery.ajax({
361            type: 'post',
362            url: '/wp-admin/admin-ajax.php',
363            data: data,
364            beforeSend: function (response) {
365		/**/
366            },
367            complete: function (response) {
368		/**/
369            },
370            success: function (response) {
371                jQuery('#addToCart').removeClass('button-loading');
372                jQuery('#hCartCount').html(response.total_count);
373                jQuery('#miniCartCount').html(response.total_count);
374		/* Currency be moved to check-variations to be translatable */
375                jQuery('#cartTotalPrice').html(`₪${response.total_price}`);
376		/* Currency be moved to check-variations to be translatable */
377                jQuery('#miniCartTotal').html(`₪${response.total_price}`);
378                var ages = jQuery('.cart-item');
379
380                ages.toArray().forEach( function(age, id) {
381                    jQuery(age).find('input').val(0);
382                });
383
384		/* Currency be moved to check-variations to be translatable */
385                jQuery('#totalPrice').html(`₪0`); // 2024-04-30
386                jQuery('.mini-cart-items').html(response.cart_items);
387                jQuery('.mini-cart').addClass('opened-cart');
388                jQuery('html').addClass('no-scroll');
389                jQuery('.searchbg').fadeIn();
390                jQuery('.mini-cart-totals').css({ display : 'block' });
391            },
392        });
393    }
394
395});
396
397function cartItemMinusClicked(jQueryinput)
398{
399	var count = parseInt(jQueryinput.val()) - 1;
400        var min = parseInt(jQueryinput.data('min'));
401        var max = parseInt(jQueryinput.data('max'));
402	var chk = parseInt(jQueryinput.data('allow-display-of-quantity'));
403
404        count = count < 0 ? 0 : count;
405        if(min != '' && count < min) {
406                count = 0;
407        }
408	if(chk && count < min) {
409		count = min;
410	}
411        if(max != '' && count > max) {
412                count = max;
413        }
414
415        jQueryinput.val(count);
416        jQueryinput.change();
417        set_total_price();
418        return false;
419}
420
421function cartItemPlusClicked(jQueryinput)
422{
423	var count = parseInt(jQueryinput.val()) + 1;
424        var min = parseInt(jQueryinput.data('min'));
425        var max = parseInt(jQueryinput.data('max'));
426        count = count < 0 ? 0 : count;
427        if(min != '' && count < min) {
428                count = min;
429        }
430        if(max != '' && count > max) {
431                count = max;
432        }
433
434        jQueryinput.val(count);
435        jQueryinput.change();
436        set_total_price();
437        return false;
438}
439
440function cartItemAllowDisplayOfQuantityCheking()
441{
442	jQuery( ".cart-list .cart-item" ).each(function( index ) {
443 	        /*console.log( index + ": " + $( this ).text() );*/
444                var jQueryinput = jQuery(this).find('.number input');
445                var chk = parseInt(jQueryinput.data('allow-display-of-quantity'));
446                if(chk) {
447        		cartItemPlusClicked(jQueryinput);
448                }
449        });	
450}
451
452/* no need it
453jQuery(document).ready(function () {
454
455	setTimeout(() => {
456		cartItemAllowDisplayOfQuantityCheking();
457	}, 2000);
458});
459*/
460
461
462
463

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.