@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.
47 lines • 2.17 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";
export class CouponDatabase {
/** Name of the shop for which the API operations will be performed. */
shop_name;
constructor(shop_name) {
this.shop_name = shop_name;
}
getCouponCodes() {
const raw = localStorage.getItem(StorefrontLocalStorages.GetShopCouponsCodes(window.$storefront.local_storage_path));
if (raw)
try {
const arr = JSON.parse(raw);
if (arr && Array.isArray(arr))
return arr;
}
catch (e) {
console.error(e);
}
return [];
}
addCouponCode(code) {
const codes = window.$storefront.database.coupon.getCouponCodes();
if (!codes.includes(code))
codes.push(code);
localStorage.setItem(StorefrontLocalStorages.GetShopCouponsCodes(window.$storefront.local_storage_path), JSON.stringify(codes));
}
removeCouponCode(code) {
const codes = window.$storefront.database.coupon.getCouponCodes();
if (codes.includes(code))
codes.splice(codes.indexOf(code), 1);
localStorage.setItem(StorefrontLocalStorages.GetShopCouponsCodes(window.$storefront.local_storage_path), JSON.stringify(codes));
}
}
//# sourceMappingURL=coupon.database.js.map