PageSourceSearch

https://www.isaro.be/themes/isaro/modules/combinationsincatalog/views/js/ps17/global.js

js isaro.be collected 2026-10-02 12:55:05 UTC 7,285 bytes, 155 lines download raw bytes

1/*
2* 2018 Singleton software
3*
4*  @author Singleton software <[email protected]>
5*  @copyright 2018 Singleton software
6*/
7
8var addToCardProductID;
9
10$(document).ready(function() {
11	appendCartControllerLink();
12	resizeCombinationsSection();
13
14	prestashop.on('updateCart', function (event) {
15		if (event.reason.linkAction == 'add-to-cart') {
16			addToCardProductID = event.reason.idProduct;
17			displayProgressWheel(addToCardProductID, true);
18			//pokial je ps verzia vascia, alebo rovna 1750, nefunguje emit "updatedCart", v ktorom bolo zastavene tocenie progress wheelu po pridani produktu do kosika, tak sa to zastavi samo po sekunde
19			if (greaterThan1750) {
20				setTimeout(function() {
21					displayProgressWheel(addToCardProductID, false);
22				}, 1000);
23			}
24		}
25	});
26
27	// po tom ako sa vlozi produkt do kosika sa zavola emit "updatedCart"
28	prestashop.on('updatedCart', function (event) {
29		if (typeof addToCardProductID !== 'undefined') {
30			displayProgressWheel(addToCardProductID, false);
31			addToCardProductID = undefined;
32		}
33	});
34
35	// vzdy po zbehnuti akehokolvek filtru v katalogu produktov (blocklayered, paginacia, zoradenie), sa cez tento emit vykreslia nanovo ceny prefiltrovanych produktov
36	prestashop.on('updateProductList', function (data) {
37		appendCartControllerLink();
38		resizeCombinationsSection();
39	});
40
41	$(document).on('change','.variants-product [name="productCombinations"]', function() {
42		idProduct = parseInt($(this).parents('.addToCartFormWrapper:eq(0)').attr('data-product-id'));
43		$(this).parents('.addToCartFormWrapper:eq(0)').find('.productCombinationsHiddenInput').remove();
44		$.each(productsVariantsJson[idProduct][$(this).val()]['attributes'], function(index, value) {
45			generateInput(idProduct, value[3], value[2]);
46		});
47		getCombinationsForProducts(idProduct, $(this).parents('.addToCartFormWrapper:eq(0)').find('.addToCartForm').serialize() + '&ajax=1&action=getProductCombinations');
48	});
49
50	$(document).on('change','.variants-product [data-product-attribute]', function() {
51		idProduct = parseInt($(this).parents('.addToCartFormWrapper:eq(0)').attr('data-product-id'));
52		getCombinationsForProducts(idProduct, $(this).parents('.addToCartFormWrapper:eq(0)').find('.addToCartForm').serialize() + '&ajax=1&action=getProductCombinations');
53	});
54});
55
56function resizeCombinationsSection() {
57	$('.addToCartFormWrapper').each(function() {
58		appendProgressWheel($(this).attr('data-product-id'));
59	});
60}
61
62function appendCartControllerLink() {
63	$('.addToCartFormWrapper').each(function() {
64		$(this).find('.addToCartForm').attr('action', cartControllerLink);
65	});
66}
67
68function getCombinationsForProducts(idProduct, query) {
69	displayProgressWheel(idProduct, true);
70	$.ajax({
71		type: "POST",
72		url: productCombinationsControllerLink,
73		async: false,
74		data : query,
75		dataType: 'json',
76		success : function(res) {
77			$('.addToCartFormWrapper[data-product-id=' + idProduct + ']').each(function(){
78				refreshCombinations($(this), res);
79			});
80		}
81	});
82}
83
84function refreshCombinations(object, res) {
85  console.log('REFRESH MONICA');
86
87	object.find('.variants-product').remove();
88	object.find('.variantsProductWrapper').append(res.productVariants);
89	if (parseInt(combinationsInCatalogData.display_add_to_cart) == 1) {
90		object.find('.add-to-cart').html(((res.addToCartUrl == null && combinationsInCatalogData.button_out_of_stock[idLang].length > 0) ? combinationsInCatalogData.button_out_of_stock[idLang] : addToCartLabel));
91		object.find('.add-to-cart').prop('disabled', (res.addToCartUrl == null));
92		object.find('.addToCartButtonNumber').prop('disabled', (res.addToCartUrl == null));
93		object.find('.addToCartButtonNumber').val(res.quantity_wanted);
94		object.find('.addToCartButtonNumber').attr('min', res.minimal_quantity);
95	}
96	if (typeof res.images.medium !== 'undefined') {
97		if (object.parents(getCorrectPathFromConfiguration('miniature_root_path') + ':eq(0)').find(getCorrectPathFromConfiguration('miniature_thumbnail_image_path')).attr('src') != res.images.medium) {
98			object.parents(getCorrectPathFromConfiguration('miniature_root_path') + ':eq(0)').find(getCorrectPathFromConfiguration('miniature_thumbnail_image_path')).attr('src', res.images.medium)
99			object.parents(getCorrectPathFromConfiguration('miniature_root_path') + ':eq(0)').find(getCorrectPathFromConfiguration('miniature_thumbnail_image_path')).attr('data-full-size-image-url', res.images.large);
100		}
101	}
102  console.log(object.closest('.js-product-miniature').find('.product-card__price-amount').html());
103  console.log(res.prices.price);
104
105	if (object.closest('.js-product-miniature').find('.product-card__price-amount').html().trim() != res.prices.price.replace(' ', '&nbsp;')) {
106		regularPriceIsChanged = false;
107		if (res.prices.has_discount && object.parents(getCorrectPathFromConfiguration('miniature_root_path') + ':eq(0)').find(getCorrectPathFromConfiguration('miniature_old_price_path')).length > 0) {
108			if (object.parents(getCorrectPathFromConfiguration('miniature_root_path') + ':eq(0)').find(getCorrectPathFromConfiguration('miniature_old_price_path')).html().trim() != res.prices.regular_price) {
109				regularPriceIsChanged = true;
110			}
111		}
112		if (regularPriceIsChanged) {
113			object.parents(getCorrectPathFromConfiguration('miniature_root_path') + ':eq(0)').find(getCorrectPathFromConfiguration('miniature_old_price_path')).html(res.prices.regular_price);
114		}
115
116		object.closest('.js-product-miniature').find('.product-card__price-amount').html(res.prices.price);
117	}
118	displayProgressWheel(idProduct, false);
119}
120
121function appendProgressWheel(idProduct) {
122	$('.addToCartFormWrapper[data-product-id=' + idProduct + ']').each(function() {
123		if ($(this).parents(getCorrectPathFromConfiguration('miniature_root_path') + ':eq(0)').find("button[data-button-action='add-to-cart']").length > 0) {
124			$(this).parents(getCorrectPathFromConfiguration('miniature_root_path') + ':eq(0)').find("button[data-button-action='add-to-cart']").css('position', 'relative').append('<span class="preLoading"></span>');
125		} else {
126			$(this).parents(getCorrectPathFromConfiguration('miniature_root_path') + ':eq(0)').find(getCorrectPathFromConfiguration('miniature_thumbnail_container_path')).append('<span class="preLoading" style="width: 30px; height: 30px; left: auto; top: 5px; right: 5px; background-color: white !important;"></span>');
127		}
128	});
129}
130
131function displayProgressWheel(idProduct, display) {
132	$('.addToCartFormWrapper[data-product-id=' + idProduct + ']').each(function() {
133		$(this).parents(getCorrectPathFromConfiguration('miniature_root_path') + ':eq(0)').find('.preLoading').css('display', (display ? 'block' : 'none'));
134	});
135}
136
137function generateInput(idProduct, group, value) {
138	$('.addToCartFormWrapper[data-product-id=' + idProduct + ']').each(function() {
139		$(this).find('.addToCartForm').append("<input class='productCombinationsHiddenInput' name='group[" + group + "]' value='" + value + "' type='hidden' />");
140	});
141}
142
143function getCorrectPathFromConfiguration(name) {
144	correctValue = '.product-miniature';
145	if (combinationsInCatalogData[name].length > 0) {
146		correctValue = combinationsInCatalogData[name];
147	} else {
148		$(advancedFormFields).each(function(key, value){
149			if (value['name'] == name) {
150				correctValue = value['init_value'];
151			}
152		});
153	}
154	return correctValue;
155}

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.