fix: improve storage matching for instant deploy button

- Require exact capacity match for storage matching (score >= 100)
- Fallback to URL preselected values if no match found
- Remove excessive debug logging
- Ensure configIds contains all selected storage IDs

This should fix the issue where the deploy button after customization
showed incorrect storage configuration in WHMCS.

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Claude
2025-12-06 02:23:36 +04:00
Unverified
parent db556e532e
commit 51f036c6f2

View File

@@ -4281,16 +4281,12 @@ var wpcf7 = {
// Map requirements to available storage options // Map requirements to available storage options
let reqIndex = 0; let reqIndex = 0;
console.log("Total options:", options.length);
console.log("Options by type:", options.map(o => ({id: o.id, type: o.type, label: o.label})));
options.forEach(opt => { options.forEach(opt => {
let selectedValId = null; let selectedValId = null;
console.log(`Processing option ${opt.id}: type=${opt.type}, label=${opt.label}`);
if (opt.type === 'storage' && reqIndex < storageReqs.length) { if (opt.type === 'storage' && reqIndex < storageReqs.length) {
const req = storageReqs[reqIndex]; const req = storageReqs[reqIndex];
console.log(` Requirement ${reqIndex}: ${req.qty}x ${req.spec}`);
let bestMatch = null; let bestMatch = null;
let bestScore = 0; let bestScore = 0;
@@ -4300,51 +4296,40 @@ var wpcf7 = {
const valText = val.text.toLowerCase(); const valText = val.text.toLowerCase();
const reqSpec = req.spec.toLowerCase(); const reqSpec = req.spec.toLowerCase();
console.log(` Checking value: ${val.text} (ID: ${val.id})`); // Check capacity match (exact match required)
// Check capacity match
const valCap = valText.match(/(\d+(?:\.\d+)?)\s*tb/i); const valCap = valText.match(/(\d+(?:\.\d+)?)\s*tb/i);
const reqCap = reqSpec.match(/(\d+(?:\.\d+)?)\s*tb/i); const reqCap = reqSpec.match(/(\d+(?:\.\d+)?)\s*tb/i);
if (valCap && reqCap && valCap[1] === reqCap[1]) { if (valCap && reqCap && valCap[1] === reqCap[1]) {
score += 100; score += 100;
console.log(` ✓ Capacity match: ${valCap[1]}TB`);
} }
// Check brand match // Check brand match
if (valText.includes('crucial') && reqSpec.includes('crucial')) { if (valText.includes('crucial') && reqSpec.includes('crucial')) score += 50;
score += 50; if (valText.includes('kioxia') && reqSpec.includes('kioxia')) score += 50;
console.log(` ✓ Brand match: Crucial`); if (valText.includes('samsung') && reqSpec.includes('samsung')) score += 50;
}
if (valText.includes('kioxia') && reqSpec.includes('kioxia')) {
score += 50;
console.log(` ✓ Brand match: Kioxia`);
}
// Check model match // Check model match
if (valText.includes('t705') && reqSpec.includes('t705')) { if (valText.includes('t705') && reqSpec.includes('t705')) score += 50;
score += 50; if (valText.includes('cm7') && reqSpec.includes('cm7')) score += 50;
console.log(` ✓ Model match: T705`);
}
if (valText.includes('cm7') && reqSpec.includes('cm7')) {
score += 50;
console.log(` ✓ Model match: CM7`);
}
console.log(` Score: ${score}`);
if (score > bestScore) { if (score > bestScore) {
bestScore = score; bestScore = score;
bestMatch = val; bestMatch = val;
} }
}); });
console.log(` Best match for ${opt.id}: score=${bestScore}`); if (bestMatch && bestScore >= 100) {
if (bestMatch && bestScore > 100) {
selectedValId = bestMatch.id; selectedValId = bestMatch.id;
preselected[opt.id] = selectedValId; preselected[opt.id] = selectedValId;
console.log(`✓ Storage option ${opt.id} (${opt.label}): selected ${selectedValId} (${bestMatch.text})`);
reqIndex++; reqIndex++;
} else { } else {
console.log(`✗ No suitable match found for ${opt.id}`); // If no match found, try to use URL preselected value
if (preselected[opt.id]) {
const urlMatch = opt.values.find(v => v.id === preselected[opt.id]);
if (urlMatch) {
selectedValId = preselected[opt.id];
}
}
} }
} else if (opt.type !== 'storage' && preselected[opt.id]) { } else if (opt.type !== 'storage' && preselected[opt.id]) {
// Use preselected IDs for non-storage options // Use preselected IDs for non-storage options
@@ -4898,9 +4883,6 @@ var wpcf7 = {
// Fill slots based on storage requirements // Fill slots based on storage requirements
if (storageRequirements && storageRequirements.length > 0) { if (storageRequirements && storageRequirements.length > 0) {
console.log("Pre-filling storage with requirements:", storageRequirements);
console.log("Initial configIds before pre-filling:", configIds);
// Clear storageSelection to start fresh // Clear storageSelection to start fresh
storageSelection = {}; storageSelection = {};
@@ -4965,8 +4947,7 @@ var wpcf7 = {
} }
}); });
console.log("Final storageSelection:", storageSelection); }
console.log("Final configIds after pre-filling:", configIds);
} }
} else { } else {
// Pre-set configState for custom servers // Pre-set configState for custom servers
@@ -5469,25 +5450,18 @@ var wpcf7 = {
const urlObj = new URL(selectedServer.orderUrl); const urlObj = new URL(selectedServer.orderUrl);
const params = urlObj.searchParams; const params = urlObj.searchParams;
console.log("Building Instant Order URL - ConfigIds:", configIds);
console.log("Building Instant Order URL - Storage Selection:", storageSelection);
// Update only the configuration options that are tracked in configIds // Update only the configuration options that are tracked in configIds
Object.entries(configIds).forEach(([id, val]) => { Object.entries(configIds).forEach(([id, val]) => {
if (id && val) { if (id && val) {
// WHMCS format: configoption[123] // WHMCS format: configoption[123]
params.set(`configoption[${id}]`, val); params.set(`configoption[${id}]`, val);
console.log(`Setting configoption[${id}] = ${val}`);
} }
}); });
// Ensure billing cycle is enforced // Ensure billing cycle is enforced
params.set('billingcycle', 'monthly'); params.set('billingcycle', 'monthly');
const finalUrl = urlObj.toString(); return urlObj.toString();
console.log("Final Instant Order URL:", finalUrl);
return finalUrl;
} catch (e) { } catch (e) {
console.error("Error building instant URL:", e); console.error("Error building instant URL:", e);
return selectedServer.orderUrl; return selectedServer.orderUrl;