@storepecker/storefront-core 2.10.0 → 2.10.1

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.
Files changed (59) hide show
  1. package/dist/api/index.cjs +20 -20
  2. package/dist/api/index.d.cts +8 -15
  3. package/dist/api/index.d.ts +8 -15
  4. package/dist/api/index.js +2 -2
  5. package/dist/{buy-now-kII0KrhP.d.ts → buy-now-CDug6LJ_.d.ts} +1 -1
  6. package/dist/{buy-now-B_15RUVT.d.cts → buy-now-DrKY5_9R.d.cts} +1 -1
  7. package/dist/checkout/index.cjs +92 -98
  8. package/dist/checkout/index.d.cts +17 -30
  9. package/dist/checkout/index.d.ts +17 -30
  10. package/dist/checkout/index.js +48 -63
  11. package/dist/{pincode-Ch3bZSJz.d.cts → checkout-totals-CbmXM9L7.d.cts} +42 -1
  12. package/dist/{pincode-CHM-ZD3H.d.ts → checkout-totals-DU8l-Wyb.d.ts} +42 -1
  13. package/dist/{chunk-NQZ5GUOG.cjs → chunk-3YPE6UPC.cjs} +24 -16
  14. package/dist/{chunk-Y4RNRPBC.js → chunk-DZPK7GPG.js} +58 -2
  15. package/dist/{chunk-TH7OAMGC.js → chunk-E4D4XOAE.js} +24 -16
  16. package/dist/{chunk-NRPK5GCJ.cjs → chunk-EFYAFXIS.cjs} +3 -3
  17. package/dist/{chunk-NOT6VKXA.cjs → chunk-H6UZTS5O.cjs} +67 -23
  18. package/dist/{chunk-ZAWZ3RB6.js → chunk-NNE42NMP.js} +1 -1
  19. package/dist/{chunk-QED6QJZC.cjs → chunk-PN6KH5PX.cjs} +59 -1
  20. package/dist/{chunk-QQHQTBAM.js → chunk-QSRVMOXT.js} +48 -6
  21. package/dist/{collections-CXgOv5_G.d.cts → collections-CKNFcE2d.d.cts} +1 -1
  22. package/dist/{collections-CNh2OGbl.d.ts → collections-CtRKsWVx.d.ts} +1 -1
  23. package/dist/components/digital-product-download-modal.d.cts +2 -2
  24. package/dist/components/digital-product-download-modal.d.ts +2 -2
  25. package/dist/components/index.d.cts +4 -5
  26. package/dist/components/index.d.ts +4 -5
  27. package/dist/components/share-button.d.cts +1 -1
  28. package/dist/components/share-button.d.ts +1 -1
  29. package/dist/components/theme-data-initializer.d.cts +4 -5
  30. package/dist/components/theme-data-initializer.d.ts +4 -5
  31. package/dist/hooks/index.cjs +62 -58
  32. package/dist/hooks/index.d.cts +9 -7
  33. package/dist/hooks/index.d.ts +9 -7
  34. package/dist/hooks/index.js +8 -5
  35. package/dist/{instagram-DalreBu6.d.cts → instagram-CSzrxk10.d.cts} +8 -2
  36. package/dist/{instagram-BADLnNQ3.d.ts → instagram-CagTLmyq.d.ts} +8 -2
  37. package/dist/models/index.d.cts +6 -7
  38. package/dist/models/index.d.ts +6 -7
  39. package/dist/orders-B6BmHCJN.d.ts +337 -0
  40. package/dist/orders-ZKP0lqRN.d.cts +337 -0
  41. package/dist/{pixelEvents-Ds6fwS9t.d.ts → pixelEvents-DqJ_CEEr.d.ts} +3 -4
  42. package/dist/{pixelEvents-COqZIgTu.d.cts → pixelEvents-bahgVW4_.d.cts} +3 -4
  43. package/dist/{product-D9liEtl4.d.cts → product-D4kol-Z-.d.cts} +26 -2
  44. package/dist/{product-D9liEtl4.d.ts → product-D4kol-Z-.d.ts} +26 -2
  45. package/dist/store/index.cjs +20 -30
  46. package/dist/store/index.d.cts +21 -7
  47. package/dist/store/index.d.ts +21 -7
  48. package/dist/store/index.js +9 -26
  49. package/dist/utils/index.cjs +2 -2
  50. package/dist/utils/index.d.cts +14 -8
  51. package/dist/utils/index.d.ts +14 -8
  52. package/dist/utils/index.js +1 -1
  53. package/dist/{wishlist-Cj0sQxiY.d.ts → wishlist-L3fM5-ie.d.ts} +1 -1
  54. package/dist/{wishlist-BakHvIFN.d.cts → wishlist-_0x0r1jt.d.cts} +1 -1
  55. package/package.json +1 -1
  56. package/dist/cart-DZq1ZEnE.d.ts +0 -153
  57. package/dist/cart-DwMFBmpC.d.cts +0 -153
  58. package/dist/orders-B3G4CyhH.d.cts +0 -166
  59. package/dist/orders-Bl-Slh72.d.ts +0 -166
@@ -1,6 +1,11 @@
1
1
  import { USER_CART } from './chunk-BQ256JKN.js';
2
2
 
3
3
  // src/utils/cart.ts
4
+ function remainingStock(product, inCart) {
5
+ const stock = Number(product?.stock_quantity);
6
+ if (product?.stock_quantity == null || Number.isNaN(stock)) return null;
7
+ return Math.max(stock - inCart, 0);
8
+ }
4
9
  var LocalCart = {
5
10
  get() {
6
11
  const storeData = localStorage.getItem(USER_CART);
@@ -9,9 +14,21 @@ var LocalCart = {
9
14
  set(cart) {
10
15
  localStorage.setItem(USER_CART, JSON.stringify(cart));
11
16
  },
17
+ /**
18
+ * Adds `quantity` of `product`, capped so the line never goes past the
19
+ * product's stock: the guest cart isn't checked against the server until
20
+ * checkout, so repeated adds would otherwise pile up past what's available.
21
+ * Returns how many units were actually added (0 when at the limit or for a
22
+ * pre-order); compare it with the requested quantity to tell the shopper.
23
+ */
12
24
  add(product, quantity = 1) {
13
- const qty = Number(quantity) || 1;
25
+ if (product?.is_preorder) return 0;
26
+ const requested = Number(quantity) || 1;
14
27
  const cart = this.get();
28
+ const inCart = Number(cart?.products_quantity?.[product.id]) || 0;
29
+ const remaining = remainingStock(product, inCart);
30
+ const qty = remaining === null ? requested : Math.min(requested, remaining);
31
+ if (qty <= 0) return 0;
15
32
  if (!cart) {
16
33
  this.set({
17
34
  product_variants: [product],
@@ -21,31 +38,22 @@ var LocalCart = {
21
38
  total_amount: Number(product.selling_price) * qty,
22
39
  variant_discounts: {}
23
40
  });
24
- return;
41
+ return qty;
25
42
  }
26
43
  const newCart = cart.product_variants || [];
27
- const existingProduct = newCart.find((prod) => prod.id === product.id);
28
- if (existingProduct) {
29
- cart.products_quantity = {
30
- ...cart.products_quantity,
31
- [product.id]: (Number(cart.products_quantity[product.id]) || 0) + qty
32
- };
33
- cart.total_quantity = Number(cart.total_quantity) + qty;
34
- cart.cart_count = Number(cart.cart_count) + qty;
35
- cart.total_amount = Number(cart.total_amount) + Number(product.selling_price) * qty;
36
- this.set(cart);
37
- return;
44
+ if (!newCart.some((prod) => prod.id === product.id)) {
45
+ newCart.push(product);
46
+ cart.product_variants = newCart;
38
47
  }
39
- newCart.push(product);
40
48
  cart.products_quantity = {
41
49
  ...cart.products_quantity,
42
- [product.id]: (cart.products_quantity[product.id] || 0) + qty
50
+ [product.id]: inCart + qty
43
51
  };
44
- cart.product_variants = newCart;
45
52
  cart.total_quantity = Number(cart.total_quantity) + qty;
46
53
  cart.cart_count = Number(cart.cart_count) + qty;
47
54
  cart.total_amount = Number(cart.total_amount) + Number(product.selling_price) * qty;
48
55
  this.set(cart);
56
+ return qty;
49
57
  },
50
58
  remove(product) {
51
59
  const cart = this.get();
@@ -1,12 +1,12 @@
1
1
  'use strict';
2
2
 
3
- var chunkNQZ5GUOG_cjs = require('./chunk-NQZ5GUOG.cjs');
3
+ var chunk3YPE6UPC_cjs = require('./chunk-3YPE6UPC.cjs');
4
4
  var chunkECHV2JSY_cjs = require('./chunk-ECHV2JSY.cjs');
5
5
  var chunkBBRXE57K_cjs = require('./chunk-BBRXE57K.cjs');
6
6
 
7
7
  // src/api/cart.ts
8
8
  async function getCart(url, addressId, shippingOptionId) {
9
- const localCart = chunkNQZ5GUOG_cjs.cart_default.get();
9
+ const localCart = chunk3YPE6UPC_cjs.cart_default.get();
10
10
  return chunkBBRXE57K_cjs.auth_default.getUserDetails() ? (await chunkECHV2JSY_cjs.http_service_default.get(url, { params: { address_id: addressId, shipping_option_id: shippingOptionId } })).data : localCart || {
11
11
  product_variants: [],
12
12
  total_amount: 0,
@@ -28,7 +28,7 @@ async function getCart(url, addressId, shippingOptionId) {
28
28
  };
29
29
  }
30
30
  async function getCartItemQuantity() {
31
- const localCart = chunkNQZ5GUOG_cjs.cart_default.get();
31
+ const localCart = chunk3YPE6UPC_cjs.cart_default.get();
32
32
  return chunkBBRXE57K_cjs.auth_default.getUserDetails() ? (await chunkECHV2JSY_cjs.http_service_default.get("/customer/cart/quantity/")).data : { total_quantity: localCart?.total_quantity || 0 };
33
33
  }
34
34
  async function addToCart(product, customizationInputs) {
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var chunkNRPK5GCJ_cjs = require('./chunk-NRPK5GCJ.cjs');
4
- var chunkNQZ5GUOG_cjs = require('./chunk-NQZ5GUOG.cjs');
3
+ var chunkEFYAFXIS_cjs = require('./chunk-EFYAFXIS.cjs');
4
+ var chunk3YPE6UPC_cjs = require('./chunk-3YPE6UPC.cjs');
5
5
  var chunkH6FJYRO3_cjs = require('./chunk-H6FJYRO3.cjs');
6
6
  var chunkBBRXE57K_cjs = require('./chunk-BBRXE57K.cjs');
7
7
  var chunkNE3ZHELZ_cjs = require('./chunk-NE3ZHELZ.cjs');
@@ -9,21 +9,62 @@ var zustand = require('zustand');
9
9
  var typescriptCookie = require('typescript-cookie');
10
10
 
11
11
  var initialState = {
12
+ wishlist_count: 0,
13
+ product_variants: []
14
+ };
15
+ var useWishlistStore = zustand.create((set, get) => ({
16
+ ...initialState,
17
+ loaded: false,
18
+ setWishlist: (wishlist) => set({ ...wishlist, loaded: true }),
19
+ resetWishlist: () => set({ ...initialState, loaded: false }),
20
+ syncWishlist: async () => {
21
+ try {
22
+ const response = await chunkEFYAFXIS_cjs.getWishlist("/customer/wishlist/");
23
+ if (response.data) {
24
+ set({
25
+ wishlist_count: response.data.wishlist_count,
26
+ product_variants: response.data.product_variants,
27
+ loaded: true
28
+ });
29
+ }
30
+ } catch {
31
+ }
32
+ },
33
+ removeAddedFromWishlist: async (variantIds) => {
34
+ if (!chunkBBRXE57K_cjs.auth_default.getUserDetails() || variantIds.length === 0) return true;
35
+ try {
36
+ if (!get().loaded) await get().syncWishlist();
37
+ const ids = get().product_variants.filter((item) => variantIds.includes(item.id)).map((item) => item.id);
38
+ if (ids.length === 0) return true;
39
+ const response = await chunkEFYAFXIS_cjs.removeFromWishlist(ids);
40
+ if (response.data) get().setWishlist(response.data);
41
+ return true;
42
+ } catch {
43
+ return false;
44
+ }
45
+ }
46
+ }));
47
+ function useIsWishlisted(variantId, initial) {
48
+ return useWishlistStore(
49
+ (s) => s.loaded && variantId !== void 0 ? s.product_variants.some((item) => item.id === variantId) : !!initial
50
+ );
51
+ }
52
+ var initialState2 = {
12
53
  cart: null,
13
54
  total_quantity: 0,
14
55
  status: "idle" /* IDLE */
15
56
  };
16
57
  var useCartStore = zustand.create((set) => ({
17
- ...initialState,
58
+ ...initialState2,
18
59
  setCart: (cart) => set({ cart, total_quantity: cart.total_quantity, status: "idle" /* IDLE */ }),
19
- resetCart: () => set(initialState),
60
+ resetCart: () => set(initialState2),
20
61
  resetCartCount: () => set((state) => {
21
62
  if (!state.cart) return { ...state, total_quantity: 0 };
22
63
  return { cart: { ...state.cart, total_quantity: 0 }, total_quantity: 0 };
23
64
  }),
24
65
  fetchCartItemQuantity: async () => {
25
66
  try {
26
- const { total_quantity } = await chunkNRPK5GCJ_cjs.getCartItemQuantity();
67
+ const { total_quantity } = await chunkEFYAFXIS_cjs.getCartItemQuantity();
27
68
  set({ total_quantity });
28
69
  } catch (error) {
29
70
  console.error("Failed to fetch cart item quantity", error);
@@ -32,7 +73,7 @@ var useCartStore = zustand.create((set) => ({
32
73
  syncCart: async (addressId, shippingOptionId) => {
33
74
  set({ status: "loading" /* LOADING */ });
34
75
  try {
35
- const response = await chunkNRPK5GCJ_cjs.getCart("/customer/cart/", addressId, shippingOptionId);
76
+ const response = await chunkEFYAFXIS_cjs.getCart("/customer/cart/", addressId, shippingOptionId);
36
77
  if (response) {
37
78
  set({ cart: response, total_quantity: response.total_quantity, status: "idle" /* IDLE */ });
38
79
  }
@@ -43,7 +84,7 @@ var useCartStore = zustand.create((set) => ({
43
84
  fetchCart: async (addressId, shippingOptionId) => {
44
85
  set({ status: "loading" /* LOADING */ });
45
86
  try {
46
- const response = await chunkNRPK5GCJ_cjs.getCart("/customer/cart/", addressId, shippingOptionId);
87
+ const response = await chunkEFYAFXIS_cjs.getCart("/customer/cart/", addressId, shippingOptionId);
47
88
  if (response) {
48
89
  set({ cart: response, total_quantity: response.total_quantity, status: "idle" /* IDLE */ });
49
90
  }
@@ -55,16 +96,17 @@ var useCartStore = zustand.create((set) => ({
55
96
  set({ status: "loading" /* LOADING */ });
56
97
  try {
57
98
  if (chunkBBRXE57K_cjs.auth_default.getUserDetails()) {
58
- await chunkNRPK5GCJ_cjs.addToCart(items, customizationInputs);
99
+ await chunkEFYAFXIS_cjs.addToCart(items, customizationInputs);
59
100
  await useCartStore.getState().syncCart(addressId);
101
+ await useWishlistStore.getState().removeAddedFromWishlist(items.map((item) => item.variant_id));
60
102
  } else {
61
- const cart = chunkNQZ5GUOG_cjs.cart_default.get();
103
+ const cart = chunk3YPE6UPC_cjs.cart_default.get();
62
104
  items.forEach((item) => {
63
105
  const product = products?.find((p) => p.id === item.variant_id) || cart?.product_variants?.find((p) => p.id === item.variant_id);
64
106
  if (!product) return;
65
- chunkNQZ5GUOG_cjs.cart_default.add(product, item.quantity);
107
+ chunk3YPE6UPC_cjs.cart_default.add(product, item.quantity);
66
108
  });
67
- const updatedCart = chunkNQZ5GUOG_cjs.cart_default.get();
109
+ const updatedCart = chunk3YPE6UPC_cjs.cart_default.get();
68
110
  if (updatedCart) {
69
111
  set({ cart: updatedCart, total_quantity: updatedCart.total_quantity });
70
112
  }
@@ -78,26 +120,26 @@ var useCartStore = zustand.create((set) => ({
78
120
  set({ status: "loading" /* LOADING */ });
79
121
  try {
80
122
  if (chunkBBRXE57K_cjs.auth_default.getUserDetails()) {
81
- await chunkNRPK5GCJ_cjs.removeFromCart(items);
123
+ await chunkEFYAFXIS_cjs.removeFromCart(items);
82
124
  await useCartStore.getState().syncCart(addressId);
83
125
  } else {
84
- const cart = chunkNQZ5GUOG_cjs.cart_default.get();
126
+ const cart = chunk3YPE6UPC_cjs.cart_default.get();
85
127
  if (cart) {
86
128
  items.forEach((item) => {
87
129
  const product = cart.product_variants.find(
88
130
  (p) => p.id === item.variant_id
89
131
  );
90
- if (product) chunkNQZ5GUOG_cjs.cart_default.remove(product);
132
+ if (product) chunk3YPE6UPC_cjs.cart_default.remove(product);
91
133
  });
92
134
  }
93
- const updatedCart = chunkNQZ5GUOG_cjs.cart_default.get();
135
+ const updatedCart = chunk3YPE6UPC_cjs.cart_default.get();
94
136
  if (updatedCart) {
95
137
  set({
96
138
  cart: updatedCart,
97
139
  total_quantity: updatedCart.total_quantity
98
140
  });
99
141
  } else {
100
- set(initialState);
142
+ set(initialState2);
101
143
  }
102
144
  }
103
145
  } catch {
@@ -109,19 +151,19 @@ var useCartStore = zustand.create((set) => ({
109
151
  set({ status: "loading" /* LOADING */ });
110
152
  try {
111
153
  if (chunkBBRXE57K_cjs.auth_default.getUserDetails()) {
112
- await chunkNRPK5GCJ_cjs.updateCart(items);
154
+ await chunkEFYAFXIS_cjs.updateCart(items);
113
155
  await useCartStore.getState().syncCart(addressId);
114
156
  } else {
115
- const cart = chunkNQZ5GUOG_cjs.cart_default.get();
157
+ const cart = chunk3YPE6UPC_cjs.cart_default.get();
116
158
  if (cart) {
117
159
  items.forEach((item) => {
118
160
  const product = cart.product_variants.find(
119
161
  (p) => p.id === item.variant_id
120
162
  );
121
- if (product) chunkNQZ5GUOG_cjs.cart_default.updateQuantity(product, item.quantity);
163
+ if (product) chunk3YPE6UPC_cjs.cart_default.updateQuantity(product, item.quantity);
122
164
  });
123
165
  }
124
- const updatedCart = chunkNQZ5GUOG_cjs.cart_default.get();
166
+ const updatedCart = chunk3YPE6UPC_cjs.cart_default.get();
125
167
  if (updatedCart) {
126
168
  set({
127
169
  cart: updatedCart,
@@ -169,10 +211,10 @@ var useAuthStore = zustand.create((set, get) => ({
169
211
  setTimeout(async () => {
170
212
  try {
171
213
  set({ user, status: "success" /* SUCCESS */, isAuthenticated: true });
172
- const localCartItems = chunkNQZ5GUOG_cjs.cart_default.get();
214
+ const localCartItems = chunk3YPE6UPC_cjs.cart_default.get();
173
215
  if (localCartItems) {
174
216
  await mergeLocalCart(localCartItems);
175
- chunkNQZ5GUOG_cjs.cart_default.clear();
217
+ chunk3YPE6UPC_cjs.cart_default.clear();
176
218
  await useCartStore.getState().fetchCart();
177
219
  setTimeout(() => {
178
220
  if (!preventRefreshAfterLogin) {
@@ -211,7 +253,7 @@ async function mergeLocalCart(localCart) {
211
253
  (item) => !Number.isNaN(item.variant_id) && Number.isInteger(item.quantity) && item.quantity >= 1
212
254
  );
213
255
  if (cartItems.length === 0) return;
214
- await chunkNRPK5GCJ_cjs.mergeCart(cartItems, localCart.customization_inputs);
256
+ await chunkEFYAFXIS_cjs.mergeCart(cartItems, localCart.customization_inputs);
215
257
  }
216
258
  var loginUser = async (user) => {
217
259
  const { access, refresh, ...userData } = user;
@@ -223,3 +265,5 @@ var loginUser = async (user) => {
223
265
  exports.loginUser = loginUser;
224
266
  exports.useAuthStore = useAuthStore;
225
267
  exports.useCartStore = useCartStore;
268
+ exports.useIsWishlisted = useIsWishlisted;
269
+ exports.useWishlistStore = useWishlistStore;
@@ -1,4 +1,4 @@
1
- import { cart_default } from './chunk-TH7OAMGC.js';
1
+ import { cart_default } from './chunk-E4D4XOAE.js';
2
2
  import { http_service_default } from './chunk-3SYYP3XV.js';
3
3
  import { auth_default } from './chunk-WEMNXIRS.js';
4
4
 
@@ -101,7 +101,7 @@ async function handleRazorpaySuccess(data, order, callbacks, options) {
101
101
  try {
102
102
  callbacks.onPaymentStart?.();
103
103
  if (options?.isPublic) {
104
- await chunkH6FJYRO3_cjs.razorpayPublicOrderSuccess(data);
104
+ await chunkH6FJYRO3_cjs.razorpayPublicOrderSuccess({ ...data, order_number: order.order_number });
105
105
  } else {
106
106
  await chunkH6FJYRO3_cjs.razorpayOrderSuccess(data);
107
107
  }
@@ -564,6 +564,62 @@ function getAreaOptions(match) {
564
564
  return unique.length > 1 ? unique : NO_AREAS;
565
565
  }
566
566
 
567
+ // src/checkout/checkout-totals.ts
568
+ function getCustomizationPrice(input) {
569
+ return Number(
570
+ input?.effective_price ?? input?.additional_price ?? input?.customization_price ?? 0
571
+ ) || 0;
572
+ }
573
+ function calculateCartTotals(cart, customizationOverride) {
574
+ var _a;
575
+ const variants = cart?.product_variants || [];
576
+ const quantityOf = (variantId) => {
577
+ const line = variants.find((item) => item.id === variantId);
578
+ return Number(line?.quantity) || Number(cart?.products_quantity?.[variantId]) || 0;
579
+ };
580
+ let subtotal = 0;
581
+ let discountAmount = 0;
582
+ let totalInclusiveTax = 0;
583
+ let totalExclusiveTax = 0;
584
+ for (const item of variants) {
585
+ const quantity = quantityOf(item.id);
586
+ const actualPrice = Number(item.actual_price);
587
+ const sellingPrice = Number(item.selling_price);
588
+ if (actualPrice > 0) {
589
+ subtotal += actualPrice * quantity;
590
+ discountAmount += (actualPrice - sellingPrice) * quantity;
591
+ } else {
592
+ subtotal += sellingPrice * quantity;
593
+ }
594
+ const tax = Number(item.total_tax_price) || 0;
595
+ if (item.is_tax_inclusive_price) totalInclusiveTax += tax;
596
+ else totalExclusiveTax += tax;
597
+ }
598
+ const groupedCustomizeInputs = {};
599
+ for (const input of cart?.customization_inputs || []) {
600
+ (groupedCustomizeInputs[_a = input.product_variant] || (groupedCustomizeInputs[_a] = [])).push(input);
601
+ }
602
+ const customizationTotalsByVariant = {};
603
+ for (const input of customizationOverride || cart?.customization_inputs || []) {
604
+ customizationTotalsByVariant[input.product_variant] = (customizationTotalsByVariant[input.product_variant] || 0) + getCustomizationPrice(input);
605
+ }
606
+ const totalCustomizationPrice = Object.entries(
607
+ customizationTotalsByVariant
608
+ ).reduce(
609
+ (acc, [variantId, perUnit]) => acc + perUnit * quantityOf(Number(variantId)),
610
+ 0
611
+ );
612
+ return {
613
+ subtotal,
614
+ discountAmount,
615
+ totalInclusiveTax,
616
+ totalExclusiveTax,
617
+ totalCustomizationPrice,
618
+ customizationTotalsByVariant,
619
+ groupedCustomizeInputs
620
+ };
621
+ }
622
+
567
623
  exports.DEFAULT_ADDRESS_SCHEMA_MESSAGES = DEFAULT_ADDRESS_SCHEMA_MESSAGES;
568
624
  exports.INVALID_PINCODE = INVALID_PINCODE;
569
625
  exports.NO_POSTAL_CODE = NO_POSTAL_CODE;
@@ -573,6 +629,7 @@ exports.PINCODE_VALIDATION_UNAVAILABLE = PINCODE_VALIDATION_UNAVAILABLE;
573
629
  exports.applyCheckoutCoupon = applyCheckoutCoupon;
574
630
  exports.buildAddressFormat = buildAddressFormat;
575
631
  exports.buildAddressSchema = buildAddressSchema;
632
+ exports.calculateCartTotals = calculateCartTotals;
576
633
  exports.clearPincodeCache = clearPincodeCache;
577
634
  exports.detectForeignPhone = detectForeignPhone;
578
635
  exports.fetchAppliedCoupon = fetchAppliedCoupon;
@@ -580,6 +637,7 @@ exports.fetchAvailableCoupons = fetchAvailableCoupons;
580
637
  exports.findStateByName = findStateByName;
581
638
  exports.findSubdivision = findSubdivision;
582
639
  exports.getAreaOptions = getAreaOptions;
640
+ exports.getCustomizationPrice = getCustomizationPrice;
583
641
  exports.getPincodeError = getPincodeError;
584
642
  exports.getPostcodeHint = getPostcodeHint;
585
643
  exports.handleCODPayment = handleCODPayment;
@@ -1,5 +1,5 @@
1
- import { updateCart, removeFromCart, addToCart, getCart, getCartItemQuantity, mergeCart } from './chunk-ZAWZ3RB6.js';
2
- import { cart_default } from './chunk-TH7OAMGC.js';
1
+ import { removeFromWishlist, getWishlist, updateCart, removeFromCart, addToCart, getCart, getCartItemQuantity, mergeCart } from './chunk-NNE42NMP.js';
2
+ import { cart_default } from './chunk-E4D4XOAE.js';
3
3
  import { updateOrderCustomization } from './chunk-KCLVR6G5.js';
4
4
  import { auth_default } from './chunk-WEMNXIRS.js';
5
5
  import { USER_CRED_TOKEN, USER_CREDENTIALS } from './chunk-BQ256JKN.js';
@@ -7,14 +7,55 @@ import { create } from 'zustand';
7
7
  import { getCookie } from 'typescript-cookie';
8
8
 
9
9
  var initialState = {
10
+ wishlist_count: 0,
11
+ product_variants: []
12
+ };
13
+ var useWishlistStore = create((set, get) => ({
14
+ ...initialState,
15
+ loaded: false,
16
+ setWishlist: (wishlist) => set({ ...wishlist, loaded: true }),
17
+ resetWishlist: () => set({ ...initialState, loaded: false }),
18
+ syncWishlist: async () => {
19
+ try {
20
+ const response = await getWishlist("/customer/wishlist/");
21
+ if (response.data) {
22
+ set({
23
+ wishlist_count: response.data.wishlist_count,
24
+ product_variants: response.data.product_variants,
25
+ loaded: true
26
+ });
27
+ }
28
+ } catch {
29
+ }
30
+ },
31
+ removeAddedFromWishlist: async (variantIds) => {
32
+ if (!auth_default.getUserDetails() || variantIds.length === 0) return true;
33
+ try {
34
+ if (!get().loaded) await get().syncWishlist();
35
+ const ids = get().product_variants.filter((item) => variantIds.includes(item.id)).map((item) => item.id);
36
+ if (ids.length === 0) return true;
37
+ const response = await removeFromWishlist(ids);
38
+ if (response.data) get().setWishlist(response.data);
39
+ return true;
40
+ } catch {
41
+ return false;
42
+ }
43
+ }
44
+ }));
45
+ function useIsWishlisted(variantId, initial) {
46
+ return useWishlistStore(
47
+ (s) => s.loaded && variantId !== void 0 ? s.product_variants.some((item) => item.id === variantId) : !!initial
48
+ );
49
+ }
50
+ var initialState2 = {
10
51
  cart: null,
11
52
  total_quantity: 0,
12
53
  status: "idle" /* IDLE */
13
54
  };
14
55
  var useCartStore = create((set) => ({
15
- ...initialState,
56
+ ...initialState2,
16
57
  setCart: (cart) => set({ cart, total_quantity: cart.total_quantity, status: "idle" /* IDLE */ }),
17
- resetCart: () => set(initialState),
58
+ resetCart: () => set(initialState2),
18
59
  resetCartCount: () => set((state) => {
19
60
  if (!state.cart) return { ...state, total_quantity: 0 };
20
61
  return { cart: { ...state.cart, total_quantity: 0 }, total_quantity: 0 };
@@ -55,6 +96,7 @@ var useCartStore = create((set) => ({
55
96
  if (auth_default.getUserDetails()) {
56
97
  await addToCart(items, customizationInputs);
57
98
  await useCartStore.getState().syncCart(addressId);
99
+ await useWishlistStore.getState().removeAddedFromWishlist(items.map((item) => item.variant_id));
58
100
  } else {
59
101
  const cart = cart_default.get();
60
102
  items.forEach((item) => {
@@ -95,7 +137,7 @@ var useCartStore = create((set) => ({
95
137
  total_quantity: updatedCart.total_quantity
96
138
  });
97
139
  } else {
98
- set(initialState);
140
+ set(initialState2);
99
141
  }
100
142
  }
101
143
  } catch {
@@ -218,4 +260,4 @@ var loginUser = async (user) => {
218
260
  auth_default.setRefreshToken(refresh);
219
261
  };
220
262
 
221
- export { loginUser, useAuthStore, useCartStore };
263
+ export { loginUser, useAuthStore, useCartStore, useIsWishlisted, useWishlistStore };
@@ -1,4 +1,4 @@
1
- import { d as Product } from './product-D9liEtl4.cjs';
1
+ import { d as Product } from './product-D4kol-Z-.cjs';
2
2
 
3
3
  interface CollectionResponse {
4
4
  id: number;
@@ -1,4 +1,4 @@
1
- import { d as Product } from './product-D9liEtl4.js';
1
+ import { d as Product } from './product-D4kol-Z-.js';
2
2
 
3
3
  interface CollectionResponse {
4
4
  id: number;
@@ -1,5 +1,5 @@
1
- import { O as Order } from '../orders-B3G4CyhH.cjs';
2
- import { f as ProductDetail } from '../product-D9liEtl4.cjs';
1
+ import { O as Order } from '../orders-ZKP0lqRN.cjs';
2
+ import { f as ProductDetail } from '../product-D4kol-Z-.cjs';
3
3
  import 'react-toastify';
4
4
 
5
5
  interface DigitalProductDownloadModalProps {
@@ -1,5 +1,5 @@
1
- import { O as Order } from '../orders-Bl-Slh72.js';
2
- import { f as ProductDetail } from '../product-D9liEtl4.js';
1
+ import { O as Order } from '../orders-B6BmHCJN.js';
2
+ import { f as ProductDetail } from '../product-D4kol-Z-.js';
3
3
  import 'react-toastify';
4
4
 
5
5
  interface DigitalProductDownloadModalProps {
@@ -8,10 +8,9 @@ import 'react';
8
8
  import '../useAddressForm-wleIo78M.cjs';
9
9
  import 'formik';
10
10
  import '../address-BdIB6IuI.cjs';
11
- import '../product-D9liEtl4.cjs';
11
+ import '../product-D4kol-Z-.cjs';
12
12
  import 'react-toastify';
13
13
  import 'react/jsx-runtime';
14
- import '../orders-B3G4CyhH.cjs';
15
- import '../pixelEvents-COqZIgTu.cjs';
16
- import '../cart-DwMFBmpC.cjs';
17
- import '../collections-CXgOv5_G.cjs';
14
+ import '../orders-ZKP0lqRN.cjs';
15
+ import '../pixelEvents-bahgVW4_.cjs';
16
+ import '../collections-CKNFcE2d.cjs';
@@ -8,10 +8,9 @@ import 'react';
8
8
  import '../useAddressForm-fMOb5Z-a.js';
9
9
  import 'formik';
10
10
  import '../address-BdIB6IuI.js';
11
- import '../product-D9liEtl4.js';
11
+ import '../product-D4kol-Z-.js';
12
12
  import 'react-toastify';
13
13
  import 'react/jsx-runtime';
14
- import '../orders-Bl-Slh72.js';
15
- import '../pixelEvents-Ds6fwS9t.js';
16
- import '../cart-DZq1ZEnE.js';
17
- import '../collections-CNh2OGbl.js';
14
+ import '../orders-B6BmHCJN.js';
15
+ import '../pixelEvents-DqJ_CEEr.js';
16
+ import '../collections-CtRKsWVx.js';
@@ -1,4 +1,4 @@
1
- import { f as ProductDetail } from '../product-D9liEtl4.cjs';
1
+ import { f as ProductDetail } from '../product-D4kol-Z-.cjs';
2
2
  import 'react-toastify';
3
3
 
4
4
  interface ShareButtonProps {
@@ -1,4 +1,4 @@
1
- import { f as ProductDetail } from '../product-D9liEtl4.js';
1
+ import { f as ProductDetail } from '../product-D4kol-Z-.js';
2
2
  import 'react-toastify';
3
3
 
4
4
  interface ShareButtonProps {
@@ -1,9 +1,8 @@
1
- import { P as PageHeaderProps } from '../pixelEvents-COqZIgTu.cjs';
2
- import '../cart-DwMFBmpC.cjs';
3
- import '../product-D9liEtl4.cjs';
1
+ import { P as PageHeaderProps } from '../pixelEvents-bahgVW4_.cjs';
2
+ import '../orders-ZKP0lqRN.cjs';
3
+ import '../product-D4kol-Z-.cjs';
4
4
  import 'react-toastify';
5
- import '../collections-CXgOv5_G.cjs';
6
- import '../orders-B3G4CyhH.cjs';
5
+ import '../collections-CKNFcE2d.cjs';
7
6
 
8
7
  declare function ThemeDataInitializer({ themeData, }: {
9
8
  themeData: PageHeaderProps;
@@ -1,9 +1,8 @@
1
- import { P as PageHeaderProps } from '../pixelEvents-Ds6fwS9t.js';
2
- import '../cart-DZq1ZEnE.js';
3
- import '../product-D9liEtl4.js';
1
+ import { P as PageHeaderProps } from '../pixelEvents-DqJ_CEEr.js';
2
+ import '../orders-B6BmHCJN.js';
3
+ import '../product-D4kol-Z-.js';
4
4
  import 'react-toastify';
5
- import '../collections-CNh2OGbl.js';
6
- import '../orders-Bl-Slh72.js';
5
+ import '../collections-CtRKsWVx.js';
7
6
 
8
7
  declare function ThemeDataInitializer({ themeData, }: {
9
8
  themeData: PageHeaderProps;