Welcome,
Guest
|
|
TOPIC: Total Price showing NaN
Total Price showing NaN 8 years 7 months ago #34188
|
I have Matukio 6.0.5 installed.
Everything works fine on the bookings until I get to the final page before making payment (step 3). On the page to confirm the order, I see the following: Total amount $ NaN That should have the total amount of the event |
Total Price showing NaN 8 years 6 months ago #34206
|
Hey Steven,
Yes, this is a known bug, but Yves was not able to release a fix last week. I can't reproduce the bug on my machine, but would you please try with this booking.jquery.js file: /*
* Matukio Booking; v20160506
* https://compojoom.com
* Copyright (c) 2013 - 2016 Yves Hoppe - compojoom;
*/
(function ($) {
var version = "20160506";
var debug = 0;
$.fn.mat_booking = function (options, translationstrings) {
var settings = $.extend({
// Default settings - see API instructions
juri : '',
imgpath: 'media/com_matukio/images/',
steps: 3,
fees: 0,
different_fees: 0,
max_bookings: 0,
coupon: 1,
fieldnames: null,
event_id: 0,
setting_multiple_places: 1,
registration: false,
net_fees: false,
tax_value: 0,
currency_sign: '$',
currency_decimal: '.',
currency_position: '1'
}, options);
var translations = $.extend({
error_payment: 'Please select a payment method',
error_required_fields: 'Please fill out all required fields!',
error_coupon: 'The coupon code is not valid',
error_max_places: 'You have exceeded the maximum number of bookable places',
error_agb: 'You need to accept the Terms and Conditions',
text_person: 'Details for place'
}, translationstrings);
var holder = $.extend({
log: $.fn.mat_booking.log,
form: null,
intro: null,
currentstep: 1,
btn_next: null,
btn_back: null,
btn_submit: null,
btn_addticket: null,
page_zero: null,
page_one: null,
page_two: null,
page_three: null,
mat_control: null,
payment: null,
agb: null,
revoke: null,
nrbooked: null,
coupon_code: null,
mh1: null,
mh2: null,
mh3: null,
mat_tickets_total: null,
count_tickets: 0,
fields: {},
conf_fields: {},
per_place_fields: {}
});
var API = $.extend({
hideall: function () {
holder.divmonthly.hide();
holder.divweekly.hide();
},
nextPage: function () {
holder.log('-- Next Page ' + holder.currentstep + '--');
if (holder.currentstep == settings.steps) {
return false;
}
holder.currentstep++;
if (holder.currentstep == 3 && !API.validatePayment()) {
alert(translations.error_payment);
holder.currentstep--;
return false;
}
if (!API.validateForm()) {
alert(translations.error_required_fields);
holder.currentstep--;
return false;
}
if (holder.currentstep == 3 && settings.coupon == 1 && !API.validateCoupon()) {
alert(translations.error_coupon);
holder.currentstep--;
return false;
}
if (settings.different_fees && holder.currentstep == 2 && settings.max_bookings > 1) {
var difpl = 0;
$(".ticket_places").each(function (index, element) {
difpl += parseInt($(element).val());
});
// Set total places
holder.nrbooked.val(difpl);
}
if (holder.nrbooked.val() > settings.max_bookings) {
alert(translations.error_max_places + " " + settings.max_bookings + ")");
holder.currentstep--;
return false;
}
holder.btn_back.css('display', 'inline-block');
holder.page_one.css('display', 'none');
holder.mh1.css('display', 'none');
if (settings.steps == 3 && holder.currentstep == 2) {
holder.page_two.css('display', 'block');
holder.mh2.css('display', 'block');
}
if (holder.currentstep == settings.steps) {
holder.page_two.css('display', 'none');
holder.page_three.css('display', 'block');
if (settings.steps != 2) {
holder.mh2.css('display', 'none');
}
holder.mh3.css('display', 'block');
holder.btn_next.css('display', 'none');
holder.btn_submit.css('display', 'inline-block');
API.fillConfirmation();
if (settings.steps == 3) {
if (settings.different_fees == 1) {
API.calculateDifferentFees();
} else {
API.calculatePayment();
}
} else {
if (settings.fees > 0) {
if (settings.different_fees == 1) {
API.calculateDifferentFees();
} else {
API.calculatePayment();
}
}
}
}
// Scroll to top
$('html, body').animate({
scrollTop: $("#mat_heading").offset().top
}, 1000);
return true;
},
prevPage: function () {
holder.log('-- Prev Page ' + holder.currentstep + ' --');
if (holder.currentstep == 1) {
return true;
}
holder.currentstep--;
if (settings.steps != 2) {
holder.mh2.css('display', 'none');
}
holder.mh3.css('display', 'none');
holder.page_three.css('display', 'none');
holder.btn_submit.css('display', 'none');
holder.btn_next.css('display', 'inline-block');
if (settings.steps == 3 && holder.currentstep == 2) {
holder.page_two.css('display', 'block');
holder.mh2.css('display', 'block');
}
if (holder.currentstep == 1) {
holder.mh1.css('display', 'block');
holder.btn_back.css('display', 'none');
holder.page_two.css('display', 'none');
holder.page_one.css('display', 'block');
}
return true;
},
sendPage: function () {
holder.log('-- Send Page ' + holder.currentstep + ' --');
if (!API.validateAGB()) {
alert(translations.error_agb);
return false;
}
if (!API.validateForm()) {
return false;
}
holder.btn_submit.attr("disabled", "disabled");
$("#BookingForm").submit();
},
validateForm: function () {
var valid = document.formvalidator.isValid(document.BookingForm);
return valid;
},
validatePayment: function () {
if (holder.payment.val() == '') {
return false;
}
return true;
},
validateCoupon: function () {
var response = false;
var code = holder.coupon_code.val();
if (code == '') {
return true;
}
$.ajax({
url: settings.juri + 'index.php?option=com_matukio&view=requests&format=raw&task=validate_coupon&code=' + code,
type: 'get',
async: false
}).done(function (data) {
response = data;
});
return (response === 'true');
},
fillConfirmation: function () {
$.each(holder.fields, function (key, value) {
var conffield = holder.conf_fields["conf_" + key];
if (value.is("input[type=radio]")){
conffield.text(value.filter(":checked").val());
} else {
conffield.text(value.val());
}
});
var conf_nrbooked = $("#conf_nrbooked");
if (conf_nrbooked.length) {
conf_nrbooked.text(holder.nrbooked.val());
}
return true;
},
calculateDifferentFees: function () {
var places = 0;
var code = "";
if (holder.coupon_code.length) {
code = holder.coupon_code.val();
}
var conf_payment_type = $("#conf_payment_type");
var conf_nrbooked = $("#conf_nrbooked");
var conf_coupon_code = $("#conf_coupon_code");
if (conf_payment_type.length) {
// Not using value here, use name of the plugin
var selc = $("option:selected", holder.payment);
conf_payment_type.text(selc.text());
}
if (conf_coupon_code.length) {
conf_coupon_code.text(holder.coupon_code.val());
}
var conf_payment_total = $("#conf_payment_total");
var cnt = 0;
var ticket_places = [], ticket_types = [], ticket_disc_value = [], ticket_percent = [], ticket_discount = [], extra_values = [], extra_perplace = [];
$(".ticket_places").each(function (index, num) {
var tval = $(num).val();
ticket_places[cnt] = tval;
places += parseInt(tval);
cnt++;
});
// Set total places
if (settings.max_bookings > 1) {
holder.nrbooked.val(places);
} else {
places = 1;
ticket_places[0] = 1;
}
if (conf_nrbooked.length) {
conf_nrbooked.text(places);
}
cnt = 0;
$(".ticket_fees").each(function (index, fee) {
fee = $(fee);
ticket_types[cnt] = fee.val();
var selected = $("option:selected", fee);
ticket_disc_value[cnt] = selected.attr("discvalue");
ticket_discount[cnt] = selected.attr("discount");
ticket_percent[cnt] = selected.attr("percent");
cnt++;
});
cnt = 0;
$(".mat_extra_option").each(function(index, extra) {
extra = $(extra);
if (!extra.is(':checked')) {
return true;
}
extra_values[cnt] = extra.attr('extravalue');
extra_perplace[cnt] = extra.attr('perplace');
cnt++;
});
$.ajax({
url: settings.juri + 'index.php?option=com_matukio&view=requests&format=raw&task=get_total_different',
data: {
code: code,
event_id: settings.event_id,
fee: settings.fees,
nrbooked: places,
places: ticket_places.join(','),
types: ticket_types.join(','),
disc_value: ticket_disc_value.join(','),
percent: ticket_percent.join(','),
discount: ticket_discount.join(','),
extra_value: extra_values.join(','),
extra_perplace: extra_perplace.join(',')
},
method: 'post'
}).done(function (data) {
var total = parseFloat(data);
holder.mat_tickets_total.text(API.formatCurrency(total));
API.setTextPayment(total);
holder.nrbooked.val(places);
});
return true;
},
calculatePayment: function () {
var conf_payment_type = $("#conf_payment_type");
var conf_nrbooked = $("#conf_nrbooked");
var conf_payment_total = $("#conf_payment_total");
var conf_coupon_code = $("#conf_coupon_code");
if (conf_payment_type.length) {
// Not using value here, use name of the plugin
var selc = $("option:selected", holder.payment);
conf_payment_type.text(selc.text());
}
if (conf_nrbooked.length) {
conf_nrbooked.text(holder.nrbooked.val());
}
if (conf_coupon_code.length) {
conf_coupon_code.text(holder.coupon_code.val());
}
// The tricky part
if (conf_payment_total.length) {
var extra_values = [], extra_perplace = [];
var code = "";
if (holder.coupon_code.length) {
code = holder.coupon_code.val();
}
var places = 1;
if (holder.nrbooked.length) {
places = holder.nrbooked.val();
}
var types = [];
if (settings.different_fees == 1) {
var cnt = 0;
$(".ticket_fees").each(function (index, fee) {
types[cnt] = fee.val();
cnt++;
});
}
cnt = 0;
$(".mat_extra_option").each(function(index, extra) {
extra = $(extra);
if (!extra.is(':checked')) {
return true;
}
extra_values[cnt] = extra.attr('extravalue');
extra_perplace[cnt] = extra.attr('perplace');
cnt++;
});
$.ajax({
url: settings.juri + 'index.php?option=com_matukio&view=requests&format=raw&task=get_total',
data: {
code: code,
event_id: settings.event_id,
fee: settings.fees,
nrbooked: places,
types: types.join(','),
extra_value: extra_values.join(','),
extra_perplace: extra_perplace.join(',')
},
method: 'post'
}).done(function (data) {
var total = parseFloat(data);
holder.mat_tickets_total.text(API.formatCurrency(total));
API.setTextPayment(total);
});
}
return true;
},
setTextPayment: function(total) {
total = parseFloat(total);
var conf_payment_net = $("#conf_payment_net");
var conf_payment_taxes = $("#conf_payment_taxes");
var conf_payment_total = $("#conf_payment_total");
if (settings.net_fees) {
var gross = total * ((100 + settings.tax_value) / 100);
var tax = (gross - total);
var net = total;
} else {
// Gross
var factor = 100 / (100 + settings.tax_value);
var net = total * factor;
var tax = total - net;
var gross = total;
}
net = Math.round(net * 100) / 100;
gross = Math.round(gross * 100) / 100;
tax = Math.round(tax * 100) / 100;
if (conf_payment_net.length) {
conf_payment_net.text(API.formatCurrency(net));
}
if (conf_payment_taxes.length) {
conf_payment_taxes.text(API.formatCurrency(tax));
}
conf_payment_total.text(API.formatCurrency(gross));
},
formatCurrency: function(value) {
value = value.toFixed(2);
if (settings.currency_position == '1')
{
return settings.currency_sign + ' ' + value;
}
return value + ' ' + settings.currency_sign;
},
newTicketRow: function () {
holder.count_tickets++;
$.ajax({
url: settings.juri + 'index.php?option=com_matukio&format=raw&view=requests&task=getnewfeerow&event_id=' + settings.event_id,
type: 'get',
encoding: 'utf-8',
data: {num: holder.count_tickets}
}).done(function (html) {
var new_rows = html;
// inject new fields at bottom
$(new_rows).appendTo('#mat_tickets');
$("#delticket" + holder.count_tickets).click(function () {
$("#tickets_" + $(this).attr("num")).remove();
$(".ticket_places").trigger("change");
return false;
});
API.addFieldsPerPlace();
// Recalculate total
$(".ticket_places").trigger("change");
// Trigger onchange update for the new elements
API.updateTicketVal();
});
return true;
},
validateAGB: function () {
if (holder.agb.length) { // No AGB, so they are always true..
if (holder.agb.prop('checked') == false) {
return false;
}
}
if (holder.revoke.length) {
if (holder.revoke.prop('checked') == false) {
return false;
}
}
return true;
},
addFieldsPerPlace: function() {
$(".ticket_places").change(function(){
var places = 0;
var targ = $("#per_place_fields");
$(".ticket_places").each(function (index, element) {
places += parseInt($(element).val());
});
holder.nrbooked.val(places);
if (places > 1) {
// Reset
targ.html("");
for (var i = 1; i < places; i++)
{
var begin = $('<div class="top-10 margin-bottom-20">' + translations.text_person + " " + (i + 1) + "</div>");
if (Object.keys(holder.per_place_fields).length) {
begin.appendTo(targ);
}
$.each(holder.per_place_fields, function(index, item) {
var copy = $("#" + item.field_name).parents(".field_row:first").clone();
copy.find("#" + item.field_name).attr("id", item.field_name + i)
.attr("name", item.field_name + i).val("");
copy.appendTo(targ);
});
}
} else {
// Reset
targ.html("");
}
});
},
updateTicketVal: function() {
$(".ticket_places").change(function(){
if (settings.fees > 0) {
if (settings.different_fees == 1) {
API.calculateDifferentFees();
} else {
API.calculatePayment();
}
}
});
$('.mat_extra_option').change(function(){
if (settings.different_fees == 1) {
API.calculateDifferentFees();
} else {
API.calculatePayment();
}
});
if (settings.different_fees == 1) {
$('.ticket_fees').change(function(){
API.calculateDifferentFees();
});
}
},
initRegistration: function() {
if (!settings.registration) {
return;
}
holder.page_zero = $("#mat_pagezero");
holder.mat_control = $("#mat_control");
holder.page_one.hide();
holder.mat_control.hide();
holder.page_zero.show();
$('#btnBookAsGuest').click(function(e){
e.preventDefault();
holder.page_zero.hide();
$('#mat_username').val("");
$('#mat_password').val("");
holder.page_one.show();
holder.mat_control.show();
});
$('#btnRegisterDuring').click(function(e){
e.preventDefault();
holder.page_zero.hide();
holder.page_one.show();
holder.mat_control.show();
$('#user_registration').show();
$('#mat_username').addClass('required');
$('#mat_password').addClass('required');
});
},
init: function () {
// Init fields
holder.intro = $("#mat_intro");
holder.btn_next = $("#btn_next");
holder.btn_back = $("#btn_back");
holder.btn_submit = $("#btn_submit");
holder.page_one = $("#mat_pageone");
holder.page_two = $("#mat_pagetwo");
holder.page_three = $("#mat_pagethree");
holder.payment = $("#payment");
holder.agb = $("#agb");
holder.revoke = $("#revoke");
holder.nrbooked = $("#nrbooked");
holder.coupon_code = $("#coupon_code");
holder.mat_tickets_total = $("#mat_tickets_total_val");
API.initRegistration();
$(settings.fieldnames).each(function (key, field) {
var fname = field.field_name;
var ftype = field.type;
var fperplace = field.per_place;
if (ftype != "spacer" && ftype != "spacertext") {
if (ftype != "radio") {
holder.fields[fname] = $("#" + fname);
} else {
holder.fields[fname] = $("input[name='" + fname + "']");
}
// Confirmation fields
holder.conf_fields["conf_" + fname] = $("#conf_" + fname);
if (fperplace == 1) {
holder.per_place_fields[fname] = field;
}
}
});
if (debug == 1) {
console.log(holder.fields);
console.log(holder.conf_fields);
}
// Header
if (settings.steps == 2) {
holder.mh1 = $('#mat_h1');
holder.mh3 = $('#mat_h2');
} else {
holder.mh1 = $('#mat_hp1');
holder.mh2 = $('#mat_hp2');
holder.mh3 = $('#mat_hp3');
}
// Different fees
if (settings.different_fees == 1 && settings.max_bookings > 1) {
holder.btn_addticket = $("#addticket");
holder.btn_addticket.click(function () {
API.newTicketRow();
return false;
});
}
API.addFieldsPerPlace();
holder.btn_next.click(function () {
API.nextPage();
return false;
});
holder.btn_back.click(function () {
API.prevPage();
return false;
});
holder.btn_submit.click(function () {
API.sendPage();
return false;
});
if (settings.steps == 1) {
holder.btn_next.hide();
holder.btn_submit.show();
}
// Fees on first page
if (settings.fees > 0) {
if (settings.different_fees == 1) {
API.calculateDifferentFees();
} else {
API.calculatePayment();
}
}
// Terms and conditions
$(".open_terms_dialog").magnificPopup({
type: 'inline',
midClick: true
});
API.updateTicketVal();
return true;
}
});
return this.each(function () {
holder.log('-- Matukio Bookingform Init --');
holder.log('-- Version ' + version + " --");
holder.bookingform = $(this);
var success = API.init();
holder.log('-- Init Status: ' + success + ' --');
holder.log('-- Finished loading Matukio Bookingform --');
});
};
// Logging to console
$.fn.mat_booking.log = function log() {
if (window.console && console.log && debug == 1)
console.log('[recurring] ' + Array.prototype.join.call(arguments, ' '));
}
}(jQuery)); You need to replace the contents of media/com_matukio/js/booking.jquery.js. Let me know if this works or not. (don't forget to clean your browser cache after the change) Regards, Daniel |
|
Time to create page: 0.125 seconds