Cervezas La Salve

LA SALVE en marcha para su semana más importante del año, Aste Nagusia

LA SALVE en marcha para su semana más importante del año, Aste Nagusia

function getQueryParams(qs) { qs = qs.split('+').join(' '); var params = {}, tokens, re = /[?&]?([^=]+)=([^&]*)/g; while (tokens = re.exec(qs)) { params[decodeURIComponent(tokens[1])] = decodeURIComponent(tokens[2]); } return params; } jQuery(document).ready(function($) { var baseURL = window.location.origin + "/"; var location = document.location.href; var query = getQueryParams(document.location.search); var finCompraURL = baseURL + "finalizar-compra/"; // URL OAuth precomputada server-side por el mu-plugin (incluye state + cookie). // Si no está disponible, no reescribimos: el botón mantiene su href original. var oauthUrl = window.LASALVE_SF_OAUTH_URL || null; // Ocultar widget de carrito en tienda (comportamiento heredado) jQuery('.mkdf-shopping-cart-holder').hide(); // PAGINA CARRITO: reescribir botón "Finalizar Compra" hacia el OAuth de SF if (location.indexOf(baseURL + "carrito") !== -1 && oauthUrl) { function rewriteCheckoutBtn() { var btn = jQuery('.woocommerce-cart-form__contents > tbody a.button')[0]; if (btn && jQuery(btn).attr("href") === finCompraURL) { jQuery(btn).attr("href", oauthUrl); } } rewriteCheckoutBtn(); jQuery(document.body).on('updated_cart_totals', rewriteCheckoutBtn); } // PAGINA FINALIZAR COMPRA: recibe el code de SF y delega en /api/sf_login.php if (location.indexOf(finCompraURL) !== -1) { if (typeof query.sfdc_community_id !== "undefined" && query.code) { $('.woocommerce-form-login-toggle').hide(); var params = { code: query.code }; if (query.state) params.state = query.state; $.ajax({ url: "/api/sf_login.php", method: "GET", data: params, timeout: 20000, dataType: "json" }) .done(function (json) { if (json && json.ok && typeof json.redirect === "string" && json.redirect.charAt(0) === "/" && json.redirect.charAt(1) !== "/") { history.replaceState('data', '', json.redirect); window.location.replace(json.redirect); } else { console.error('sf_login: respuesta inválida', json); alert('No hemos podido iniciar tu sesión. Por favor, vuelve a intentarlo.'); } }) .fail(function (xhr, textStatus) { console.error('sf_login: fallo', xhr && xhr.status, textStatus); alert('Error al iniciar tu sesión. Inténtalo de nuevo.'); }); } } });