File: /var/www/vhost/disk-apps/demo.sports-crowd.com/resources/views/web_experiences/detail/js.blade.php
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function() {
function formatCurrency(value) {
return new Intl.NumberFormat('es-CO', {
style: 'currency',
currency: <?php echo json_encode($corporateIdentity->currency); ?>,
currencyDisplay: 'narrowSymbol',
minimumFractionDigits: <?php echo json_encode($corporateIdentity->minimum_fraction_digits); ?>,
maximumFractionDigits: <?php echo json_encode($corporateIdentity->maximum_fraction_digits); ?>,
}).format(value);
}
$('.plan-price').each(function() {
let amountText = $(this).text();
let formatted = formatCurrency(amountText);
$(this).text(formatted);
});
$('.plan-total-price').each(function() {
let amountText = $(this).text();
let formatted = formatCurrency(amountText);
$(this).text(formatted);
});
document.querySelectorAll('.plan-box').forEach(box => {
const decrementBtn = box.querySelector('[data-action="decrement"]');
const incrementBtn = box.querySelector('[data-action="increment"]');
const input = box.querySelector('.quantity-input');
const total = box.querySelector('.plan-total-price');
const price = parseFloat(total.dataset.base || 0);
const limit = parseInt(input.dataset.limit || '1');
function updateTotal(qty) {
const totalAmount = price * qty;
total.textContent = `$ ${totalAmount.toLocaleString('es-CO')}`;
}
decrementBtn.addEventListener('click', () => {
let current = parseInt(input.value);
if (current > 1) {
current--;
input.value = current;
updateTotal(current);
}
});
incrementBtn.addEventListener('click', () => {
let current = parseInt(input.value);
if (current < limit) {
current++;
input.value = current;
updateTotal(current);
}
});
box.addEventListener('click', () => {
document.querySelectorAll('.plan-box').forEach(b => b.classList.remove('selected'));
box.classList.add('selected');
const $button = $('.register-btn');
$button.prop('disabled', false);
$button.off('click');
$button.on('click', function() {
const experienceId = $('#experienceId').val();
const planPriceId = box.dataset.planId;
const amount = box.querySelector('.quantity-input').value;
const url = `/web_experiences/${experienceId}/preview-enroll/${planPriceId}/${amount}`;
window.location.href = url;
});
// Centrar en el box seleccionado
$('html, body').animate({
scrollTop: $(box).offset().top - ($(window).height() / 2) + ($(box).outerHeight() / 2)
}, 500);
})
});
history.pushState(null, null, location.href);
window.onpopstate = function() {
window.location.href = "{{ url('/web_experiences') }}";
};
});
</script>