`;
}
}
// Fonctions globales
function addToCart(productId, productName, price) {
showLoading('Ajout au panier...');
fetch('https://www.djoralcharm.com/panier/ajouter', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').getAttribute('content')
},
body: JSON.stringify({
product_id: productId,
quantity: 1
})
})
.then(response => response.json())
.then(data => {
hideLoading();
if (data.success) {
showSuccess(`${productName} ajouté au panier !`);
updateCartCount(data.cart_count);
} else {
showError(data.error || 'Erreur lors de l\'ajout au panier');
}
})
.catch(error => {
hideLoading();
showError('Erreur de connexion');
console.error('Error:', error);
});
}
function addToCartFromQuickView(productId, productName, price) {
const quantity = parseInt(document.getElementById('quick-view-quantity').value);
showLoading('Ajout au panier...');
fetch('https://www.djoralcharm.com/panier/ajouter', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').getAttribute('content')
},
body: JSON.stringify({
product_id: productId,
quantity: quantity
})
})
.then(response => response.json())
.then(data => {
hideLoading();
if (data.success) {
showSuccess(`${productName} (x${quantity}) ajouté au panier !`);
updateCartCount(data.cart_count);
bootstrap.Modal.getInstance(document.getElementById('quickViewModal')).hide();
} else {
showError(data.error || 'Erreur lors de l\'ajout au panier');
}
})
.catch(error => {
hideLoading();
showError('Erreur de connexion');
console.error('Error:', error);
});
}
function addToWishlist(productId, productName, price) {
const isLoggedIn = false;
if (!isLoggedIn) {
Swal.fire({
title: 'Connexion requise pour les favoris',
text: 'Créez un compte pour sauvegarder vos produits préférés.',
icon: 'info',
showCancelButton: true,
confirmButtonText: 'Créer un compte',
cancelButtonText: 'Se connecter',
confirmButtonColor: '#3A7D44',
cancelButtonColor: '#6c757d'
}).then((result) => {
if (result.isConfirmed) {
window.location.href = 'https://www.djoralcharm.com/inscription';
} else if (result.dismiss === Swal.DismissReason.cancel) {
window.location.href = 'https://www.djoralcharm.com/connexion';
}
});
return;
}
showLoading('Ajout aux favoris...');
setTimeout(() => {
hideLoading();
showSuccess(`${productName} ajouté aux favoris !`);
}, 1000);
}
// Initialiser le gestionnaire de boutique
let shopManager;
document.addEventListener('DOMContentLoaded', function() {
console.log('DOM loaded, initializing ShopManager...');
// Attendre un peu pour s'assurer que toutes les bibliothèques sont chargées
setTimeout(() => {
try {
// Vérifier que noUiSlider est disponible
if (typeof noUiSlider === 'undefined') {
console.error('noUiSlider library not loaded');
return;
}
shopManager = new ShopManager();
console.log('ShopManager initialized successfully');
} catch (error) {
console.error('Error initializing ShopManager:', error);
}
}, 100);
});
Nous utilisons des cookies afin d’améliorer votre expérience sur notre site, analyser le trafic et personnaliser le contenu.
Vous pouvez accepter tous les cookies, les refuser ou personnaliser vos choix à tout moment.