retrieve storage price from db
This commit is contained in:
parent
c8c224cfb8
commit
8bb8930361
2 changed files with 45 additions and 4 deletions
|
@ -6,7 +6,7 @@
|
|||
class PriceCalculator {
|
||||
constructor() {
|
||||
this.pricingData = null;
|
||||
this.storagePrice = 0.15; // CHF per GB per month
|
||||
this.storagePrice = null;
|
||||
this.currentOffering = null;
|
||||
this.selectedConfiguration = null;
|
||||
this.init();
|
||||
|
@ -145,6 +145,10 @@ Please contact me with next steps for ordering this configuration.`;
|
|||
}
|
||||
|
||||
this.pricingData = await response.json();
|
||||
|
||||
// Extract storage price from the first available plan
|
||||
this.extractStoragePrice();
|
||||
|
||||
this.setupEventListeners();
|
||||
this.populatePlanDropdown();
|
||||
this.updatePricing();
|
||||
|
@ -154,6 +158,23 @@ Please contact me with next steps for ordering this configuration.`;
|
|||
}
|
||||
}
|
||||
|
||||
// Extract storage price from pricing data
|
||||
extractStoragePrice() {
|
||||
if (!this.pricingData) return;
|
||||
|
||||
// Find the first plan with storage pricing data
|
||||
for (const groupName of Object.keys(this.pricingData)) {
|
||||
const group = this.pricingData[groupName];
|
||||
for (const serviceLevel of Object.keys(group)) {
|
||||
const plans = group[serviceLevel];
|
||||
if (plans.length > 0 && plans[0].storage_price !== undefined) {
|
||||
this.storagePrice = parseFloat(plans[0].storage_price);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Setup event listeners for calculator controls
|
||||
setupEventListeners() {
|
||||
if (!this.cpuRange || !this.memoryRange || !this.storageRange) return;
|
||||
|
@ -437,11 +458,14 @@ Please contact me with next steps for ordering this configuration.`;
|
|||
if (this.planMemory) this.planMemory.textContent = plan.ram + ' GB';
|
||||
if (this.planServiceLevel) this.planServiceLevel.textContent = serviceLevel;
|
||||
|
||||
// Calculate pricing
|
||||
// Calculate pricing using storage price from the plan data
|
||||
const computePriceValue = parseFloat(plan.compute_plan_price);
|
||||
const servicePriceValue = parseFloat(plan.sla_price);
|
||||
const managedServicePrice = computePriceValue + servicePriceValue;
|
||||
const storagePriceValue = storage * this.storagePrice;
|
||||
|
||||
// Use storage price from plan data or fallback to instance variable
|
||||
const storageUnitPrice = plan.storage_price !== undefined ? parseFloat(plan.storage_price) : this.storagePrice;
|
||||
const storagePriceValue = storage * storageUnitPrice;
|
||||
const totalPriceValue = managedServicePrice + storagePriceValue;
|
||||
|
||||
// Update pricing display
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue