@storepecker/storefront-core 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.
|
@@ -42,8 +42,24 @@ var useCartStore = create((set) => ({
|
|
|
42
42
|
addToCart: async (items, customizationInputs, addressId) => {
|
|
43
43
|
set({ status: "loading" /* LOADING */ });
|
|
44
44
|
try {
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
if (auth_default.getUserDetails()) {
|
|
46
|
+
await addToCart(items, customizationInputs);
|
|
47
|
+
await useCartStore.getState().syncCart(addressId);
|
|
48
|
+
} else {
|
|
49
|
+
const cart = cart_default.get();
|
|
50
|
+
if (cart) {
|
|
51
|
+
items.forEach((item) => {
|
|
52
|
+
const product = cart.product_variants.find(
|
|
53
|
+
(p) => p.id === item.variant_id
|
|
54
|
+
);
|
|
55
|
+
if (product) {
|
|
56
|
+
cart_default.add(product);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
const updatedCart = cart_default.get();
|
|
61
|
+
if (updatedCart) set({ cart: updatedCart });
|
|
62
|
+
}
|
|
47
63
|
} catch {
|
|
48
64
|
} finally {
|
|
49
65
|
set({ status: "idle" /* IDLE */ });
|
|
@@ -52,8 +68,26 @@ var useCartStore = create((set) => ({
|
|
|
52
68
|
removeFromCart: async (items, addressId) => {
|
|
53
69
|
set({ status: "loading" /* LOADING */ });
|
|
54
70
|
try {
|
|
55
|
-
|
|
56
|
-
|
|
71
|
+
if (auth_default.getUserDetails()) {
|
|
72
|
+
await removeFromCart(items);
|
|
73
|
+
await useCartStore.getState().syncCart(addressId);
|
|
74
|
+
} else {
|
|
75
|
+
const cart = cart_default.get();
|
|
76
|
+
if (cart) {
|
|
77
|
+
items.forEach((item) => {
|
|
78
|
+
const product = cart.product_variants.find(
|
|
79
|
+
(p) => p.id === item.variant_id
|
|
80
|
+
);
|
|
81
|
+
if (product) cart_default.remove(product);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
const updatedCart = cart_default.get();
|
|
85
|
+
if (updatedCart) {
|
|
86
|
+
set({ cart: updatedCart });
|
|
87
|
+
} else {
|
|
88
|
+
set(initialState);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
57
91
|
} catch {
|
|
58
92
|
} finally {
|
|
59
93
|
set({ status: "idle" /* IDLE */ });
|
|
@@ -62,8 +96,22 @@ var useCartStore = create((set) => ({
|
|
|
62
96
|
updateCart: async (items, addressId) => {
|
|
63
97
|
set({ status: "loading" /* LOADING */ });
|
|
64
98
|
try {
|
|
65
|
-
|
|
66
|
-
|
|
99
|
+
if (auth_default.getUserDetails()) {
|
|
100
|
+
await updateCart(items);
|
|
101
|
+
await useCartStore.getState().syncCart(addressId);
|
|
102
|
+
} else {
|
|
103
|
+
const cart = cart_default.get();
|
|
104
|
+
if (cart) {
|
|
105
|
+
items.forEach((item) => {
|
|
106
|
+
const product = cart.product_variants.find(
|
|
107
|
+
(p) => p.id === item.variant_id
|
|
108
|
+
);
|
|
109
|
+
if (product) cart_default.updateQuantity(product, item.quantity);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
const updatedCart = cart_default.get();
|
|
113
|
+
if (updatedCart) set({ cart: updatedCart });
|
|
114
|
+
}
|
|
67
115
|
} catch {
|
|
68
116
|
} finally {
|
|
69
117
|
set({ status: "idle" /* IDLE */ });
|
|
@@ -44,8 +44,24 @@ var useCartStore = zustand.create((set) => ({
|
|
|
44
44
|
addToCart: async (items, customizationInputs, addressId) => {
|
|
45
45
|
set({ status: "loading" /* LOADING */ });
|
|
46
46
|
try {
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
if (chunkBBRXE57K_cjs.auth_default.getUserDetails()) {
|
|
48
|
+
await chunkA67PCF55_cjs.addToCart(items, customizationInputs);
|
|
49
|
+
await useCartStore.getState().syncCart(addressId);
|
|
50
|
+
} else {
|
|
51
|
+
const cart = chunkSMHJRNCR_cjs.cart_default.get();
|
|
52
|
+
if (cart) {
|
|
53
|
+
items.forEach((item) => {
|
|
54
|
+
const product = cart.product_variants.find(
|
|
55
|
+
(p) => p.id === item.variant_id
|
|
56
|
+
);
|
|
57
|
+
if (product) {
|
|
58
|
+
chunkSMHJRNCR_cjs.cart_default.add(product);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
const updatedCart = chunkSMHJRNCR_cjs.cart_default.get();
|
|
63
|
+
if (updatedCart) set({ cart: updatedCart });
|
|
64
|
+
}
|
|
49
65
|
} catch {
|
|
50
66
|
} finally {
|
|
51
67
|
set({ status: "idle" /* IDLE */ });
|
|
@@ -54,8 +70,26 @@ var useCartStore = zustand.create((set) => ({
|
|
|
54
70
|
removeFromCart: async (items, addressId) => {
|
|
55
71
|
set({ status: "loading" /* LOADING */ });
|
|
56
72
|
try {
|
|
57
|
-
|
|
58
|
-
|
|
73
|
+
if (chunkBBRXE57K_cjs.auth_default.getUserDetails()) {
|
|
74
|
+
await chunkA67PCF55_cjs.removeFromCart(items);
|
|
75
|
+
await useCartStore.getState().syncCart(addressId);
|
|
76
|
+
} else {
|
|
77
|
+
const cart = chunkSMHJRNCR_cjs.cart_default.get();
|
|
78
|
+
if (cart) {
|
|
79
|
+
items.forEach((item) => {
|
|
80
|
+
const product = cart.product_variants.find(
|
|
81
|
+
(p) => p.id === item.variant_id
|
|
82
|
+
);
|
|
83
|
+
if (product) chunkSMHJRNCR_cjs.cart_default.remove(product);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
const updatedCart = chunkSMHJRNCR_cjs.cart_default.get();
|
|
87
|
+
if (updatedCart) {
|
|
88
|
+
set({ cart: updatedCart });
|
|
89
|
+
} else {
|
|
90
|
+
set(initialState);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
59
93
|
} catch {
|
|
60
94
|
} finally {
|
|
61
95
|
set({ status: "idle" /* IDLE */ });
|
|
@@ -64,8 +98,22 @@ var useCartStore = zustand.create((set) => ({
|
|
|
64
98
|
updateCart: async (items, addressId) => {
|
|
65
99
|
set({ status: "loading" /* LOADING */ });
|
|
66
100
|
try {
|
|
67
|
-
|
|
68
|
-
|
|
101
|
+
if (chunkBBRXE57K_cjs.auth_default.getUserDetails()) {
|
|
102
|
+
await chunkA67PCF55_cjs.updateCart(items);
|
|
103
|
+
await useCartStore.getState().syncCart(addressId);
|
|
104
|
+
} else {
|
|
105
|
+
const cart = chunkSMHJRNCR_cjs.cart_default.get();
|
|
106
|
+
if (cart) {
|
|
107
|
+
items.forEach((item) => {
|
|
108
|
+
const product = cart.product_variants.find(
|
|
109
|
+
(p) => p.id === item.variant_id
|
|
110
|
+
);
|
|
111
|
+
if (product) chunkSMHJRNCR_cjs.cart_default.updateQuantity(product, item.quantity);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
const updatedCart = chunkSMHJRNCR_cjs.cart_default.get();
|
|
115
|
+
if (updatedCart) set({ cart: updatedCart });
|
|
116
|
+
}
|
|
69
117
|
} catch {
|
|
70
118
|
} finally {
|
|
71
119
|
set({ status: "idle" /* IDLE */ });
|
package/dist/hooks/index.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var chunkKKQKHG26_cjs = require('../chunk-KKQKHG26.cjs');
|
|
4
4
|
var chunk2AHH3XBW_cjs = require('../chunk-2AHH3XBW.cjs');
|
|
5
|
-
var
|
|
5
|
+
var chunkSABICUTC_cjs = require('../chunk-SABICUTC.cjs');
|
|
6
6
|
var chunkA67PCF55_cjs = require('../chunk-A67PCF55.cjs');
|
|
7
7
|
var chunkSMHJRNCR_cjs = require('../chunk-SMHJRNCR.cjs');
|
|
8
8
|
var chunkXLQAALMU_cjs = require('../chunk-XLQAALMU.cjs');
|
|
@@ -32,6 +32,7 @@ var useAddress = () => {
|
|
|
32
32
|
setError(null);
|
|
33
33
|
} catch (err) {
|
|
34
34
|
setError(err);
|
|
35
|
+
setData([]);
|
|
35
36
|
} finally {
|
|
36
37
|
setIsLoading(false);
|
|
37
38
|
}
|
|
@@ -318,7 +319,7 @@ function useCheckoutPayment(options) {
|
|
|
318
319
|
const [isConfirmingPayment, setIsConfirmingPayment] = react.useState(false);
|
|
319
320
|
const [showSuccessModal, setShowSuccessModal] = react.useState(false);
|
|
320
321
|
const [showFailureModal, setShowFailureModal] = react.useState(false);
|
|
321
|
-
const resetCartCount =
|
|
322
|
+
const resetCartCount = chunkSABICUTC_cjs.useCartStore((s) => s.resetCartCount);
|
|
322
323
|
const callbacks = {
|
|
323
324
|
onSuccess: (order) => {
|
|
324
325
|
setOrderSummary(order);
|
|
@@ -504,8 +505,8 @@ function useVariantSelector(options) {
|
|
|
504
505
|
}
|
|
505
506
|
function useShopCheckout(options) {
|
|
506
507
|
const { product, onNavigateToCart, onToast } = options;
|
|
507
|
-
const { addToCart, setCart } =
|
|
508
|
-
const isUserAuthenticated =
|
|
508
|
+
const { addToCart, setCart } = chunkSABICUTC_cjs.useCartStore();
|
|
509
|
+
const isUserAuthenticated = chunkSABICUTC_cjs.useAuthStore((s) => s.isAuthenticated);
|
|
509
510
|
const [isWishlisted, setIsWishlisted] = react.useState(product.is_wishlisted);
|
|
510
511
|
const [isAddedToCart, setIsAddedToCart] = react.useState(false);
|
|
511
512
|
const [loading, setLoading] = react.useState(false);
|
package/dist/hooks/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getUserDetails } from '../chunk-C7ZJZEEN.js';
|
|
2
2
|
import { findMatchingVariant, findSimilarVariant, isVariantCombinationAvailable, isColorVariantType } from '../chunk-HEFA67WK.js';
|
|
3
|
-
import { useCartStore, useAuthStore } from '../chunk-
|
|
3
|
+
import { useCartStore, useAuthStore } from '../chunk-QBRME5AG.js';
|
|
4
4
|
import { getCart, getProductList, getProductDetail, getWishlist, notifyProductStock, getProductCategories, getCategories } from '../chunk-ERLBPVFK.js';
|
|
5
5
|
import { cart_default } from '../chunk-QAC72HKO.js';
|
|
6
6
|
import { processPayment, fetchAvailableCoupons, applyCheckoutCoupon, removeCheckoutCoupon } from '../chunk-BHOXJGIE.js';
|
|
@@ -30,6 +30,7 @@ var useAddress = () => {
|
|
|
30
30
|
setError(null);
|
|
31
31
|
} catch (err) {
|
|
32
32
|
setError(err);
|
|
33
|
+
setData([]);
|
|
33
34
|
} finally {
|
|
34
35
|
setIsLoading(false);
|
|
35
36
|
}
|
package/dist/store/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkSABICUTC_cjs = require('../chunk-SABICUTC.cjs');
|
|
4
4
|
var chunkA67PCF55_cjs = require('../chunk-A67PCF55.cjs');
|
|
5
5
|
require('../chunk-SMHJRNCR.cjs');
|
|
6
6
|
require('../chunk-ZO2HREQL.cjs');
|
|
@@ -67,15 +67,15 @@ var useProductStore = zustand.create((set, get) => ({
|
|
|
67
67
|
|
|
68
68
|
Object.defineProperty(exports, "loginUser", {
|
|
69
69
|
enumerable: true,
|
|
70
|
-
get: function () { return
|
|
70
|
+
get: function () { return chunkSABICUTC_cjs.loginUser; }
|
|
71
71
|
});
|
|
72
72
|
Object.defineProperty(exports, "useAuthStore", {
|
|
73
73
|
enumerable: true,
|
|
74
|
-
get: function () { return
|
|
74
|
+
get: function () { return chunkSABICUTC_cjs.useAuthStore; }
|
|
75
75
|
});
|
|
76
76
|
Object.defineProperty(exports, "useCartStore", {
|
|
77
77
|
enumerable: true,
|
|
78
|
-
get: function () { return
|
|
78
|
+
get: function () { return chunkSABICUTC_cjs.useCartStore; }
|
|
79
79
|
});
|
|
80
80
|
exports.useProductStore = useProductStore;
|
|
81
81
|
exports.useWishlistStore = useWishlistStore;
|
package/dist/store/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { loginUser, useAuthStore, useCartStore } from '../chunk-
|
|
1
|
+
export { loginUser, useAuthStore, useCartStore } from '../chunk-QBRME5AG.js';
|
|
2
2
|
import { getWishlist, getProducts } from '../chunk-ERLBPVFK.js';
|
|
3
3
|
import '../chunk-QAC72HKO.js';
|
|
4
4
|
import '../chunk-JWKDXFS4.js';
|