Skip to content

Commit

Permalink
Merge branch 'dex-20840-vlaicu-implementation' into dex-20840-vlaicu-…
Browse files Browse the repository at this point in the history
…stage
  • Loading branch information
iconstantin-bd committed Dec 11, 2024
2 parents 8cb6c0d + c044bb6 commit 0ef6f9c
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions _src/scripts/libs/store/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -764,19 +764,19 @@ export class Product {
}

class BitCheckout {
static cachedZuoraConfig = this.#fetchZuoraConfig();
static #cachedZuoraConfig = null;

static async #fetchZuoraConfig() {
const defaultJsonFilePath = '/zuoraconfig.json';
const jsonFilePath = window.location.hostname === 'www.bitdefender.com'
? `https://${window.location.hostname}/pages/zuoraconfig.json`
: defaultJsonFilePath;
static async fetchZuoraConfig() {
if (this.#cachedZuoraConfig) {
return this.#cachedZuoraConfig
}

try {
const response = await fetch(jsonFilePath);
const response = await fetch(`${Constants.PUBLIC_URL_ORIGIN}/nl-nl/consumer/zuoraconfig.json`);

if (!response.ok) {
console.error(`Failed to fetch data. Status: ${response.status}`);
this.#cachedZuoraConfig = {};
return {};
}

Expand All @@ -799,10 +799,11 @@ class BitCheckout {
}
});

this.cachedZuoraConfig = zuoraConfigData;
this.#cachedZuoraConfig = zuoraConfigData;
return zuoraConfigData;
} catch (error) {
console.error(`Error fetching Zuora config: ${error.message}`);
this.#cachedZuoraConfig = {};
return {};
}
}
Expand Down Expand Up @@ -974,7 +975,7 @@ class BitCheckout {
window.StoreProducts = window.StoreProducts || [];
window.StoreProducts.product = window.StoreProducts.product || {}

const fetchedData = await this.cachedZuoraConfig;
const fetchedData = await this.fetchZuoraConfig();
if (campaign) fetchedData.CAMPAIGN_NAME = campaign;
return await this.getProductVariationsPrice(id, fetchedData);
}
Expand Down Expand Up @@ -1170,7 +1171,7 @@ class StoreConfig {
return Store.NO_PROMOTION;
}

const fetchedData = await BitCheckout.cachedZuoraConfig;
const fetchedData = await BitCheckout.fetchZuoraConfig();
if (!Object.keys(fetchedData).length) {
console.error(`Failed to fetch data.`);
return Store.NO_PROMOTION;
Expand Down

0 comments on commit 0ef6f9c

Please sign in to comment.