Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dex 20840 vlaicu stage #441

Merged
merged 4 commits into from
Dec 11, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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