PageSourceSearch

https://electroniger.com/modules/tvcmswishlist/views/js/ajax-wishlist.js

js electroniger.com collected 2026-09-24 13:58:26 UTC 14,059 bytes, 447 lines download raw bytes

1/**
2* 2007-2025 PrestaShop
3*
4* NOTICE OF LICENSE
5*
6* This source file is subject to the Academic Free License (AFL 3.0)
7* that is bundled with this package in the file LICENSE.txt.
8* It is also available through the world-wide-web at this URL:
9* http://opensource.org/licenses/afl-3.0.php
10* If you did not receive a copy of the license and are unable to
11* obtain it through the world-wide-web, please send an email
12* to [email protected] so we can send you a copy immediately.
13*
14* DISCLAIMER
15*
16* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
17* versions in the future. If you wish to customize PrestaShop for your
18* needs please refer to http://www.prestashop.com for more information.
19*
20*  @author PrestaShop SA <[email protected]>
21*  @copyright  2007-2025 PrestaShop SA
22*  @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
23*  International Registered Trademark & Property of PrestaShop SA
24*/
25
26var wishlistProductsIds = [];
27jQuery(document).ready(function($){
28	wishlistRefreshStatus();
29
30	$(document).on('change', 'select[name=wishlists]', function(){
31		WishlistChangeDefault('wishlist_block_list', $(this).val());
32	});
33	$('.wishlist').each(function() {
34		current = $(this);
35		$(this).children('.wishlist_button_list').popover({
36			html: true,
37			content: function () {
38				return current.children('.popover-content').html();
39			}
40		});
41	});
42	$(document).on('click','.product_infos .btn_action .wishlist_change_button', function(){
43		if ($(this).parent().find('.popover-content').attr('hidden') == '' || $(this).parent().find('.popover-content').attr('hidden') == 'hidden') {
44			$('.product_infos .btn_action .popover-content').attr('hidden', 'hidden');
45			$(this).parent().find('.popover-content').removeAttr('hidden');
46		} else {
47			$(this).parent().find('.popover-content').attr('hidden','hidden');
48		}
49	});
50});
51
52function WishlistCart(id, action, id_product, id_product_attribute, quantity, id_wishlist){
53	$.ajax({
54		type: 'GET',
55		url: baseDir + 'modules/tvcmswishlist/cart.php?rand=' + new Date().getTime(),
56		headers: { "cache-control": "no-cache" },
57		async: true,
58		cache: false,
59		data: 'action=' + action + '&id_product=' + id_product + '&quantity=' + quantity + '&token=' + static_token + '&id_product_attribute=' + id_product_attribute + '&id_wishlist=' + id_wishlist,
60		success: function(data)
61		{
62			if (action == 'add'){
63					if (isLogged == true) {
64						wishlistProductsIdsAdd(id_product);
65						wishlistRefreshStatus();
66	                    $('.tvcmsdesktop-view-wishlist .cart-wishlist-number').html('(' + data + ')');
67	                    $('.tvsticky-wishlist .cart-wishlist-number').html('(' + data + ')');
68							$html = '<div class="tvwishlist-popup success" style="top:'+$('#header').height()+'px"><i class="material-icons">&#xe877</i><p>' + added_to_wishlist + '</p></div>';
69							$('#wrapper').append($html);
70							$('.tvwishlist-popup').slideDown().delay(3000).slideUp(function(){  $(this).remove(); });
71					}else{
72							$html = '<div class="tvwishlist-popup warning" style="top:'+$('#header').height()+'px"><i class="material-icons">&#xe899</i><p>' + loggin_required + '</p></div>';
73							$('#wrapper').append($html);
74							$('.tvwishlist-popup').slideDown().delay(3000).slideUp(function(){  $(this).remove(); });
75					}
76					
77			}
78			if (action == 'delete') {
79				wishlistProductsIdsRemove(id_product);
80				wishlistRefreshStatus();
81			}
82			if($('#' + id).length != 0){
83				$('#' + id).slideUp('normal');
84				document.getElementById(id).innerHTML = data;
85				$('#' + id).slideDown('normal');
86			}
87
88		}
89	});
90}
91
92/**
93* Change customer default wishlist
94*
95* @return void
96*/
97function WishlistChangeDefault(id, id_wishlist){
98	$.ajax({
99		type: 'GET',
100		url: baseDir + 'modules/tvcmswishlist/cart.php?rand=' + new Date().getTime(),
101		headers: { "cache-control": "no-cache" },
102		async: true,
103		data: 'id_wishlist=' + id_wishlist + '&token=' + static_token,
104		cache: false,
105		success: function(data)
106		{
107			$('#' + id).slideUp('normal');
108			document.getElementById(id).innerHTML = data;
109			$('#' + id).slideDown('normal');
110
111		}
112	});
113}
114
115/**
116* Buy Product
117*
118* @return void
119*/
120function WishlistBuyProduct(token, id_product, id_product_attribute, id_quantity, button, ajax){
121	if(ajax)
122		ajaxCart.add(id_product, id_product_attribute, false, button, 1, [token, id_quantity]);
123	else
124	{
125		$('#' + id_quantity).val(0);
126		WishlistAddProductCart(token, id_product, id_product_attribute, id_quantity)
127		document.forms['addtocart' + '_' + id_product + '_' + id_product_attribute].method='POST';
128		document.forms['addtocart' + '_' + id_product + '_' + id_product_attribute].action=baseUri + '?controller=cart';
129		document.forms['addtocart' + '_' + id_product + '_' + id_product_attribute].elements['token'].value = static_token;
130		document.forms['addtocart' + '_' + id_product + '_' + id_product_attribute].submit();
131	}
132	return (true);
133}
134
135function WishlistAddProductCart(token, id_product, id_product_attribute, id_quantity){
136	if ($('#' + id_quantity).val() <= 0)
137		return (false);
138
139	$.ajax({
140			type: 'GET',
141			url: baseDir + 'modules/tvcmswishlist/buywishlistproduct.php?rand=' + new Date().getTime(),
142			headers: { "cache-control": "no-cache" },
143			data: 'token=' + token + '&static_token=' + static_token + '&id_product=' + id_product + '&id_product_attribute=' + id_product_attribute,
144			async: true,
145			cache: false,
146			success: function(data)
147			{
148				if (data)
149				{
150					if (!!$.prototype.fancybox)
151						$.fancybox.open([
152							{
153								type: 'inline',
154								autoScale: true,
155								minHeight: 30,
156								content: '<p class="fancybox-error">' + data + '</p>'
157							}
158						], {
159							padding: 0
160						});
161					else
162						alert(data);
163				}
164				else{
165					$('#' + id_quantity).val($('#' + id_quantity).val() - 1);
166				}
167			}
168	});
169	return (true);
170}
171/**
172* Show wishlist managment page
173*
174* @return void
175*/
176function WishlistManage(id, id_wishlist){
177	$.ajax({
178		type: 'GET',
179		async: true,
180		url: baseDir + 'modules/tvcmswishlist/managewishlist.php?rand=' + new Date().getTime(),
181		headers: { "cache-control": "no-cache" },
182		data: 'id_wishlist=' + id_wishlist + '&refresh=' + false,
183		cache: false,
184		success: function(data)
185		{
186			$('#' + id).hide();
187			document.getElementById(id).innerHTML = data;
188			$('#' + id).fadeIn('slow');
189
190			$('.wishlist_change_button').each(function(index) {
191				$(this).change(function () {
192					wishlistProductChange($('option:selected', this).attr('data-id-product'), $('option:selected', this).attr('data-id-product-attribute'), $('option:selected', this).attr('data-id-old-wishlist'), $('option:selected', this).attr('data-id-new-wishlist'));
193	 		 	});
194			});
195			$('#mywishlist .product-name').balance();
196			$('#hideSendWishlist').trigger('click');
197		}
198	});
199}
200
201/**
202* Show wishlist product managment page
203*
204* @return void
205*/
206function WishlistProductManage(id, action, id_wishlist, id_product, id_product_attribute, quantity, priority){
207	$.ajax({
208		type: 'GET',
209		async: true,
210		url: baseDir + 'modules/tvcmswishlist/managewishlist.php?rand=' + new Date().getTime(),
211		headers: { "cache-control": "no-cache" },
212		data: 'action=' + action + '&id_wishlist=' + id_wishlist + '&id_product=' + id_product + '&id_product_attribute=' + id_product_attribute + '&quantity=' + quantity + '&priority=' + priority + '&refresh=' + true,
213		cache: false,
214		success: function(data)
215		{
216			if (action == 'delete')
217				$('#wlp_' + id_product + '_' + id_product_attribute).fadeOut('fast');
218			else if (action == 'update')
219			{
220				$('#wlp_' + id_product + '_' + id_product_attribute).fadeOut('fast');
221				$('#wlp_' + id_product + '_' + id_product_attribute).fadeIn('fast');
222			}
223			nb_products = 0;
224			$("[id^='quantity']").each(function(index, element){
225				nb_products += parseInt(element.value);
226			});
227			$("#wishlist_"+id_wishlist).children('td').eq(1).html(nb_products);
228		}
229	});
230}
231/**
232* Delete wishlist
233*
234* @return boolean succeed
235*/
236function WishlistDelete(id, id_wishlist, msg){
237	var res = confirm(msg);
238	if (res == false)
239		return (false);
240
241	if (typeof wish_link == 'undefined')
242		return (false);
243
244	$.ajax({
245		type: 'GET',
246		async: true,
247		dataType: "json",
248		url: wish_link,
249		headers: { "cache-control": "no-cache" },
250		cache: false,
251		data: {
252			rand: new Date().getTime(),
253			deleted: 1,
254			myajax: 1,
255			id_wishlist: id_wishlist,
256			action: 'deletelist'
257		},
258		success: function(data)
259		{
260			var mywishlist_siblings_count = $('#' + id).siblings().length;
261			$('#' + id).fadeOut('slow').remove();
262			$("#block-order-detail").html('');
263			if (mywishlist_siblings_count == 0)
264				$("#block-history").remove();
265			if (data.id_default)
266			{
267				var td_default = $("#wishlist_"+data.id_default+" > .wishlist_default");
268				$("#wishlist_"+data.id_default+" > .wishlist_default > a").remove();
269				td_default.append('<p class="is_wish_list_default"><i class="icon icon-check-square"></i></p>');
270			}
271			$html = '<div class="tvwishlist-popup error" style="top:'+$('#header').height()+'px"><i class="material-icons">&#xe877</i><p>' + deleted_wishlist + '</p></div>';
272			$('#wrapper').append($html);
273			$('.tvwishlist-popup').slideDown().delay(3000).slideUp(function(){  $(this).remove(); });
274		}
275	});
276}
277
278function WishlistDefault(id, id_wishlist){
279	if (typeof wish_link == 'undefined')
280		return (false);
281
282	$.ajax({
283		type: 'GET',
284		async: true,
285		url: wish_link,
286		headers: { "cache-control": "no-cache" },
287		cache: false,
288		data: {
289			rand:new Date().getTime(),
290			'default': 1,
291			id_wishlist:id_wishlist,
292			myajax: 1,
293			action: 'setdefault'
294		},
295		success: function (data)
296		{
297			var old_default_id = $(".is_wish_list_default").parents("tr").attr("id");
298			var td_check = $(".is_wish_list_default").parent();
299			$(".is_wish_list_default").remove();
300			td_check.append('<a href="#" onclick="javascript:event.preventDefault();(WishlistDefault(\''+old_default_id+'\', \''+old_default_id.replace("wishlist_", "")+'\'));"><i class=\'material-icons\'>&#xe835</i></a>');
301			var td_default = $("#"+id+" > .wishlist_default");
302			$("#"+id+" > .wishlist_default > a").remove();
303			td_default.append('<p class="is_wish_list_default"><i class=\'material-icons\'>&#xe834</i></p>');
304			$html = '<div class="tvwishlist-popup success" style="top:'+$('#header').height()+'px"><i class="material-icons">&#xe877</i><p>' + default_wishlist + '</p></div>';
305			$('#wrapper').append($html);
306			$('.tvwishlist-popup').slideDown().delay(3000).slideUp(function(){  $(this).remove(); });
307		}
308	});
309}
310
311/**
312* Hide/Show bought product
313*
314* @return void
315*/
316function WishlistVisibility(bought_class, id_button){
317	if ($('#hide' + id_button).is(':hidden')){
318		$('.' + bought_class).slideDown('fast');
319		$('#show' + id_button).hide();
320		$('#hide' + id_button).css('display', 'block');
321	} else{
322		$('.' + bought_class).slideUp('fast');
323		$('#hide' + id_button).hide();
324		$('#show' + id_button).css('display', 'block');
325	}
326	if (id_button == "SendWishlist"){
327		setTimeout(function() {
328			var scrollDiv = document.getElementById("wishlist_form").offsetTop;
329			window.scrollTo({ top: scrollDiv, behavior: 'smooth'});
330		}, 200);
331	}
332}
333
334/**
335* Send wishlist by email
336*
337* @return void
338*/
339function WishlistSend(id, id_wishlist, id_email){
340	var checkVal = $('#email1').val();
341	if(checkVal != ''){
342		$.post(
343		baseDir + 'modules/tvcmswishlist/sendwishlist.php',
344		{
345			token: static_token,
346			id_wishlist: id_wishlist,
347			email1: $('#' + id_email + '1').val(),
348			email2: $('#' + id_email + '2').val(),
349			email3: $('#' + id_email + '3').val(),
350			email4: $('#' + id_email + '4').val(),
351			email5: $('#' + id_email + '5').val(),
352			email6: $('#' + id_email + '6').val(),
353			email7: $('#' + id_email + '7').val(),
354			email8: $('#' + id_email + '8').val(),
355			email9: $('#' + id_email + '9').val(),
356			email10: $('#' + id_email + '10').val()
357		},
358		function(data)
359		{
360			if (data)
361			{
362				if (!!$.prototype.fancybox)
363					$.fancybox.open([
364						{
365							type: 'inline',
366							autoScale: true,
367							minHeight: 30,
368							content: '<p class="fancybox-error">' + data + '</p>'
369						}
370					], {
371						padding: 0
372					});
373				else
374					alert(data);
375			}
376			else
377				WishlistVisibility(id, 'hideSendWishlist');
378		}
379	);
380	}
381	
382}
383
384function wishlistProductsIdsAdd(id){
385	if ($.inArray(parseInt(id),wishlistProductsIds) == -1)
386		wishlistProductsIds.push(parseInt(id))
387}
388
389function wishlistProductsIdsRemove(id){
390	wishlistProductsIds.splice($.inArray(parseInt(id),wishlistProductsIds), 1)
391}
392
393function wishlistRefreshStatus(){
394	$('.addToWishlist').each(function(){
395		if ($.inArray(parseInt($(this).prop('rel')),wishlistProductsIds)!= -1){
396			$(this).addClass('checked');
397		} else{
398			$(this).removeClass('checked');
399		}
400			
401	});
402}
403
404function wishlistProductChange(id_product, id_product_attribute, id_old_wishlist, id_new_wishlist){
405	if (typeof wish_link == 'undefined')
406		return (false);
407
408	var quantity = $('#quantity_' + id_product + '_' + id_product_attribute).val();
409
410	$.ajax({
411		type: 'GET',
412		url: wish_link,
413		headers: { "cache-control": "no-cache" },
414		async: true,
415		cache: false,
416		dataType: "json",
417		data: {
418			id_product:id_product,
419			id_product_attribute:id_product_attribute,
420			quantity: quantity,
421			priority: $('#priority_' + id_product + '_' + id_product_attribute).val(),
422			id_old_wishlist:id_old_wishlist,
423			id_new_wishlist:id_new_wishlist,
424			myajax: 1,
425			action: 'productchangewishlist'
426		},
427		success: function (data){
428			if (data.success == true) {
429				$('#wlp_' + id_product + '_' + id_product_attribute).fadeOut('slow');
430				$('#wishlist_' + id_old_wishlist + ' td:nth-child(2)').text($('#wishlist_' + id_old_wishlist + ' td:nth-child(2)').text() - quantity);
431				$('#wishlist_' + id_new_wishlist + ' td:nth-child(2)').text(+$('#wishlist_' + id_new_wishlist + ' td:nth-child(2)').text() + +quantity);
432			}else{
433				if (!!$.prototype.fancybox)
434					$.fancybox.open([
435						{
436							type: 'inline',
437							autoScale: true,
438							minHeight: 30,
439							content: '<p class="fancybox-error">' + data.error + '</p>'
440						}
441					], {
442						padding: 0
443					});
444			}
445		}
446	});
447}

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.