cloudcommerce 2.2.2 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/ecomplus-stores/barra-doce/functions/many/package.json +3 -3
- package/ecomplus-stores/barra-doce/functions/ssr/package.json +6 -6
- package/ecomplus-stores/barra-doce/functions/with-apps/package.json +3 -3
- package/ecomplus-stores/barra-doce/package.json +2 -2
- package/package.json +2 -2
- package/packages/api/package.json +1 -1
- package/packages/apps/affiliate-program/package.json +1 -1
- package/packages/apps/correios/package.json +1 -1
- package/packages/apps/custom-payment/package.json +1 -1
- package/packages/apps/custom-shipping/package.json +1 -1
- package/packages/apps/datafrete/package.json +1 -1
- package/packages/apps/discounts/package.json +1 -1
- package/packages/apps/emails/package.json +1 -1
- package/packages/apps/fb-conversions/package.json +1 -1
- package/packages/apps/flash-courier/package.json +1 -1
- package/packages/apps/frenet/package.json +1 -1
- package/packages/apps/galaxpay/package.json +1 -1
- package/packages/apps/google-analytics/package.json +1 -1
- package/packages/apps/jadlog/package.json +1 -1
- package/packages/apps/loyalty-points/package.json +1 -1
- package/packages/apps/mandae/package.json +1 -1
- package/packages/apps/melhor-envio/package.json +1 -1
- package/packages/apps/mercadopago/package.json +1 -1
- package/packages/apps/pagarme/package.json +1 -1
- package/packages/apps/pagarme-v5/package.json +1 -1
- package/packages/apps/paghiper/package.json +1 -1
- package/packages/apps/pix/package.json +1 -1
- package/packages/apps/tiny-erp/package.json +1 -1
- package/packages/apps/webhooks/package.json +1 -1
- package/packages/cli/package.json +1 -1
- package/packages/config/package.json +1 -1
- package/packages/emails/package.json +1 -1
- package/packages/eslint/package.json +1 -1
- package/packages/events/package.json +1 -1
- package/packages/feeds/package.json +1 -1
- package/packages/firebase/package.json +1 -1
- package/packages/i18n/package.json +1 -1
- package/packages/modules/lib/firebase/handle-module.js +28 -7
- package/packages/modules/lib/firebase/handle-module.js.map +1 -1
- package/packages/modules/package.json +1 -1
- package/packages/modules/src/firebase/handle-module.ts +37 -9
- package/packages/passport/package.json +1 -1
- package/packages/ssr/lib/lib/cron-ssr-save-views.js +11 -3
- package/packages/ssr/lib/lib/cron-ssr-save-views.js.map +1 -1
- package/packages/ssr/package.json +2 -2
- package/packages/ssr/src/lib/cron-ssr-save-views.ts +14 -3
- package/packages/storefront/package.json +2 -2
- package/packages/storefront/src/helpers/afetch.ts +22 -5
- package/packages/storefront/src/lib/composables/use-pagination.ts +1 -1
- package/packages/storefront/src/lib/composables/use-shipping-calculator.ts +273 -0
- package/packages/storefront/src/lib/scripts/push-analytics-events.ts +1 -1
- package/packages/storefront/src/lib/state/modules-info.ts +34 -10
- package/packages/test-base/package.json +1 -1
- package/packages/types/index.ts +82 -53
- package/packages/types/package.json +1 -1
|
@@ -89,12 +89,15 @@ const saveViews = async () => {
|
|
|
89
89
|
const pageViewsSnapshot = await db.collection('ssrPageViews')
|
|
90
90
|
.where('at', '>', new Date(Date.now() - 1000 * 60 * 20))
|
|
91
91
|
.where('at', '<', new Date(Date.now() - 1000 * sMaxAge))
|
|
92
|
-
.where('isCachePurged', '!=', true)
|
|
93
92
|
.get();
|
|
94
93
|
const purgedUrls = [];
|
|
95
94
|
for (let i = 0; i < pageViewsSnapshot.docs.length; i++) {
|
|
96
95
|
const doc = pageViewsSnapshot.docs[i];
|
|
97
|
-
const { url } = doc.data();
|
|
96
|
+
const { url, isCachePurged } = doc.data();
|
|
97
|
+
if (isCachePurged) {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
doc.ref.update({ isCachePurged: true });
|
|
98
101
|
if (url?.startsWith(`https://${domain}`) && !purgedUrls.includes(url)) {
|
|
99
102
|
await bunnyAxios('/purge', {
|
|
100
103
|
method: 'POST',
|
|
@@ -126,7 +129,6 @@ const saveViews = async () => {
|
|
|
126
129
|
if (err.response?.status !== 404) throw err;
|
|
127
130
|
});
|
|
128
131
|
}
|
|
129
|
-
doc.ref.update({ isCachePurged: true });
|
|
130
132
|
}
|
|
131
133
|
}
|
|
132
134
|
} catch (err) {
|
|
@@ -141,6 +143,12 @@ const saveViews = async () => {
|
|
|
141
143
|
}
|
|
142
144
|
}
|
|
143
145
|
}
|
|
146
|
+
const date = new Date();
|
|
147
|
+
if (date.getHours() > 1) return;
|
|
148
|
+
if (!process.env.CRONTAB_SSR_SAVE_VIEWS) {
|
|
149
|
+
const dateMinutes = date.getMinutes();
|
|
150
|
+
if (dateMinutes < 48 || dateMinutes > 50) return;
|
|
151
|
+
}
|
|
144
152
|
const pageViewsQuery = db.collection('ssrPageViews')
|
|
145
153
|
.where('at', '<', new Date(Date.now() - 1000 * 60 * 60 * 24 * 90));
|
|
146
154
|
await deleteQueryBatch(db, pageViewsQuery);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cron-ssr-save-views.js","sourceRoot":"","sources":["../../src/lib/cron-ssr-save-views.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAClD,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,GAAG,MAAM,oBAAoB,CAAC;AACrC,OAAO,MAAM,MAAM,oCAAoC,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+CAA+C,CAAC;AAEjF,MAAM,SAAS,GAAG,KAAK,IAAI,EAAE;IAC3B,qCAAqC;IACrC,MAAM,EAAE,GAAG,YAAY,EAAE,CAAC;IAC1B,MAAM,oBAAoB,GAAG,MAAM,EAAE,CAAC,UAAU,CAAC,iBAAiB,CAAC;SAChE,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;IACpB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,oBAAoB,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACzD,MAAM,GAAG,GAAG,oBAAoB,CAAC,IAAI,CAAC,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,GAAG,EAAE,GAAG,IAAI,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC;IACrE,MAAM,gBAAgB,CAAC,EAAE,EAAE,cAAc,CAAC,CAAC;AAC7C,CAAC,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudcommerce/ssr",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.3.0",
|
|
5
5
|
"description": "E-Com Plus Cloud Commerce storefront SSR",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"exports": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@cloudcommerce/i18n": "workspace:*",
|
|
33
33
|
"@ecomplus/utils": "1.5.0-rc.6",
|
|
34
34
|
"@vueuse/core": "10.7.2",
|
|
35
|
-
"astro": "4.2.
|
|
35
|
+
"astro": "4.2.8",
|
|
36
36
|
"astro-capo": "^0.0.1",
|
|
37
37
|
"axios": "^1.6.7",
|
|
38
38
|
"firebase-admin": "^12.0.0",
|
|
@@ -91,12 +91,18 @@ const saveViews = async () => {
|
|
|
91
91
|
const pageViewsSnapshot = await db.collection('ssrPageViews')
|
|
92
92
|
.where('at', '>', new Date(Date.now() - 1000 * 60 * 20))
|
|
93
93
|
.where('at', '<', new Date(Date.now() - 1000 * sMaxAge))
|
|
94
|
-
.where('isCachePurged', '!=', true)
|
|
95
94
|
.get();
|
|
96
95
|
const purgedUrls: string[] = [];
|
|
97
96
|
for (let i = 0; i < pageViewsSnapshot.docs.length; i++) {
|
|
98
97
|
const doc = pageViewsSnapshot.docs[i];
|
|
99
|
-
const {
|
|
98
|
+
const {
|
|
99
|
+
url,
|
|
100
|
+
isCachePurged,
|
|
101
|
+
} = doc.data() as { url: string, isCachePurged?: true };
|
|
102
|
+
if (isCachePurged) {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
doc.ref.update({ isCachePurged: true });
|
|
100
106
|
if (url?.startsWith(`https://${domain}`) && !purgedUrls.includes(url)) {
|
|
101
107
|
await bunnyAxios('/purge', {
|
|
102
108
|
method: 'POST',
|
|
@@ -128,7 +134,6 @@ const saveViews = async () => {
|
|
|
128
134
|
if (err.response?.status !== 404) throw err;
|
|
129
135
|
});
|
|
130
136
|
}
|
|
131
|
-
doc.ref.update({ isCachePurged: true });
|
|
132
137
|
}
|
|
133
138
|
}
|
|
134
139
|
} catch (err: any) {
|
|
@@ -143,6 +148,12 @@ const saveViews = async () => {
|
|
|
143
148
|
}
|
|
144
149
|
}
|
|
145
150
|
}
|
|
151
|
+
const date = new Date();
|
|
152
|
+
if (date.getHours() > 1) return;
|
|
153
|
+
if (!process.env.CRONTAB_SSR_SAVE_VIEWS) {
|
|
154
|
+
const dateMinutes = date.getMinutes();
|
|
155
|
+
if (dateMinutes < 48 || dateMinutes > 50) return;
|
|
156
|
+
}
|
|
146
157
|
const pageViewsQuery = db.collection('ssrPageViews')
|
|
147
158
|
.where('at', '<', new Date(Date.now() - 1000 * 60 * 60 * 24 * 90));
|
|
148
159
|
await deleteQueryBatch(db, pageViewsQuery);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudcommerce/storefront",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.3.0",
|
|
5
5
|
"description": "E-Com Plus Cloud Commerce storefront with Astro",
|
|
6
6
|
"bin": {
|
|
7
7
|
"storefront": "./scripts/build-prod.sh"
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"@types/gtag.js": "^0.0.18",
|
|
44
44
|
"@vite-pwa/astro": "^0.2.0",
|
|
45
45
|
"@vueuse/core": "10.7.2",
|
|
46
|
-
"astro": "4.2.
|
|
46
|
+
"astro": "4.2.8",
|
|
47
47
|
"astro-capo": "^0.0.1",
|
|
48
48
|
"chroma-js": "^2.4.2",
|
|
49
49
|
"dotenv": "^16.4.1",
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
type FetchParams = Parameters<typeof fetch>;
|
|
2
2
|
type RequestInit = Exclude<FetchParams[1], undefined>;
|
|
3
3
|
type BodyInit = RequestInit['body'] | Record<string, any> | Array<any>;
|
|
4
|
+
type AFetchInit = Omit<RequestInit, 'body'> & {
|
|
5
|
+
body?: BodyInit,
|
|
6
|
+
params?: Record<string, string | number | (string | number)[]>,
|
|
7
|
+
};
|
|
4
8
|
|
|
5
|
-
const afetch = (
|
|
6
|
-
url: FetchParams[0],
|
|
7
|
-
init?: Omit<RequestInit, 'body'> & { body?: BodyInit },
|
|
8
|
-
timeout = 10000,
|
|
9
|
-
) => {
|
|
9
|
+
const afetch = (url: FetchParams[0], init?: AFetchInit, timeout = 10000) => {
|
|
10
10
|
let abortController: AbortController | undefined;
|
|
11
11
|
let timer: NodeJS.Timeout | undefined;
|
|
12
12
|
if (timeout) {
|
|
@@ -28,6 +28,23 @@ const afetch = (
|
|
|
28
28
|
body = init.body;
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
+
if (init?.params && typeof url === 'string') {
|
|
32
|
+
let query = '';
|
|
33
|
+
Object.keys(init.params).forEach((key) => {
|
|
34
|
+
const value: string | number | (string | number)[] = init.params![key];
|
|
35
|
+
if (Array.isArray(value)) {
|
|
36
|
+
value.forEach((val) => {
|
|
37
|
+
query += `&${key}=${val}`;
|
|
38
|
+
});
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
query += `&${key}=${value}`;
|
|
42
|
+
});
|
|
43
|
+
if (query) {
|
|
44
|
+
if (!url.includes('?')) url += `?${query.slice(1)}`;
|
|
45
|
+
else url += query;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
31
48
|
const promise = fetch(url, {
|
|
32
49
|
...init,
|
|
33
50
|
body,
|
|
@@ -56,7 +56,7 @@ const usePagination = (props: Props) => {
|
|
|
56
56
|
});
|
|
57
57
|
|
|
58
58
|
const baseUrl = ref('');
|
|
59
|
-
watch(toRef(props
|
|
59
|
+
watch(toRef(props, 'isUrlPath'), () => {
|
|
60
60
|
const url = import.meta.env.SSR
|
|
61
61
|
? global.astroUrl
|
|
62
62
|
: new URL(window.location.toString());
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import type { Ref } from 'vue';
|
|
2
|
+
import type {
|
|
3
|
+
Products,
|
|
4
|
+
Carts,
|
|
5
|
+
CalculateShippingParams,
|
|
6
|
+
CalculateShippingResponse,
|
|
7
|
+
ModuleApiResult,
|
|
8
|
+
} from '@cloudcommerce/types';
|
|
9
|
+
import {
|
|
10
|
+
ref,
|
|
11
|
+
computed,
|
|
12
|
+
shallowReactive,
|
|
13
|
+
watch,
|
|
14
|
+
toRef,
|
|
15
|
+
} from 'vue';
|
|
16
|
+
import { useDebounceFn, watchOnce } from '@vueuse/core';
|
|
17
|
+
import { price as getPrice } from '@ecomplus/utils';
|
|
18
|
+
import config from '@cloudcommerce/config';
|
|
19
|
+
import { fetchModule } from '@@sf/state/modules-info';
|
|
20
|
+
|
|
21
|
+
export type ShippedItem = Exclude<CalculateShippingParams['items'], undefined>[0];
|
|
22
|
+
|
|
23
|
+
export type ShippingService = CalculateShippingResponse['shipping_services'][0];
|
|
24
|
+
|
|
25
|
+
type CartOrProductItem = Carts['items'][0] | (Partial<Products> & {
|
|
26
|
+
product_id: string & { length: 24 },
|
|
27
|
+
price: number,
|
|
28
|
+
quantity: number,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export interface Props {
|
|
32
|
+
zipInput?: Ref<HTMLInputElement | null>;
|
|
33
|
+
zipCode?: string;
|
|
34
|
+
canSelectService?: boolean;
|
|
35
|
+
countryCode?: string;
|
|
36
|
+
shippedItems?: (ShippedItem | CartOrProductItem)[];
|
|
37
|
+
shippingResult?: ModuleApiResult<'calculate_shipping'>['result'];
|
|
38
|
+
baseParams?: Partial<CalculateShippingParams>;
|
|
39
|
+
skippedAppIds?: number[];
|
|
40
|
+
appIdsOrder?: number[];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const localStorage = typeof window === 'object' && window.localStorage;
|
|
44
|
+
|
|
45
|
+
export const ZIP_STORAGE_KEY = 'shipping-to-zip';
|
|
46
|
+
|
|
47
|
+
const sortApps = (results: any, order: number[]) => {
|
|
48
|
+
return results.sort((a: any, b: any) => {
|
|
49
|
+
if (a.app_id === b.app_id) {
|
|
50
|
+
return 0;
|
|
51
|
+
}
|
|
52
|
+
const indexA = order.indexOf(a.app_id);
|
|
53
|
+
const indexB = order.indexOf(b.app_id);
|
|
54
|
+
if (indexA > -1) {
|
|
55
|
+
if (indexB > -1) {
|
|
56
|
+
return indexA < indexB ? -1 : 1;
|
|
57
|
+
}
|
|
58
|
+
return -1;
|
|
59
|
+
}
|
|
60
|
+
if (indexB > -1) return 1;
|
|
61
|
+
return 0;
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
const reduceItemBody = (itemOrProduct: Record<string, any>) => {
|
|
65
|
+
const shippedItem = {};
|
|
66
|
+
const fields: (keyof ShippedItem)[] = [
|
|
67
|
+
'product_id',
|
|
68
|
+
'variation_id',
|
|
69
|
+
'sku',
|
|
70
|
+
'name',
|
|
71
|
+
'quantity',
|
|
72
|
+
'inventory',
|
|
73
|
+
'currency_id',
|
|
74
|
+
'currency_symbol',
|
|
75
|
+
'price',
|
|
76
|
+
'final_price',
|
|
77
|
+
'dimensions',
|
|
78
|
+
'weight',
|
|
79
|
+
];
|
|
80
|
+
fields.forEach((field) => {
|
|
81
|
+
if (itemOrProduct[field] !== undefined) {
|
|
82
|
+
shippedItem[field] = itemOrProduct[field];
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
return shippedItem as ShippedItem;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export const useShippingCalculator = (props: Props) => {
|
|
89
|
+
const localZipCode = ref(props.zipCode);
|
|
90
|
+
const zipCode = ref<string | null>(null);
|
|
91
|
+
if (!localZipCode.value && localStorage) {
|
|
92
|
+
const storedZip = localStorage.getItem(ZIP_STORAGE_KEY);
|
|
93
|
+
if (storedZip) {
|
|
94
|
+
localZipCode.value = storedZip;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const countryCode = props.countryCode || config.get().countryCode;
|
|
98
|
+
const _shippedItems = toRef(props, 'shippedItems');
|
|
99
|
+
const shippedItems = computed(() => {
|
|
100
|
+
return _shippedItems.value?.map(reduceItemBody) || [];
|
|
101
|
+
});
|
|
102
|
+
const amountSubtotal = computed(() => {
|
|
103
|
+
return shippedItems.value.reduce((subtotal, item) => {
|
|
104
|
+
return subtotal + getPrice(item) * item.quantity;
|
|
105
|
+
}, 0);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
const isFetching = ref(false);
|
|
109
|
+
const fetchShippingServices = useDebounceFn((isRetry?: boolean) => {
|
|
110
|
+
if (isFetching.value) {
|
|
111
|
+
watchOnce((isFetching), (_isFetching) => {
|
|
112
|
+
if (!_isFetching) fetchShippingServices();
|
|
113
|
+
});
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const body: CalculateShippingParams = {
|
|
117
|
+
...props.baseParams,
|
|
118
|
+
to: {
|
|
119
|
+
...props.baseParams?.to,
|
|
120
|
+
zip: localZipCode.value!,
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
if (shippedItems.value.length) {
|
|
124
|
+
body.items = shippedItems.value;
|
|
125
|
+
body.subtotal = amountSubtotal.value;
|
|
126
|
+
}
|
|
127
|
+
isFetching.value = true;
|
|
128
|
+
fetchModule('calculate_shipping', {
|
|
129
|
+
method: 'POST',
|
|
130
|
+
params: {
|
|
131
|
+
skip_ids: props.skippedAppIds,
|
|
132
|
+
},
|
|
133
|
+
body,
|
|
134
|
+
})
|
|
135
|
+
.then(async (response) => {
|
|
136
|
+
const data = await response.json();
|
|
137
|
+
// eslint-disable-next-line no-use-before-define
|
|
138
|
+
parseShippingResult(data.result, isRetry);
|
|
139
|
+
})
|
|
140
|
+
.catch((err) => {
|
|
141
|
+
if (!isRetry) {
|
|
142
|
+
// eslint-disable-next-line no-use-before-define
|
|
143
|
+
scheduleRetry(4000);
|
|
144
|
+
}
|
|
145
|
+
console.error(err);
|
|
146
|
+
})
|
|
147
|
+
.finally(() => {
|
|
148
|
+
isFetching.value = false;
|
|
149
|
+
});
|
|
150
|
+
}, 100);
|
|
151
|
+
let retryTimer: NodeJS.Timeout | null = null;
|
|
152
|
+
const scheduleRetry = (timeout = 10000) => {
|
|
153
|
+
if (retryTimer) clearTimeout(retryTimer);
|
|
154
|
+
retryTimer = setTimeout(() => {
|
|
155
|
+
fetchShippingServices(true);
|
|
156
|
+
}, timeout);
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
const shippingServices = shallowReactive<(ShippingService & { app_id: number })[]>([]);
|
|
160
|
+
const freeFromValue = ref<number | null>(null);
|
|
161
|
+
const hasPaidOption = ref<boolean | undefined>();
|
|
162
|
+
const parseShippingResult = (
|
|
163
|
+
shippingResult: ModuleApiResult<'calculate_shipping'>['result'] = [],
|
|
164
|
+
isRetry = false,
|
|
165
|
+
) => {
|
|
166
|
+
freeFromValue.value = null;
|
|
167
|
+
shippingServices.splice(0);
|
|
168
|
+
if (shippingResult.length) {
|
|
169
|
+
let hasSomeFailedApp = false;
|
|
170
|
+
shippingResult.forEach((appResult) => {
|
|
171
|
+
const { validated, error, response } = appResult;
|
|
172
|
+
if (!validated || error) {
|
|
173
|
+
hasSomeFailedApp = true;
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
if (props.skippedAppIds?.includes(appResult.app_id)) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
response.shipping_services.forEach((service) => {
|
|
180
|
+
shippingServices.push({
|
|
181
|
+
app_id: appResult.app_id,
|
|
182
|
+
...service,
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
const freeShippingFromValue = response.free_shipping_from_value;
|
|
186
|
+
if (
|
|
187
|
+
freeShippingFromValue
|
|
188
|
+
&& (!freeFromValue.value || freeFromValue.value > freeShippingFromValue)
|
|
189
|
+
) {
|
|
190
|
+
freeFromValue.value = freeShippingFromValue;
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
if (!shippingServices.length) {
|
|
194
|
+
if (hasSomeFailedApp) {
|
|
195
|
+
if (!isRetry) {
|
|
196
|
+
fetchShippingServices(true);
|
|
197
|
+
} else {
|
|
198
|
+
scheduleRetry();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
shippingServices.sort((a, b) => {
|
|
204
|
+
const lineA = a.shipping_line;
|
|
205
|
+
const lineB = b.shipping_line;
|
|
206
|
+
const priceDiff = lineA.total_price! - lineB.total_price!;
|
|
207
|
+
if (priceDiff < 0) return -1;
|
|
208
|
+
if (priceDiff > 0) return 1;
|
|
209
|
+
return lineA.delivery_time?.days! < lineB.delivery_time?.days!
|
|
210
|
+
? -1 : 1;
|
|
211
|
+
});
|
|
212
|
+
hasPaidOption.value = Boolean(shippingServices.find((service) => {
|
|
213
|
+
return service.shipping_line.total_price || service.shipping_line.price;
|
|
214
|
+
}));
|
|
215
|
+
const appIdsOrder = props.appIdsOrder || globalThis.ecomShippingApps || [];
|
|
216
|
+
if (Array.isArray(appIdsOrder) && appIdsOrder.length) {
|
|
217
|
+
sortApps(shippingServices, appIdsOrder);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
const submitZipCode = () => {
|
|
223
|
+
const _zipCode = localZipCode.value;
|
|
224
|
+
if (countryCode === 'BR') {
|
|
225
|
+
if (_zipCode?.replace(/\D/g, '').length !== 8) return;
|
|
226
|
+
} else if (!_zipCode) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
zipCode.value = _zipCode;
|
|
230
|
+
if (localStorage) {
|
|
231
|
+
localStorage.setItem(ZIP_STORAGE_KEY, zipCode.value);
|
|
232
|
+
}
|
|
233
|
+
fetchShippingServices();
|
|
234
|
+
};
|
|
235
|
+
watch(localZipCode, submitZipCode, {
|
|
236
|
+
immediate: !props.shippingResult,
|
|
237
|
+
});
|
|
238
|
+
watch(toRef(props, 'shippingResult'), (shippingResult) => {
|
|
239
|
+
if (!shippingResult?.length) return;
|
|
240
|
+
if (localZipCode.value) zipCode.value = localZipCode.value;
|
|
241
|
+
parseShippingResult(shippingResult);
|
|
242
|
+
}, {
|
|
243
|
+
immediate: true,
|
|
244
|
+
});
|
|
245
|
+
const zipInput = props.zipInput?.value;
|
|
246
|
+
if (zipInput) {
|
|
247
|
+
zipInput.addEventListener('input', (ev) => {
|
|
248
|
+
const value = (ev.target as HTMLInputElement).value;
|
|
249
|
+
if (value.length) {
|
|
250
|
+
if (countryCode === 'BR') {
|
|
251
|
+
const fmt = value.replace(/\D/g, '').padEnd(8, '_');
|
|
252
|
+
zipInput.innerHTML = fmt.substring(0, 5) + '-' + fmt.substring(5, 8);
|
|
253
|
+
} else {
|
|
254
|
+
zipInput.innerHTML = value.substring(0, 30);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
localZipCode.value = value;
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
return {
|
|
262
|
+
zipCode,
|
|
263
|
+
shippedItems,
|
|
264
|
+
amountSubtotal,
|
|
265
|
+
submitZipCode,
|
|
266
|
+
fetchShippingServices,
|
|
267
|
+
freeFromValue,
|
|
268
|
+
shippingServices,
|
|
269
|
+
parseShippingResult,
|
|
270
|
+
};
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
export default useShippingCalculator;
|
|
@@ -2,6 +2,9 @@ import type {
|
|
|
2
2
|
ListPaymentsResponse,
|
|
3
3
|
CalculateShippingResponse,
|
|
4
4
|
ApplyDiscountResponse,
|
|
5
|
+
ModuleApiEndpoint,
|
|
6
|
+
ModuleApiParams,
|
|
7
|
+
ModuleApiResult,
|
|
5
8
|
} from '@cloudcommerce/types';
|
|
6
9
|
import { reactive, computed } from 'vue';
|
|
7
10
|
import { formatMoney } from '@ecomplus/utils';
|
|
@@ -32,6 +35,32 @@ loadingGlobalInfoPreset.then((modulesInfoPreset) => {
|
|
|
32
35
|
Object.assign(modulesInfo, modulesInfoPreset);
|
|
33
36
|
});
|
|
34
37
|
|
|
38
|
+
type FetchModule = <M extends ModuleApiEndpoint>(
|
|
39
|
+
modName: M,
|
|
40
|
+
reqOptions?: {
|
|
41
|
+
method: 'GET',
|
|
42
|
+
params?: Record<string, string | number | (string | number)[]>,
|
|
43
|
+
} | {
|
|
44
|
+
method: 'POST',
|
|
45
|
+
params?: {
|
|
46
|
+
app_id?: number,
|
|
47
|
+
skip_ids?: number | number[],
|
|
48
|
+
},
|
|
49
|
+
body: ModuleApiParams<M>,
|
|
50
|
+
},
|
|
51
|
+
) => Promise<Omit<Response, 'json'> & {
|
|
52
|
+
json(): Promise<ModuleApiResult<M>>,
|
|
53
|
+
}>;
|
|
54
|
+
|
|
55
|
+
export const fetchModule: FetchModule = (modName, reqOptions) => {
|
|
56
|
+
const { hostname } = window.location;
|
|
57
|
+
const { domain } = globalThis.$storefront.settings;
|
|
58
|
+
const modulesBaseUri = hostname !== 'localhost' && hostname !== '127.0.0.1'
|
|
59
|
+
? `https://${domain}/_api/modules/`
|
|
60
|
+
: '/_api/modules/';
|
|
61
|
+
return afetch(`${modulesBaseUri}${modName}`, reqOptions);
|
|
62
|
+
};
|
|
63
|
+
|
|
35
64
|
if (!import.meta.env.SSR) {
|
|
36
65
|
const storageKey = 'MODULES_INFO';
|
|
37
66
|
const sessionJson = sessionStorage.getItem(storageKey);
|
|
@@ -50,8 +79,8 @@ if (!import.meta.env.SSR) {
|
|
|
50
79
|
}
|
|
51
80
|
|
|
52
81
|
const fetchInfo = () => {
|
|
53
|
-
const modulesToFetch: { modName:
|
|
54
|
-
['list_payments', 'calculate_shipping'].forEach((modName) => {
|
|
82
|
+
const modulesToFetch: { modName: ModuleApiEndpoint, reqOptions?: any }[] = [];
|
|
83
|
+
(['list_payments', 'calculate_shipping'] as const).forEach((modName) => {
|
|
55
84
|
if (!Object.keys(modulesInfo[modName]).length) {
|
|
56
85
|
modulesToFetch.push({ modName });
|
|
57
86
|
}
|
|
@@ -60,19 +89,14 @@ if (!import.meta.env.SSR) {
|
|
|
60
89
|
modulesToFetch.push({
|
|
61
90
|
modName: 'apply_discount',
|
|
62
91
|
reqOptions: {
|
|
63
|
-
method: '
|
|
92
|
+
method: 'POST',
|
|
64
93
|
body: { utm },
|
|
65
94
|
},
|
|
66
95
|
});
|
|
67
96
|
}
|
|
68
97
|
|
|
69
98
|
modulesToFetch.forEach(({ modName, reqOptions }) => {
|
|
70
|
-
|
|
71
|
-
const { domain } = globalThis.$storefront.settings;
|
|
72
|
-
const modulesBaseUri = hostname !== 'localhost' && hostname !== '127.0.0.1'
|
|
73
|
-
? `https://${domain}/_api/modules/`
|
|
74
|
-
: '/_api/modules/';
|
|
75
|
-
afetch(`${modulesBaseUri}${modName}`, reqOptions)
|
|
99
|
+
fetchModule(modName, reqOptions)
|
|
76
100
|
.then(async (response) => {
|
|
77
101
|
if (response.ok) {
|
|
78
102
|
const modInfo = {};
|
|
@@ -108,7 +132,7 @@ if (!import.meta.env.SSR) {
|
|
|
108
132
|
field = 'discount_option';
|
|
109
133
|
val = data[field];
|
|
110
134
|
if (val && (!modInfo[field] || val.value > modInfo[field].value)) {
|
|
111
|
-
data.payment_gateways.forEach(({ discount }) => {
|
|
135
|
+
(data as ListPaymentsResponse).payment_gateways.forEach(({ discount }) => {
|
|
112
136
|
if (
|
|
113
137
|
discount && discount.apply_at !== 'freight'
|
|
114
138
|
&& discount.value === val.value
|