xhr.ontimeout = onError; xhr.onerror = onError; xhr.open('GET', apiUrl); xhr.timeout = 20000; xhr.send();}/** * An array of product IDs and returns an array of products * * @param {Array} idArr - array of product ids * @param {object} options * @param {Function} onDone - callback on success * @param {Function} onFail - callback on error **/function t_store_loadProducts_byId(idArr, options, onDone, onFail) { var c = Date.now(); var dataObj = { productsuid: idArr, c: c, }; var apiUrl = 'https://' + window.t_store_endpoint + '/api/getproductsbyuid/'; // inside tilda we get data from another url if (options && !options.isPublishedPage) { dataObj.projectid = document.getElementById('allrecords').getAttribute('data-tilda-project-id'); var domainParts = window.location.hostname.split('.'); var link = 'tilda.' + domainParts[domainParts.length - 1]; apiUrl = 'https://' + link + '/projects/store/getproductsbyuid/'; } dataObj = JSON.stringify(dataObj); var xhr = new XMLHttpRequest(); xhr.onload = function () { if (xhr.readyState === xhr.DONE && xhr.status === 200) { if (typeof xhr.responseText !== 'string' || xhr.responseText.substring(0, 1) !== '{') { console.error("Can't get products array by uid list"); } if (t_store__handleRootzoneRedirect(xhr.responseText, apiUrl)) { t_store_loadProducts_byId(idArr, options, onDone, onFail); return; } onDone(JSON.parse(xhr.responseText)); } }; function onError(error) { console.error("Can't get getproductsbyuid. Requesting idArr: " + idArr); if (typeof onFail === 'function') { onFail(error); } } xhr.ontimeout = onError; xhr.onerror = onError; xhr.open('POST', apiUrl); xhr.timeout = 20000; xhr.send(dataObj);}/** * Sends a request to the server to get the filters for the store part * * @param {object} options * @param {Function} onDone - callback on success * @param {Function} onFail - callback on error **/function t_store_loadFilters(options, onDone, onFail) { var c = Date.now(); var storepartuid = options.storepart; var dataObj = { storepartuid: storepartuid, c: c, }; var allRecords = document.getElementById('allrecords'); if (options && options.defaultSort && options.defaultSort.in_stock) { if (!dataObj.filters) dataObj.filters = {}; dataObj.filters['quantity'] = 'y'; }