1// Declara el espacio de nombres ITER 2var ITER = ITER || {}; 3 4// Declara el subespacio de nombres ITER.RECOMMENDATIONS 5ITER.SUBSCRIPTION = ITER.SUBSCRIPTION || {}; 6 7// Funciones para la tienda 8ITER.SUBSCRIPTION.SHOP = ITER.SUBSCRIPTION.SHOP || (function() { 9 10 //Configuración 11 var config = { 12 shopDomain: null, 13 frameUrl: null 14 }; 15 16 return { 17 setConfig: function(iframePageUrl, shopDomain) { 18 config.frameUrl = iframePageUrl; 19 config.shopDomain = shopDomain; 20 }, 21 login: function(iframePageUrl) { 22 var pageUrl = typeof iframePageUrl !== 'undefined' ? iframePageUrl : config.frameUrl; 23 document.location.href = pageUrl + '?page=login&redirect=' + encodeURIComponent(document.location.href); 24 }, 25 logout: function() { 26 // Logout en Iter 27 jQuery.ajax({ 28 type: "POST", 29 url: "/restapi/user/logout", 30 dataType: "json", 31 error: function(xhr, status, error) { 32 alert(error); 33 }, 34 success: function(data) { 35 var exception = data.exception; 36 if(!exception) 37 { 38 // Logout en PrestaShop 39 if (typeof data.shopUrl !== 'undefined') 40 document.location.href = data.shopUrl + "/?mylogout=&redirect=" + encodeURIComponent(document.location.href); 41 } 42 else 43 { 44 alert(exception); 45 } 46 } 47 }); 48 }, 49 account: function(iframePageUrl) { 50 var pageUrl = typeof iframePageUrl !== 'undefined' ? iframePageUrl : config.frameUrl; 51 pageUrl += '?page=account'; 52 pageUrl = "/user-portlet/refreshuserentitlements?redirect=" + encodeURIComponent(pageUrl); 53 document.location.href = pageUrl; 54 }, 55 catalog: function(iframePageUrl) { 56 var pageUrl = typeof iframePageUrl !== 'undefined' ? iframePageUrl : config.frameUrl; 57 document.location.href = pageUrl + '?page=catalog&redirect=' + encodeURIComponent(document.location.href); 58 }, 59 buy: function(idProduct, iframePageUrl) { 60 var pageUrl = typeof iframePageUrl !== 'undefined' ? iframePageUrl : config.frameUrl; 61 document.location.href = pageUrl + '?page=buy&product=' + idProduct + '&redirect=' + encodeURIComponent(document.location.href); 62 }, 63 getShipoEndpoint: async(shipoMetod, options) => { 64 if (!config.shopDomain || !config.shopDomain.trim()) { 65 throw new Error('The store domain has not been configured.'); 66 } 67 68 shipoMetod = shipoMetod ? shipoMetod.trim().replace(/^\/|\/$/g, '').trim() : null; 69 if (!shipoMetod) { 70 throw new Error('No method specified or it is malformed.'); 71 } 72 73 // Pide a eCDXP la información de la URL del WS de Shipo. 74 const response = await fetch(`/_ecdxp_/${config.shopDomain}/api/shipo/url`, {mode: 'cors', credentials: 'include'}); 75 const shipoUrl = await response.json(); 76 if (!Object.hasOwn(shipoUrl, "scheme") || !Object.hasOwn(shipoUrl, "host") || !Object.hasOwn(shipoUrl, "path")) { 77 throw new Error('The URL returned by eCDXP is invalid.'); 78 } 79 80 // Calcula el prefijo ssl del path. 81 const sslPath = shipoUrl.scheme === 'https' ? '_shipapis_' : '_shipapi_'; 82 83 // Crea la URL inicial. 84 85 let url = (new URL(window.location.href)).origin + `/_ecdxp_/${config.shopDomain}/${sslPath}/${shipoUrl.host}${shipoUrl.path}/${shipoMetod}`; 86 87 // Comprueba si llegan parámetros. 88 if (typeof options === 'object') { 89 // Le añade los parámetros del path si llega alguno. 90 if (Object.hasOwn(options, "pathVariables")) {
91 options.pathVariables.forEach(pathVariable => { 92 pathVariable = encodeURIComponent(pathVariable.trim()); 93 if (pathVariable) { 94 url += `/${pathVariable}`; 95 } 96 }); 97 } 98 // Le añade los parámetros del query string si llega alguno. 99 if (Object.hasOwn(options, "queryParams")) { 100 const qs = Object.keys(options.queryParams) 101 .filter(param => param && param.trim()) 102 .map(key => encodeURIComponent(key) + '=' + encodeURIComponent(options.queryParams[key])) 103 .join('&'); 104 if (qs) { 105 url += `?${qs}`; 106 } 107 } 108 } 109 110 // Retorna la URL calculada. 111 return url; 112 } 113 }; 114}());
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.