Public Access
Add server location select in pricing section, pre-select best server after ping, pass location in basket JSON payload
This commit is contained in:
@@ -448,16 +448,19 @@ var si = 0,
|
||||
var results = [];
|
||||
var pending = SERVERS.length;
|
||||
|
||||
/* Populate trial form location dropdown */
|
||||
/* Populate trial form AND pricing server location dropdowns */
|
||||
var trialLoc = document.getElementById('trialLocation');
|
||||
if (trialLoc) {
|
||||
SERVERS.forEach(function(s) {
|
||||
var opt = document.createElement('option');
|
||||
opt.value = s.host;
|
||||
opt.textContent = s.city;
|
||||
trialLoc.appendChild(opt);
|
||||
});
|
||||
}
|
||||
var pricingLoc = document.getElementById('pricingServerLocation');
|
||||
[trialLoc, pricingLoc].forEach(function(el) {
|
||||
if (el) {
|
||||
SERVERS.forEach(function(s) {
|
||||
var opt = document.createElement('option');
|
||||
opt.value = s.host;
|
||||
opt.textContent = s.city;
|
||||
el.appendChild(opt);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
SERVERS.forEach(function(s) {
|
||||
pingServer(s.host).then(function(r) {
|
||||
@@ -469,14 +472,18 @@ var si = 0,
|
||||
valid.sort(function(a, b) { return a.time - b.time; });
|
||||
var best = valid[0];
|
||||
var bestServer = SERVERS.filter(function(s) { return s.host === best.host; })[0];
|
||||
/* Preselect best server in trial form */
|
||||
if (trialLoc && bestServer) {
|
||||
for (var i = 0; i < trialLoc.options.length; i++) {
|
||||
if (trialLoc.options[i].value === bestServer.host) {
|
||||
trialLoc.selectedIndex = i;
|
||||
break;
|
||||
/* Preselect best server in trial and pricing forms */
|
||||
if (bestServer) {
|
||||
[trialLoc, pricingLoc].forEach(function(el) {
|
||||
if (el) {
|
||||
for (var i = 0; i < el.options.length; i++) {
|
||||
if (el.options[i].value === bestServer.host) {
|
||||
el.selectedIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
if (bestServer && heroImages[best.host]) {
|
||||
/* Highlight the matching server card */
|
||||
@@ -627,8 +634,10 @@ var si = 0,
|
||||
});
|
||||
})();
|
||||
|
||||
/* Buy Now — POST basket via form, opens checkout in new tab */
|
||||
/* Buy Now — POST basket via form with server location, opens checkout in new tab */
|
||||
window.buyNow = function (productId) {
|
||||
var locSelect = document.getElementById('pricingServerLocation');
|
||||
var location = locSelect ? locSelect.value : '';
|
||||
var form = document.createElement('form');
|
||||
form.method = 'POST';
|
||||
form.action = 'https://ODOO4projects.com/shop/post_basket';
|
||||
@@ -637,7 +646,9 @@ var si = 0,
|
||||
var basket = document.createElement('input');
|
||||
basket.type = 'hidden';
|
||||
basket.name = 'basket';
|
||||
basket.value = JSON.stringify([{ product_id: productId, qty: 1 }]);
|
||||
var item = { product_id: productId, qty: 1 };
|
||||
if (location) { item.location = location; }
|
||||
basket.value = JSON.stringify([item]);
|
||||
form.appendChild(basket);
|
||||
var clear = document.createElement('input');
|
||||
clear.type = 'hidden';
|
||||
|
||||
Reference in New Issue
Block a user