@selldone/sdk-storefront
Version:
A TypeScript SDK to connect to your shop and build a fully functional storefront and website by simply developing a frontend web application. All backend operations are seamlessly managed by the serverless Selldone solution.
54 lines • 2.38 kB
JavaScript
/*
* Copyright (c) 2023. Selldone® Business OS™
*
* Author: M.Pajuhaan
* Web: https://selldone.com
* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
*
* All rights reserved. In the weave of time, where traditions and innovations intermingle, this content was crafted.
* From the essence of thought, through the corridors of creativity, each word, and sentiment has been molded.
* Not just to exist, but to inspire. Like an artist's stroke or a sculptor's chisel, every nuance is deliberate.
* Our journey is not just about reaching a destination, but about creating a masterpiece.
* Tread carefully, for you're treading on dreams.
*/
import { StorefrontLocalStorages } from "@selldone/core-js/helper/local-storage/StorefrontLocalStorages";
import { Currency } from "@selldone/core-js/enums/payment/Currency";
import { SetupService } from "@selldone/core-js/server/SetupService";
import { TrackConfig } from "@selldone/core-js/enums/gtag/TrackConfig";
export class CurrencyDatabase {
/** Name of the shop for which the API operations will be performed. */
shop_name;
constructor(shop_name) {
this.shop_name = shop_name;
}
getCurrency() {
const _base_path = `shop/@${this.shop_name}/`;
// Try to read from local storage:
const user_currency = localStorage.getItem(StorefrontLocalStorages.GetUserCurrencyPath(_base_path));
if (user_currency && Currency[user_currency]) {
return Currency[user_currency];
}
// Get from meta header (set by server side)
const _default_code = SetupService.DefaultCurrency();
if (!_default_code)
return Currency.USD;
return Currency[_default_code];
}
saveCurrency(currency) {
let currencyCode;
if (!currency)
return;
if (typeof currency === "string") {
currencyCode = currency;
}
else {
currencyCode = currency.code;
}
const _base_path = `shop/@${this.shop_name}/`;
localStorage.setItem(
// @ts-ignore
StorefrontLocalStorages.GetUserCurrencyPath(_base_path), currencyCode);
TrackConfig.SetCurrency(currencyCode);
}
}
//# sourceMappingURL=currency.database.js.map