@storepecker/storefront-core 2.4.2 → 2.5.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 (37) hide show
  1. package/dist/api/index.cjs +50 -42
  2. package/dist/api/index.d.cts +11 -4
  3. package/dist/api/index.d.ts +11 -4
  4. package/dist/api/index.js +2 -2
  5. package/dist/{cart-y-7RPmnQ.d.ts → cart-CLf2ljxd.d.ts} +21 -0
  6. package/dist/{cart-kJoawc_Z.d.cts → cart-CuLMWnfy.d.cts} +21 -0
  7. package/dist/checkout/index.cjs +22 -22
  8. package/dist/checkout/index.d.cts +2 -2
  9. package/dist/checkout/index.d.ts +2 -2
  10. package/dist/checkout/index.js +2 -2
  11. package/dist/{chunk-QU53I4AA.cjs → chunk-23YAZNVF.cjs} +37 -18
  12. package/dist/{chunk-AOJRQMJZ.cjs → chunk-DXQX7ZIL.cjs} +8 -1
  13. package/dist/{chunk-Y2CPMT34.cjs → chunk-MTSMQAZR.cjs} +11 -3
  14. package/dist/{chunk-SFMTL3AQ.js → chunk-NXQIWB36.js} +10 -6
  15. package/dist/{chunk-ZIALBJZK.cjs → chunk-PZJT2Y5B.cjs} +15 -11
  16. package/dist/{chunk-YFF6DWZM.js → chunk-S3ZZ3ZA7.js} +8 -2
  17. package/dist/{chunk-BR45AXQP.js → chunk-VZAIAQZJ.js} +33 -14
  18. package/dist/{chunk-U25T7M6S.js → chunk-XURYZRER.js} +11 -4
  19. package/dist/components/index.d.cts +2 -2
  20. package/dist/components/index.d.ts +2 -2
  21. package/dist/components/theme-data-initializer.d.cts +2 -2
  22. package/dist/components/theme-data-initializer.d.ts +2 -2
  23. package/dist/hooks/index.cjs +22 -21
  24. package/dist/hooks/index.d.cts +2 -2
  25. package/dist/hooks/index.d.ts +2 -2
  26. package/dist/hooks/index.js +6 -5
  27. package/dist/models/index.d.cts +1 -1
  28. package/dist/models/index.d.ts +1 -1
  29. package/dist/{pixelEvents-C1rFPOwb.d.cts → pixelEvents-CXViXGtV.d.cts} +1 -1
  30. package/dist/{pixelEvents-Bo-VjAx8.d.ts → pixelEvents-LqK0Ltr_.d.ts} +1 -1
  31. package/dist/store/index.cjs +8 -8
  32. package/dist/store/index.d.cts +5 -4
  33. package/dist/store/index.d.ts +5 -4
  34. package/dist/store/index.js +3 -3
  35. package/dist/utils/index.d.cts +3 -3
  36. package/dist/utils/index.d.ts +3 -3
  37. package/package.json +1 -1
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var chunkY2CPMT34_cjs = require('./chunk-Y2CPMT34.cjs');
3
+ var chunkMTSMQAZR_cjs = require('./chunk-MTSMQAZR.cjs');
4
4
  var chunkSMHJRNCR_cjs = require('./chunk-SMHJRNCR.cjs');
5
- var chunkAOJRQMJZ_cjs = require('./chunk-AOJRQMJZ.cjs');
5
+ var chunkDXQX7ZIL_cjs = require('./chunk-DXQX7ZIL.cjs');
6
6
  var chunkBBRXE57K_cjs = require('./chunk-BBRXE57K.cjs');
7
7
  var chunkNE3ZHELZ_cjs = require('./chunk-NE3ZHELZ.cjs');
8
8
  var zustand = require('zustand');
@@ -10,33 +10,42 @@ var typescriptCookie = require('typescript-cookie');
10
10
 
11
11
  var initialState = {
12
12
  cart: null,
13
+ total_quantity: 0,
13
14
  status: "idle" /* IDLE */
14
15
  };
15
16
  var useCartStore = zustand.create((set) => ({
16
17
  ...initialState,
17
- setCart: (cart) => set({ cart, status: "idle" /* IDLE */ }),
18
+ setCart: (cart) => set({ cart, total_quantity: cart.total_quantity, status: "idle" /* IDLE */ }),
18
19
  resetCart: () => set(initialState),
19
20
  resetCartCount: () => set((state) => {
20
- if (!state.cart) return state;
21
- return { cart: { ...state.cart, total_quantity: 0 } };
21
+ if (!state.cart) return { ...state, total_quantity: 0 };
22
+ return { cart: { ...state.cart, total_quantity: 0 }, total_quantity: 0 };
22
23
  }),
23
- syncCart: async (addressId) => {
24
+ fetchCartQuantity: async () => {
25
+ try {
26
+ const { total_quantity } = await chunkMTSMQAZR_cjs.getCartItemQuantity();
27
+ set({ total_quantity });
28
+ } catch (error) {
29
+ console.error("Failed to fetch cart quantity", error);
30
+ }
31
+ },
32
+ syncCart: async (addressId, shippingOptionId) => {
24
33
  set({ status: "loading" /* LOADING */ });
25
34
  try {
26
- const response = await chunkY2CPMT34_cjs.getCart("/customer/cart/", addressId);
35
+ const response = await chunkMTSMQAZR_cjs.getCart("/customer/cart/", addressId, shippingOptionId);
27
36
  if (response) {
28
- set({ cart: response, status: "idle" /* IDLE */ });
37
+ set({ cart: response, total_quantity: response.total_quantity, status: "idle" /* IDLE */ });
29
38
  }
30
39
  } catch {
31
40
  set({ status: "idle" /* IDLE */ });
32
41
  }
33
42
  },
34
- fetchCart: async (addressId) => {
43
+ fetchCart: async (addressId, shippingOptionId) => {
35
44
  set({ status: "loading" /* LOADING */ });
36
45
  try {
37
- const response = await chunkY2CPMT34_cjs.getCart("/customer/cart/", addressId);
46
+ const response = await chunkMTSMQAZR_cjs.getCart("/customer/cart/", addressId, shippingOptionId);
38
47
  if (response) {
39
- set({ cart: response, status: "idle" /* IDLE */ });
48
+ set({ cart: response, total_quantity: response.total_quantity, status: "idle" /* IDLE */ });
40
49
  }
41
50
  } catch {
42
51
  set({ status: "idle" /* IDLE */ });
@@ -46,7 +55,7 @@ var useCartStore = zustand.create((set) => ({
46
55
  set({ status: "loading" /* LOADING */ });
47
56
  try {
48
57
  if (chunkBBRXE57K_cjs.auth_default.getUserDetails()) {
49
- await chunkY2CPMT34_cjs.addToCart(items, customizationInputs);
58
+ await chunkMTSMQAZR_cjs.addToCart(items, customizationInputs);
50
59
  await useCartStore.getState().syncCart(addressId);
51
60
  } else {
52
61
  const cart = chunkSMHJRNCR_cjs.cart_default.get();
@@ -61,7 +70,9 @@ var useCartStore = zustand.create((set) => ({
61
70
  });
62
71
  }
63
72
  const updatedCart = chunkSMHJRNCR_cjs.cart_default.get();
64
- if (updatedCart) set({ cart: updatedCart });
73
+ if (updatedCart) {
74
+ set({ cart: updatedCart, total_quantity: updatedCart.total_quantity });
75
+ }
65
76
  }
66
77
  } catch {
67
78
  } finally {
@@ -72,7 +83,7 @@ var useCartStore = zustand.create((set) => ({
72
83
  set({ status: "loading" /* LOADING */ });
73
84
  try {
74
85
  if (chunkBBRXE57K_cjs.auth_default.getUserDetails()) {
75
- await chunkY2CPMT34_cjs.removeFromCart(items);
86
+ await chunkMTSMQAZR_cjs.removeFromCart(items);
76
87
  await useCartStore.getState().syncCart(addressId);
77
88
  } else {
78
89
  const cart = chunkSMHJRNCR_cjs.cart_default.get();
@@ -86,7 +97,10 @@ var useCartStore = zustand.create((set) => ({
86
97
  }
87
98
  const updatedCart = chunkSMHJRNCR_cjs.cart_default.get();
88
99
  if (updatedCart) {
89
- set({ cart: updatedCart });
100
+ set({
101
+ cart: updatedCart,
102
+ total_quantity: updatedCart.total_quantity
103
+ });
90
104
  } else {
91
105
  set(initialState);
92
106
  }
@@ -100,7 +114,7 @@ var useCartStore = zustand.create((set) => ({
100
114
  set({ status: "loading" /* LOADING */ });
101
115
  try {
102
116
  if (chunkBBRXE57K_cjs.auth_default.getUserDetails()) {
103
- await chunkY2CPMT34_cjs.updateCart(items);
117
+ await chunkMTSMQAZR_cjs.updateCart(items);
104
118
  await useCartStore.getState().syncCart(addressId);
105
119
  } else {
106
120
  const cart = chunkSMHJRNCR_cjs.cart_default.get();
@@ -113,7 +127,12 @@ var useCartStore = zustand.create((set) => ({
113
127
  });
114
128
  }
115
129
  const updatedCart = chunkSMHJRNCR_cjs.cart_default.get();
116
- if (updatedCart) set({ cart: updatedCart });
130
+ if (updatedCart) {
131
+ set({
132
+ cart: updatedCart,
133
+ total_quantity: updatedCart.total_quantity
134
+ });
135
+ }
117
136
  }
118
137
  } catch {
119
138
  } finally {
@@ -123,7 +142,7 @@ var useCartStore = zustand.create((set) => ({
123
142
  updateCustomization: async (customizationInputs) => {
124
143
  set({ status: "loading" /* LOADING */ });
125
144
  try {
126
- await chunkAOJRQMJZ_cjs.updateOrderCustomization({ customization_inputs: customizationInputs });
145
+ await chunkDXQX7ZIL_cjs.updateOrderCustomization({ customization_inputs: customizationInputs });
127
146
  } catch {
128
147
  } finally {
129
148
  set({ status: "idle" /* IDLE */ });
@@ -18,6 +18,11 @@ async function getOrderDetailsByNumber(orderNumber) {
18
18
  });
19
19
  }
20
20
  async function getOrderDetailsByRef(orderRef) {
21
+ return chunkECHV2JSY_cjs.http_service_default.get("/customer/order/", {
22
+ params: { order_ref: orderRef }
23
+ });
24
+ }
25
+ async function getOrderDetailsByRefV2(orderRef) {
21
26
  return chunkECHV2JSY_cjs.http_service_default.get("/customer/order-detail/", {
22
27
  params: { order_ref: orderRef }
23
28
  });
@@ -27,11 +32,12 @@ async function getPublicOrderDetailsByNumber(orderNumber) {
27
32
  params: { order_number: orderNumber }
28
33
  });
29
34
  }
30
- async function placeOrder(address_id, redirect, isCod, stripeRedirect, tabbyRedirect) {
35
+ async function placeOrder(address_id, redirect, isCod, shipping_option_id, stripeRedirect, tabbyRedirect) {
31
36
  return chunkECHV2JSY_cjs.http_service_default.post("/customer/order/", {
32
37
  address_id,
33
38
  phonepe_redirect_url: redirect,
34
39
  is_cod: isCod,
40
+ shipping_option_id,
35
41
  stripe_redirect_url: stripeRedirect,
36
42
  tabby_redirect_url: tabbyRedirect
37
43
  });
@@ -117,6 +123,7 @@ exports.checkPhonepePaymentStatus = checkPhonepePaymentStatus;
117
123
  exports.getOrderDetails = getOrderDetails;
118
124
  exports.getOrderDetailsByNumber = getOrderDetailsByNumber;
119
125
  exports.getOrderDetailsByRef = getOrderDetailsByRef;
126
+ exports.getOrderDetailsByRefV2 = getOrderDetailsByRefV2;
120
127
  exports.getOrders = getOrders;
121
128
  exports.getPublicOrderDetailsByNumber = getPublicOrderDetailsByNumber;
122
129
  exports.getStripePaymentStatus = getStripePaymentStatus;
@@ -5,9 +5,9 @@ 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
- async function getCart(url, addressId) {
8
+ async function getCart(url, addressId, shippingOptionId) {
9
9
  const localCart = chunkSMHJRNCR_cjs.cart_default.get();
10
- return chunkBBRXE57K_cjs.auth_default.getUserDetails() ? (await chunkECHV2JSY_cjs.http_service_default.get(url, { params: { address_id: addressId } })).data : localCart || {
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,
13
13
  total_quantity: 0,
@@ -20,9 +20,16 @@ async function getCart(url, addressId) {
20
20
  variant_discounts: {},
21
21
  total_shipping: 0,
22
22
  total_tax_amount: 0,
23
- applied_coupon: {}
23
+ applied_coupon: {},
24
+ shipping_options: [],
25
+ selected_shipping_option_id: null,
26
+ selected_address_id: null
24
27
  };
25
28
  }
29
+ async function getCartItemQuantity() {
30
+ const localCart = chunkSMHJRNCR_cjs.cart_default.get();
31
+ return chunkBBRXE57K_cjs.auth_default.getUserDetails() ? (await chunkECHV2JSY_cjs.http_service_default.get("/customer/cart/quantity/")).data : { total_quantity: localCart?.total_quantity || 0 };
32
+ }
26
33
  async function addToCart(product, customizationInputs) {
27
34
  return chunkECHV2JSY_cjs.http_service_default.post("/customer/cart/", {
28
35
  action: "add",
@@ -117,6 +124,7 @@ async function removeFromWishlist(product_variants) {
117
124
  exports.addToCart = addToCart;
118
125
  exports.addWishlist = addWishlist;
119
126
  exports.getCart = getCart;
127
+ exports.getCartItemQuantity = getCartItemQuantity;
120
128
  exports.getCategories = getCategories;
121
129
  exports.getDigitalProductDownloadLink = getDigitalProductDownloadLink;
122
130
  exports.getProductCategories = getProductCategories;
@@ -1,6 +1,6 @@
1
1
  import { getCoupons, getAppliedCoupon, applyCoupon, removeCoupon } from './chunk-7M5CVYZJ.js';
2
2
  import { pixelEvents } from './chunk-WFDKKOO7.js';
3
- import { razorpayOrderSuccess, razorpayOrderFail, publicMakeCODOrder, makeCODOrder, stripeOrderSuccess } from './chunk-YFF6DWZM.js';
3
+ import { razorpayOrderSuccess, razorpayOrderFail, publicMakeCODOrder, makeCODOrder, stripeOrderSuccess } from './chunk-S3ZZ3ZA7.js';
4
4
  import { getCloudFront } from './chunk-JQMLHRWL.js';
5
5
  import { AxiosError } from 'axios';
6
6
 
@@ -52,12 +52,15 @@ function openRazorpayCheckout(order, callbacks) {
52
52
  phone: customer_phone
53
53
  },
54
54
  modal: {
55
- ondismiss: () => handleRazorpayFail(order, callbacks)
55
+ ondismiss: () => handleRazorpayFail(order, callbacks, {
56
+ description: "User cancelled the payment manually",
57
+ reason: "user_cancelled_payment_manually"
58
+ })
56
59
  }
57
60
  };
58
61
  const paymentObject = new window.Razorpay(options);
59
- paymentObject.on("payment.failed", () => {
60
- handleRazorpayFail(order, callbacks);
62
+ paymentObject.on("payment.failed", (response) => {
63
+ handleRazorpayFail(order, callbacks, response?.error);
61
64
  });
62
65
  paymentObject.open();
63
66
  }
@@ -75,11 +78,12 @@ async function handleRazorpaySuccess(data, order, callbacks) {
75
78
  callbacks.onPaymentEnd?.();
76
79
  }
77
80
  }
78
- async function handleRazorpayFail(order, callbacks) {
81
+ async function handleRazorpayFail(order, callbacks, error) {
79
82
  try {
80
83
  await razorpayOrderFail({
81
84
  order_id: order.id,
82
- razorpay_order_id: order.razorpay_order_id
85
+ razorpay_order_id: order.razorpay_order_id,
86
+ error
83
87
  });
84
88
  } catch {
85
89
  }
@@ -2,7 +2,7 @@
2
2
 
3
3
  var chunkXFOUNOKO_cjs = require('./chunk-XFOUNOKO.cjs');
4
4
  var chunkK44JZ5NL_cjs = require('./chunk-K44JZ5NL.cjs');
5
- var chunkAOJRQMJZ_cjs = require('./chunk-AOJRQMJZ.cjs');
5
+ var chunkDXQX7ZIL_cjs = require('./chunk-DXQX7ZIL.cjs');
6
6
  var chunkN3CTXRFT_cjs = require('./chunk-N3CTXRFT.cjs');
7
7
  var axios = require('axios');
8
8
 
@@ -54,19 +54,22 @@ function openRazorpayCheckout(order, callbacks) {
54
54
  phone: customer_phone
55
55
  },
56
56
  modal: {
57
- ondismiss: () => handleRazorpayFail(order, callbacks)
57
+ ondismiss: () => handleRazorpayFail(order, callbacks, {
58
+ description: "User cancelled the payment manually",
59
+ reason: "user_cancelled_payment_manually"
60
+ })
58
61
  }
59
62
  };
60
63
  const paymentObject = new window.Razorpay(options);
61
- paymentObject.on("payment.failed", () => {
62
- handleRazorpayFail(order, callbacks);
64
+ paymentObject.on("payment.failed", (response) => {
65
+ handleRazorpayFail(order, callbacks, response?.error);
63
66
  });
64
67
  paymentObject.open();
65
68
  }
66
69
  async function handleRazorpaySuccess(data, order, callbacks) {
67
70
  try {
68
71
  callbacks.onPaymentStart?.();
69
- await chunkAOJRQMJZ_cjs.razorpayOrderSuccess(data);
72
+ await chunkDXQX7ZIL_cjs.razorpayOrderSuccess(data);
70
73
  chunkK44JZ5NL_cjs.pixelEvents.purchase(order);
71
74
  chunkK44JZ5NL_cjs.pixelEvents.checkoutCompleted(order);
72
75
  callbacks.onCartReset();
@@ -77,11 +80,12 @@ async function handleRazorpaySuccess(data, order, callbacks) {
77
80
  callbacks.onPaymentEnd?.();
78
81
  }
79
82
  }
80
- async function handleRazorpayFail(order, callbacks) {
83
+ async function handleRazorpayFail(order, callbacks, error) {
81
84
  try {
82
- await chunkAOJRQMJZ_cjs.razorpayOrderFail({
85
+ await chunkDXQX7ZIL_cjs.razorpayOrderFail({
83
86
  order_id: order.id,
84
- razorpay_order_id: order.razorpay_order_id
87
+ razorpay_order_id: order.razorpay_order_id,
88
+ error
85
89
  });
86
90
  } catch {
87
91
  }
@@ -111,9 +115,9 @@ async function handleCODPayment(order, callbacks, options) {
111
115
  callbacks.onPaymentStart?.();
112
116
  chunkK44JZ5NL_cjs.pixelEvents.initiateCheckout(order, "cod");
113
117
  if (options?.isPublic) {
114
- await chunkAOJRQMJZ_cjs.publicMakeCODOrder(order.order_number);
118
+ await chunkDXQX7ZIL_cjs.publicMakeCODOrder(order.order_number);
115
119
  } else {
116
- await chunkAOJRQMJZ_cjs.makeCODOrder(order.id);
120
+ await chunkDXQX7ZIL_cjs.makeCODOrder(order.id);
117
121
  }
118
122
  chunkK44JZ5NL_cjs.pixelEvents.purchase(order);
119
123
  chunkK44JZ5NL_cjs.pixelEvents.checkoutCompleted(order);
@@ -141,7 +145,7 @@ function handleStripePayment(order, callbacks) {
141
145
  async function handleStripeSuccess(order, paymentIntentId, callbacks) {
142
146
  try {
143
147
  callbacks.onPaymentStart?.();
144
- await chunkAOJRQMJZ_cjs.stripeOrderSuccess({
148
+ await chunkDXQX7ZIL_cjs.stripeOrderSuccess({
145
149
  order_id: order.id,
146
150
  payment_intent_id: paymentIntentId
147
151
  });
@@ -16,6 +16,11 @@ async function getOrderDetailsByNumber(orderNumber) {
16
16
  });
17
17
  }
18
18
  async function getOrderDetailsByRef(orderRef) {
19
+ return http_service_default.get("/customer/order/", {
20
+ params: { order_ref: orderRef }
21
+ });
22
+ }
23
+ async function getOrderDetailsByRefV2(orderRef) {
19
24
  return http_service_default.get("/customer/order-detail/", {
20
25
  params: { order_ref: orderRef }
21
26
  });
@@ -25,11 +30,12 @@ async function getPublicOrderDetailsByNumber(orderNumber) {
25
30
  params: { order_number: orderNumber }
26
31
  });
27
32
  }
28
- async function placeOrder(address_id, redirect, isCod, stripeRedirect, tabbyRedirect) {
33
+ async function placeOrder(address_id, redirect, isCod, shipping_option_id, stripeRedirect, tabbyRedirect) {
29
34
  return http_service_default.post("/customer/order/", {
30
35
  address_id,
31
36
  phonepe_redirect_url: redirect,
32
37
  is_cod: isCod,
38
+ shipping_option_id,
33
39
  stripe_redirect_url: stripeRedirect,
34
40
  tabby_redirect_url: tabbyRedirect
35
41
  });
@@ -111,4 +117,4 @@ async function verifyTabbyPayment(orderNumber) {
111
117
  });
112
118
  }
113
119
 
114
- export { checkPhonepePaymentStatus, getOrderDetails, getOrderDetailsByNumber, getOrderDetailsByRef, getOrders, getPublicOrderDetailsByNumber, getStripePaymentStatus, getStripePaymentStatusPublic, makeCODOrder, phonepeOrderSuccess, phonepePublicOrderSuccess, placeOrder, publicMakeCODOrder, publicPlaceOrder, razorpayOrderFail, razorpayOrderSuccess, razorpayPublicOrderSuccess, stripeOrderFail, stripeOrderSuccess, stripePublicOrderSuccess, updateOrder, updateOrderCustomization, uploadCustomizationImage, verifyTabbyPayment };
120
+ export { checkPhonepePaymentStatus, getOrderDetails, getOrderDetailsByNumber, getOrderDetailsByRef, getOrderDetailsByRefV2, getOrders, getPublicOrderDetailsByNumber, getStripePaymentStatus, getStripePaymentStatusPublic, makeCODOrder, phonepeOrderSuccess, phonepePublicOrderSuccess, placeOrder, publicMakeCODOrder, publicPlaceOrder, razorpayOrderFail, razorpayOrderSuccess, razorpayPublicOrderSuccess, stripeOrderFail, stripeOrderSuccess, stripePublicOrderSuccess, updateOrder, updateOrderCustomization, uploadCustomizationImage, verifyTabbyPayment };
@@ -1,6 +1,6 @@
1
- import { updateCart, removeFromCart, addToCart, getCart } from './chunk-U25T7M6S.js';
1
+ import { updateCart, removeFromCart, addToCart, getCart, getCartItemQuantity } from './chunk-XURYZRER.js';
2
2
  import { cart_default } from './chunk-QAC72HKO.js';
3
- import { updateOrderCustomization } from './chunk-YFF6DWZM.js';
3
+ import { updateOrderCustomization } from './chunk-S3ZZ3ZA7.js';
4
4
  import { auth_default } from './chunk-WEMNXIRS.js';
5
5
  import { USER_CRED_TOKEN, USER_CREDENTIALS } from './chunk-BQ256JKN.js';
6
6
  import { create } from 'zustand';
@@ -8,33 +8,42 @@ import { getCookie } from 'typescript-cookie';
8
8
 
9
9
  var initialState = {
10
10
  cart: null,
11
+ total_quantity: 0,
11
12
  status: "idle" /* IDLE */
12
13
  };
13
14
  var useCartStore = create((set) => ({
14
15
  ...initialState,
15
- setCart: (cart) => set({ cart, status: "idle" /* IDLE */ }),
16
+ setCart: (cart) => set({ cart, total_quantity: cart.total_quantity, status: "idle" /* IDLE */ }),
16
17
  resetCart: () => set(initialState),
17
18
  resetCartCount: () => set((state) => {
18
- if (!state.cart) return state;
19
- return { cart: { ...state.cart, total_quantity: 0 } };
19
+ if (!state.cart) return { ...state, total_quantity: 0 };
20
+ return { cart: { ...state.cart, total_quantity: 0 }, total_quantity: 0 };
20
21
  }),
21
- syncCart: async (addressId) => {
22
+ fetchCartQuantity: async () => {
23
+ try {
24
+ const { total_quantity } = await getCartItemQuantity();
25
+ set({ total_quantity });
26
+ } catch (error) {
27
+ console.error("Failed to fetch cart quantity", error);
28
+ }
29
+ },
30
+ syncCart: async (addressId, shippingOptionId) => {
22
31
  set({ status: "loading" /* LOADING */ });
23
32
  try {
24
- const response = await getCart("/customer/cart/", addressId);
33
+ const response = await getCart("/customer/cart/", addressId, shippingOptionId);
25
34
  if (response) {
26
- set({ cart: response, status: "idle" /* IDLE */ });
35
+ set({ cart: response, total_quantity: response.total_quantity, status: "idle" /* IDLE */ });
27
36
  }
28
37
  } catch {
29
38
  set({ status: "idle" /* IDLE */ });
30
39
  }
31
40
  },
32
- fetchCart: async (addressId) => {
41
+ fetchCart: async (addressId, shippingOptionId) => {
33
42
  set({ status: "loading" /* LOADING */ });
34
43
  try {
35
- const response = await getCart("/customer/cart/", addressId);
44
+ const response = await getCart("/customer/cart/", addressId, shippingOptionId);
36
45
  if (response) {
37
- set({ cart: response, status: "idle" /* IDLE */ });
46
+ set({ cart: response, total_quantity: response.total_quantity, status: "idle" /* IDLE */ });
38
47
  }
39
48
  } catch {
40
49
  set({ status: "idle" /* IDLE */ });
@@ -59,7 +68,9 @@ var useCartStore = create((set) => ({
59
68
  });
60
69
  }
61
70
  const updatedCart = cart_default.get();
62
- if (updatedCart) set({ cart: updatedCart });
71
+ if (updatedCart) {
72
+ set({ cart: updatedCart, total_quantity: updatedCart.total_quantity });
73
+ }
63
74
  }
64
75
  } catch {
65
76
  } finally {
@@ -84,7 +95,10 @@ var useCartStore = create((set) => ({
84
95
  }
85
96
  const updatedCart = cart_default.get();
86
97
  if (updatedCart) {
87
- set({ cart: updatedCart });
98
+ set({
99
+ cart: updatedCart,
100
+ total_quantity: updatedCart.total_quantity
101
+ });
88
102
  } else {
89
103
  set(initialState);
90
104
  }
@@ -111,7 +125,12 @@ var useCartStore = create((set) => ({
111
125
  });
112
126
  }
113
127
  const updatedCart = cart_default.get();
114
- if (updatedCart) set({ cart: updatedCart });
128
+ if (updatedCart) {
129
+ set({
130
+ cart: updatedCart,
131
+ total_quantity: updatedCart.total_quantity
132
+ });
133
+ }
115
134
  }
116
135
  } catch {
117
136
  } finally {
@@ -3,9 +3,9 @@ import { http_service_default } from './chunk-3SYYP3XV.js';
3
3
  import { auth_default } from './chunk-WEMNXIRS.js';
4
4
 
5
5
  // src/api/cart.ts
6
- async function getCart(url, addressId) {
6
+ async function getCart(url, addressId, shippingOptionId) {
7
7
  const localCart = cart_default.get();
8
- return auth_default.getUserDetails() ? (await http_service_default.get(url, { params: { address_id: addressId } })).data : localCart || {
8
+ return auth_default.getUserDetails() ? (await http_service_default.get(url, { params: { address_id: addressId, shipping_option_id: shippingOptionId } })).data : localCart || {
9
9
  product_variants: [],
10
10
  total_amount: 0,
11
11
  total_quantity: 0,
@@ -18,9 +18,16 @@ async function getCart(url, addressId) {
18
18
  variant_discounts: {},
19
19
  total_shipping: 0,
20
20
  total_tax_amount: 0,
21
- applied_coupon: {}
21
+ applied_coupon: {},
22
+ shipping_options: [],
23
+ selected_shipping_option_id: null,
24
+ selected_address_id: null
22
25
  };
23
26
  }
27
+ async function getCartItemQuantity() {
28
+ const localCart = cart_default.get();
29
+ return auth_default.getUserDetails() ? (await http_service_default.get("/customer/cart/quantity/")).data : { total_quantity: localCart?.total_quantity || 0 };
30
+ }
24
31
  async function addToCart(product, customizationInputs) {
25
32
  return http_service_default.post("/customer/cart/", {
26
33
  action: "add",
@@ -112,4 +119,4 @@ async function removeFromWishlist(product_variants) {
112
119
  });
113
120
  }
114
121
 
115
- export { addToCart, addWishlist, getCart, getCategories, getDigitalProductDownloadLink, getProductCategories, getProductDetail, getProductDetailBySlug, getProductList, getProducts, getWishlist, notifyProductStock, removeFromCart, removeFromWishlist, updateCart, updateDigitalProductDownloadLinkCount };
122
+ export { addToCart, addWishlist, getCart, getCartItemQuantity, getCategories, getDigitalProductDownloadLink, getProductCategories, getProductDetail, getProductDetailBySlug, getProductList, getProducts, getWishlist, notifyProductStock, removeFromCart, removeFromWishlist, updateCart, updateDigitalProductDownloadLinkCount };
@@ -12,6 +12,6 @@ import '../product-DJMdi4D4.cjs';
12
12
  import 'react-toastify';
13
13
  import 'react/jsx-runtime';
14
14
  import '../orders-CjNmCY5I.cjs';
15
- import '../pixelEvents-C1rFPOwb.cjs';
16
- import '../cart-kJoawc_Z.cjs';
15
+ import '../pixelEvents-CXViXGtV.cjs';
16
+ import '../cart-CuLMWnfy.cjs';
17
17
  import '../collections-WzvTO0OQ.cjs';
@@ -12,6 +12,6 @@ import '../product-DJMdi4D4.js';
12
12
  import 'react-toastify';
13
13
  import 'react/jsx-runtime';
14
14
  import '../orders-L_8eIkUS.js';
15
- import '../pixelEvents-Bo-VjAx8.js';
16
- import '../cart-y-7RPmnQ.js';
15
+ import '../pixelEvents-LqK0Ltr_.js';
16
+ import '../cart-CLf2ljxd.js';
17
17
  import '../collections-BDSVfRNo.js';
@@ -1,5 +1,5 @@
1
- import { P as PageHeaderProps } from '../pixelEvents-C1rFPOwb.cjs';
2
- import '../cart-kJoawc_Z.cjs';
1
+ import { P as PageHeaderProps } from '../pixelEvents-CXViXGtV.cjs';
2
+ import '../cart-CuLMWnfy.cjs';
3
3
  import '../product-DJMdi4D4.cjs';
4
4
  import 'react-toastify';
5
5
  import '../collections-WzvTO0OQ.cjs';
@@ -1,5 +1,5 @@
1
- import { P as PageHeaderProps } from '../pixelEvents-Bo-VjAx8.js';
2
- import '../cart-y-7RPmnQ.js';
1
+ import { P as PageHeaderProps } from '../pixelEvents-LqK0Ltr_.js';
2
+ import '../cart-CLf2ljxd.js';
3
3
  import '../product-DJMdi4D4.js';
4
4
  import 'react-toastify';
5
5
  import '../collections-BDSVfRNo.js';