Fix Snipcart v3 API compatibility for order completion redirect

Update event listener from deprecated v2 Snipcart.execute to v3 Snipcart.events.on API. Change event from 'order.completed' (webhook-only) to 'cart.confirmed' (client-side) and update parameter from order to cartState to match v3 structure.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
isUnknown 2025-12-22 10:21:28 +01:00
parent 48b744e8f1
commit 3ba37020ff

View file

@ -6,13 +6,13 @@ window.SnipcartSettings = {
// Redirection après paiement réussi // Redirection après paiement réussi
document.addEventListener('snipcart.ready', function() { document.addEventListener('snipcart.ready', function() {
Snipcart.execute('bind', 'order.completed', function(order) { Snipcart.events.on('cart.confirmed', function(cartState) {
// Détecter la langue actuelle depuis l'URL // Détecter la langue actuelle depuis l'URL
const currentPath = window.location.pathname; const currentPath = window.location.pathname;
const langMatch = currentPath.match(/^\/([a-z]{2})(\/|$)/); const langMatch = currentPath.match(/^\/([a-z]{2})(\/|$)/);
const langPrefix = langMatch ? '/' + langMatch[1] : ''; const langPrefix = langMatch ? '/' + langMatch[1] : '';
window.location.href = langPrefix + '/thanks?order=' + order.token; window.location.href = langPrefix + '/thanks?order=' + cartState.token;
}); });
}); });