flowrix 1.0.1-beta.14 → 1.0.1-beta.141
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/dist/module.d.mts +1 -6
- package/dist/module.json +1 -1
- package/dist/module.mjs +169 -30
- package/dist/runtime/composables/Blog/useBlogIndex.d.ts +2 -5
- package/dist/runtime/composables/Blog/useBlogSingle.js +2 -4
- package/dist/runtime/composables/Brand/brand.d.ts +1 -1
- package/dist/runtime/composables/Brand/brand.js +30 -2
- package/dist/runtime/composables/Cart/useCart.d.ts +40 -0
- package/dist/runtime/composables/Cart/useCart.js +10 -0
- package/dist/runtime/composables/Cart/useCartComponent.d.ts +1 -0
- package/dist/runtime/composables/Cart/useCartComponent.js +11 -0
- package/dist/runtime/composables/Cart/useCartDetail.d.ts +15 -5
- package/dist/runtime/composables/Cart/useCartDetail.js +3 -0
- package/dist/runtime/composables/Category/useCategoryIndex.d.ts +25 -32
- package/dist/runtime/composables/Category/useCategoryIndex.js +63 -44
- package/dist/runtime/composables/Checkout/PaymentMethods/useDirectDeposit.js +8 -0
- package/dist/runtime/composables/Checkout/PaymentMethods/useEway.js +16 -6
- package/dist/runtime/composables/Checkout/PaymentMethods/useFlowrixpay.d.ts +40 -1
- package/dist/runtime/composables/Checkout/PaymentMethods/useFlowrixpay.js +10 -2
- package/dist/runtime/composables/Checkout/PaymentMethods/useOpayo.d.ts +40 -1
- package/dist/runtime/composables/Checkout/PaymentMethods/useOpayo.js +10 -2
- package/dist/runtime/composables/Checkout/PaymentMethods/usePaymentMethods.js +3 -14
- package/dist/runtime/composables/Checkout/PaymentMethods/usePaypal.js +8 -0
- package/dist/runtime/composables/Checkout/PaymentMethods/useStripe.d.ts +2 -2
- package/dist/runtime/composables/Checkout/PaymentMethods/useStripe.js +8 -0
- package/dist/runtime/composables/Checkout/PaymentMethods/useZippay.js +8 -0
- package/dist/runtime/composables/Checkout/useCheckout.d.ts +85 -73
- package/dist/runtime/composables/Checkout/useCheckout.js +84 -53
- package/dist/runtime/composables/Checkout/useCheckoutBillingAddress.d.ts +43 -0
- package/dist/runtime/composables/Checkout/useCheckoutBillingAddress.js +84 -0
- package/dist/runtime/composables/Checkout/useCheckoutShippingAddress.d.ts +55 -0
- package/dist/runtime/composables/Checkout/useCheckoutShippingAddress.js +196 -0
- package/dist/runtime/composables/Checkout/useCreateAccount.d.ts +7 -7
- package/dist/runtime/composables/Checkout/useCreateAccount.js +3 -1
- package/dist/runtime/composables/Checkout/useDeliveryMethod.d.ts +2 -2
- package/dist/runtime/composables/Checkout/useDeliveryMethod.js +18 -11
- package/dist/runtime/composables/Customer/useBillingAddress.d.ts +112 -0
- package/dist/runtime/composables/Customer/useBillingAddress.js +93 -0
- package/dist/runtime/composables/Customer/useLogin.d.ts +9 -0
- package/dist/runtime/composables/Customer/useLogin.js +34 -0
- package/dist/runtime/composables/Customer/useOrders.d.ts +29 -0
- package/dist/runtime/composables/Customer/useOrders.js +56 -0
- package/dist/runtime/composables/Customer/usePasswordReset.d.ts +26 -0
- package/dist/runtime/composables/Customer/usePasswordReset.js +258 -0
- package/dist/runtime/composables/Customer/useProfile.d.ts +75 -0
- package/dist/runtime/composables/Customer/useProfile.js +106 -0
- package/dist/runtime/composables/Customer/useQuotations.d.ts +32 -0
- package/dist/runtime/composables/Customer/useQuotations.js +40 -0
- package/dist/runtime/composables/Customer/useRegister.d.ts +121 -13
- package/dist/runtime/composables/Customer/useRegister.js +310 -35
- package/dist/runtime/composables/Customer/useShippingAddress.d.ts +121 -0
- package/dist/runtime/composables/Customer/useShippingAddress.js +145 -0
- package/dist/runtime/composables/Customer/useUpdatePassword.d.ts +21 -0
- package/dist/runtime/composables/Customer/useUpdatePassword.js +130 -0
- package/dist/runtime/composables/Customer/useUserCards.d.ts +22 -0
- package/dist/runtime/composables/Customer/useUserCards.js +65 -0
- package/dist/runtime/composables/{useWishlists.d.ts → Customer/useWishlists.d.ts} +7 -20
- package/dist/runtime/composables/{useWishlists.js → Customer/useWishlists.js} +21 -30
- package/dist/runtime/composables/Extras/useCountry.d.ts +11 -6
- package/dist/runtime/composables/Extras/useCountry.js +5 -4
- package/dist/runtime/composables/Footer/useFooter.d.ts +4 -4
- package/dist/runtime/composables/Footer/useFooter.js +12 -8
- package/dist/runtime/composables/Header/useHeader.d.ts +6 -20
- package/dist/runtime/composables/Header/useHeader.js +3 -2
- package/dist/runtime/composables/Product/CustomProduct/useCustomeScript.js +4 -5
- package/dist/runtime/composables/Product/CustomProduct/useSteps.d.ts +1 -1
- package/dist/runtime/composables/Product/useProductComponent.js +110 -0
- package/dist/runtime/composables/Product/useProductSlug.d.ts +8 -1
- package/dist/runtime/composables/Product/useQuickView.d.ts +8 -0
- package/dist/runtime/composables/Product/useQuickView.js +27 -0
- package/dist/runtime/composables/Product/useService.d.ts +42 -15
- package/dist/runtime/composables/Product/useService.js +137 -48
- package/dist/runtime/composables/Samples/useSamples.d.ts +5 -6
- package/dist/runtime/composables/Samples/useSamples.js +19 -15
- package/dist/runtime/composables/SideBar/Filters/useFilters.d.ts +2 -2
- package/dist/runtime/composables/SideBar/Filters/useSorting.d.ts +2 -2
- package/dist/runtime/composables/index.d.ts +18 -12
- package/dist/runtime/composables/index.js +18 -12
- package/dist/runtime/composables/useAddresses.js +6 -6
- package/dist/runtime/composables/useApp.d.ts +1 -0
- package/dist/runtime/composables/useApp.js +88 -0
- package/dist/runtime/composables/useCards.js +2 -2
- package/dist/runtime/composables/useDataLayer.js +1 -1
- package/dist/runtime/composables/useDotDigital.d.ts +3 -0
- package/dist/runtime/composables/useDotDigital.js +122 -0
- package/dist/runtime/composables/useLocation.d.ts +61 -19
- package/dist/runtime/composables/useLocation.js +353 -25
- package/dist/runtime/composables/useMetaLayer.js +11 -11
- package/dist/runtime/composables/useQuotationCheckout.d.ts +78 -0
- package/dist/runtime/composables/useQuotationCheckout.js +137 -0
- package/dist/runtime/composables/useSubscriptions.d.ts +17 -10
- package/dist/runtime/composables/useSubscriptions.js +68 -33
- package/dist/runtime/composables/useTikTokDatalayer.js +7 -7
- package/dist/runtime/composables/useWebforms.d.ts +38 -9
- package/dist/runtime/composables/useWebforms.js +93 -60
- package/dist/runtime/middleware/flowrix.d.ts +5 -4
- package/dist/runtime/middleware/flowrix.js +40 -22
- package/dist/runtime/pages/404.d.vue.ts +3 -0
- package/dist/runtime/pages/404.vue +6 -0
- package/dist/runtime/pages/404.vue.d.ts +3 -0
- package/dist/runtime/pages/flowrix-default.d.vue.ts +3 -0
- package/dist/runtime/pages/flowrix-default.vue +42 -0
- package/dist/runtime/pages/flowrix-default.vue.d.ts +3 -0
- package/dist/runtime/plugin.d.ts +1 -1
- package/dist/runtime/plugins/router.d.ts +2 -0
- package/dist/runtime/plugins/router.js +11 -0
- package/dist/runtime/server/api/albums.d.ts +1 -0
- package/dist/runtime/server/api/albums.js +35 -7
- package/dist/runtime/server/api/auth/forgot.js +1 -2
- package/dist/runtime/server/api/auth/login.d.ts +7 -0
- package/dist/runtime/server/api/auth/login.js +4 -16
- package/dist/runtime/server/api/auth/logout.js +1 -2
- package/dist/runtime/server/api/auth/register.js +1 -2
- package/dist/runtime/server/api/auth/session.get.js +1 -3
- package/dist/runtime/server/api/auth/user/reset-password.js +1 -2
- package/dist/runtime/server/api/auth/user/session.js +1 -2
- package/dist/runtime/server/api/auth/user/verify-token.js +1 -2
- package/dist/runtime/server/api/banners.js +20 -15
- package/dist/runtime/server/api/brand/[...slug].js +55 -0
- package/dist/runtime/server/api/brand/index.d.ts +3 -0
- package/dist/runtime/server/api/brand/index.js +46 -0
- package/dist/runtime/server/api/cache/[...slug].delete.d.ts +4 -1
- package/dist/runtime/server/api/cache/[...slug].delete.js +4 -7
- package/dist/runtime/server/api/cache/clean.get.d.ts +5 -0
- package/dist/runtime/server/api/cache/clean.get.js +4 -7
- package/dist/runtime/server/api/cart/[slug]/add.d.ts +1 -1
- package/dist/runtime/server/api/cart/[slug]/add.js +11 -11
- package/dist/runtime/server/api/cart/[slug]/update.d.ts +1 -1
- package/dist/runtime/server/api/cart/[slug]/update.js +11 -11
- package/dist/runtime/server/api/{v2/[...slug].d.ts → cart/related.d.ts} +0 -1
- package/dist/runtime/server/api/cart/related.js +21 -0
- package/dist/runtime/server/api/cart/remove.d.ts +1 -1
- package/dist/runtime/server/api/cart/remove.js +10 -10
- package/dist/runtime/server/api/cart/service/[slug]/add.d.ts +1 -1
- package/dist/runtime/server/api/cart/service/[slug]/add.js +12 -12
- package/dist/runtime/server/api/catalog/brands.d.ts +3 -0
- package/dist/runtime/server/api/catalog/brands.js +52 -0
- package/dist/runtime/server/api/catalog/categories.js +28 -19
- package/dist/runtime/server/api/catalog/categoriesall.d.ts +3 -0
- package/dist/runtime/server/api/catalog/categoriesall.js +52 -0
- package/dist/runtime/server/api/catalog/featured.js +28 -17
- package/dist/runtime/server/api/catalog/posts.d.ts +3 -0
- package/dist/runtime/server/api/catalog/posts.js +52 -0
- package/dist/runtime/server/api/catalog/samples.js +28 -19
- package/dist/runtime/server/api/catalog/search.js +28 -19
- package/dist/runtime/server/api/category/[...slug].js +31 -20
- package/dist/runtime/server/api/check-404.d.ts +4 -0
- package/dist/runtime/server/api/check-404.js +8 -0
- package/dist/runtime/server/api/checkout/applyCoupon.d.ts +1 -1
- package/dist/runtime/server/api/checkout/applyCoupon.js +13 -13
- package/dist/runtime/server/api/checkout/configs.d.ts +1 -1
- package/dist/runtime/server/api/checkout/configs.js +11 -11
- package/dist/runtime/server/api/checkout/countries.d.ts +1 -1
- package/dist/runtime/server/api/checkout/countries.js +5 -9
- package/dist/runtime/server/api/checkout/paymentmethod.d.ts +1 -1
- package/dist/runtime/server/api/checkout/paymentmethod.js +16 -11
- package/dist/runtime/server/api/{blog/blog.d.ts → checkout/quotation/[slug].d.ts} +0 -1
- package/dist/runtime/server/api/checkout/quotation/[slug].js +20 -0
- package/dist/runtime/server/api/checkout/quotation/guest/[slug].d.ts +2 -0
- package/dist/runtime/server/api/checkout/quotation/guest/[slug].js +35 -0
- package/dist/runtime/server/api/checkout/quotation/guest/customer.d.ts +2 -0
- package/dist/runtime/server/api/checkout/quotation/guest/customer.js +20 -0
- package/dist/runtime/server/api/checkout/quotation/submit/[slug].d.ts +2 -0
- package/dist/runtime/server/api/checkout/quotation/submit/[slug].js +22 -0
- package/dist/runtime/server/api/checkvariables.d.ts +3 -0
- package/dist/runtime/server/api/checkvariables.js +37 -0
- package/dist/runtime/server/api/cmspost/[...slug].js +54 -0
- package/dist/runtime/server/api/cmspost/all.d.ts +3 -0
- package/dist/runtime/server/api/cmspost/all.js +52 -0
- package/dist/runtime/server/api/company/profile.d.ts +1 -1
- package/dist/runtime/server/api/company/profile.js +12 -7
- package/dist/runtime/server/api/contact-center/webforms/[id]/details.d.ts +1 -1
- package/dist/runtime/server/api/contact-center/webforms/[id]/details.js +50 -15
- package/dist/runtime/server/api/contact-center/webforms/create.d.ts +1 -1
- package/dist/runtime/server/api/contact-center/webforms/create.js +13 -9
- package/dist/runtime/server/api/countries.d.ts +2 -0
- package/dist/runtime/server/api/countries.js +44 -0
- package/dist/runtime/server/api/customer/address/add.js +1 -2
- package/dist/runtime/server/api/customer/address/delete.js +2 -3
- package/dist/runtime/server/api/customer/address/setshipping.js +1 -2
- package/dist/runtime/server/api/customer/address/update.js +1 -2
- package/dist/runtime/server/api/customer/cards/delete.js +2 -3
- package/dist/runtime/server/api/customer/cards/get.js +2 -3
- package/dist/runtime/server/api/customer/change-password.js +2 -3
- package/dist/runtime/server/api/customer/checkout.js +1 -2
- package/dist/runtime/server/api/customer/orders.js +2 -3
- package/dist/runtime/server/api/customer/profile/update.js +1 -2
- package/dist/runtime/server/api/customer/quotations.js +2 -3
- package/dist/runtime/server/api/customer/search.js +1 -2
- package/dist/runtime/server/api/customer/tax-invoice.js +1 -2
- package/dist/runtime/server/api/customer/wishlist/add.js +1 -2
- package/dist/runtime/server/api/customer/wishlist/createWishList.js +1 -2
- package/dist/runtime/server/api/customer/wishlist/deleteFromWishList.js +1 -2
- package/dist/runtime/server/api/customer/wishlist/deleteWishList.js +1 -2
- package/dist/runtime/server/api/customer/wishlist/get.js +2 -3
- package/dist/runtime/server/api/customer/wishlist/getWishListItems.js +1 -2
- package/dist/runtime/server/api/customer/wishlist/updateWishList.js +2 -3
- package/dist/runtime/server/api/featured.d.ts +3 -0
- package/dist/runtime/server/api/featured.js +52 -0
- package/dist/runtime/server/api/generate/robots.get.d.ts +2 -0
- package/dist/runtime/server/api/generate/robots.get.js +20 -0
- package/dist/runtime/server/api/generate/sitemap.get.d.ts +2 -0
- package/dist/runtime/server/api/generate/sitemap.get.js +32 -0
- package/dist/runtime/server/api/location.d.ts +1 -1
- package/dist/runtime/server/api/location.js +24 -12
- package/dist/runtime/server/api/nav/[id]/links.d.ts +1 -0
- package/dist/runtime/server/api/nav/[id]/links.js +46 -10
- package/dist/runtime/server/api/page/[...slug].js +54 -0
- package/dist/runtime/server/api/product/[...slug].js +28 -13
- package/dist/runtime/server/api/quickview/[slug].d.ts +2 -0
- package/dist/runtime/server/api/quickview/[slug].js +21 -0
- package/dist/runtime/server/api/reviews.d.ts +2 -0
- package/dist/runtime/server/api/reviews.js +23 -0
- package/dist/runtime/server/api/samples.d.ts +3 -0
- package/dist/runtime/server/api/samples.js +53 -0
- package/dist/runtime/server/api/search.d.ts +3 -0
- package/dist/runtime/server/api/search.js +53 -0
- package/dist/runtime/server/api/service/[slug].js +22 -16
- package/dist/runtime/server/api/service/availability.d.ts +1 -1
- package/dist/runtime/server/api/service/availability.js +14 -12
- package/dist/runtime/server/api/service/getall.d.ts +3 -0
- package/dist/runtime/server/api/service/getall.js +57 -0
- package/dist/runtime/server/api/shop.d.ts +3 -0
- package/dist/runtime/server/api/shop.js +53 -0
- package/dist/runtime/server/api/subscribe.d.ts +1 -1
- package/dist/runtime/server/api/subscribe.js +23 -14
- package/dist/runtime/server/api/v2/[...slug].get.d.ts +2 -0
- package/dist/runtime/server/api/v2/[...slug].get.js +32 -0
- package/dist/runtime/server/api/webform.d.ts +3 -0
- package/dist/runtime/server/api/webform.js +54 -0
- package/dist/runtime/server/tsconfig.json +3 -3
- package/dist/runtime/stores/Cart.d.ts +12 -0
- package/dist/runtime/stores/Cart.js +62 -17
- package/dist/runtime/stores/Checkout.d.ts +9 -15
- package/dist/runtime/stores/Checkout.js +38 -45
- package/dist/runtime/stores/IpLocation.d.ts +95 -4
- package/dist/runtime/stores/IpLocation.js +93 -15
- package/dist/runtime/stores/Search.d.ts +1 -1
- package/dist/runtime/stores/Services.d.ts +5 -0
- package/dist/runtime/stores/Services.js +59 -8
- package/dist/runtime/stores/auth.d.ts +8 -11
- package/dist/runtime/stores/auth.js +385 -8
- package/dist/runtime/stores/countries.d.ts +1 -3
- package/dist/runtime/stores/countries.js +4 -8
- package/dist/runtime/stores/product/README.md +6 -6
- package/dist/runtime/stores/product/slug.d.ts +1 -17
- package/dist/runtime/stores/webforms.d.ts +24 -9
- package/dist/runtime/stores/webforms.js +105 -5
- package/dist/runtime/stores/wishlists.d.ts +125 -8
- package/dist/runtime/stores/wishlists.js +212 -20
- package/dist/runtime/utils/api.js +7 -13
- package/dist/runtime/utils/htmlCache.d.ts +2 -2
- package/dist/runtime/utils/htmlCache.js +23 -13
- package/dist/types.d.mts +6 -2
- package/package.json +16 -5
- package/dist/runtime/composables/Checkout/useBillingAddress.d.ts +0 -19
- package/dist/runtime/composables/Checkout/useBillingAddress.js +0 -82
- package/dist/runtime/composables/Checkout/useShippingAddress.d.ts +0 -9
- package/dist/runtime/composables/Checkout/useShippingAddress.js +0 -121
- package/dist/runtime/composables/useAuth.d.ts +0 -45
- package/dist/runtime/composables/useAuth.js +0 -180
- package/dist/runtime/composables/useCountries.d.ts +0 -12
- package/dist/runtime/composables/useCountries.js +0 -50
- package/dist/runtime/composables/useOrders.d.ts +0 -21
- package/dist/runtime/composables/useOrders.js +0 -82
- package/dist/runtime/composables/useQuotations.d.ts +0 -14
- package/dist/runtime/composables/useQuotations.js +0 -50
- package/dist/runtime/server/api/blog/[slug].js +0 -51
- package/dist/runtime/server/api/blog/blog.js +0 -17
- package/dist/runtime/server/api/brand/[slug].js +0 -58
- package/dist/runtime/server/api/page/[slug].js +0 -51
- package/dist/runtime/server/api/v2/[...slug].js +0 -9
- /package/dist/runtime/server/api/brand/{[slug].d.ts → [...slug].d.ts} +0 -0
- /package/dist/runtime/server/api/{blog/[slug].d.ts → cmspost/[...slug].d.ts} +0 -0
- /package/dist/runtime/server/api/page/{[slug].d.ts → [...slug].d.ts} +0 -0
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { defineEventHandler, getRouterParam, getQuery, createError, readBody } from "h3";
|
|
2
|
-
import { $fetch } from "ofetch";
|
|
1
|
+
import { defineEventHandler, getRouterParam, getQuery, createError, readBody, getCookie, setResponseStatus } from "h3";
|
|
3
2
|
import { writeFile, mkdir, readFile } from "fs/promises";
|
|
4
3
|
import { join } from "path";
|
|
5
|
-
|
|
4
|
+
import { useRuntimeConfig } from "#imports";
|
|
5
|
+
import { flowrixApi } from "../../../middleware/flowrix.js";
|
|
6
|
+
const CACHE_DIR = join("/tmp", ".cache", "nitro", "services");
|
|
6
7
|
export const serviceCache = /* @__PURE__ */ new Map();
|
|
7
8
|
async function ensureCacheDir() {
|
|
8
9
|
try {
|
|
@@ -13,6 +14,7 @@ async function ensureCacheDir() {
|
|
|
13
14
|
}
|
|
14
15
|
export default defineEventHandler(async (event) => {
|
|
15
16
|
const slug = getRouterParam(event, "slug");
|
|
17
|
+
const customerType = getCookie(event, "customertype") || "";
|
|
16
18
|
const query = getQuery(event);
|
|
17
19
|
const body = await readBody(event);
|
|
18
20
|
if (!slug) {
|
|
@@ -23,7 +25,7 @@ export default defineEventHandler(async (event) => {
|
|
|
23
25
|
}
|
|
24
26
|
const cacheKey = `${slug}-${JSON.stringify(query)}`;
|
|
25
27
|
const fileName = cacheKey.replace(/[^a-zA-Z0-9-_]/g, "_");
|
|
26
|
-
const filePath = join(CACHE_DIR, `${fileName}.json`);
|
|
28
|
+
const filePath = join(CACHE_DIR, `${fileName}-${customerType}.json`);
|
|
27
29
|
try {
|
|
28
30
|
const fileContent = await readFile(filePath, "utf-8");
|
|
29
31
|
const service = JSON.parse(fileContent);
|
|
@@ -31,21 +33,25 @@ export default defineEventHandler(async (event) => {
|
|
|
31
33
|
} catch (error) {
|
|
32
34
|
}
|
|
33
35
|
try {
|
|
34
|
-
const
|
|
36
|
+
const config = useRuntimeConfig();
|
|
37
|
+
const rawCookies = event.req.headers.cookie || "";
|
|
38
|
+
const apiConfig = {
|
|
39
|
+
...config,
|
|
40
|
+
cookies: rawCookies
|
|
41
|
+
};
|
|
42
|
+
const options = {
|
|
35
43
|
headers: {
|
|
36
|
-
"x-api-
|
|
37
|
-
"x-api-secret": process.env.FLOWRIX_API_SECRET,
|
|
38
|
-
"Origin": process.env.FLOWRIX_API_ORIGIN
|
|
44
|
+
"x-api-secret": apiConfig?.FLOWRIX_API_SECRET || ""
|
|
39
45
|
}
|
|
40
|
-
}
|
|
41
|
-
await
|
|
42
|
-
|
|
46
|
+
};
|
|
47
|
+
const service = await flowrixApi.get(`services/${slug}`, apiConfig, options);
|
|
48
|
+
if (config.FLOWRIX_CACHE == "true" || config.public.FLOWRIX_CACHE == "true") {
|
|
49
|
+
await ensureCacheDir();
|
|
50
|
+
await writeFile(filePath, JSON.stringify(service, null, 2), "utf-8");
|
|
51
|
+
}
|
|
43
52
|
return service;
|
|
44
53
|
} catch (error) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
statusMessage: `Failed to fetch service for slug: ${slug}`,
|
|
48
|
-
data: error.message
|
|
49
|
-
});
|
|
54
|
+
setResponseStatus(event, 500);
|
|
55
|
+
return { success: false, error: error.message };
|
|
50
56
|
}
|
|
51
57
|
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<
|
|
1
|
+
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<unknown>>;
|
|
2
2
|
export default _default;
|
|
@@ -1,25 +1,27 @@
|
|
|
1
|
+
import { useRuntimeConfig } from "#imports";
|
|
1
2
|
import { defineEventHandler, readBody } from "h3";
|
|
3
|
+
import { flowrixApi } from "../../../middleware/flowrix.js";
|
|
2
4
|
export default defineEventHandler(async (event) => {
|
|
3
5
|
const body = await readBody(event);
|
|
4
6
|
try {
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
+
const config = useRuntimeConfig();
|
|
8
|
+
const rawCookies = event.req.headers.cookie || "";
|
|
9
|
+
const apiConfig = {
|
|
10
|
+
...config,
|
|
11
|
+
cookies: rawCookies
|
|
12
|
+
};
|
|
13
|
+
const options = {
|
|
7
14
|
headers: {
|
|
8
|
-
"x-api-
|
|
9
|
-
"x-api-secret": process.env.FLOWRIX_API_SECRET || "",
|
|
10
|
-
"Origin": process.env.FLOWRIX_API_ORIGIN || "",
|
|
11
|
-
"Content-Type": "application/json",
|
|
12
|
-
"Accept": "application/json"
|
|
15
|
+
"x-api-secret": apiConfig?.FLOWRIX_API_SECRET || ""
|
|
13
16
|
},
|
|
14
17
|
body: JSON.stringify(body)
|
|
15
|
-
}
|
|
16
|
-
const
|
|
17
|
-
return
|
|
18
|
+
};
|
|
19
|
+
const response = await flowrixApi.post(`services/availability`, apiConfig, options);
|
|
20
|
+
return response;
|
|
18
21
|
} catch (error) {
|
|
19
|
-
console.error("Error in service availability:", error);
|
|
20
22
|
return {
|
|
21
23
|
status: "Error",
|
|
22
|
-
statusCode:
|
|
24
|
+
statusCode: 422,
|
|
23
25
|
message: "Internal server error",
|
|
24
26
|
error: error.message || "Unknown error"
|
|
25
27
|
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { defineEventHandler, getQuery, createError, readBody, getCookie, setResponseStatus } from "h3";
|
|
2
|
+
import { writeFile, mkdir, readFile } from "fs/promises";
|
|
3
|
+
import { join } from "path";
|
|
4
|
+
import { useRuntimeConfig } from "#imports";
|
|
5
|
+
import { flowrixApi } from "../../../middleware/flowrix.js";
|
|
6
|
+
const CACHE_DIR = join("/tmp", ".cache", "nitro", "services");
|
|
7
|
+
export const serviceCache = /* @__PURE__ */ new Map();
|
|
8
|
+
async function ensureCacheDir() {
|
|
9
|
+
try {
|
|
10
|
+
await mkdir(CACHE_DIR, { recursive: true });
|
|
11
|
+
} catch (error) {
|
|
12
|
+
console.error("Error creating cache directory:", error);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export default defineEventHandler(async (event) => {
|
|
16
|
+
const slug = "all";
|
|
17
|
+
const customerType = getCookie(event, "customertype") || "";
|
|
18
|
+
let query = getQuery(event);
|
|
19
|
+
const body = await readBody(event);
|
|
20
|
+
if (!slug) {
|
|
21
|
+
throw createError({ statusCode: 400, statusMessage: "Missing slug parameter" });
|
|
22
|
+
}
|
|
23
|
+
if (!/^[a-zA-Z0-9-_]+$/.test(slug)) {
|
|
24
|
+
throw createError({ statusCode: 400, statusMessage: "Invalid slug" });
|
|
25
|
+
}
|
|
26
|
+
const cacheKey = `${slug}-${JSON.stringify(query)}`;
|
|
27
|
+
const fileName = cacheKey.replace(/[^a-zA-Z0-9-_]/g, "_");
|
|
28
|
+
const filePath = join(CACHE_DIR, `${fileName}-${customerType}.json`);
|
|
29
|
+
try {
|
|
30
|
+
const fileContent = await readFile(filePath, "utf-8");
|
|
31
|
+
const service = JSON.parse(fileContent);
|
|
32
|
+
return service;
|
|
33
|
+
} catch (error) {
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const config = useRuntimeConfig();
|
|
37
|
+
const rawCookies = event.req.headers.cookie || "";
|
|
38
|
+
const apiConfig = {
|
|
39
|
+
...config,
|
|
40
|
+
cookies: rawCookies
|
|
41
|
+
};
|
|
42
|
+
const options = {
|
|
43
|
+
headers: {
|
|
44
|
+
"x-api-secret": apiConfig?.FLOWRIX_API_SECRET || ""
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const service = await flowrixApi.get(`services`, apiConfig, options);
|
|
48
|
+
if (config.FLOWRIX_CACHE == "true" || config.public.FLOWRIX_CACHE == "true") {
|
|
49
|
+
await ensureCacheDir();
|
|
50
|
+
await writeFile(filePath, JSON.stringify(service, null, 2), "utf-8");
|
|
51
|
+
}
|
|
52
|
+
return service;
|
|
53
|
+
} catch (error) {
|
|
54
|
+
setResponseStatus(event, 500);
|
|
55
|
+
return { success: false, error: error.message };
|
|
56
|
+
}
|
|
57
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { defineEventHandler, getQuery, getCookie, setResponseStatus } from "h3";
|
|
2
|
+
import { writeFile, mkdir, readFile } from "fs/promises";
|
|
3
|
+
import { join } from "path";
|
|
4
|
+
import { useRuntimeConfig } from "#imports";
|
|
5
|
+
import { flowrixApi } from "../../middleware/flowrix.js";
|
|
6
|
+
const CACHE_DIR = join("/tmp", ".cache", "nitro", "catalog");
|
|
7
|
+
export const catelogCache = /* @__PURE__ */ new Map();
|
|
8
|
+
async function ensureCacheDir() {
|
|
9
|
+
try {
|
|
10
|
+
await mkdir(CACHE_DIR, { recursive: true });
|
|
11
|
+
} catch (error) {
|
|
12
|
+
console.error("Error creating cache directory:", error);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export default defineEventHandler(async (event) => {
|
|
16
|
+
let query = getQuery(event);
|
|
17
|
+
const customerType = getCookie(event, "customertype") || "";
|
|
18
|
+
const cacheKey = `search-${JSON.stringify(query)}`;
|
|
19
|
+
const fileName = cacheKey.replace(/[^a-zA-Z0-9-_]/g, "_");
|
|
20
|
+
const filePath = join(CACHE_DIR, `${fileName}-${customerType}.json`);
|
|
21
|
+
try {
|
|
22
|
+
const fileContent = await readFile(filePath, "utf-8");
|
|
23
|
+
const catelog = JSON.parse(fileContent);
|
|
24
|
+
return catelog;
|
|
25
|
+
} catch (error) {
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
const config = useRuntimeConfig();
|
|
29
|
+
const rawCookies = event.req.headers.cookie || "";
|
|
30
|
+
const apiConfig = {
|
|
31
|
+
...config,
|
|
32
|
+
cookies: rawCookies
|
|
33
|
+
};
|
|
34
|
+
query = {
|
|
35
|
+
...query
|
|
36
|
+
};
|
|
37
|
+
const options = {
|
|
38
|
+
headers: {
|
|
39
|
+
"x-api-secret": apiConfig?.FLOWRIX_API_SECRET || ""
|
|
40
|
+
},
|
|
41
|
+
query
|
|
42
|
+
};
|
|
43
|
+
const search = await flowrixApi.get(`search`, apiConfig, options);
|
|
44
|
+
if (config.FLOWRIX_CACHE == "true" || config.public.FLOWRIX_CACHE == "true") {
|
|
45
|
+
await ensureCacheDir();
|
|
46
|
+
await writeFile(filePath, JSON.stringify(search, null, 2), "utf-8");
|
|
47
|
+
}
|
|
48
|
+
return search;
|
|
49
|
+
} catch (error) {
|
|
50
|
+
setResponseStatus(event, 500);
|
|
51
|
+
return { success: false, error: error.message };
|
|
52
|
+
}
|
|
53
|
+
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<
|
|
1
|
+
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<unknown>>;
|
|
2
2
|
export default _default;
|
|
@@ -1,16 +1,25 @@
|
|
|
1
|
-
import { defineEventHandler, readBody } from "h3";
|
|
2
|
-
import {
|
|
1
|
+
import { defineEventHandler, readBody, setResponseStatus } from "h3";
|
|
2
|
+
import { flowrixApi } from "../../middleware/flowrix.js";
|
|
3
|
+
import { useRuntimeConfig } from "#imports";
|
|
3
4
|
export default defineEventHandler(async (event) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
headers
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
5
|
+
try {
|
|
6
|
+
const body = await readBody(event);
|
|
7
|
+
const config = useRuntimeConfig();
|
|
8
|
+
const rawCookies = event.req.headers.cookie || "";
|
|
9
|
+
const apiConfig = {
|
|
10
|
+
...config,
|
|
11
|
+
cookies: rawCookies
|
|
12
|
+
};
|
|
13
|
+
const options = {
|
|
14
|
+
headers: {
|
|
15
|
+
"x-api-secret": apiConfig?.FLOWRIX_API_SECRET || ""
|
|
16
|
+
},
|
|
17
|
+
body: JSON.stringify(body)
|
|
18
|
+
};
|
|
19
|
+
const subscribe = await flowrixApi.post(`subscribe`, apiConfig, options);
|
|
20
|
+
return subscribe;
|
|
21
|
+
} catch (error) {
|
|
22
|
+
setResponseStatus(event, 500);
|
|
23
|
+
return { success: false, error: error.message };
|
|
24
|
+
}
|
|
16
25
|
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { defineEventHandler } from "h3";
|
|
2
|
+
import { flowrixApi } from "../../../middleware/flowrix.js";
|
|
3
|
+
import { useRuntimeConfig } from "#imports";
|
|
4
|
+
import { existsSync } from "fs";
|
|
5
|
+
import { join } from "path";
|
|
6
|
+
import { rm } from "fs/promises";
|
|
7
|
+
export default defineEventHandler(async (event) => {
|
|
8
|
+
const slug = event.context.params._;
|
|
9
|
+
const config = useRuntimeConfig();
|
|
10
|
+
const rawCookies = event.req.headers.cookie || "";
|
|
11
|
+
const apiConfig = {
|
|
12
|
+
...config,
|
|
13
|
+
cookies: rawCookies
|
|
14
|
+
};
|
|
15
|
+
const options = {
|
|
16
|
+
headers: {
|
|
17
|
+
"x-api-secret": apiConfig?.FLOWRIX_API_SECRET || ""
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const page = await flowrixApi.get(`permalink/${slug}`, apiConfig, options);
|
|
21
|
+
if (config.FLOWRIX_CACHE != "true" || config.public?.FLOWRIX_CACHE != "true") {
|
|
22
|
+
const CACHE_DIR = join("/tmp", ".cache");
|
|
23
|
+
if (existsSync(CACHE_DIR)) {
|
|
24
|
+
await rm(CACHE_DIR, { recursive: true, force: true });
|
|
25
|
+
} else {
|
|
26
|
+
console.log("\u2139\uFE0F Flowrix: No .cache folder found \u2014 skipping cleanup.");
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (page.status === "Success" && page.data.type === "Redirect") {
|
|
30
|
+
}
|
|
31
|
+
return page;
|
|
32
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { defineEventHandler, getRouterParam, getQuery, createError, readBody, getCookie, setResponseStatus } from "h3";
|
|
2
|
+
import { writeFile, mkdir, readFile } from "fs/promises";
|
|
3
|
+
import { join } from "path";
|
|
4
|
+
import { useRuntimeConfig } from "#imports";
|
|
5
|
+
import { flowrixApi } from "../../middleware/flowrix.js";
|
|
6
|
+
const CACHE_DIR = join("/tmp", ".cache", "nitro", "webfroms");
|
|
7
|
+
export const webfromCache = /* @__PURE__ */ new Map();
|
|
8
|
+
async function ensureCacheDir() {
|
|
9
|
+
try {
|
|
10
|
+
await mkdir(CACHE_DIR, { recursive: true });
|
|
11
|
+
} catch (error) {
|
|
12
|
+
console.error("Error creating cache directory:", error);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export default defineEventHandler(async (event) => {
|
|
16
|
+
const slug = getRouterParam(event, "id");
|
|
17
|
+
const customerType = getCookie(event, "customertype") || "";
|
|
18
|
+
let query = getQuery(event);
|
|
19
|
+
const body = await readBody(event);
|
|
20
|
+
if (!slug) {
|
|
21
|
+
throw createError({ statusCode: 400, statusMessage: "Missing slug parameter" });
|
|
22
|
+
}
|
|
23
|
+
const cacheKey = `${slug}-${JSON.stringify(query)}`;
|
|
24
|
+
const fileName = cacheKey.replace(/[^a-zA-Z0-9-_]/g, "_");
|
|
25
|
+
const filePath = join(CACHE_DIR, `${fileName}-${customerType}.json`);
|
|
26
|
+
try {
|
|
27
|
+
const fileContent = await readFile(filePath, "utf-8");
|
|
28
|
+
const webfrom = JSON.parse(fileContent);
|
|
29
|
+
return webfrom;
|
|
30
|
+
} catch (error) {
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
const config = useRuntimeConfig();
|
|
34
|
+
const rawCookies = event.req.headers.cookie || "";
|
|
35
|
+
const apiConfig = {
|
|
36
|
+
...config,
|
|
37
|
+
cookies: rawCookies
|
|
38
|
+
};
|
|
39
|
+
const options = {
|
|
40
|
+
headers: {
|
|
41
|
+
"x-api-secret": apiConfig?.FLOWRIX_API_SECRET || ""
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const webfrom = await flowrixApi.get(`contact-center/webforms/${slug}/details`, apiConfig, options);
|
|
45
|
+
if (config.FLOWRIX_CACHE == "true" || config.public.FLOWRIX_CACHE == "true") {
|
|
46
|
+
await ensureCacheDir();
|
|
47
|
+
await writeFile(filePath, JSON.stringify(webfrom, null, 2), "utf-8");
|
|
48
|
+
}
|
|
49
|
+
return webfrom;
|
|
50
|
+
} catch (error) {
|
|
51
|
+
setResponseStatus(event, 500);
|
|
52
|
+
return { success: false, error: error.message };
|
|
53
|
+
}
|
|
54
|
+
});
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../../.nuxt/tsconfig.server.json",
|
|
3
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../.nuxt/tsconfig.server.json",
|
|
3
|
+
}
|
|
@@ -36,6 +36,17 @@ export interface CartData {
|
|
|
36
36
|
shippingmethod?: string | number;
|
|
37
37
|
vouchercodes?: string[];
|
|
38
38
|
}
|
|
39
|
+
export interface RelatedData {
|
|
40
|
+
cart: Record<string, CartItem> | undefined;
|
|
41
|
+
qty?: number;
|
|
42
|
+
abndToken?: string;
|
|
43
|
+
deliverymethod?: number | string;
|
|
44
|
+
shipping_state?: string | number;
|
|
45
|
+
shipping_postcode?: number;
|
|
46
|
+
shipping_country?: string | number;
|
|
47
|
+
shippingmethod?: string | number;
|
|
48
|
+
vouchercodes?: string[];
|
|
49
|
+
}
|
|
39
50
|
export interface FormData {
|
|
40
51
|
cart: Record<string, CartItem> | undefined;
|
|
41
52
|
qty: number;
|
|
@@ -63,5 +74,6 @@ export interface CartState {
|
|
|
63
74
|
responseData: [];
|
|
64
75
|
errorResponseData: Record<string, any>;
|
|
65
76
|
addedResponse: string;
|
|
77
|
+
relatedProducts: any[];
|
|
66
78
|
}
|
|
67
79
|
export declare const useCartStore: import("pinia").StoreDefinition<"cart", CartState, {}, {}>;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { defineStore } from "pinia";
|
|
2
2
|
import { flowrixApi } from "../middleware/flowrix.js";
|
|
3
3
|
import { useCheckoutStore } from "./Checkout.js";
|
|
4
|
-
import {
|
|
4
|
+
import { useRuntimeConfig } from "#imports";
|
|
5
|
+
import { GTM_add_to_cart, GTM_remove_from_cart } from "../composables/useDataLayer.js";
|
|
6
|
+
import { META_add_to_cart, META_remove_from_cart } from "../composables/useMetaLayer.js";
|
|
7
|
+
import { TikTok_add_to_cart, TikTok_remove_from_cart } from "../composables/useTikTokDatalayer.js";
|
|
5
8
|
export const useCartStore = defineStore("cart", {
|
|
6
9
|
state: () => ({
|
|
7
10
|
cart: {},
|
|
@@ -64,8 +67,14 @@ export const useCartStore = defineStore("cart", {
|
|
|
64
67
|
apiUrl = `cart/service/${service.slug}/add`;
|
|
65
68
|
}
|
|
66
69
|
try {
|
|
67
|
-
|
|
68
|
-
const response = await flowrixApi.post(
|
|
70
|
+
const config = useRuntimeConfig();
|
|
71
|
+
const response = await flowrixApi.post(
|
|
72
|
+
apiUrl,
|
|
73
|
+
config,
|
|
74
|
+
{
|
|
75
|
+
body: formData
|
|
76
|
+
}
|
|
77
|
+
);
|
|
69
78
|
if (response?.status == "Success") {
|
|
70
79
|
this.addedResponse = "success";
|
|
71
80
|
this.cart = {
|
|
@@ -73,7 +82,10 @@ export const useCartStore = defineStore("cart", {
|
|
|
73
82
|
["totals"]: response?.data.calculations,
|
|
74
83
|
["abndToken"]: response?.data.abndToken
|
|
75
84
|
};
|
|
76
|
-
this.lastitem = response?.data.
|
|
85
|
+
this.lastitem = response?.data.lastitem;
|
|
86
|
+
GTM_add_to_cart(response?.data.lastitem);
|
|
87
|
+
META_add_to_cart(response?.data.lastitem);
|
|
88
|
+
TikTok_add_to_cart(response?.data.lastitem);
|
|
77
89
|
useCheckoutStore().saveToCheckoutSession({
|
|
78
90
|
cart: response?.data,
|
|
79
91
|
calculations: response?.data.calculations,
|
|
@@ -88,9 +100,23 @@ export const useCartStore = defineStore("cart", {
|
|
|
88
100
|
this.addedResponse = "";
|
|
89
101
|
}
|
|
90
102
|
},
|
|
103
|
+
async fetchRelated() {
|
|
104
|
+
try {
|
|
105
|
+
const request = {
|
|
106
|
+
cart: this.cart.items
|
|
107
|
+
};
|
|
108
|
+
const apiUrl = `/api/cart/related`;
|
|
109
|
+
const response = await $fetch(apiUrl, {
|
|
110
|
+
method: "POST",
|
|
111
|
+
body: request
|
|
112
|
+
});
|
|
113
|
+
return response;
|
|
114
|
+
} catch (error) {
|
|
115
|
+
console.error("Error removing from cart:", error);
|
|
116
|
+
}
|
|
117
|
+
},
|
|
91
118
|
async removeFromCart(id, product) {
|
|
92
119
|
try {
|
|
93
|
-
const { post } = useApi();
|
|
94
120
|
const checkoutSession = useCheckoutStore().checkoutSession;
|
|
95
121
|
const apiUrl = `cart/remove`;
|
|
96
122
|
const request = {
|
|
@@ -106,14 +132,18 @@ export const useCartStore = defineStore("cart", {
|
|
|
106
132
|
if (this.coupon?.length > 0) {
|
|
107
133
|
request.vouchercodes = this.coupon;
|
|
108
134
|
}
|
|
109
|
-
const
|
|
135
|
+
const config = useRuntimeConfig();
|
|
136
|
+
const response = await flowrixApi.post(apiUrl, config, {
|
|
137
|
+
body: request
|
|
138
|
+
});
|
|
110
139
|
if (response?.status == "Success") {
|
|
111
140
|
this.cart = {
|
|
112
141
|
["items"]: response?.data.cart,
|
|
113
142
|
["totals"]: response?.data.calculations,
|
|
114
143
|
["abndToken"]: response?.data.abndToken
|
|
115
144
|
};
|
|
116
|
-
this.lastitem = response?.data.
|
|
145
|
+
this.lastitem = response?.data.lastitem;
|
|
146
|
+
GTM_remove_from_cart(response?.data.lastitem);
|
|
117
147
|
useCheckoutStore().saveToCheckoutSession({
|
|
118
148
|
cart: response.cart.items,
|
|
119
149
|
calculations: response.cart.calculations,
|
|
@@ -130,36 +160,37 @@ export const useCartStore = defineStore("cart", {
|
|
|
130
160
|
async updateQuantity(product, qty) {
|
|
131
161
|
try {
|
|
132
162
|
const checkoutSession = useCheckoutStore().checkoutSession;
|
|
133
|
-
const { post } = useApi();
|
|
134
163
|
const apiUrl = `cart/${product.slug}/update`;
|
|
135
164
|
const request = {
|
|
136
165
|
cart: this.cart.items,
|
|
137
166
|
rowId: product.rowId,
|
|
138
167
|
qty,
|
|
139
168
|
deliverymethod: checkoutSession?.fields?.deliverymethod,
|
|
140
|
-
// shipping_state: checkoutSession?.fields?.shipping_state,
|
|
141
|
-
// shipping_postcode: checkoutSession?.fields?.shipping_postcode,
|
|
142
|
-
// shipping_country: checkoutSession?.fields?.shipping_country,
|
|
143
169
|
shippingmethod: checkoutSession?.fields?.shippingmethod,
|
|
144
170
|
abndToken: this.cart.abndToken
|
|
145
171
|
};
|
|
146
172
|
if (this.coupon?.length > 0) {
|
|
147
173
|
request.vouchercodes = this.coupon;
|
|
148
174
|
}
|
|
149
|
-
const
|
|
175
|
+
const config = useRuntimeConfig();
|
|
176
|
+
const response = await flowrixApi.post(apiUrl, config, {
|
|
177
|
+
body: request
|
|
178
|
+
});
|
|
150
179
|
if (response?.status == "Success") {
|
|
151
180
|
this.cart = {
|
|
152
181
|
["items"]: response?.data.cart,
|
|
153
182
|
["totals"]: response?.data.calculations,
|
|
154
183
|
["abndToken"]: response?.data.abndToken
|
|
155
184
|
};
|
|
156
|
-
this.lastitem = response?.data.
|
|
185
|
+
this.lastitem = response?.data.lastitem;
|
|
157
186
|
if (qty < product.qty) {
|
|
158
187
|
GTM_remove_from_cart(this.lastitem);
|
|
159
188
|
META_remove_from_cart(this.lastitem);
|
|
189
|
+
TikTok_remove_from_cart(this.lastitem);
|
|
160
190
|
} else {
|
|
161
191
|
GTM_add_to_cart(this.lastitem);
|
|
162
192
|
META_add_to_cart(this.lastitem);
|
|
193
|
+
TikTok_add_to_cart(this.lastitem);
|
|
163
194
|
}
|
|
164
195
|
useCheckoutStore().saveToCheckoutSession({
|
|
165
196
|
cart: response.data.cart,
|
|
@@ -178,12 +209,11 @@ export const useCartStore = defineStore("cart", {
|
|
|
178
209
|
try {
|
|
179
210
|
let couponsCodes = this.coupon || [];
|
|
180
211
|
const checkoutSession = useCheckoutStore().checkoutSession;
|
|
181
|
-
|
|
182
|
-
let apiUrl = "/checkout/applyCoupon";
|
|
212
|
+
let apiUrl = "checkout/applyCoupon";
|
|
183
213
|
const removeValue = coupon.remove ?? void 0;
|
|
184
214
|
if (removeValue !== void 0) {
|
|
185
215
|
couponsCodes.splice(removeValue, 1);
|
|
186
|
-
apiUrl = "
|
|
216
|
+
apiUrl = "checkout/remove-coupon";
|
|
187
217
|
}
|
|
188
218
|
const couponData = {
|
|
189
219
|
cart: this.cart.items,
|
|
@@ -192,7 +222,10 @@ export const useCartStore = defineStore("cart", {
|
|
|
192
222
|
code: removeValue === void 0 ? coupon.code : "",
|
|
193
223
|
abndToken: this.cart.abndToken
|
|
194
224
|
};
|
|
195
|
-
const
|
|
225
|
+
const config = useRuntimeConfig();
|
|
226
|
+
const response = await flowrixApi.post(apiUrl, config, {
|
|
227
|
+
body: couponData
|
|
228
|
+
});
|
|
196
229
|
if (response?.status === "Success" && response?.data?.calculations) {
|
|
197
230
|
this.cart.totals = response.data.calculations;
|
|
198
231
|
if (removeValue === void 0) {
|
|
@@ -201,6 +234,18 @@ export const useCartStore = defineStore("cart", {
|
|
|
201
234
|
this.coupon = Array.from(new Set(couponsCodes));
|
|
202
235
|
useCheckoutStore().saveToCheckoutSession(response.data);
|
|
203
236
|
this.errorResponseData = {};
|
|
237
|
+
this.cart = {
|
|
238
|
+
["items"]: response?.data.cart,
|
|
239
|
+
["totals"]: response?.data.calculations,
|
|
240
|
+
["abndToken"]: response?.data.abndToken
|
|
241
|
+
};
|
|
242
|
+
this.lastitem = response?.data.lastitem;
|
|
243
|
+
useCheckoutStore().saveToCheckoutSession({
|
|
244
|
+
cart: response?.data,
|
|
245
|
+
calculations: response?.data.calculations,
|
|
246
|
+
abndToken: response?.data.abndToken,
|
|
247
|
+
fields: checkoutSession?.fields
|
|
248
|
+
});
|
|
204
249
|
return response;
|
|
205
250
|
} else {
|
|
206
251
|
const errorMessage = response?.message || "Failed to apply coupon";
|
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
interface PreferenceData {
|
|
1
|
+
export interface PreferenceData {
|
|
2
2
|
fields?: Record<string, any>;
|
|
3
3
|
deliverytype?: string;
|
|
4
4
|
order_no?: string;
|
|
5
5
|
publishableKey?: any;
|
|
6
6
|
[key: string]: any;
|
|
7
7
|
}
|
|
8
|
-
interface CartItem {
|
|
8
|
+
export interface CartItem {
|
|
9
9
|
fields?: Record<string, any>;
|
|
10
10
|
deliverytype?: string;
|
|
11
11
|
order_no?: string;
|
|
12
12
|
publishableKey?: any;
|
|
13
13
|
[key: string]: any;
|
|
14
14
|
}
|
|
15
|
-
interface
|
|
15
|
+
export interface Country {
|
|
16
|
+
id: number | string;
|
|
17
|
+
}
|
|
18
|
+
export interface ConfigData {
|
|
16
19
|
preferences?: Record<string, any>[];
|
|
17
20
|
outlets?: Record<string, any>[];
|
|
18
21
|
deliverytype?: string;
|
|
@@ -24,7 +27,7 @@ interface ConfigData {
|
|
|
24
27
|
totals?: Record<string, any>;
|
|
25
28
|
[key: string]: any;
|
|
26
29
|
}
|
|
27
|
-
interface FieldData {
|
|
30
|
+
export interface FieldData {
|
|
28
31
|
billing_state?: number | string;
|
|
29
32
|
billing_firstname?: string | number;
|
|
30
33
|
firstname?: string | number;
|
|
@@ -58,7 +61,7 @@ interface FieldData {
|
|
|
58
61
|
quotation_no?: string;
|
|
59
62
|
[key: string]: any;
|
|
60
63
|
}
|
|
61
|
-
interface CheckoutState {
|
|
64
|
+
export interface CheckoutState {
|
|
62
65
|
publishableKey: Record<string, any>;
|
|
63
66
|
responseData: any[];
|
|
64
67
|
config: ConfigData;
|
|
@@ -73,13 +76,4 @@ interface CheckoutState {
|
|
|
73
76
|
PaymentErrors: any;
|
|
74
77
|
loading: boolean;
|
|
75
78
|
}
|
|
76
|
-
export declare const useCheckoutStore: import("pinia").StoreDefinition<"checkout", CheckoutState, {}, {
|
|
77
|
-
resetState(): void;
|
|
78
|
-
paymentMethods(formData: any): Promise<any>;
|
|
79
|
-
getConfig(): Promise<void>;
|
|
80
|
-
submitCheckout(): Promise<any>;
|
|
81
|
-
confirmPayment(checkoutId: string): Promise<void>;
|
|
82
|
-
CheckUserAccount(email: string): Promise<any>;
|
|
83
|
-
saveToCheckoutSession(fieldsData: FieldData): Promise<void>;
|
|
84
|
-
}>;
|
|
85
|
-
export {};
|
|
79
|
+
export declare const useCheckoutStore: import("pinia").StoreDefinition<"checkout", CheckoutState, {}, {}>;
|