-
Notifications
You must be signed in to change notification settings - Fork 12
/
storefront.ts
155 lines (130 loc) · 8.41 KB
/
storefront.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
* 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.
*/
//█████████████████████████████████████████████████████████████
//―――――――――――――――― Imports ――――――――――――――――
//█████████████████████████████████████████████████████████████
import "@selldone/core-js/utils/service-worker/registerServiceWorker"; // Register service worker:
import {createApp} from "vue";
import StorefrontApp from "./StorefrontApp.vue";
import router from "./router/StorefrontRouter";
import store from "./store/StorefrontStore";
import {i18n} from "./lang/i18n_shop";
import {Language} from "@selldone/core-js/enums/language/Language";
import {
ApplicationExecutorStorefront
} from "@selldone/core-js/models/application/executor/storefront/ApplicationExecutorStorefront.ts";
import {StorefrontSDK} from "@selldone/sdk-storefront";
import StorefrontMixin from "./mixin/StorefrontMixin";
import {CapiCommunity} from "@selldone/sdk-community"; // Register the service worker.
import {VuetifyInstance} from "@selldone/components-vue/plugins/vuetify/vuetify";
//█████████████████████████████████████████████████████████████
//―――――――――――― Selldone® Components ――――――――――――
//█████████████████████████████████████████████████████████████
import {createComponents} from "@selldone/components-vue/components";
// Load fonts:
import "@fortawesome/fontawesome-free/css/all.css"; // Ensure your project is capable of handling css files
import "@selldone/components-vue/style/fonts/material-design-fonts/material-design-icons.scss"; // Ensure your project is capable of handling css files
import "@selldone/components-vue/style/fonts/lang/fa/lang-fa-iransans.css";
import { PageHyper } from "@selldone/page-builder/PageHyperService.ts";
import {SetupPageBuilder} from "@selldone/page-builder/page-builder.ts";
import {SetupService} from "@selldone/core-js/server";
import {Shop} from "@selldone/core-js/models";
const vuetify = VuetifyInstance(i18n);
//█████████████████████████████████████████████████████████████
//―――――――――――――― Global Types ―――――――――――――――
//█████████████████████████████████████████████████████████████
// ━━━ Global Language ━━━
// @ts-ignore
window.$language = Language[i18n.locale] ? Language[i18n.locale] : Language.en;
//━━━ Multi languages support ━━━
window.$i18n_global = i18n.global; // Important! used by styler!
//━━━ Globally keep store ━━━
window.$global_store = store; // Important! used in page builder!
//━━━ Globally keep route ━━━
window.$global_router = router; // Important! used by styler!
//━━━ Globally keep vuetify ━━━
window.$global_vuetify = vuetify; // Important! used by page build dynamic component generator! USE THIS NOW: vuetify=Vue.prototype.$vuetify
// ━━━ App Interface ━━━
window.AppInterface = new ApplicationExecutorStorefront();
// ━━━ Override language packs ━━━
window.OverrideShopLanguagePacks = {};
//█████████████████████████████████████████████████████████████
//――――――――――――― Initialize Vue App ―――――――――――――
//█████████████████████████████████████████████████████████████
// @ts-ignore
const app = createApp(StorefrontApp);
const components = createComponents({});
app.use(components);
//█████████████████████████████████████████████████████████████
//――――――――――― Selldone® Storefront SDK ―――――――――――
//█████████████████████████████████████████████████████████████
// ━━━ Storefront SDK (xapi) ━━━
StorefrontSDK.Setup(); // Set up the Shop SDK.
// ━━━ Community SDK (capi) ━━━
CapiCommunity.Setup(); // Setup community.
//█████████████████████████████████████████████████████████████
//―――――――――――――――― Cookie ―――――――――――――――――
//█████████████████████████████████████████████████████████████
/**
* Sets a token in the cookies and the Authorization header. Also fetches user and shop info.
*
* @param token - The token to set.
* @param expire_date - The expiration date for the token cookie.
*/
window.SetToken = function (
token: string,
expire_date: Date | null = null,
cookie_key: string = "access_token",
): void {
console.log("Set Customer Token!");
window.$cookies.set(
cookie_key,
token,
expire_date ? expire_date.toUTCString() : "",
window.$storefront.prefix_url,
undefined,
false,
);
window.axios.defaults.headers.common["Authorization"] = "Bearer " + token;
(storefrontVueApp as InstanceType<typeof StorefrontMixin>)?.UpdateUserInfo();
(
storefrontVueApp as InstanceType<typeof StorefrontMixin>
)?.fetchBasketAndShop();
};
//█████████████████████████████████████████████████████████████
//―――――――――――――――――― Vue ―――――――――――――――――
//█████████████████████████████████████████████████████████████
// ━━━ Global Mixin ━━━
// @ts-ignore
app.mixin(StorefrontMixin); // Mixin with global helper methods.
// ━━━ Native App Interface ━━━
//require("@selldone/components-vue/plugins/native/NativeAppInterface");
// ━━━ Vue Instance ━━━
app.use(i18n);
app.use(router);
app.use(store);
app.use(vuetify);
//――――――――――――――――――――――――― Page Builder ―――――――――――――――――――――――――
const $PageHyper=PageHyper(app, { mode: "view" });
function isNumericNumber(value) {
return typeof value === "string" && /^\d+$/.test(value.trim());
}
const CUSTOM_HOME = SetupService.GetMetaValue("custom-home") as Shop.Home;
if(CUSTOM_HOME && isNumericNumber(CUSTOM_HOME) && !window.location.pathname?.includes("/product/")/*Fast load product page!*/){
SetupPageBuilder(app, { mode: "view" });
$PageHyper.isInitialized.value = true;
console.log("⚡ Turbo loading landing page.")
}
// Mount the application
const storefrontVueApp = app.mount("#app");