forked from snap-cloud/snapcon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathosem-tickets.js
50 lines (42 loc) · 1.58 KB
/
osem-tickets.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
function update_price($this){
var id = $this.data('id');
var selectedCurrency = $('#currency_selector').val();
var conversionData = window.currencyRates[selectedCurrency] || { rate: 1, symbol: '$' };
var conversionRate = conversionData.rate;
var originalPrice = parseFloat($('#price_'+id).data('original-price'));
var convertedPrice = originalPrice*conversionRate;
// Calculate price for row
$('#currency_symbol_' + id).text(conversionData.symbol);
$('#total_currency_symbol_' + id).text(conversionData.symbol);
$('#price_' + id).text(convertedPrice.toFixed(2));
$('#total_row_' + id).text((convertedPrice * $this.val()).toFixed(2));
// Calculate total price
var total = 0;
$('span[id^="total_row_"]').each(function() {
total += parseFloat($(this).text());
});
$('#total-currency-symbol').text(conversionData.symbol);
$('#total-price').text(total.toFixed(2));
}
$( document ).ready(function() {
window.currencyRates = {};
if (window.currencyMeta) {
window.currencyMeta.forEach(function(currencyInfo) {
window.currencyRates[currencyInfo.currency] = { rate: currencyInfo.rate, symbol: currencyInfo.symbol };
});
}
$('.quantity').each(function() {
update_price($(this));
});
$('.quantity').change(function() {
update_price($(this));
});
$(function () {
$('[data-toggle="tooltip"]').tooltip()
});
$('#currency_selector').change(function() {
$('.quantity').each(function() {
update_price($(this));
});
});
});