@anker-in/shopify-react 0.1.1-beta.43 → 0.1.1-beta.45

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.
@@ -1,6 +1,6 @@
1
1
  import { createContext, useMemo, useRef, useState, useEffect, useCallback, useContext } from 'react';
2
2
  import useSWRMutation from 'swr/mutation';
3
- import { getProductsByHandles, createCart, updateCartCodes, addCartLines, updateCartLines, removeCartLines, updateCartAttributes, getLocalStorage, getProduct, getAllProducts, getCollection, getAllCollections, getCollections, getBlog, getAllBlogs, getArticle, getArticles, getArticlesInBlog, setLocalStorage } from '@anker-in/shopify-sdk';
3
+ import { getProductsByHandles, createCart, updateCartCodes, addCartLines, getLocalStorage, updateCartLines, removeCartLines, updateCartAttributes, getProduct, getAllProducts, getCollection, getAllCollections, getCollections, getBlog, getAllBlogs, getArticle, getArticles, getArticlesInBlog, setLocalStorage } from '@anker-in/shopify-sdk';
4
4
  import Cookies5 from 'js-cookie';
5
5
  import { jsx } from 'react/jsx-runtime';
6
6
  import Decimal2 from 'decimal.js';
@@ -516,7 +516,8 @@ var useScriptAutoFreeGift = ({
516
516
  _giveaway,
517
517
  cart,
518
518
  locale: providedLocale,
519
- lines
519
+ lines,
520
+ profile
520
521
  }) => {
521
522
  const { client, locale: contextLocale } = useShopify();
522
523
  const locale = providedLocale || contextLocale;
@@ -540,8 +541,9 @@ var useScriptAutoFreeGift = ({
540
541
  const utmCampaign = Cookies5.get("utm_campaign") || query?.utm_campaign;
541
542
  if (campaign.activityAvailableQuery && !utmCampaign?.includes(campaign.activityAvailableQuery))
542
543
  return false;
544
+ if (campaign.requireLogin && !profile?.email) return false;
543
545
  return true;
544
- }, [campaign]);
546
+ }, [campaign, profile]);
545
547
  const [upgrade_multiple, upgrade_value] = useMemo(() => {
546
548
  let upgrade_multiple2 = 1;
547
549
  let upgrade_value2 = 0;
@@ -680,7 +682,10 @@ function useCartContext(options) {
680
682
  }
681
683
 
682
684
  // src/hooks/cart/use-create-cart.ts
683
- function useCreateCart(options) {
685
+ function useCreateCart({
686
+ updateCookie = false,
687
+ options
688
+ }) {
684
689
  const { client, locale, cartCookieAdapter } = useShopify();
685
690
  const { mutateCart, metafieldIdentifiers } = useCartContext();
686
691
  const createNewCart = useCallback(
@@ -688,7 +693,8 @@ function useCreateCart(options) {
688
693
  let newCart = await createCart(client, {
689
694
  ...arg,
690
695
  metafieldIdentifiers,
691
- cookieAdapter: cartCookieAdapter
696
+ cookieAdapter: cartCookieAdapter,
697
+ updateCookie
692
698
  });
693
699
  if (newCart) {
694
700
  const unApplicableCodes = newCart.discountCodes.filter((item) => !item.applicable).map((item) => item.code);
@@ -1026,260 +1032,6 @@ var getLinesWithAttributes = ({
1026
1032
  return functionLine;
1027
1033
  });
1028
1034
  };
1029
-
1030
- // src/hooks/cart/use-add-to-cart.ts
1031
- function useAddToCart({ withTrack = true } = {}, swrOptions) {
1032
- const { client, config, locale, cartCookieAdapter, userAdapter, performanceAdapter } = useShopify();
1033
- const { cart, addCustomAttributes } = useCartContext();
1034
- const { trigger: applyCartCodes } = useApplyCartCodes();
1035
- const { trigger: removeInvalidCodes } = useRemoveCartCodes();
1036
- const { trigger: addCartLines2 } = useAddCartLines();
1037
- const { trigger: createCart4 } = useCreateCart();
1038
- const addToCart = useCallback(
1039
- async (_key, { arg }) => {
1040
- const {
1041
- lineItems,
1042
- cartId: providedCartId,
1043
- discountCodes,
1044
- gtmParams = {},
1045
- buyerIdentity,
1046
- needCreateCart = false,
1047
- onCodesInvalid,
1048
- replaceExistingCodes,
1049
- customAttributes
1050
- } = arg;
1051
- if (!lineItems || lineItems.length === 0) {
1052
- return;
1053
- }
1054
- performanceAdapter?.addToCartStart();
1055
- const linesWithFunctionAttributes = getLinesWithAttributes({ cart, lineItems });
1056
- const lines = linesWithFunctionAttributes.map((item) => ({
1057
- merchandiseId: item.variant?.id || "",
1058
- quantity: item.quantity || 1,
1059
- attributes: item.attributes,
1060
- sellingPlanId: item.sellingPlanId
1061
- })).filter((item) => item.merchandiseId && item.quantity);
1062
- if (lines.length === 0) {
1063
- return;
1064
- }
1065
- let cartId = needCreateCart ? void 0 : providedCartId || cart?.id;
1066
- let resultCart = null;
1067
- if (!cartId) {
1068
- resultCart = await createCart4({
1069
- lines,
1070
- buyerIdentity,
1071
- discountCodes,
1072
- customAttributes
1073
- });
1074
- } else {
1075
- resultCart = await addCartLines2({
1076
- cartId,
1077
- lines
1078
- });
1079
- console.log("npm addCartLines resultCart", resultCart);
1080
- if (resultCart && resultCart.discountCodes && resultCart.discountCodes.length > 0) {
1081
- const unapplicableCodes = resultCart.discountCodes.filter((item) => !item.applicable).map((item) => item.code);
1082
- if (unapplicableCodes.length > 0) {
1083
- if (onCodesInvalid) {
1084
- const handledCart = await onCodesInvalid(resultCart, unapplicableCodes);
1085
- if (handledCart) {
1086
- resultCart = handledCart;
1087
- }
1088
- } else {
1089
- await removeInvalidCodes({
1090
- discountCodes: unapplicableCodes
1091
- });
1092
- }
1093
- }
1094
- }
1095
- if (resultCart && discountCodes && discountCodes.length > 0) {
1096
- applyCartCodes({
1097
- replaceExistingCodes,
1098
- discountCodes
1099
- });
1100
- }
1101
- if (customAttributes && customAttributes.length > 0) {
1102
- addCustomAttributes(customAttributes);
1103
- }
1104
- }
1105
- if (withTrack) {
1106
- trackAddToCartGA({
1107
- lineItems,
1108
- gtmParams: { ...gtmParams, brand: config.getBrand() }
1109
- });
1110
- trackAddToCartFBQ({ lineItems });
1111
- }
1112
- performanceAdapter?.addToCartEnd();
1113
- return resultCart;
1114
- },
1115
- [
1116
- client,
1117
- locale,
1118
- cartCookieAdapter,
1119
- userAdapter,
1120
- cart,
1121
- withTrack,
1122
- performanceAdapter,
1123
- createCart4,
1124
- addCartLines2,
1125
- applyCartCodes,
1126
- removeInvalidCodes,
1127
- addCustomAttributes,
1128
- config
1129
- ]
1130
- );
1131
- return useSWRMutation("add-to-cart", addToCart, swrOptions);
1132
- }
1133
- function useUpdateCartLines(options) {
1134
- const { client, locale, cartCookieAdapter } = useShopify();
1135
- const { mutateCart, metafieldIdentifiers } = useCartContext();
1136
- const updateLines = useCallback(
1137
- async (_key, { arg }) => {
1138
- const updatedCart = await updateCartLines(client, {
1139
- ...arg,
1140
- metafieldIdentifiers,
1141
- cookieAdapter: cartCookieAdapter
1142
- });
1143
- if (updatedCart) {
1144
- mutateCart(updatedCart);
1145
- }
1146
- console.log("use-update-cart-lines updatedCart", metafieldIdentifiers, updatedCart);
1147
- return updatedCart;
1148
- },
1149
- [client, locale, cartCookieAdapter, mutateCart, metafieldIdentifiers]
1150
- );
1151
- return useSWRMutation("update-cart-lines", updateLines, options);
1152
- }
1153
- function useRemoveCartLines(options) {
1154
- const { client, locale, cartCookieAdapter } = useShopify();
1155
- const { mutateCart, metafieldIdentifiers } = useCartContext();
1156
- const removeLines = useCallback(
1157
- async (_key, { arg }) => {
1158
- const { autoRemoveInvalidCodes = true, onCodesRemoved, cartId, lineIds } = arg;
1159
- let updatedCart = await removeCartLines(client, {
1160
- cartId,
1161
- lineIds,
1162
- metafieldIdentifiers,
1163
- cookieAdapter: cartCookieAdapter
1164
- });
1165
- if (updatedCart && autoRemoveInvalidCodes) {
1166
- const unApplicableCodes = updatedCart.discountCodes.filter((item) => !item.applicable).map((item) => item.code);
1167
- if (unApplicableCodes.length > 0) {
1168
- if (onCodesRemoved) {
1169
- const handledCart = await onCodesRemoved(updatedCart, unApplicableCodes);
1170
- if (handledCart) {
1171
- updatedCart = handledCart;
1172
- }
1173
- } else {
1174
- updatedCart = await updateCartCodes(client, {
1175
- cartId: updatedCart.id,
1176
- discountCodes: updatedCart.discountCodes.filter((item) => item.applicable).map((item) => item.code),
1177
- metafieldIdentifiers,
1178
- cookieAdapter: cartCookieAdapter
1179
- }) || updatedCart;
1180
- }
1181
- }
1182
- }
1183
- if (updatedCart) {
1184
- mutateCart(updatedCart);
1185
- }
1186
- return updatedCart;
1187
- },
1188
- [client, locale, cartCookieAdapter, mutateCart, metafieldIdentifiers]
1189
- );
1190
- return useSWRMutation("remove-cart-lines", removeLines, options);
1191
- }
1192
- function useUpdateCartAttributes({
1193
- mutate,
1194
- metafieldIdentifiers,
1195
- disabled = false,
1196
- swrOptions
1197
- }) {
1198
- const { client, locale, cartCookieAdapter } = useShopify();
1199
- const updateAttributes = useCallback(
1200
- async (_key, { arg }) => {
1201
- if (disabled || !cartCookieAdapter?.getCartId(locale)) {
1202
- return void 0;
1203
- }
1204
- const updatedCart = await updateCartAttributes(client, {
1205
- ...arg,
1206
- metafieldIdentifiers,
1207
- cookieAdapter: cartCookieAdapter
1208
- });
1209
- if (updatedCart) {
1210
- mutate(updatedCart);
1211
- }
1212
- return updatedCart;
1213
- },
1214
- [client, locale, cartCookieAdapter, mutate, metafieldIdentifiers, disabled]
1215
- );
1216
- return useSWRMutation("update-cart-attributes", updateAttributes, swrOptions);
1217
- }
1218
- function useBuyNow({ withTrack = true } = {}, swrOptions) {
1219
- const { client, config, locale, cartCookieAdapter, userAdapter } = useShopify();
1220
- const isLoggedIn = userAdapter?.isLoggedIn || false;
1221
- const buyNow = useCallback(
1222
- async (_key, { arg }) => {
1223
- const {
1224
- lineItems,
1225
- discountCodes,
1226
- gtmParams = {},
1227
- buyerIdentity,
1228
- fbqTrackConfig,
1229
- customAttributes,
1230
- metafieldIdentifiers,
1231
- redirectToCheckout
1232
- } = arg;
1233
- if (!lineItems || lineItems.length === 0) {
1234
- return;
1235
- }
1236
- const linesWithFunctionAttributes = getLinesWithAttributes({
1237
- lineItems
1238
- });
1239
- const lines = linesWithFunctionAttributes.map((item) => ({
1240
- merchandiseId: item.variant?.id || "",
1241
- quantity: item.quantity || 1,
1242
- attributes: item.attributes,
1243
- sellingPlanId: item.sellingPlanId
1244
- })).filter((item) => item.merchandiseId);
1245
- if (lines.length === 0) {
1246
- return;
1247
- }
1248
- const resultCart = await createCart(client, {
1249
- lines,
1250
- metafieldIdentifiers,
1251
- cookieAdapter: cartCookieAdapter,
1252
- buyerIdentity,
1253
- discountCodes,
1254
- customAttributes
1255
- });
1256
- if (!resultCart) {
1257
- throw new Error("Failed to create cart for buy now");
1258
- }
1259
- if (withTrack && resultCart.lineItems) {
1260
- trackBuyNowGA({
1261
- lineItems,
1262
- gtmParams: { ...gtmParams, brand: config.getBrand() }
1263
- });
1264
- if (fbqTrackConfig) {
1265
- trackBuyNowFBQ({ trackConfig: fbqTrackConfig });
1266
- }
1267
- }
1268
- if (redirectToCheckout) {
1269
- if (resultCart.url) {
1270
- if (typeof window !== "undefined") {
1271
- window.location.href = resultCart.url;
1272
- }
1273
- } else {
1274
- throw new Error("Failed to get checkout URL");
1275
- }
1276
- }
1277
- return resultCart;
1278
- },
1279
- [client, locale, isLoggedIn, cartCookieAdapter, withTrack]
1280
- );
1281
- return useSWRMutation("buy-now", buyNow, swrOptions);
1282
- }
1283
1035
  function useCalcGiftsFromLines({
1284
1036
  lines,
1285
1037
  customer,
@@ -1451,47 +1203,6 @@ var useCalcOrderDiscount = (cart, orderDiscountConfig, customer) => {
1451
1203
  isLoading: isCustomerLoading
1452
1204
  };
1453
1205
  };
1454
- function hasPlusMemberInCart({
1455
- memberSetting,
1456
- cart
1457
- }) {
1458
- const { plus_monthly_product, plus_annual_product } = memberSetting || {};
1459
- if (!cart?.lineItems) {
1460
- return {
1461
- hasPlusMember: false,
1462
- hasMonthlyPlus: false,
1463
- hasAnnualPlus: false
1464
- };
1465
- }
1466
- const monthlyPlusItem = cart.lineItems.find(
1467
- (item) => item.product?.handle === plus_monthly_product?.handle && item.variant?.sku === plus_monthly_product?.sku
1468
- );
1469
- const annualPlusItem = cart.lineItems.find(
1470
- (item) => item.product?.handle === plus_annual_product?.handle && item.variant?.sku === plus_annual_product?.sku
1471
- );
1472
- const hasMonthlyPlus = !!monthlyPlusItem;
1473
- const hasAnnualPlus = !!annualPlusItem;
1474
- const hasPlusMember = hasMonthlyPlus || hasAnnualPlus;
1475
- return {
1476
- hasPlusMember,
1477
- hasMonthlyPlus,
1478
- hasAnnualPlus,
1479
- monthlyPlusItem,
1480
- annualPlusItem
1481
- };
1482
- }
1483
- function useHasPlusMemberInCart({
1484
- memberSetting,
1485
- cart
1486
- }) {
1487
- return useMemo(
1488
- () => hasPlusMemberInCart({
1489
- memberSetting,
1490
- cart
1491
- }),
1492
- [memberSetting, cart]
1493
- );
1494
- }
1495
1206
  var getReferralAttributes = () => {
1496
1207
  const inviteCode = getLocalStorage("inviteCode") || Cookies5.get("inviteCode");
1497
1208
  const playModeId = getLocalStorage("playModeId") || Cookies5.get("playModeId");
@@ -1508,158 +1219,130 @@ var getReferralAttributes = () => {
1508
1219
  }
1509
1220
  return [];
1510
1221
  };
1222
+ var getUserType = (customer) => {
1223
+ let userInfo = Cookies5.get("userInfo");
1224
+ if (userInfo) {
1225
+ userInfo = JSON.parse(userInfo);
1226
+ let arr = typeof userInfo?.id == "string" && userInfo?.id.split("/");
1227
+ userInfo.setId = arr[arr.length - 1];
1228
+ }
1229
+ const customerInfo = userInfo || customer;
1230
+ if (!customerInfo) {
1231
+ return "new_user_unlogin";
1232
+ }
1233
+ if (customer) {
1234
+ const { orders = {} } = customer;
1235
+ if (orders?.edges?.length === 1) {
1236
+ return "old_user_orders_once";
1237
+ } else if (orders?.edges?.length > 1) {
1238
+ return "old_user_orders_twice";
1239
+ }
1240
+ }
1241
+ return "new_user_login";
1242
+ };
1243
+ function getCartAttributes({
1244
+ profile,
1245
+ customer,
1246
+ cart,
1247
+ memberType,
1248
+ currentUrl = ""
1249
+ }) {
1250
+ const userType = getUserType(customer);
1251
+ const memberAttributes = [
1252
+ {
1253
+ key: "_token",
1254
+ value: profile?.token
1255
+ },
1256
+ {
1257
+ key: "_member_type",
1258
+ value: memberType ?? String(profile?.memberType)
1259
+ },
1260
+ {
1261
+ key: "_user_type",
1262
+ value: userType
1263
+ },
1264
+ {
1265
+ key: "_is_login",
1266
+ value: profile?.token ? "true" : "false"
1267
+ }
1268
+ ];
1269
+ if (profile?.token) {
1270
+ memberAttributes.push({
1271
+ key: "_login_user",
1272
+ value: "1"
1273
+ });
1274
+ }
1275
+ const discountCodes = cart?.discountCodes.map((item) => item.code).filter((code) => code) || [];
1276
+ const functionAttributes = [
1277
+ {
1278
+ key: CUSTOMER_ATTRIBUTE_KEY,
1279
+ value: JSON.stringify({
1280
+ discount_code: discountCodes,
1281
+ user_tags: customer?.tags || []
1282
+ })
1283
+ }
1284
+ ];
1285
+ const presellAttributes = [
1286
+ {
1287
+ key: "_presale",
1288
+ value: cart?.lineItems.some((item) => item?.variant?.metafields?.presell === "presell")
1289
+ }
1290
+ ];
1291
+ const weightAttributes = [
1292
+ {
1293
+ key: "_weight",
1294
+ value: cart?.lineItems.reduce((acc, item) => {
1295
+ return new Decimal2(acc).plus(item.variant.weight ?? 0).toNumber();
1296
+ }, 0).toString()
1297
+ },
1298
+ {
1299
+ key: "_app_source_name",
1300
+ value: "dtc"
1301
+ }
1302
+ ];
1303
+ const trackingAttributes = [
1304
+ {
1305
+ key: "utm_params",
1306
+ value: currentUrl
1307
+ }
1308
+ ];
1309
+ const commonAttributes = [
1310
+ ...memberAttributes,
1311
+ ...functionAttributes,
1312
+ ...presellAttributes,
1313
+ ...weightAttributes,
1314
+ ...trackingAttributes,
1315
+ ...getReferralAttributes()
1316
+ ].filter((item) => item?.value);
1317
+ const extraAttributesInCart = cart?.customAttributes?.filter(
1318
+ (item) => !commonAttributes.some((attr) => attr.key === item.key)
1319
+ ) || [];
1320
+ return [...commonAttributes, ...extraAttributesInCart].filter((item) => item?.value);
1321
+ }
1511
1322
  var useCartAttributes = ({
1512
1323
  profile,
1513
1324
  customer,
1514
1325
  cart,
1515
- memberSetting
1326
+ memberType
1516
1327
  }) => {
1517
1328
  const [currentUrl, setCurrentUrl] = useState("");
1518
- const { hasPlusMember } = useHasPlusMemberInCart({
1519
- memberSetting,
1520
- cart
1521
- });
1522
1329
  useEffect(() => {
1523
1330
  setCurrentUrl(window.location.href);
1524
1331
  }, []);
1525
- const userType = useMemo(() => {
1526
- let userInfo = Cookies5.get("userInfo");
1527
- if (userInfo) {
1528
- userInfo = JSON.parse(userInfo);
1529
- let arr = typeof userInfo?.id == "string" && userInfo?.id.split("/");
1530
- userInfo.setId = arr[arr.length - 1];
1531
- }
1532
- const customerInfo = userInfo || customer;
1533
- if (!customerInfo) {
1534
- return "new_user_unlogin";
1535
- }
1536
- if (customer) {
1537
- const { orders = {} } = customer;
1538
- if (orders?.edges?.length === 1) {
1539
- return "old_user_orders_once";
1540
- } else if (orders?.edges?.length > 1) {
1541
- return "old_user_orders_twice";
1542
- }
1543
- }
1544
- return "new_user_login";
1545
- }, [customer]);
1546
- const memberAttributes = useMemo(() => {
1547
- const attributes = [
1548
- {
1549
- key: "_token",
1550
- value: profile?.token
1551
- //是否登录
1552
- },
1553
- {
1554
- key: "_member_type",
1555
- value: hasPlusMember ? "2" : profile?.memberType
1556
- //:0(游客),1(普通会员),2(付费会员)
1557
- },
1558
- {
1559
- key: "_user_type",
1560
- value: userType
1561
- // n
1562
- },
1563
- {
1564
- key: "_is_login",
1565
- value: profile?.token ? "true" : "false"
1566
- }
1567
- ];
1568
- if (profile?.token) {
1569
- attributes.push({
1570
- key: "_login_user",
1571
- value: "1"
1572
- });
1573
- }
1574
- return attributes;
1575
- }, [profile?.memberType, profile?.token, userType, hasPlusMember]);
1576
- const functionAttributes = useMemo(() => {
1577
- const hasFunctionEnvAttribute = cart?.lineItems.some(
1578
- (item) => item.customAttributes?.some((attr) => attr.key === CUSTOMER_ATTRIBUTE_KEY)
1579
- );
1580
- const discountCodes = cart?.discountCodes.map((item) => item.code).filter((code) => code) || [];
1581
- return hasFunctionEnvAttribute ? [
1582
- {
1583
- key: "_discounts_function_env",
1584
- value: JSON.stringify({
1585
- discount_code: discountCodes,
1586
- user_tags: customer?.tags || []
1587
- })
1588
- }
1589
- ] : [];
1590
- }, [cart, customer]);
1591
- const presellAttributes = useMemo(() => {
1592
- return [
1593
- {
1594
- key: "_presale",
1595
- value: cart?.lineItems.some((item) => item?.variant?.metafields?.presell === "presell")
1596
- }
1597
- ];
1598
- }, [cart]);
1599
- const weightAttributes = useMemo(() => {
1600
- return [
1601
- {
1602
- key: "_weight",
1603
- value: cart?.lineItems.reduce((acc, item) => {
1604
- return new Decimal2(acc).plus(item.variant.weight ?? 0).toNumber();
1605
- }, 0).toString()
1606
- },
1607
- {
1608
- key: "_app_source_name",
1609
- value: "dtc"
1610
- }
1611
- ];
1612
- }, [cart]);
1613
- const trackingAttributes = useMemo(() => {
1614
- return [
1615
- {
1616
- key: "utm_params",
1617
- value: currentUrl
1618
- }
1619
- ];
1620
- }, [currentUrl]);
1621
- const commonAttributes = useMemo(
1622
- () => [
1623
- ...memberAttributes,
1624
- ...functionAttributes,
1625
- ...presellAttributes,
1626
- ...weightAttributes,
1627
- ...trackingAttributes,
1628
- ...getReferralAttributes()
1629
- ].filter((item) => item?.value),
1630
- [memberAttributes, functionAttributes, presellAttributes, weightAttributes, trackingAttributes]
1631
- );
1632
- const extraAttributesInCart = useMemo(() => {
1633
- const commonAttributeKeys = [
1634
- // member attributes
1635
- "_token",
1636
- "_member_type",
1637
- "_user_type",
1638
- "_is_login",
1639
- "_login_user",
1640
- // function attributes
1641
- "_discounts_function_env",
1642
- // presell attributes
1643
- "_presale",
1644
- // weight attributes
1645
- "_weight",
1646
- "_app_source_name",
1647
- // tracking attributes
1648
- "utm_params",
1649
- // referral attributes
1650
- "_invite_code",
1651
- "_play_mode_id",
1652
- "_popup"
1653
- ];
1654
- return cart?.customAttributes?.filter((item) => !commonAttributeKeys.includes(item.key)) || [];
1655
- }, [cart]);
1332
+ const attributes = useMemo(() => {
1333
+ return getCartAttributes({
1334
+ profile,
1335
+ customer,
1336
+ cart,
1337
+ memberType,
1338
+ currentUrl
1339
+ });
1340
+ }, [profile, customer, cart, memberType, currentUrl]);
1656
1341
  return useMemo(
1657
1342
  () => ({
1658
- attributes: [...commonAttributes, ...extraAttributesInCart].filter(
1659
- (item) => item?.value
1660
- )
1343
+ attributes
1661
1344
  }),
1662
- [commonAttributes, extraAttributesInCart]
1345
+ [attributes]
1663
1346
  );
1664
1347
  };
1665
1348
  var DEFAULT_MIN = 1;
@@ -1811,45 +1494,61 @@ var useUpdateLineCodeAmountAttributes = ({
1811
1494
  }, [loading, setLoadingState]);
1812
1495
  };
1813
1496
 
1814
- // src/hooks/cart/types/price-discount.ts
1815
- var PriceDiscountType = /* @__PURE__ */ ((PriceDiscountType2) => {
1816
- PriceDiscountType2[PriceDiscountType2["PERCENTAGE"] = 1] = "PERCENTAGE";
1817
- PriceDiscountType2[PriceDiscountType2["FIXED_AMOUNT"] = 2] = "FIXED_AMOUNT";
1818
- return PriceDiscountType2;
1819
- })(PriceDiscountType || {});
1820
- var PriceBasePriceType = /* @__PURE__ */ ((PriceBasePriceType2) => {
1821
- PriceBasePriceType2[PriceBasePriceType2["MIN_DISCOUNTED_PRICE"] = 1] = "MIN_DISCOUNTED_PRICE";
1822
- PriceBasePriceType2[PriceBasePriceType2["MIN_TOTAL_PRICE"] = 2] = "MIN_TOTAL_PRICE";
1823
- return PriceBasePriceType2;
1824
- })(PriceBasePriceType || {});
1825
- function useProduct(options = {}) {
1826
- const { client, locale } = useShopify();
1827
- const { handle, metafieldIdentifiers, ...swrOptions } = options;
1828
- return useSWR(
1829
- handle ? ["product", locale, handle, metafieldIdentifiers] : null,
1830
- () => getProduct(client, {
1831
- handle,
1832
- locale,
1833
- metafieldIdentifiers
1834
- }),
1835
- swrOptions
1836
- );
1837
- }
1838
- function useAllProducts(options = {}) {
1839
- const { client, locale } = useShopify();
1840
- const { first, query, sortKey, reverse, metafieldIdentifiers, ...swrOptions } = options;
1841
- return useSWR(
1842
- ["all-products", locale, first, query, sortKey, reverse, metafieldIdentifiers],
1843
- () => getAllProducts(client, {
1844
- locale,
1845
- first,
1846
- query,
1847
- sortKey,
1848
- reverse,
1849
- metafieldIdentifiers
1850
- }),
1851
- swrOptions
1852
- );
1497
+ // src/hooks/member/plus/types.ts
1498
+ var PLUS_MEMBER_TYPE = /* @__PURE__ */ ((PLUS_MEMBER_TYPE2) => {
1499
+ PLUS_MEMBER_TYPE2[PLUS_MEMBER_TYPE2["FREE"] = 0] = "FREE";
1500
+ PLUS_MEMBER_TYPE2[PLUS_MEMBER_TYPE2["MONTHLY"] = 1] = "MONTHLY";
1501
+ PLUS_MEMBER_TYPE2[PLUS_MEMBER_TYPE2["ANNUAL"] = 2] = "ANNUAL";
1502
+ return PLUS_MEMBER_TYPE2;
1503
+ })(PLUS_MEMBER_TYPE || {});
1504
+ var PlusMemberMode = /* @__PURE__ */ ((PlusMemberMode2) => {
1505
+ PlusMemberMode2["MONTHLY"] = "monthly";
1506
+ PlusMemberMode2["ANNUAL"] = "annual";
1507
+ return PlusMemberMode2;
1508
+ })(PlusMemberMode || {});
1509
+ var DeliveryPlusType = /* @__PURE__ */ ((DeliveryPlusType2) => {
1510
+ DeliveryPlusType2["FREE"] = "free";
1511
+ DeliveryPlusType2["MONTHLY"] = "monthly";
1512
+ DeliveryPlusType2["ANNUAL"] = "annual";
1513
+ return DeliveryPlusType2;
1514
+ })(DeliveryPlusType || {});
1515
+ var ShippingMethodMode = /* @__PURE__ */ ((ShippingMethodMode2) => {
1516
+ ShippingMethodMode2["FREE"] = "free";
1517
+ ShippingMethodMode2["TDD"] = "tdd";
1518
+ ShippingMethodMode2["NDD"] = "ndd";
1519
+ return ShippingMethodMode2;
1520
+ })(ShippingMethodMode || {});
1521
+ var createInitialValue = () => ({
1522
+ plusMemberMetafields: {},
1523
+ selectedPlusMemberMode: "free",
1524
+ setSelectedPlusMemberMode: () => {
1525
+ },
1526
+ selectedShippingMethod: void 0,
1527
+ setSelectedShippingMethod: () => {
1528
+ },
1529
+ showMoreShippingMethod: false,
1530
+ setShowMoreShippingMethod: () => {
1531
+ },
1532
+ variant: {},
1533
+ product: {},
1534
+ shippingMethodsContext: {
1535
+ freeShippingMethods: [],
1536
+ paymentShippingMethods: [],
1537
+ nddOverweight: false,
1538
+ tddOverweight: false,
1539
+ nddCoupon: void 0,
1540
+ tddCoupon: void 0,
1541
+ isLoadingCoupon: false
1542
+ },
1543
+ selectedPlusMemberVariant: void 0,
1544
+ showPlusMemberBenefit: false,
1545
+ setShowPlusMemberBenefit: () => {
1546
+ },
1547
+ profile: void 0
1548
+ });
1549
+ var PlusMemberContext = createContext(createInitialValue());
1550
+ function usePlusMemberContext() {
1551
+ return useContext(PlusMemberContext);
1853
1552
  }
1854
1553
  function useProductsByHandles(options = {}) {
1855
1554
  const { client, locale } = useShopify();
@@ -1875,994 +1574,1344 @@ function useProductsByHandles(options = {}) {
1875
1574
  }
1876
1575
  );
1877
1576
  }
1878
- function getFirstAvailableVariant(product) {
1879
- const availableVariant = product.variants.find((v) => v.availableForSale);
1880
- return availableVariant || product.variants[0];
1881
- }
1882
- function getVariantFromSelectedOptions(product, selectedOptions) {
1883
- return product.variants.find((variant) => {
1884
- return variant.selectedOptions.every((option) => {
1885
- return selectedOptions[option.name] === option.value;
1886
- });
1577
+
1578
+ // src/hooks/member/plus/use-plus-member-variants.ts
1579
+ function usePlusMemberVariants({
1580
+ memberSetting
1581
+ }) {
1582
+ const plusMonthly = memberSetting?.plus_monthly_product;
1583
+ const plusAnnual = memberSetting?.plus_annual_product;
1584
+ const plusMemberHandles = useMemo(() => {
1585
+ return [plusMonthly?.handle, plusAnnual?.handle].filter(Boolean);
1586
+ }, [plusMonthly?.handle, plusAnnual?.handle]);
1587
+ const { data: plusMemberProducts = [] } = useProductsByHandles({
1588
+ handles: plusMemberHandles
1887
1589
  });
1590
+ const monthlyProduct = useMemo(() => {
1591
+ return plusMemberProducts?.find((item) => item?.handle === plusMonthly?.handle);
1592
+ }, [plusMemberProducts, plusMonthly]);
1593
+ const annualProduct = useMemo(() => {
1594
+ return plusMemberProducts?.find((item) => item?.handle === plusAnnual?.handle);
1595
+ }, [plusMemberProducts, plusAnnual]);
1596
+ const monthlyVariant = useMemo(() => {
1597
+ return monthlyProduct?.variants?.find((item) => item.sku === plusMonthly?.sku);
1598
+ }, [monthlyProduct, plusMonthly]);
1599
+ const annualVariant = useMemo(() => {
1600
+ return annualProduct?.variants?.find((item) => item.sku === plusAnnual?.sku);
1601
+ }, [annualProduct, plusAnnual]);
1602
+ return {
1603
+ monthlyVariant: monthlyVariant ? {
1604
+ ...monthlyVariant,
1605
+ product: monthlyProduct
1606
+ } : void 0,
1607
+ annualVariant: annualVariant ? {
1608
+ ...annualVariant,
1609
+ product: annualProduct
1610
+ } : void 0
1611
+ };
1888
1612
  }
1889
- function useVariant({
1890
- product,
1891
- selectedOptions
1892
- }) {
1893
- const [variant, setVariant] = useState(
1894
- product ? getFirstAvailableVariant(product) : void 0
1895
- );
1896
- useEffect(() => {
1897
- if (!product) {
1898
- setVariant(void 0);
1899
- return;
1900
- }
1901
- const newVariant = getVariantFromSelectedOptions(product, selectedOptions);
1902
- if (newVariant && newVariant.id !== variant?.id) {
1903
- setVariant(newVariant);
1904
- } else if (!newVariant) {
1905
- setVariant(getFirstAvailableVariant(product));
1613
+ var useAvailableDeliveryCoupon = ({
1614
+ profile
1615
+ }) => {
1616
+ const { data: availableDeliveryCoupon, isLoading } = useSWR(
1617
+ profile?.email ? ["/api/multipass/subsrv/v1/prime/delivery_coupons/current/available", profile?.email] : void 0,
1618
+ async ([apiPath]) => {
1619
+ return fetch(apiPath).then((res) => res.json());
1906
1620
  }
1907
- }, [selectedOptions, product, variant?.id]);
1908
- return variant;
1909
- }
1910
- var FAKE_PRICE = 999999999e-2;
1911
- function formatPrice({
1912
- amount,
1913
- currencyCode,
1914
- locale,
1915
- maximumFractionDigits,
1916
- minimumFractionDigits,
1917
- removeTrailingZeros
1918
- }) {
1919
- const formatter = new Intl.NumberFormat(locale, {
1920
- style: "currency",
1921
- currency: currencyCode,
1922
- maximumFractionDigits: maximumFractionDigits ?? 2,
1923
- minimumFractionDigits: minimumFractionDigits ?? 2
1924
- });
1925
- let formatted = formatter.format(amount);
1926
- if (removeTrailingZeros) {
1927
- formatted = formatted.replace(/\.00$/, "");
1928
- }
1929
- return formatted;
1930
- }
1931
- function formatVariantPrice({
1932
- amount,
1933
- baseAmount,
1934
- currencyCode,
1935
- locale,
1936
- maximumFractionDigits,
1937
- minimumFractionDigits,
1938
- removeTrailingZeros
1939
- }) {
1621
+ );
1622
+ console.log("availableDeliveryCoupon", availableDeliveryCoupon);
1623
+ const { ndd_coupon: nddCoupon, tdd_coupon: tddCoupon } = availableDeliveryCoupon?.data?.data || {};
1940
1624
  return {
1941
- price: formatPrice({
1942
- amount,
1943
- currencyCode,
1944
- locale,
1945
- maximumFractionDigits,
1946
- minimumFractionDigits,
1947
- removeTrailingZeros
1948
- }),
1949
- basePrice: formatPrice({
1950
- amount: baseAmount,
1951
- currencyCode,
1952
- locale,
1953
- maximumFractionDigits,
1954
- minimumFractionDigits,
1955
- removeTrailingZeros
1956
- })
1625
+ nddCoupon,
1626
+ tddCoupon,
1627
+ isLoading
1957
1628
  };
1958
- }
1959
- function usePrice({
1960
- amount,
1961
- baseAmount,
1962
- currencyCode,
1963
- soldOutDescription = "",
1964
- maximumFractionDigits,
1965
- minimumFractionDigits,
1966
- removeTrailingZeros
1967
- }) {
1968
- const { locale } = useShopify();
1969
- const value = useMemo(() => {
1970
- if (typeof amount !== "number" || !currencyCode) {
1971
- return "";
1972
- }
1973
- if (soldOutDescription && amount >= FAKE_PRICE) {
1974
- return soldOutDescription;
1975
- }
1976
- return baseAmount ? formatVariantPrice({
1977
- amount,
1978
- baseAmount,
1979
- currencyCode,
1980
- locale,
1981
- maximumFractionDigits,
1982
- minimumFractionDigits,
1983
- removeTrailingZeros
1984
- }) : formatPrice({
1985
- amount,
1986
- currencyCode,
1987
- locale,
1988
- maximumFractionDigits,
1989
- minimumFractionDigits,
1990
- removeTrailingZeros
1629
+ };
1630
+
1631
+ // src/hooks/member/plus/use-shipping-methods.ts
1632
+ function useShippingMethods(options) {
1633
+ const { variant, plusMemberMetafields, selectedPlusMemberMode, profile } = options;
1634
+ const isPlus = profile?.isPlus || false;
1635
+ const { nddCoupon, tddCoupon, isLoading } = useAvailableDeliveryCoupon({ profile });
1636
+ const { plus_shipping, shippingMethod } = plusMemberMetafields || {};
1637
+ const nddOverweight = useMemo(() => {
1638
+ return (variant?.weight || 0) > (shippingMethod?.overWeight_ndd || Infinity);
1639
+ }, [shippingMethod?.overWeight_ndd, variant?.weight]);
1640
+ const tddOverweight = useMemo(() => {
1641
+ return (variant?.weight || 0) > (shippingMethod?.overWeight_tdd || Infinity);
1642
+ }, [shippingMethod?.overWeight_tdd, variant?.weight]);
1643
+ const paymentShippingMethods = useMemo(() => {
1644
+ const weight = variant?.weight || 0;
1645
+ const methods = plus_shipping?.shipping_methods?.filter(({ weight_low, weight_high, __mode, __plus }) => {
1646
+ const fitWeight = (!weight_low || weight >= weight_low) && (!weight_high || weight <= weight_high);
1647
+ return __mode !== "free" /* FREE */ && !__plus && fitWeight;
1648
+ }) || [];
1649
+ return methods.map((method) => {
1650
+ let disabled = false;
1651
+ const selectedFreeMember = selectedPlusMemberMode === "free";
1652
+ if (method.__mode === "ndd" /* NDD */) {
1653
+ disabled = selectedFreeMember || nddOverweight;
1654
+ } else if (method.__mode === "tdd" /* TDD */) {
1655
+ disabled = selectedFreeMember || tddOverweight;
1656
+ }
1657
+ return {
1658
+ ...method,
1659
+ id: method.__mode + method.__code,
1660
+ useCoupon: false,
1661
+ subtitle: plus_shipping?.directly || "",
1662
+ disabled
1663
+ };
1991
1664
  });
1992
1665
  }, [
1993
- amount,
1994
- baseAmount,
1995
- currencyCode,
1996
- locale,
1997
- maximumFractionDigits,
1998
- minimumFractionDigits,
1999
- soldOutDescription,
2000
- removeTrailingZeros
1666
+ nddOverweight,
1667
+ plus_shipping?.directly,
1668
+ plus_shipping?.shipping_methods,
1669
+ selectedPlusMemberMode,
1670
+ tddOverweight,
1671
+ variant?.weight
2001
1672
  ]);
2002
- const result = useMemo(() => {
2003
- const free = Boolean(amount && amount <= 0);
2004
- return typeof value === "string" ? { price: value, basePrice: value, free } : { ...value, free };
2005
- }, [value, amount]);
2006
- return result;
2007
- }
2008
- function optionsConstructor(selectedOptions) {
2009
- return selectedOptions.reduce((acc, option) => {
2010
- acc[option.name] = option.value;
2011
- return acc;
2012
- }, {});
2013
- }
2014
- function decodeShopifyId(gid) {
2015
- try {
2016
- const base64 = gid.split("/").pop() || "";
2017
- return atob(base64);
2018
- } catch {
2019
- return gid;
2020
- }
2021
- }
2022
- function useSelectedOptions(product, sku) {
2023
- const [options, setOptions] = useState({});
2024
- useEffect(() => {
2025
- if (!product || !product.variants.length) {
2026
- setOptions({});
2027
- return;
1673
+ const nddPrice = useMemo(() => {
1674
+ const weight = variant?.weight || 0;
1675
+ const nddMethod = paymentShippingMethods.find(({ __mode, weight_high, weight_low }) => {
1676
+ const fitWeight = (!weight_low || weight >= weight_low) && (!weight_high || weight <= weight_high);
1677
+ return __mode === "ndd" && fitWeight;
1678
+ });
1679
+ return nddMethod?.price || 0;
1680
+ }, [variant?.weight, paymentShippingMethods]);
1681
+ const tddPrice = useMemo(() => {
1682
+ const weight = variant?.weight || 0;
1683
+ const tddMethod = paymentShippingMethods.find(({ __mode, weight_high, weight_low }) => {
1684
+ const fitWeight = (!weight_low || weight >= weight_low) && (!weight_high || weight <= weight_high);
1685
+ return __mode === "tdd" && fitWeight;
1686
+ });
1687
+ return tddMethod?.price || 0;
1688
+ }, [variant?.weight, paymentShippingMethods]);
1689
+ const freeShippingMethods = useMemo(() => {
1690
+ const weight = variant?.weight || 0;
1691
+ let methods = plus_shipping?.shipping_methods?.filter(({ __mode, __plus, weight_low, weight_high }) => {
1692
+ if (__mode === "free" /* FREE */) {
1693
+ return true;
1694
+ }
1695
+ if (isPlus) {
1696
+ const hasCoupon = isPlus && __mode === "ndd" /* NDD */ && nddCoupon || isPlus && __mode === "tdd" /* TDD */ && (tddCoupon || nddCoupon);
1697
+ const fitWeight = (!weight_low || weight >= weight_low) && (!weight_high || weight <= weight_high);
1698
+ return hasCoupon && fitWeight && !__plus;
1699
+ } else {
1700
+ return __plus;
1701
+ }
1702
+ }) || [];
1703
+ if (isPlus) {
1704
+ methods = methods.sort((a, b) => {
1705
+ if (b.__mode === "free" /* FREE */) return -1;
1706
+ return 0;
1707
+ });
2028
1708
  }
2029
- let variant = product.variants[0];
2030
- if (typeof window !== "undefined") {
2031
- const searchParams = new URLSearchParams(window.location.search);
2032
- const variantIdParam = searchParams.get("variant");
2033
- if (variantIdParam) {
2034
- const foundVariant = product.variants.find((v) => {
2035
- if (sku) return v.sku === sku;
2036
- return v.id === variantIdParam || v.id.includes(variantIdParam) || decodeShopifyId(v.id) === variantIdParam;
2037
- });
2038
- if (foundVariant) {
2039
- variant = foundVariant;
1709
+ return methods.map((method) => {
1710
+ let price = 0;
1711
+ let coupon;
1712
+ let disabled;
1713
+ if (method.__mode !== "free" /* FREE */) {
1714
+ switch (method.__mode) {
1715
+ case "tdd":
1716
+ price = tddPrice;
1717
+ coupon = tddCoupon || nddCoupon;
1718
+ break;
1719
+ case "ndd":
1720
+ price = nddPrice;
1721
+ coupon = nddCoupon;
1722
+ break;
1723
+ }
1724
+ disabled = selectedPlusMemberMode === "free";
1725
+ if (method.__mode === "ndd" /* NDD */) {
1726
+ disabled = disabled || nddOverweight;
1727
+ } else if (method.__mode === "tdd" /* TDD */) {
1728
+ disabled = disabled || tddOverweight;
2040
1729
  }
2041
1730
  }
2042
- }
2043
- if (variant) {
2044
- const newOptions = optionsConstructor(variant.selectedOptions);
2045
- setOptions(newOptions);
2046
- }
2047
- }, [product, sku]);
2048
- return [options, setOptions];
2049
- }
2050
- function decodeShopifyId2(gid) {
2051
- try {
2052
- const parts = gid.split("/");
2053
- return parts[parts.length - 1] || gid;
2054
- } catch {
2055
- return gid;
2056
- }
1731
+ return {
1732
+ ...method,
1733
+ id: method.__mode + method.__code,
1734
+ useCoupon: true,
1735
+ disabled,
1736
+ coupon,
1737
+ price
1738
+ };
1739
+ });
1740
+ }, [
1741
+ variant?.weight,
1742
+ plus_shipping?.shipping_methods,
1743
+ isPlus,
1744
+ nddCoupon,
1745
+ tddCoupon,
1746
+ selectedPlusMemberMode,
1747
+ tddPrice,
1748
+ nddPrice,
1749
+ nddOverweight,
1750
+ tddOverweight
1751
+ ]);
1752
+ return {
1753
+ freeShippingMethods,
1754
+ paymentShippingMethods,
1755
+ nddOverweight,
1756
+ tddOverweight,
1757
+ nddCoupon,
1758
+ tddCoupon,
1759
+ isLoadingCoupon: isLoading
1760
+ };
2057
1761
  }
2058
- function useProductUrl(otherQuery) {
2059
- const { routerAdapter } = useShopify();
2060
- return useCallback(
2061
- ({ product, variant }) => {
2062
- if (!product) return "";
2063
- const queryParams = new URLSearchParams();
2064
- if (variant?.id) {
2065
- const variantId = decodeShopifyId2(variant.id);
2066
- if (variantId) {
2067
- queryParams.set("variant", variantId);
2068
- }
1762
+ var useReplaceCartPlusMember = () => {
1763
+ const { plusMemberMetafields, selectedPlusMemberMode } = usePlusMemberContext();
1764
+ const { trigger: removeCartLines2 } = useRemoveCartLines();
1765
+ const { cart } = useCartContext();
1766
+ const plusMonthly = plusMemberMetafields?.plus_monthly_product;
1767
+ const plusAnnual = plusMemberMetafields?.plus_annual_product;
1768
+ const handler = useCallback(async () => {
1769
+ const plusMonthlyInCart = cart?.lineItems.find(
1770
+ (item) => item.variant?.sku === plusMonthly?.sku
1771
+ );
1772
+ const plusAnnualInCart = cart?.lineItems.find(
1773
+ (item) => item.variant?.sku === plusAnnual?.sku
1774
+ );
1775
+ if (selectedPlusMemberMode === "annual" /* ANNUAL */ && plusMonthlyInCart) {
1776
+ await removeCartLines2({
1777
+ lineIds: [plusMonthlyInCart.id]
1778
+ });
1779
+ } else if (selectedPlusMemberMode === "monthly" /* MONTHLY */ && plusAnnualInCart) {
1780
+ await removeCartLines2({
1781
+ lineIds: [plusAnnualInCart.id]
1782
+ });
1783
+ }
1784
+ }, [
1785
+ cart?.lineItems,
1786
+ selectedPlusMemberMode,
1787
+ plusMonthly?.sku,
1788
+ plusAnnual?.sku,
1789
+ removeCartLines2
1790
+ ]);
1791
+ return handler;
1792
+ };
1793
+ var usePlusMemberCheckoutCustomAttributes = ({
1794
+ disableShipping = false,
1795
+ isPresaleContains = false
1796
+ }) => {
1797
+ const { profile, selectedShippingMethod, selectedPlusMemberMode } = usePlusMemberContext();
1798
+ return useMemo(() => {
1799
+ const checkoutCustomAttributes = [
1800
+ {
1801
+ key: "_last_url",
1802
+ value: typeof window !== "undefined" ? window.location.origin + window.location.pathname : ""
2069
1803
  }
2070
- if (otherQuery) {
2071
- Object.entries(otherQuery).forEach(([key, value]) => {
2072
- queryParams.set(key, value);
2073
- });
1804
+ ];
1805
+ checkoutCustomAttributes.push({
1806
+ key: "_checkout_delivery_custom",
1807
+ value: JSON.stringify({
1808
+ allow_nextday_delivery: true,
1809
+ allow_thirdday_delivery: true,
1810
+ selected_delivery_option: {
1811
+ code: selectedShippingMethod?.__code,
1812
+ mode: selectedShippingMethod?.__mode
1813
+ },
1814
+ is_presale: isPresaleContains,
1815
+ discount_code: selectedShippingMethod?.coupon ? [selectedShippingMethod.coupon] : [],
1816
+ plus_type: profile?.isPlus ? "free" /* FREE */ : selectedPlusMemberMode,
1817
+ is_prime: profile?.isPlus
1818
+ })
1819
+ });
1820
+ if (disableShipping) {
1821
+ checkoutCustomAttributes.push({
1822
+ key: "_hide_shipping",
1823
+ value: "true"
1824
+ });
1825
+ }
1826
+ return checkoutCustomAttributes;
1827
+ }, [profile, selectedShippingMethod, selectedPlusMemberMode, isPresaleContains]);
1828
+ };
1829
+ function useRemoveCartLines(options) {
1830
+ const { client, locale, cartCookieAdapter } = useShopify();
1831
+ const { mutateCart, metafieldIdentifiers } = useCartContext();
1832
+ const removeLines = useCallback(
1833
+ async (_key, { arg }) => {
1834
+ const { autoRemoveInvalidCodes = true, onCodesRemoved, cartId, lineIds } = arg;
1835
+ let updatedCart = await removeCartLines(client, {
1836
+ cartId,
1837
+ lineIds,
1838
+ metafieldIdentifiers,
1839
+ cookieAdapter: cartCookieAdapter
1840
+ });
1841
+ if (updatedCart && autoRemoveInvalidCodes) {
1842
+ const unApplicableCodes = updatedCart.discountCodes.filter((item) => !item.applicable).map((item) => item.code);
1843
+ if (unApplicableCodes.length > 0) {
1844
+ if (onCodesRemoved) {
1845
+ const handledCart = await onCodesRemoved(updatedCart, unApplicableCodes);
1846
+ if (handledCart) {
1847
+ updatedCart = handledCart;
1848
+ }
1849
+ } else {
1850
+ updatedCart = await updateCartCodes(client, {
1851
+ cartId: updatedCart.id,
1852
+ discountCodes: updatedCart.discountCodes.filter((item) => item.applicable).map((item) => item.code),
1853
+ metafieldIdentifiers,
1854
+ cookieAdapter: cartCookieAdapter
1855
+ }) || updatedCart;
1856
+ }
1857
+ }
2074
1858
  }
2075
- const queryString = queryParams.toString();
2076
- const path = `/products/${product.handle}${queryString ? `?${queryString}` : ""}`;
2077
- if (routerAdapter?.getLocalizedPath) {
2078
- return routerAdapter.getLocalizedPath(path);
1859
+ if (updatedCart) {
1860
+ mutateCart(updatedCart);
2079
1861
  }
2080
- return path;
1862
+ return updatedCart;
2081
1863
  },
2082
- [routerAdapter, otherQuery]
1864
+ [client, locale, cartCookieAdapter, mutateCart, metafieldIdentifiers]
2083
1865
  );
1866
+ return useSWRMutation("remove-cart-lines", removeLines, options);
2084
1867
  }
2085
- function decodeShopifyId3(gid) {
2086
- try {
2087
- const parts = gid.split("/");
2088
- return parts[parts.length - 1] || gid;
2089
- } catch {
2090
- return gid;
2091
- }
2092
- }
2093
- function useUpdateVariantQuery(variant) {
1868
+
1869
+ // src/hooks/member/plus/use-auto-remove-plus-member-in-cart.ts
1870
+ function useAutoRemovePlusMemberInCart({
1871
+ cart,
1872
+ profile,
1873
+ memberSetting
1874
+ }) {
1875
+ const { plus_monthly_product, plus_annual_product } = memberSetting || {};
1876
+ const { trigger: removeCartLines2 } = useRemoveCartLines();
2094
1877
  useEffect(() => {
2095
- if (!variant || typeof window === "undefined") {
2096
- return;
1878
+ if (!cart || !plus_monthly_product || !plus_annual_product) return;
1879
+ const removePlusProduct = async (productType) => {
1880
+ if (!productType) return;
1881
+ const product = cart.lineItems?.find(
1882
+ (item) => item.product?.handle === productType?.handle && item.variant?.sku === productType?.sku
1883
+ );
1884
+ if (product) {
1885
+ await removeCartLines2({
1886
+ lineIds: [product.id]
1887
+ });
1888
+ }
1889
+ };
1890
+ if (profile?.isMonthlyPlus) {
1891
+ removePlusProduct(plus_monthly_product);
2097
1892
  }
2098
- const searchParams = new URLSearchParams(window.location.search);
2099
- const currentVariantId = searchParams.get("variant");
2100
- const newVariantId = decodeShopifyId3(variant.id);
2101
- if (newVariantId && currentVariantId !== newVariantId) {
2102
- searchParams.set("variant", newVariantId);
2103
- const newUrl = `${window.location.pathname}?${searchParams.toString()}${window.location.hash}`;
2104
- window.history.replaceState({}, "", newUrl);
1893
+ if (profile?.isAnnualPlus) {
1894
+ removePlusProduct(plus_annual_product);
2105
1895
  }
2106
- }, [variant]);
1896
+ }, [cart, plus_annual_product, plus_monthly_product, profile, removeCartLines2]);
2107
1897
  }
2108
- function getVariantMediaList({
2109
- product,
2110
- variant
1898
+ function hasPlusMemberInCart({
1899
+ memberSetting,
1900
+ cart
2111
1901
  }) {
2112
- if (variant.image?.url) {
2113
- const variantMediaId = variant.image.url;
2114
- const variantMedia = product.media.filter((media) => {
2115
- if (media.mediaContentType === "IMAGE" && media.previewImage) {
2116
- return media.previewImage?.url === variantMediaId;
2117
- }
2118
- return false;
2119
- });
2120
- if (variantMedia.length > 0) {
2121
- const otherMedia = product.media.filter((media) => {
2122
- if (media.mediaContentType === "IMAGE" && media.previewImage) {
2123
- return media.previewImage.url !== variantMediaId;
2124
- }
2125
- return true;
2126
- });
2127
- return [...variantMedia, ...otherMedia];
2128
- }
1902
+ const { plus_monthly_product, plus_annual_product } = memberSetting || {};
1903
+ if (!cart?.lineItems) {
1904
+ return {
1905
+ hasPlusMember: false,
1906
+ hasMonthlyPlus: false,
1907
+ hasAnnualPlus: false
1908
+ };
2129
1909
  }
2130
- return product.media;
1910
+ const monthlyPlusItem = cart.lineItems.find(
1911
+ (item) => item.product?.handle === plus_monthly_product?.handle && item.variant?.sku === plus_monthly_product?.sku
1912
+ );
1913
+ const annualPlusItem = cart.lineItems.find(
1914
+ (item) => item.product?.handle === plus_annual_product?.handle && item.variant?.sku === plus_annual_product?.sku
1915
+ );
1916
+ const hasMonthlyPlus = !!monthlyPlusItem;
1917
+ const hasAnnualPlus = !!annualPlusItem;
1918
+ const hasPlusMember = hasMonthlyPlus || hasAnnualPlus;
1919
+ return {
1920
+ hasPlusMember,
1921
+ hasMonthlyPlus,
1922
+ hasAnnualPlus,
1923
+ monthlyPlusItem,
1924
+ annualPlusItem
1925
+ };
2131
1926
  }
2132
- function useVariantMedia({
2133
- product,
2134
- variant
1927
+ function useHasPlusMemberInCart({
1928
+ memberSetting,
1929
+ cart
2135
1930
  }) {
2136
- const [imageList, setImageList] = useState([]);
2137
- const [sceneList, setSceneList] = useState([]);
2138
- const [videoList, setVideoList] = useState([]);
2139
- useEffect(() => {
2140
- if (!product || !variant) {
2141
- setImageList([]);
2142
- setSceneList([]);
2143
- setVideoList([]);
2144
- return;
2145
- }
2146
- const mediaList = getVariantMediaList({ product, variant });
2147
- const images = mediaList.filter((media) => media.mediaContentType === "IMAGE");
2148
- const videos = mediaList.filter(
2149
- (media) => media.mediaContentType === "VIDEO" || media.mediaContentType === "EXTERNAL_VIDEO"
2150
- );
2151
- setImageList(images.length > 0 && images[0] ? [images[0]] : []);
2152
- setSceneList(images.length > 1 ? images.slice(1) : []);
2153
- setVideoList(videos);
2154
- }, [product, variant]);
2155
- return {
2156
- productList: imageList,
2157
- sceneList,
2158
- videoList
2159
- };
2160
- }
2161
- function useCollection(options = {}) {
2162
- const { client, locale } = useShopify();
2163
- const { handle, metafieldIdentifiers, ...swrOptions } = options;
2164
- return useSWR(
2165
- handle ? ["collection", locale, handle, metafieldIdentifiers] : null,
2166
- () => getCollection(client, {
2167
- handle,
2168
- locale,
2169
- metafieldIdentifiers
2170
- }),
2171
- swrOptions
2172
- );
2173
- }
2174
- function useAllCollections(options = {}) {
2175
- const { client, locale } = useShopify();
2176
- const { first, query, sortKey, reverse, metafieldIdentifiers, ...swrOptions } = options;
2177
- return useSWR(
2178
- ["all-collections", locale, first, query, sortKey, reverse, metafieldIdentifiers],
2179
- () => getAllCollections(client, {
2180
- locale,
2181
- first,
2182
- query,
2183
- sortKey,
2184
- reverse,
2185
- metafieldIdentifiers
2186
- }),
2187
- swrOptions
2188
- );
2189
- }
2190
- function useCollections(options = {}) {
2191
- const { client, locale } = useShopify();
2192
- const { first, after, query, sortKey, reverse, metafieldIdentifiers, ...swrOptions } = options;
2193
- return useSWR(
2194
- ["collections", locale, first, after, query, sortKey, reverse, metafieldIdentifiers],
2195
- () => getCollections(client, {
2196
- locale,
2197
- first,
2198
- after,
2199
- query,
2200
- sortKey,
2201
- reverse,
2202
- metafieldIdentifiers
2203
- }),
2204
- swrOptions
2205
- );
2206
- }
2207
- function useBlog(options = {}) {
2208
- const { client, locale } = useShopify();
2209
- const { handle, metafieldIdentifiers, ...swrOptions } = options;
2210
- return useSWR(
2211
- handle ? ["blog", locale, handle, metafieldIdentifiers] : null,
2212
- () => getBlog(client, { handle, locale, metafieldIdentifiers }),
2213
- swrOptions
2214
- );
2215
- }
2216
- function useAllBlogs(options = {}) {
2217
- const { client, locale } = useShopify();
2218
- const { first, query, metafieldIdentifiers, ...swrOptions } = options;
2219
- return useSWR(
2220
- ["all-blogs", locale, first, query, metafieldIdentifiers],
2221
- () => getAllBlogs(client, {
2222
- locale,
2223
- first,
2224
- query,
2225
- metafieldIdentifiers
2226
- }),
2227
- swrOptions
2228
- );
2229
- }
2230
- function useArticle(options = {}) {
2231
- const { client, locale } = useShopify();
2232
- const { blogHandle, articleHandle, metafieldIdentifiers, ...swrOptions } = options;
2233
- return useSWR(
2234
- blogHandle && articleHandle ? ["article", locale, blogHandle, articleHandle, metafieldIdentifiers] : null,
2235
- () => getArticle(client, {
2236
- blogHandle,
2237
- articleHandle,
2238
- locale,
2239
- metafieldIdentifiers
2240
- }),
2241
- swrOptions
2242
- );
2243
- }
2244
- function useArticles(options = {}) {
2245
- const { client, locale } = useShopify();
2246
- const { first, query, sortKey, reverse, metafieldIdentifiers, ...swrOptions } = options;
2247
- return useSWR(
2248
- ["articles", locale, first, query, sortKey, reverse, metafieldIdentifiers],
2249
- () => getArticles(client, {
2250
- locale,
2251
- first,
2252
- query,
2253
- sortKey,
2254
- reverse,
2255
- metafieldIdentifiers
2256
- }),
2257
- swrOptions
2258
- );
2259
- }
2260
- function useArticlesInBlog(options = {}) {
2261
- const { client, locale } = useShopify();
2262
- const { blogHandle, first, sortKey, reverse, metafieldIdentifiers, ...swrOptions } = options;
2263
- return useSWR(
2264
- blogHandle ? ["articles-in-blog", locale, blogHandle, first, sortKey, reverse, metafieldIdentifiers] : null,
2265
- () => getArticlesInBlog(client, {
2266
- blogHandle,
2267
- locale,
2268
- first,
2269
- sortKey,
2270
- reverse,
2271
- metafieldIdentifiers
1931
+ return useMemo(
1932
+ () => hasPlusMemberInCart({
1933
+ memberSetting,
1934
+ cart
2272
1935
  }),
2273
- swrOptions
1936
+ [memberSetting, cart]
2274
1937
  );
2275
1938
  }
2276
- async function performSearch(client, locale, searchQuery, first = 20, types = ["PRODUCT", "ARTICLE", "PAGE"]) {
2277
- if (!searchQuery) {
2278
- return void 0;
1939
+ function hasPlusMemberInLines({
1940
+ memberSetting,
1941
+ lines
1942
+ }) {
1943
+ const { plus_monthly_product, plus_annual_product } = memberSetting || {};
1944
+ if (!lines || lines.length === 0) {
1945
+ return {
1946
+ hasPlusMember: false,
1947
+ hasMonthlyPlus: false,
1948
+ hasAnnualPlus: false
1949
+ };
2279
1950
  }
2280
- const query = (
2281
- /* GraphQL */
2282
- `
2283
- query search($query: String!, $first: Int!, $types: [SearchType!])
2284
- @inContext(language: $language) {
2285
- search(query: $query, first: $first, types: $types, unavailableProducts: HIDE) {
2286
- totalCount
2287
- edges {
2288
- node {
2289
- ... on Article {
2290
- __typename
2291
- id
2292
- handle
2293
- title
2294
- excerpt
2295
- image {
2296
- url
2297
- altText
2298
- }
2299
- }
2300
- ... on Page {
2301
- __typename
2302
- id
2303
- handle
2304
- title
2305
- }
2306
- ... on Product {
2307
- __typename
2308
- id
2309
- handle
2310
- title
2311
- description
2312
- featuredImage {
2313
- url
2314
- altText
2315
- }
2316
- }
2317
- }
2318
- }
2319
- pageInfo {
2320
- hasNextPage
2321
- endCursor
2322
- }
2323
- }
2324
- }
2325
- `
2326
- );
2327
- const data = await client.query(query, {
2328
- query: searchQuery,
2329
- first,
2330
- types
1951
+ const monthlyPlusLine = lines.find((line) => {
1952
+ const variantHandle = line.variant?.product?.handle;
1953
+ const variantSku = line.variant?.sku;
1954
+ return variantHandle === plus_monthly_product?.handle && variantSku === plus_monthly_product?.sku;
2331
1955
  });
2332
- if (!data || !data.search) {
2333
- return void 0;
2334
- }
2335
- const items = data.search.edges?.map((edge) => {
2336
- const node = edge.node;
2337
- const item = {
2338
- type: node.__typename.toUpperCase(),
2339
- id: node.id,
2340
- handle: node.handle,
2341
- title: node.title
2342
- };
2343
- if (node.__typename === "Product") {
2344
- item.description = node.description;
2345
- item.image = node.featuredImage ? {
2346
- url: node.featuredImage.url,
2347
- altText: node.featuredImage.altText
2348
- } : void 0;
2349
- } else if (node.__typename === "Article") {
2350
- item.description = node.excerpt;
2351
- item.image = node.image ? {
2352
- url: node.image.url,
2353
- altText: node.image.altText
2354
- } : void 0;
2355
- }
2356
- return item;
2357
- }) || [];
1956
+ const annualPlusLine = lines.find((line) => {
1957
+ const variantHandle = line.variant?.product?.handle;
1958
+ const variantSku = line.variant?.sku;
1959
+ return variantHandle === plus_annual_product?.handle && variantSku === plus_annual_product?.sku;
1960
+ });
1961
+ const hasMonthlyPlus = !!monthlyPlusLine;
1962
+ const hasAnnualPlus = !!annualPlusLine;
1963
+ const hasPlusMember = hasMonthlyPlus || hasAnnualPlus;
2358
1964
  return {
2359
- items,
2360
- totalCount: data.search.totalCount || 0,
2361
- pageInfo: data.search.pageInfo
1965
+ hasPlusMember,
1966
+ hasMonthlyPlus,
1967
+ hasAnnualPlus,
1968
+ monthlyPlusLine,
1969
+ annualPlusLine
2362
1970
  };
2363
1971
  }
2364
- function useSearch(options = {}) {
2365
- const { client, locale } = useShopify();
2366
- const { query, first = 20, types = ["PRODUCT", "ARTICLE", "PAGE"], ...swrOptions } = options;
2367
- return useSWR(
2368
- query ? ["search", locale, query, first, types] : null,
2369
- () => performSearch(client, locale, query, first, types),
2370
- swrOptions
1972
+ function useHasPlusMemberInLines({
1973
+ memberSetting,
1974
+ lines
1975
+ }) {
1976
+ return useMemo(
1977
+ () => hasPlusMemberInLines({
1978
+ memberSetting,
1979
+ lines
1980
+ }),
1981
+ [memberSetting, lines]
2371
1982
  );
2372
1983
  }
2373
- async function getSiteInfo(client, locale, metafieldIdentifiers) {
2374
- const hasMetafields = metafieldIdentifiers && metafieldIdentifiers.length > 0;
2375
- const query = (
2376
- /* GraphQL */
2377
- `
2378
- query getSiteInfo(
2379
- ${hasMetafields ? "$shopMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
2380
- ) @inContext(language: $language) {
2381
- shop {
2382
- name
2383
- description
2384
- primaryDomain {
2385
- url
2386
- host
2387
- }
2388
- brand {
2389
- logo {
2390
- image {
2391
- url
2392
- }
2393
- }
2394
- colors {
2395
- primary {
2396
- background
2397
- }
2398
- secondary {
2399
- background
2400
- }
2401
- }
2402
- }
2403
- ${hasMetafields ? "metafields(identifiers: $shopMetafieldIdentifiers) { key value }" : ""}
2404
- }
1984
+ function usePlusMemberNeedAddToCart({
1985
+ cart,
1986
+ profile
1987
+ }) {
1988
+ const { selectedPlusMemberMode, selectedPlusMemberVariant, plusMemberMetafields } = usePlusMemberContext();
1989
+ const { hasMonthlyPlus, hasAnnualPlus } = useHasPlusMemberInCart({
1990
+ memberSetting: plusMemberMetafields,
1991
+ cart
1992
+ });
1993
+ const plusMemberVariant = useMemo(() => {
1994
+ if (!selectedPlusMemberVariant || selectedPlusMemberMode === "free" /* FREE */) {
1995
+ return void 0;
2405
1996
  }
2406
- `
2407
- );
2408
- const variables = {};
2409
- if (hasMetafields) {
2410
- variables.shopMetafieldIdentifiers = metafieldIdentifiers;
2411
- }
2412
- const data = await client.query(query, variables);
2413
- if (!data || !data.shop) {
2414
- return void 0;
2415
- }
2416
- const shop = data.shop;
2417
- const metafields = shop.metafields?.reduce((acc, mf) => {
2418
- if (mf && mf.key) {
2419
- acc[mf.key] = mf.value;
1997
+ if (selectedPlusMemberMode === "monthly" /* MONTHLY */ && hasMonthlyPlus) {
1998
+ return void 0;
2420
1999
  }
2421
- return acc;
2422
- }, {});
2423
- return {
2424
- name: shop.name,
2425
- description: shop.description,
2426
- primaryDomain: shop.primaryDomain,
2427
- brand: shop.brand ? {
2428
- logo: shop.brand.logo,
2429
- colors: shop.brand.colors ? {
2430
- primary: shop.brand.colors.primary?.background,
2431
- secondary: shop.brand.colors.secondary?.background
2432
- } : void 0
2433
- } : void 0,
2434
- metafields
2435
- };
2000
+ if (selectedPlusMemberMode === "annual" /* ANNUAL */ && hasAnnualPlus) {
2001
+ return void 0;
2002
+ }
2003
+ if (profile?.isMonthlyPlus && selectedPlusMemberMode === "monthly" /* MONTHLY */) {
2004
+ return void 0;
2005
+ }
2006
+ if (profile?.isAnnualPlus && selectedPlusMemberMode === "annual" /* ANNUAL */) {
2007
+ return void 0;
2008
+ }
2009
+ return selectedPlusMemberVariant;
2010
+ }, [selectedPlusMemberMode, selectedPlusMemberVariant, hasMonthlyPlus, hasAnnualPlus]);
2011
+ return plusMemberVariant;
2436
2012
  }
2437
- function useSite(options = {}) {
2438
- const { client, locale } = useShopify();
2439
- const { metafieldIdentifiers, ...swrOptions } = options;
2440
- return useSWR(
2441
- ["site", locale, metafieldIdentifiers],
2442
- () => getSiteInfo(client, locale, metafieldIdentifiers),
2443
- swrOptions
2013
+ var PlusMemberProvider = ({
2014
+ variant,
2015
+ product,
2016
+ memberSetting,
2017
+ initialSelectedPlusMemberMode = "free",
2018
+ profile,
2019
+ children
2020
+ }) => {
2021
+ const [selectedPlusMemberMode, setSelectedPlusMemberMode] = useState(
2022
+ initialSelectedPlusMemberMode
2444
2023
  );
2445
- }
2446
-
2447
- // src/hooks/member/plus/types.ts
2448
- var PLUS_MEMBER_TYPE = /* @__PURE__ */ ((PLUS_MEMBER_TYPE2) => {
2449
- PLUS_MEMBER_TYPE2[PLUS_MEMBER_TYPE2["FREE"] = 0] = "FREE";
2450
- PLUS_MEMBER_TYPE2[PLUS_MEMBER_TYPE2["MONTHLY"] = 1] = "MONTHLY";
2451
- PLUS_MEMBER_TYPE2[PLUS_MEMBER_TYPE2["ANNUAL"] = 2] = "ANNUAL";
2452
- return PLUS_MEMBER_TYPE2;
2453
- })(PLUS_MEMBER_TYPE || {});
2454
- var PlusMemberMode = /* @__PURE__ */ ((PlusMemberMode2) => {
2455
- PlusMemberMode2["MONTHLY"] = "monthly";
2456
- PlusMemberMode2["ANNUAL"] = "annual";
2457
- return PlusMemberMode2;
2458
- })(PlusMemberMode || {});
2459
- var DeliveryPlusType = /* @__PURE__ */ ((DeliveryPlusType2) => {
2460
- DeliveryPlusType2["FREE"] = "free";
2461
- DeliveryPlusType2["MONTHLY"] = "monthly";
2462
- DeliveryPlusType2["ANNUAL"] = "annual";
2463
- return DeliveryPlusType2;
2464
- })(DeliveryPlusType || {});
2465
- var ShippingMethodMode = /* @__PURE__ */ ((ShippingMethodMode2) => {
2466
- ShippingMethodMode2["FREE"] = "free";
2467
- ShippingMethodMode2["TDD"] = "tdd";
2468
- ShippingMethodMode2["NDD"] = "ndd";
2469
- return ShippingMethodMode2;
2470
- })(ShippingMethodMode || {});
2471
- var createInitialValue = () => ({
2472
- plusMemberMetafields: {},
2473
- selectedPlusMemberMode: "free",
2474
- setSelectedPlusMemberMode: () => {
2475
- },
2476
- selectedShippingMethod: void 0,
2477
- setSelectedShippingMethod: () => {
2478
- },
2479
- showMoreShippingMethod: false,
2480
- setShowMoreShippingMethod: () => {
2481
- },
2482
- variant: {},
2483
- product: {},
2484
- shippingMethodsContext: {
2485
- freeShippingMethods: [],
2486
- paymentShippingMethods: [],
2487
- nddOverweight: false,
2488
- tddOverweight: false,
2489
- nddCoupon: void 0,
2490
- tddCoupon: void 0,
2491
- isLoadingCoupon: false
2492
- },
2493
- selectedPlusMemberVariant: void 0,
2494
- showPlusMemberBenefit: false,
2495
- setShowPlusMemberBenefit: () => {
2496
- },
2497
- profile: void 0
2498
- });
2499
- var PlusMemberContext = createContext(createInitialValue());
2500
- function usePlusMemberContext() {
2501
- return useContext(PlusMemberContext);
2502
- }
2503
- function usePlusMemberVariants({
2504
- memberSetting
2505
- }) {
2506
- const plusMonthly = memberSetting?.plus_monthly_product;
2507
- const plusAnnual = memberSetting?.plus_annual_product;
2508
- const plusMemberHandles = useMemo(() => {
2509
- return [plusMonthly?.handle, plusAnnual?.handle].filter(Boolean);
2510
- }, [plusMonthly?.handle, plusAnnual?.handle]);
2511
- const { data: plusMemberProducts = [] } = useProductsByHandles({
2512
- handles: plusMemberHandles
2024
+ const [selectedShippingMethod, setSelectedShippingMethod] = useState();
2025
+ const [showMoreShippingMethod, setShowMoreShippingMethod] = useState(false);
2026
+ const [showPlusMemberBenefit, setShowPlusMemberBenefit] = useState(false);
2027
+ const shippingMethodsContext = useShippingMethods({
2028
+ variant,
2029
+ plusMemberMetafields: memberSetting,
2030
+ selectedPlusMemberMode,
2031
+ profile
2513
2032
  });
2514
- const monthlyProduct = useMemo(() => {
2515
- return plusMemberProducts?.find((item) => item?.handle === plusMonthly?.handle);
2516
- }, [plusMemberProducts, plusMonthly]);
2517
- const annualProduct = useMemo(() => {
2518
- return plusMemberProducts?.find((item) => item?.handle === plusAnnual?.handle);
2519
- }, [plusMemberProducts, plusAnnual]);
2520
- const monthlyVariant = useMemo(() => {
2521
- return monthlyProduct?.variants?.find((item) => item.sku === plusMonthly?.sku);
2522
- }, [monthlyProduct, plusMonthly]);
2523
- const annualVariant = useMemo(() => {
2524
- return annualProduct?.variants?.find((item) => item.sku === plusAnnual?.sku);
2525
- }, [annualProduct, plusAnnual]);
2526
- return {
2527
- monthlyVariant: monthlyVariant ? {
2528
- ...monthlyVariant,
2529
- product: monthlyProduct
2530
- } : void 0,
2531
- annualVariant: annualVariant ? {
2532
- ...annualVariant,
2533
- product: annualProduct
2534
- } : void 0
2535
- };
2536
- }
2537
- var useAvailableDeliveryCoupon = ({
2538
- profile
2539
- }) => {
2540
- const { data: availableDeliveryCoupon, isLoading } = useSWR(
2541
- profile?.email ? ["/api/multipass/subsrv/v1/prime/delivery_coupons/current/available", profile?.email] : void 0,
2542
- async ([apiPath]) => {
2543
- return fetch(apiPath).then((res) => res.json());
2033
+ const { monthlyVariant, annualVariant } = usePlusMemberVariants({
2034
+ memberSetting
2035
+ });
2036
+ const selectedPlusMemberVariant = useMemo(() => {
2037
+ if (selectedPlusMemberMode === "free" /* FREE */) {
2038
+ return void 0;
2039
+ }
2040
+ return selectedPlusMemberMode === "monthly" /* MONTHLY */ ? monthlyVariant : annualVariant;
2041
+ }, [monthlyVariant, annualVariant, selectedPlusMemberMode]);
2042
+ return /* @__PURE__ */ jsx(
2043
+ PlusMemberContext.Provider,
2044
+ {
2045
+ value: {
2046
+ variant,
2047
+ plusMemberMetafields: memberSetting,
2048
+ selectedPlusMemberMode,
2049
+ setSelectedPlusMemberMode,
2050
+ selectedShippingMethod,
2051
+ setSelectedShippingMethod,
2052
+ shippingMethodsContext,
2053
+ showMoreShippingMethod,
2054
+ setShowMoreShippingMethod,
2055
+ selectedPlusMemberVariant,
2056
+ product,
2057
+ showPlusMemberBenefit,
2058
+ setShowPlusMemberBenefit,
2059
+ profile
2060
+ },
2061
+ children
2544
2062
  }
2545
2063
  );
2546
- console.log("availableDeliveryCoupon", availableDeliveryCoupon);
2547
- const { ndd_coupon: nddCoupon, tdd_coupon: tddCoupon } = availableDeliveryCoupon?.data?.data || {};
2548
- return {
2549
- nddCoupon,
2550
- tddCoupon,
2551
- isLoading
2552
- };
2553
2064
  };
2554
2065
 
2555
- // src/hooks/member/plus/use-shipping-methods.ts
2556
- function useShippingMethods(options) {
2557
- const { variant, plusMemberMetafields, selectedPlusMemberMode, profile } = options;
2558
- const isPlus = profile?.isPlus || false;
2559
- const { nddCoupon, tddCoupon, isLoading } = useAvailableDeliveryCoupon({ profile });
2560
- const { plus_shipping, shippingMethod } = plusMemberMetafields || {};
2561
- const nddOverweight = useMemo(() => {
2562
- return (variant?.weight || 0) > (shippingMethod?.overWeight_ndd || Infinity);
2563
- }, [shippingMethod?.overWeight_ndd, variant?.weight]);
2564
- const tddOverweight = useMemo(() => {
2565
- return (variant?.weight || 0) > (shippingMethod?.overWeight_tdd || Infinity);
2566
- }, [shippingMethod?.overWeight_tdd, variant?.weight]);
2567
- const paymentShippingMethods = useMemo(() => {
2568
- const weight = variant?.weight || 0;
2569
- const methods = plus_shipping?.shipping_methods?.filter(({ weight_low, weight_high, __mode, __plus }) => {
2570
- const fitWeight = (!weight_low || weight >= weight_low) && (!weight_high || weight <= weight_high);
2571
- return __mode !== "free" /* FREE */ && !__plus && fitWeight;
2572
- }) || [];
2573
- return methods.map((method) => {
2574
- let disabled = false;
2575
- const selectedFreeMember = selectedPlusMemberMode === "free";
2576
- if (method.__mode === "ndd" /* NDD */) {
2577
- disabled = selectedFreeMember || nddOverweight;
2578
- } else if (method.__mode === "tdd" /* TDD */) {
2579
- disabled = selectedFreeMember || tddOverweight;
2066
+ // src/hooks/cart/use-add-to-cart.ts
2067
+ function useAddToCart({ withTrack = true } = {}, swrOptions) {
2068
+ const { client, config, locale, cartCookieAdapter, userAdapter, performanceAdapter } = useShopify();
2069
+ const { cart, addCustomAttributes, memberSetting, profile, customer } = useCartContext();
2070
+ const { trigger: applyCartCodes } = useApplyCartCodes();
2071
+ const { trigger: removeInvalidCodes } = useRemoveCartCodes();
2072
+ const { trigger: addCartLines2 } = useAddCartLines();
2073
+ const { trigger: createCart4 } = useCreateCart({
2074
+ updateCookie: true
2075
+ });
2076
+ const { hasPlusMember } = useHasPlusMemberInCart({
2077
+ memberSetting,
2078
+ cart
2079
+ });
2080
+ const { attributes: cartAttributes } = useCartAttributes({
2081
+ profile,
2082
+ customer,
2083
+ cart,
2084
+ memberType: hasPlusMember ? "2" : String(profile?.memberType ?? 0)
2085
+ });
2086
+ const addToCart = useCallback(
2087
+ async (_key, { arg }) => {
2088
+ const {
2089
+ lineItems,
2090
+ cartId: providedCartId,
2091
+ discountCodes,
2092
+ gtmParams = {},
2093
+ buyerIdentity,
2094
+ needCreateCart = false,
2095
+ onCodesInvalid,
2096
+ replaceExistingCodes,
2097
+ customAttributes
2098
+ } = arg;
2099
+ if (!lineItems || lineItems.length === 0) {
2100
+ return;
2580
2101
  }
2581
- return {
2582
- ...method,
2583
- id: method.__mode + method.__code,
2584
- useCoupon: false,
2585
- subtitle: plus_shipping?.directly || "",
2586
- disabled
2587
- };
2588
- });
2589
- }, [
2590
- nddOverweight,
2591
- plus_shipping?.directly,
2592
- plus_shipping?.shipping_methods,
2593
- selectedPlusMemberMode,
2594
- tddOverweight,
2595
- variant?.weight
2596
- ]);
2597
- const nddPrice = useMemo(() => {
2598
- const weight = variant?.weight || 0;
2599
- const nddMethod = paymentShippingMethods.find(({ __mode, weight_high, weight_low }) => {
2600
- const fitWeight = (!weight_low || weight >= weight_low) && (!weight_high || weight <= weight_high);
2601
- return __mode === "ndd" && fitWeight;
2602
- });
2603
- return nddMethod?.price || 0;
2604
- }, [variant?.weight, paymentShippingMethods]);
2605
- const tddPrice = useMemo(() => {
2606
- const weight = variant?.weight || 0;
2607
- const tddMethod = paymentShippingMethods.find(({ __mode, weight_high, weight_low }) => {
2608
- const fitWeight = (!weight_low || weight >= weight_low) && (!weight_high || weight <= weight_high);
2609
- return __mode === "tdd" && fitWeight;
2610
- });
2611
- return tddMethod?.price || 0;
2612
- }, [variant?.weight, paymentShippingMethods]);
2613
- const freeShippingMethods = useMemo(() => {
2614
- const weight = variant?.weight || 0;
2615
- let methods = plus_shipping?.shipping_methods?.filter(({ __mode, __plus, weight_low, weight_high }) => {
2616
- if (__mode === "free" /* FREE */) {
2617
- return true;
2102
+ performanceAdapter?.addToCartStart();
2103
+ const linesWithFunctionAttributes = getLinesWithAttributes({ cart, lineItems });
2104
+ const lines = linesWithFunctionAttributes.map((item) => ({
2105
+ merchandiseId: item.variant?.id || "",
2106
+ quantity: item.quantity || 1,
2107
+ attributes: item.attributes,
2108
+ sellingPlanId: item.sellingPlanId
2109
+ })).filter((item) => item.merchandiseId && item.quantity);
2110
+ if (lines.length === 0) {
2111
+ return;
2618
2112
  }
2619
- if (isPlus) {
2620
- const hasCoupon = isPlus && __mode === "ndd" /* NDD */ && nddCoupon || isPlus && __mode === "tdd" /* TDD */ && (tddCoupon || nddCoupon);
2621
- const fitWeight = (!weight_low || weight >= weight_low) && (!weight_high || weight <= weight_high);
2622
- return hasCoupon && fitWeight && !__plus;
2113
+ let cartId = needCreateCart ? void 0 : providedCartId || cart?.id;
2114
+ let resultCart = null;
2115
+ if (!cartId) {
2116
+ resultCart = await createCart4({
2117
+ lines,
2118
+ buyerIdentity,
2119
+ discountCodes,
2120
+ customAttributes: [...cartAttributes, ...customAttributes || []]
2121
+ // 初次加购时,就把所有 cart attributes 带上
2122
+ });
2623
2123
  } else {
2624
- return __plus;
2625
- }
2626
- }) || [];
2627
- if (isPlus) {
2628
- methods = methods.sort((a, b) => {
2629
- if (b.__mode === "free" /* FREE */) return -1;
2630
- return 0;
2631
- });
2632
- }
2633
- return methods.map((method) => {
2634
- let price = 0;
2635
- let coupon;
2636
- let disabled;
2637
- if (method.__mode !== "free" /* FREE */) {
2638
- switch (method.__mode) {
2639
- case "tdd":
2640
- price = tddPrice;
2641
- coupon = tddCoupon || nddCoupon;
2642
- break;
2643
- case "ndd":
2644
- price = nddPrice;
2645
- coupon = nddCoupon;
2646
- break;
2124
+ resultCart = await addCartLines2({
2125
+ cartId,
2126
+ lines
2127
+ });
2128
+ console.log("npm addCartLines resultCart", resultCart);
2129
+ if (resultCart && resultCart.discountCodes && resultCart.discountCodes.length > 0) {
2130
+ const unapplicableCodes = resultCart.discountCodes.filter((item) => !item.applicable).map((item) => item.code);
2131
+ if (unapplicableCodes.length > 0) {
2132
+ if (onCodesInvalid) {
2133
+ const handledCart = await onCodesInvalid(resultCart, unapplicableCodes);
2134
+ if (handledCart) {
2135
+ resultCart = handledCart;
2136
+ }
2137
+ } else {
2138
+ await removeInvalidCodes({
2139
+ discountCodes: unapplicableCodes
2140
+ });
2141
+ }
2142
+ }
2647
2143
  }
2648
- disabled = selectedPlusMemberMode === "free";
2649
- if (method.__mode === "ndd" /* NDD */) {
2650
- disabled = disabled || nddOverweight;
2651
- } else if (method.__mode === "tdd" /* TDD */) {
2652
- disabled = disabled || tddOverweight;
2144
+ if (resultCart && discountCodes && discountCodes.length > 0) {
2145
+ applyCartCodes({
2146
+ replaceExistingCodes,
2147
+ discountCodes
2148
+ });
2149
+ }
2150
+ if (customAttributes && customAttributes.length > 0) {
2151
+ addCustomAttributes(customAttributes);
2653
2152
  }
2654
2153
  }
2655
- return {
2656
- ...method,
2657
- id: method.__mode + method.__code,
2658
- useCoupon: true,
2659
- disabled,
2660
- coupon,
2661
- price
2662
- };
2663
- });
2664
- }, [
2665
- variant?.weight,
2666
- plus_shipping?.shipping_methods,
2667
- isPlus,
2668
- nddCoupon,
2669
- tddCoupon,
2670
- selectedPlusMemberMode,
2671
- tddPrice,
2672
- nddPrice,
2673
- nddOverweight,
2674
- tddOverweight
2675
- ]);
2676
- return {
2677
- freeShippingMethods,
2678
- paymentShippingMethods,
2679
- nddOverweight,
2680
- tddOverweight,
2681
- nddCoupon,
2682
- tddCoupon,
2683
- isLoadingCoupon: isLoading
2684
- };
2154
+ if (withTrack) {
2155
+ trackAddToCartGA({
2156
+ lineItems,
2157
+ gtmParams: { ...gtmParams, brand: config.getBrand() }
2158
+ });
2159
+ trackAddToCartFBQ({ lineItems });
2160
+ }
2161
+ performanceAdapter?.addToCartEnd();
2162
+ return resultCart;
2163
+ },
2164
+ [
2165
+ client,
2166
+ locale,
2167
+ cartCookieAdapter,
2168
+ userAdapter,
2169
+ cart,
2170
+ withTrack,
2171
+ performanceAdapter,
2172
+ createCart4,
2173
+ addCartLines2,
2174
+ applyCartCodes,
2175
+ removeInvalidCodes,
2176
+ addCustomAttributes,
2177
+ config
2178
+ ]
2179
+ );
2180
+ return useSWRMutation("add-to-cart", addToCart, swrOptions);
2685
2181
  }
2686
- var useReplaceCartPlusMember = () => {
2687
- const { plusMemberMetafields, selectedPlusMemberMode } = usePlusMemberContext();
2688
- const { trigger: removeCartLines2 } = useRemoveCartLines();
2689
- const { cart } = useCartContext();
2690
- const plusMonthly = plusMemberMetafields?.plus_monthly_product;
2691
- const plusAnnual = plusMemberMetafields?.plus_annual_product;
2692
- const handler = useCallback(async () => {
2693
- const plusMonthlyInCart = cart?.lineItems.find(
2694
- (item) => item.variant?.sku === plusMonthly?.sku
2695
- );
2696
- const plusAnnualInCart = cart?.lineItems.find(
2697
- (item) => item.variant?.sku === plusAnnual?.sku
2698
- );
2699
- if (selectedPlusMemberMode === "annual" /* ANNUAL */ && plusMonthlyInCart) {
2700
- await removeCartLines2({
2701
- lineIds: [plusMonthlyInCart.id]
2702
- });
2703
- } else if (selectedPlusMemberMode === "monthly" /* MONTHLY */ && plusAnnualInCart) {
2704
- await removeCartLines2({
2705
- lineIds: [plusAnnualInCart.id]
2182
+ function useUpdateCartLines(options) {
2183
+ const { client, locale, cartCookieAdapter } = useShopify();
2184
+ const { mutateCart, metafieldIdentifiers } = useCartContext();
2185
+ const updateLines = useCallback(
2186
+ async (_key, { arg }) => {
2187
+ const updatedCart = await updateCartLines(client, {
2188
+ ...arg,
2189
+ metafieldIdentifiers,
2190
+ cookieAdapter: cartCookieAdapter
2706
2191
  });
2707
- }
2708
- }, [
2709
- cart?.lineItems,
2710
- selectedPlusMemberMode,
2711
- plusMonthly?.sku,
2712
- plusAnnual?.sku,
2713
- removeCartLines2
2714
- ]);
2715
- return handler;
2716
- };
2717
- var usePlusMemberDeliveryCodes = () => {
2718
- const { selectedShippingMethod } = usePlusMemberContext();
2719
- return useMemo(() => [selectedShippingMethod?.coupon], [selectedShippingMethod?.coupon]);
2720
- };
2721
- var usePlusMemberCheckoutCustomAttributes = ({
2722
- disableShipping = false,
2723
- isPresaleContains = false
2724
- }) => {
2725
- const { profile, selectedShippingMethod, selectedPlusMemberMode } = usePlusMemberContext();
2726
- return useMemo(() => {
2727
- const checkoutCustomAttributes = [
2728
- {
2729
- key: "_last_url",
2730
- value: typeof window !== "undefined" ? window.location.origin + window.location.pathname : ""
2192
+ if (updatedCart) {
2193
+ mutateCart(updatedCart);
2731
2194
  }
2732
- ];
2733
- checkoutCustomAttributes.push({
2734
- key: "_checkout_delivery_custom",
2735
- value: JSON.stringify({
2736
- allow_nextday_delivery: true,
2737
- allow_thirdday_delivery: true,
2738
- selected_delivery_option: {
2739
- code: selectedShippingMethod?.__code,
2740
- mode: selectedShippingMethod?.__mode
2741
- },
2742
- is_presale: isPresaleContains,
2743
- discount_code: selectedShippingMethod?.coupon ? [selectedShippingMethod.coupon] : [],
2744
- plus_type: profile?.isPlus ? "free" /* FREE */ : selectedPlusMemberMode,
2745
- is_prime: profile?.isPlus
2746
- })
2195
+ console.log("use-update-cart-lines updatedCart", metafieldIdentifiers, updatedCart);
2196
+ return updatedCart;
2197
+ },
2198
+ [client, locale, cartCookieAdapter, mutateCart, metafieldIdentifiers]
2199
+ );
2200
+ return useSWRMutation("update-cart-lines", updateLines, options);
2201
+ }
2202
+ function useUpdateCartAttributes({
2203
+ mutate,
2204
+ metafieldIdentifiers,
2205
+ disabled = false,
2206
+ swrOptions
2207
+ }) {
2208
+ const { client, locale, cartCookieAdapter } = useShopify();
2209
+ const updateAttributes = useCallback(
2210
+ async (_key, { arg }) => {
2211
+ if (disabled) {
2212
+ return void 0;
2213
+ }
2214
+ const updatedCart = await updateCartAttributes(client, {
2215
+ ...arg,
2216
+ metafieldIdentifiers,
2217
+ cookieAdapter: cartCookieAdapter
2218
+ });
2219
+ if (updatedCart) {
2220
+ mutate(updatedCart);
2221
+ }
2222
+ return updatedCart;
2223
+ },
2224
+ [client, locale, cartCookieAdapter, mutate, metafieldIdentifiers, disabled]
2225
+ );
2226
+ return useSWRMutation("update-cart-attributes", updateAttributes, swrOptions);
2227
+ }
2228
+ function useBuyNow({ withTrack = true } = {}, swrOptions) {
2229
+ const { client, config, locale, cartCookieAdapter, userAdapter } = useShopify();
2230
+ const { profile, customer, memberSetting } = useCartContext();
2231
+ const isLoggedIn = userAdapter?.isLoggedIn || false;
2232
+ const buyNow = useCallback(
2233
+ async (_key, { arg }) => {
2234
+ const {
2235
+ lineItems,
2236
+ discountCodes,
2237
+ gtmParams = {},
2238
+ buyerIdentity,
2239
+ fbqTrackConfig,
2240
+ customAttributes,
2241
+ metafieldIdentifiers,
2242
+ redirectToCheckout
2243
+ } = arg;
2244
+ if (!lineItems || lineItems.length === 0) {
2245
+ return;
2246
+ }
2247
+ const { hasPlusMember } = hasPlusMemberInLines({
2248
+ memberSetting,
2249
+ lines: lineItems
2250
+ });
2251
+ const memberType = hasPlusMember ? "2" : String(profile?.memberType ?? 0);
2252
+ console.log("customer", customer);
2253
+ const cartAttributes = getCartAttributes({
2254
+ profile,
2255
+ customer,
2256
+ memberType,
2257
+ currentUrl: window.location.href
2258
+ });
2259
+ const linesWithFunctionAttributes = getLinesWithAttributes({
2260
+ lineItems
2261
+ });
2262
+ const lines = linesWithFunctionAttributes.map((item) => ({
2263
+ merchandiseId: item.variant?.id || "",
2264
+ quantity: item.quantity || 1,
2265
+ attributes: item.attributes,
2266
+ sellingPlanId: item.sellingPlanId
2267
+ })).filter((item) => item.merchandiseId);
2268
+ if (lines.length === 0) {
2269
+ return;
2270
+ }
2271
+ const resultCart = await createCart(client, {
2272
+ lines,
2273
+ metafieldIdentifiers,
2274
+ cookieAdapter: cartCookieAdapter,
2275
+ buyerIdentity,
2276
+ discountCodes,
2277
+ customAttributes: [...cartAttributes, ...customAttributes || []]
2278
+ });
2279
+ if (!resultCart) {
2280
+ throw new Error("Failed to create cart for buy now");
2281
+ }
2282
+ if (withTrack && resultCart.lineItems) {
2283
+ trackBuyNowGA({
2284
+ lineItems,
2285
+ gtmParams: { ...gtmParams, brand: config.getBrand() }
2286
+ });
2287
+ if (fbqTrackConfig) {
2288
+ trackBuyNowFBQ({ trackConfig: fbqTrackConfig });
2289
+ }
2290
+ }
2291
+ if (redirectToCheckout) {
2292
+ if (resultCart.url) {
2293
+ if (typeof window !== "undefined") {
2294
+ window.location.href = resultCart.url;
2295
+ }
2296
+ } else {
2297
+ throw new Error("Failed to get checkout URL");
2298
+ }
2299
+ }
2300
+ return resultCart;
2301
+ },
2302
+ [client, locale, isLoggedIn, cartCookieAdapter, withTrack]
2303
+ );
2304
+ return useSWRMutation("buy-now", buyNow, swrOptions);
2305
+ }
2306
+
2307
+ // src/hooks/cart/types/price-discount.ts
2308
+ var PriceDiscountType = /* @__PURE__ */ ((PriceDiscountType2) => {
2309
+ PriceDiscountType2[PriceDiscountType2["PERCENTAGE"] = 1] = "PERCENTAGE";
2310
+ PriceDiscountType2[PriceDiscountType2["FIXED_AMOUNT"] = 2] = "FIXED_AMOUNT";
2311
+ return PriceDiscountType2;
2312
+ })(PriceDiscountType || {});
2313
+ var PriceBasePriceType = /* @__PURE__ */ ((PriceBasePriceType2) => {
2314
+ PriceBasePriceType2[PriceBasePriceType2["MIN_DISCOUNTED_PRICE"] = 1] = "MIN_DISCOUNTED_PRICE";
2315
+ PriceBasePriceType2[PriceBasePriceType2["MIN_TOTAL_PRICE"] = 2] = "MIN_TOTAL_PRICE";
2316
+ return PriceBasePriceType2;
2317
+ })(PriceBasePriceType || {});
2318
+ function useProduct(options = {}) {
2319
+ const { client, locale } = useShopify();
2320
+ const { handle, metafieldIdentifiers, ...swrOptions } = options;
2321
+ return useSWR(
2322
+ handle ? ["product", locale, handle, metafieldIdentifiers] : null,
2323
+ () => getProduct(client, {
2324
+ handle,
2325
+ locale,
2326
+ metafieldIdentifiers
2327
+ }),
2328
+ swrOptions
2329
+ );
2330
+ }
2331
+ function useAllProducts(options = {}) {
2332
+ const { client, locale } = useShopify();
2333
+ const { first, query, sortKey, reverse, metafieldIdentifiers, ...swrOptions } = options;
2334
+ return useSWR(
2335
+ ["all-products", locale, first, query, sortKey, reverse, metafieldIdentifiers],
2336
+ () => getAllProducts(client, {
2337
+ locale,
2338
+ first,
2339
+ query,
2340
+ sortKey,
2341
+ reverse,
2342
+ metafieldIdentifiers
2343
+ }),
2344
+ swrOptions
2345
+ );
2346
+ }
2347
+ function getFirstAvailableVariant(product) {
2348
+ const availableVariant = product.variants.find((v) => v.availableForSale);
2349
+ return availableVariant || product.variants[0];
2350
+ }
2351
+ function getVariantFromSelectedOptions(product, selectedOptions) {
2352
+ return product.variants.find((variant) => {
2353
+ return variant.selectedOptions.every((option) => {
2354
+ return selectedOptions[option.name] === option.value;
2355
+ });
2356
+ });
2357
+ }
2358
+ function useVariant({
2359
+ product,
2360
+ selectedOptions
2361
+ }) {
2362
+ const [variant, setVariant] = useState(
2363
+ product ? getFirstAvailableVariant(product) : void 0
2364
+ );
2365
+ useEffect(() => {
2366
+ if (!product) {
2367
+ setVariant(void 0);
2368
+ return;
2369
+ }
2370
+ const newVariant = getVariantFromSelectedOptions(product, selectedOptions);
2371
+ if (newVariant && newVariant.id !== variant?.id) {
2372
+ setVariant(newVariant);
2373
+ } else if (!newVariant) {
2374
+ setVariant(getFirstAvailableVariant(product));
2375
+ }
2376
+ }, [selectedOptions, product, variant?.id]);
2377
+ return variant;
2378
+ }
2379
+ var FAKE_PRICE = 999999999e-2;
2380
+ function formatPrice({
2381
+ amount,
2382
+ currencyCode,
2383
+ locale,
2384
+ maximumFractionDigits,
2385
+ minimumFractionDigits,
2386
+ removeTrailingZeros
2387
+ }) {
2388
+ const formatter = new Intl.NumberFormat(locale, {
2389
+ style: "currency",
2390
+ currency: currencyCode,
2391
+ maximumFractionDigits: maximumFractionDigits ?? 2,
2392
+ minimumFractionDigits: minimumFractionDigits ?? 2
2393
+ });
2394
+ let formatted = formatter.format(amount);
2395
+ if (removeTrailingZeros) {
2396
+ formatted = formatted.replace(/\.00$/, "");
2397
+ }
2398
+ return formatted;
2399
+ }
2400
+ function formatVariantPrice({
2401
+ amount,
2402
+ baseAmount,
2403
+ currencyCode,
2404
+ locale,
2405
+ maximumFractionDigits,
2406
+ minimumFractionDigits,
2407
+ removeTrailingZeros
2408
+ }) {
2409
+ return {
2410
+ price: formatPrice({
2411
+ amount,
2412
+ currencyCode,
2413
+ locale,
2414
+ maximumFractionDigits,
2415
+ minimumFractionDigits,
2416
+ removeTrailingZeros
2417
+ }),
2418
+ basePrice: formatPrice({
2419
+ amount: baseAmount,
2420
+ currencyCode,
2421
+ locale,
2422
+ maximumFractionDigits,
2423
+ minimumFractionDigits,
2424
+ removeTrailingZeros
2425
+ })
2426
+ };
2427
+ }
2428
+ function usePrice({
2429
+ amount,
2430
+ baseAmount,
2431
+ currencyCode,
2432
+ soldOutDescription = "",
2433
+ maximumFractionDigits,
2434
+ minimumFractionDigits,
2435
+ removeTrailingZeros
2436
+ }) {
2437
+ const { locale } = useShopify();
2438
+ const value = useMemo(() => {
2439
+ if (typeof amount !== "number" || !currencyCode) {
2440
+ return "";
2441
+ }
2442
+ if (soldOutDescription && amount >= FAKE_PRICE) {
2443
+ return soldOutDescription;
2444
+ }
2445
+ return baseAmount ? formatVariantPrice({
2446
+ amount,
2447
+ baseAmount,
2448
+ currencyCode,
2449
+ locale,
2450
+ maximumFractionDigits,
2451
+ minimumFractionDigits,
2452
+ removeTrailingZeros
2453
+ }) : formatPrice({
2454
+ amount,
2455
+ currencyCode,
2456
+ locale,
2457
+ maximumFractionDigits,
2458
+ minimumFractionDigits,
2459
+ removeTrailingZeros
2460
+ });
2461
+ }, [
2462
+ amount,
2463
+ baseAmount,
2464
+ currencyCode,
2465
+ locale,
2466
+ maximumFractionDigits,
2467
+ minimumFractionDigits,
2468
+ soldOutDescription,
2469
+ removeTrailingZeros
2470
+ ]);
2471
+ const result = useMemo(() => {
2472
+ const free = Boolean(amount && amount <= 0);
2473
+ return typeof value === "string" ? { price: value, basePrice: value, free } : { ...value, free };
2474
+ }, [value, amount]);
2475
+ return result;
2476
+ }
2477
+ function optionsConstructor(selectedOptions) {
2478
+ return selectedOptions.reduce((acc, option) => {
2479
+ acc[option.name] = option.value;
2480
+ return acc;
2481
+ }, {});
2482
+ }
2483
+ function decodeShopifyId(gid) {
2484
+ try {
2485
+ const base64 = gid.split("/").pop() || "";
2486
+ return atob(base64);
2487
+ } catch {
2488
+ return gid;
2489
+ }
2490
+ }
2491
+ function useSelectedOptions(product, sku) {
2492
+ const [options, setOptions] = useState({});
2493
+ useEffect(() => {
2494
+ if (!product || !product.variants.length) {
2495
+ setOptions({});
2496
+ return;
2497
+ }
2498
+ let variant = product.variants[0];
2499
+ if (typeof window !== "undefined") {
2500
+ const searchParams = new URLSearchParams(window.location.search);
2501
+ const variantIdParam = searchParams.get("variant");
2502
+ if (variantIdParam) {
2503
+ const foundVariant = product.variants.find((v) => {
2504
+ if (sku) return v.sku === sku;
2505
+ return v.id === variantIdParam || v.id.includes(variantIdParam) || decodeShopifyId(v.id) === variantIdParam;
2506
+ });
2507
+ if (foundVariant) {
2508
+ variant = foundVariant;
2509
+ }
2510
+ }
2511
+ }
2512
+ if (variant) {
2513
+ const newOptions = optionsConstructor(variant.selectedOptions);
2514
+ setOptions(newOptions);
2515
+ }
2516
+ }, [product, sku]);
2517
+ return [options, setOptions];
2518
+ }
2519
+ function decodeShopifyId2(gid) {
2520
+ try {
2521
+ const parts = gid.split("/");
2522
+ return parts[parts.length - 1] || gid;
2523
+ } catch {
2524
+ return gid;
2525
+ }
2526
+ }
2527
+ function useProductUrl(otherQuery) {
2528
+ const { routerAdapter } = useShopify();
2529
+ return useCallback(
2530
+ ({ product, variant }) => {
2531
+ if (!product) return "";
2532
+ const queryParams = new URLSearchParams();
2533
+ if (variant?.id) {
2534
+ const variantId = decodeShopifyId2(variant.id);
2535
+ if (variantId) {
2536
+ queryParams.set("variant", variantId);
2537
+ }
2538
+ }
2539
+ if (otherQuery) {
2540
+ Object.entries(otherQuery).forEach(([key, value]) => {
2541
+ queryParams.set(key, value);
2542
+ });
2543
+ }
2544
+ const queryString = queryParams.toString();
2545
+ const path = `/products/${product.handle}${queryString ? `?${queryString}` : ""}`;
2546
+ if (routerAdapter?.getLocalizedPath) {
2547
+ return routerAdapter.getLocalizedPath(path);
2548
+ }
2549
+ return path;
2550
+ },
2551
+ [routerAdapter, otherQuery]
2552
+ );
2553
+ }
2554
+ function decodeShopifyId3(gid) {
2555
+ try {
2556
+ const parts = gid.split("/");
2557
+ return parts[parts.length - 1] || gid;
2558
+ } catch {
2559
+ return gid;
2560
+ }
2561
+ }
2562
+ function useUpdateVariantQuery(variant) {
2563
+ useEffect(() => {
2564
+ if (!variant || typeof window === "undefined") {
2565
+ return;
2566
+ }
2567
+ const searchParams = new URLSearchParams(window.location.search);
2568
+ const currentVariantId = searchParams.get("variant");
2569
+ const newVariantId = decodeShopifyId3(variant.id);
2570
+ if (newVariantId && currentVariantId !== newVariantId) {
2571
+ searchParams.set("variant", newVariantId);
2572
+ const newUrl = `${window.location.pathname}?${searchParams.toString()}${window.location.hash}`;
2573
+ window.history.replaceState({}, "", newUrl);
2574
+ }
2575
+ }, [variant]);
2576
+ }
2577
+ function getVariantMediaList({
2578
+ product,
2579
+ variant
2580
+ }) {
2581
+ if (variant.image?.url) {
2582
+ const variantMediaId = variant.image.url;
2583
+ const variantMedia = product.media.filter((media) => {
2584
+ if (media.mediaContentType === "IMAGE" && media.previewImage) {
2585
+ return media.previewImage?.url === variantMediaId;
2586
+ }
2587
+ return false;
2747
2588
  });
2748
- if (disableShipping) {
2749
- checkoutCustomAttributes.push({
2750
- key: "_hide_shipping",
2751
- value: "true"
2589
+ if (variantMedia.length > 0) {
2590
+ const otherMedia = product.media.filter((media) => {
2591
+ if (media.mediaContentType === "IMAGE" && media.previewImage) {
2592
+ return media.previewImage.url !== variantMediaId;
2593
+ }
2594
+ return true;
2752
2595
  });
2596
+ return [...variantMedia, ...otherMedia];
2753
2597
  }
2754
- return checkoutCustomAttributes;
2755
- }, [profile, selectedShippingMethod, selectedPlusMemberMode, isPresaleContains]);
2756
- };
2757
- function useAutoRemovePlusMemberInCart({
2758
- cart,
2759
- profile,
2760
- memberSetting
2598
+ }
2599
+ return product.media;
2600
+ }
2601
+ function useVariantMedia({
2602
+ product,
2603
+ variant
2761
2604
  }) {
2762
- const { plus_monthly_product, plus_annual_product } = memberSetting || {};
2763
- const { trigger: removeCartLines2 } = useRemoveCartLines();
2605
+ const [imageList, setImageList] = useState([]);
2606
+ const [sceneList, setSceneList] = useState([]);
2607
+ const [videoList, setVideoList] = useState([]);
2764
2608
  useEffect(() => {
2765
- if (!cart || !plus_monthly_product || !plus_annual_product) return;
2766
- const removePlusProduct = async (productType) => {
2767
- if (!productType) return;
2768
- const product = cart.lineItems?.find(
2769
- (item) => item.product?.handle === productType?.handle && item.variant?.sku === productType?.sku
2770
- );
2771
- if (product) {
2772
- await removeCartLines2({
2773
- lineIds: [product.id]
2774
- });
2609
+ if (!product || !variant) {
2610
+ setImageList([]);
2611
+ setSceneList([]);
2612
+ setVideoList([]);
2613
+ return;
2614
+ }
2615
+ const mediaList = getVariantMediaList({ product, variant });
2616
+ const images = mediaList.filter((media) => media.mediaContentType === "IMAGE");
2617
+ const videos = mediaList.filter(
2618
+ (media) => media.mediaContentType === "VIDEO" || media.mediaContentType === "EXTERNAL_VIDEO"
2619
+ );
2620
+ setImageList(images.length > 0 && images[0] ? [images[0]] : []);
2621
+ setSceneList(images.length > 1 ? images.slice(1) : []);
2622
+ setVideoList(videos);
2623
+ }, [product, variant]);
2624
+ return {
2625
+ productList: imageList,
2626
+ sceneList,
2627
+ videoList
2628
+ };
2629
+ }
2630
+ function useCollection(options = {}) {
2631
+ const { client, locale } = useShopify();
2632
+ const { handle, metafieldIdentifiers, ...swrOptions } = options;
2633
+ return useSWR(
2634
+ handle ? ["collection", locale, handle, metafieldIdentifiers] : null,
2635
+ () => getCollection(client, {
2636
+ handle,
2637
+ locale,
2638
+ metafieldIdentifiers
2639
+ }),
2640
+ swrOptions
2641
+ );
2642
+ }
2643
+ function useAllCollections(options = {}) {
2644
+ const { client, locale } = useShopify();
2645
+ const { first, query, sortKey, reverse, metafieldIdentifiers, ...swrOptions } = options;
2646
+ return useSWR(
2647
+ ["all-collections", locale, first, query, sortKey, reverse, metafieldIdentifiers],
2648
+ () => getAllCollections(client, {
2649
+ locale,
2650
+ first,
2651
+ query,
2652
+ sortKey,
2653
+ reverse,
2654
+ metafieldIdentifiers
2655
+ }),
2656
+ swrOptions
2657
+ );
2658
+ }
2659
+ function useCollections(options = {}) {
2660
+ const { client, locale } = useShopify();
2661
+ const { first, after, query, sortKey, reverse, metafieldIdentifiers, ...swrOptions } = options;
2662
+ return useSWR(
2663
+ ["collections", locale, first, after, query, sortKey, reverse, metafieldIdentifiers],
2664
+ () => getCollections(client, {
2665
+ locale,
2666
+ first,
2667
+ after,
2668
+ query,
2669
+ sortKey,
2670
+ reverse,
2671
+ metafieldIdentifiers
2672
+ }),
2673
+ swrOptions
2674
+ );
2675
+ }
2676
+ function useBlog(options = {}) {
2677
+ const { client, locale } = useShopify();
2678
+ const { handle, metafieldIdentifiers, ...swrOptions } = options;
2679
+ return useSWR(
2680
+ handle ? ["blog", locale, handle, metafieldIdentifiers] : null,
2681
+ () => getBlog(client, { handle, locale, metafieldIdentifiers }),
2682
+ swrOptions
2683
+ );
2684
+ }
2685
+ function useAllBlogs(options = {}) {
2686
+ const { client, locale } = useShopify();
2687
+ const { first, query, metafieldIdentifiers, ...swrOptions } = options;
2688
+ return useSWR(
2689
+ ["all-blogs", locale, first, query, metafieldIdentifiers],
2690
+ () => getAllBlogs(client, {
2691
+ locale,
2692
+ first,
2693
+ query,
2694
+ metafieldIdentifiers
2695
+ }),
2696
+ swrOptions
2697
+ );
2698
+ }
2699
+ function useArticle(options = {}) {
2700
+ const { client, locale } = useShopify();
2701
+ const { blogHandle, articleHandle, metafieldIdentifiers, ...swrOptions } = options;
2702
+ return useSWR(
2703
+ blogHandle && articleHandle ? ["article", locale, blogHandle, articleHandle, metafieldIdentifiers] : null,
2704
+ () => getArticle(client, {
2705
+ blogHandle,
2706
+ articleHandle,
2707
+ locale,
2708
+ metafieldIdentifiers
2709
+ }),
2710
+ swrOptions
2711
+ );
2712
+ }
2713
+ function useArticles(options = {}) {
2714
+ const { client, locale } = useShopify();
2715
+ const { first, query, sortKey, reverse, metafieldIdentifiers, ...swrOptions } = options;
2716
+ return useSWR(
2717
+ ["articles", locale, first, query, sortKey, reverse, metafieldIdentifiers],
2718
+ () => getArticles(client, {
2719
+ locale,
2720
+ first,
2721
+ query,
2722
+ sortKey,
2723
+ reverse,
2724
+ metafieldIdentifiers
2725
+ }),
2726
+ swrOptions
2727
+ );
2728
+ }
2729
+ function useArticlesInBlog(options = {}) {
2730
+ const { client, locale } = useShopify();
2731
+ const { blogHandle, first, sortKey, reverse, metafieldIdentifiers, ...swrOptions } = options;
2732
+ return useSWR(
2733
+ blogHandle ? ["articles-in-blog", locale, blogHandle, first, sortKey, reverse, metafieldIdentifiers] : null,
2734
+ () => getArticlesInBlog(client, {
2735
+ blogHandle,
2736
+ locale,
2737
+ first,
2738
+ sortKey,
2739
+ reverse,
2740
+ metafieldIdentifiers
2741
+ }),
2742
+ swrOptions
2743
+ );
2744
+ }
2745
+ async function performSearch(client, locale, searchQuery, first = 20, types = ["PRODUCT", "ARTICLE", "PAGE"]) {
2746
+ if (!searchQuery) {
2747
+ return void 0;
2748
+ }
2749
+ const query = (
2750
+ /* GraphQL */
2751
+ `
2752
+ query search($query: String!, $first: Int!, $types: [SearchType!])
2753
+ @inContext(language: $language) {
2754
+ search(query: $query, first: $first, types: $types, unavailableProducts: HIDE) {
2755
+ totalCount
2756
+ edges {
2757
+ node {
2758
+ ... on Article {
2759
+ __typename
2760
+ id
2761
+ handle
2762
+ title
2763
+ excerpt
2764
+ image {
2765
+ url
2766
+ altText
2767
+ }
2768
+ }
2769
+ ... on Page {
2770
+ __typename
2771
+ id
2772
+ handle
2773
+ title
2774
+ }
2775
+ ... on Product {
2776
+ __typename
2777
+ id
2778
+ handle
2779
+ title
2780
+ description
2781
+ featuredImage {
2782
+ url
2783
+ altText
2784
+ }
2785
+ }
2786
+ }
2787
+ }
2788
+ pageInfo {
2789
+ hasNextPage
2790
+ endCursor
2791
+ }
2775
2792
  }
2776
- };
2777
- if (profile?.isMonthlyPlus) {
2778
- removePlusProduct(plus_monthly_product);
2779
- }
2780
- if (profile?.isAnnualPlus) {
2781
- removePlusProduct(plus_annual_product);
2782
2793
  }
2783
- }, [cart, plus_annual_product, plus_monthly_product, profile, removeCartLines2]);
2784
- }
2785
- function usePlusMemberNeedAddToCart({
2786
- cart,
2787
- profile
2788
- }) {
2789
- const { selectedPlusMemberMode, selectedPlusMemberVariant, plusMemberMetafields } = usePlusMemberContext();
2790
- const { hasMonthlyPlus, hasAnnualPlus } = useHasPlusMemberInCart({
2791
- memberSetting: plusMemberMetafields,
2792
- cart
2794
+ `
2795
+ );
2796
+ const data = await client.query(query, {
2797
+ query: searchQuery,
2798
+ first,
2799
+ types
2793
2800
  });
2794
- const plusMemberVariant = useMemo(() => {
2795
- if (!selectedPlusMemberVariant || selectedPlusMemberMode === "free" /* FREE */) {
2796
- return void 0;
2797
- }
2798
- if (selectedPlusMemberMode === "monthly" /* MONTHLY */ && hasMonthlyPlus) {
2799
- return void 0;
2800
- }
2801
- if (selectedPlusMemberMode === "annual" /* ANNUAL */ && hasAnnualPlus) {
2802
- return void 0;
2803
- }
2804
- if (profile?.isMonthlyPlus && selectedPlusMemberMode === "monthly" /* MONTHLY */) {
2805
- return void 0;
2806
- }
2807
- if (profile?.isAnnualPlus && selectedPlusMemberMode === "annual" /* ANNUAL */) {
2808
- return void 0;
2801
+ if (!data || !data.search) {
2802
+ return void 0;
2803
+ }
2804
+ const items = data.search.edges?.map((edge) => {
2805
+ const node = edge.node;
2806
+ const item = {
2807
+ type: node.__typename.toUpperCase(),
2808
+ id: node.id,
2809
+ handle: node.handle,
2810
+ title: node.title
2811
+ };
2812
+ if (node.__typename === "Product") {
2813
+ item.description = node.description;
2814
+ item.image = node.featuredImage ? {
2815
+ url: node.featuredImage.url,
2816
+ altText: node.featuredImage.altText
2817
+ } : void 0;
2818
+ } else if (node.__typename === "Article") {
2819
+ item.description = node.excerpt;
2820
+ item.image = node.image ? {
2821
+ url: node.image.url,
2822
+ altText: node.image.altText
2823
+ } : void 0;
2809
2824
  }
2810
- return selectedPlusMemberVariant;
2811
- }, [selectedPlusMemberMode, selectedPlusMemberVariant, hasMonthlyPlus, hasAnnualPlus]);
2812
- return plusMemberVariant;
2825
+ return item;
2826
+ }) || [];
2827
+ return {
2828
+ items,
2829
+ totalCount: data.search.totalCount || 0,
2830
+ pageInfo: data.search.pageInfo
2831
+ };
2813
2832
  }
2814
- var PlusMemberProvider = ({
2815
- variant,
2816
- product,
2817
- memberSetting,
2818
- initialSelectedPlusMemberMode = "free",
2819
- profile,
2820
- children
2821
- }) => {
2822
- const [selectedPlusMemberMode, setSelectedPlusMemberMode] = useState(
2823
- initialSelectedPlusMemberMode
2833
+ function useSearch(options = {}) {
2834
+ const { client, locale } = useShopify();
2835
+ const { query, first = 20, types = ["PRODUCT", "ARTICLE", "PAGE"], ...swrOptions } = options;
2836
+ return useSWR(
2837
+ query ? ["search", locale, query, first, types] : null,
2838
+ () => performSearch(client, locale, query, first, types),
2839
+ swrOptions
2824
2840
  );
2825
- const [selectedShippingMethod, setSelectedShippingMethod] = useState();
2826
- const [showMoreShippingMethod, setShowMoreShippingMethod] = useState(false);
2827
- const [showPlusMemberBenefit, setShowPlusMemberBenefit] = useState(false);
2828
- const shippingMethodsContext = useShippingMethods({
2829
- variant,
2830
- plusMemberMetafields: memberSetting,
2831
- selectedPlusMemberMode,
2832
- profile
2833
- });
2834
- const { monthlyVariant, annualVariant } = usePlusMemberVariants({
2835
- memberSetting
2836
- });
2837
- const selectedPlusMemberVariant = useMemo(() => {
2838
- if (selectedPlusMemberMode === "free" /* FREE */) {
2839
- return void 0;
2841
+ }
2842
+ async function getSiteInfo(client, locale, metafieldIdentifiers) {
2843
+ const hasMetafields = metafieldIdentifiers && metafieldIdentifiers.length > 0;
2844
+ const query = (
2845
+ /* GraphQL */
2846
+ `
2847
+ query getSiteInfo(
2848
+ ${hasMetafields ? "$shopMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
2849
+ ) @inContext(language: $language) {
2850
+ shop {
2851
+ name
2852
+ description
2853
+ primaryDomain {
2854
+ url
2855
+ host
2856
+ }
2857
+ brand {
2858
+ logo {
2859
+ image {
2860
+ url
2861
+ }
2862
+ }
2863
+ colors {
2864
+ primary {
2865
+ background
2866
+ }
2867
+ secondary {
2868
+ background
2869
+ }
2870
+ }
2871
+ }
2872
+ ${hasMetafields ? "metafields(identifiers: $shopMetafieldIdentifiers) { key value }" : ""}
2873
+ }
2840
2874
  }
2841
- return selectedPlusMemberMode === "monthly" /* MONTHLY */ ? monthlyVariant : annualVariant;
2842
- }, [monthlyVariant, annualVariant, selectedPlusMemberMode]);
2843
- return /* @__PURE__ */ jsx(
2844
- PlusMemberContext.Provider,
2845
- {
2846
- value: {
2847
- variant,
2848
- plusMemberMetafields: memberSetting,
2849
- selectedPlusMemberMode,
2850
- setSelectedPlusMemberMode,
2851
- selectedShippingMethod,
2852
- setSelectedShippingMethod,
2853
- shippingMethodsContext,
2854
- showMoreShippingMethod,
2855
- setShowMoreShippingMethod,
2856
- selectedPlusMemberVariant,
2857
- product,
2858
- showPlusMemberBenefit,
2859
- setShowPlusMemberBenefit,
2860
- profile
2861
- },
2862
- children
2875
+ `
2876
+ );
2877
+ const variables = {};
2878
+ if (hasMetafields) {
2879
+ variables.shopMetafieldIdentifiers = metafieldIdentifiers;
2880
+ }
2881
+ const data = await client.query(query, variables);
2882
+ if (!data || !data.shop) {
2883
+ return void 0;
2884
+ }
2885
+ const shop = data.shop;
2886
+ const metafields = shop.metafields?.reduce((acc, mf) => {
2887
+ if (mf && mf.key) {
2888
+ acc[mf.key] = mf.value;
2863
2889
  }
2890
+ return acc;
2891
+ }, {});
2892
+ return {
2893
+ name: shop.name,
2894
+ description: shop.description,
2895
+ primaryDomain: shop.primaryDomain,
2896
+ brand: shop.brand ? {
2897
+ logo: shop.brand.logo,
2898
+ colors: shop.brand.colors ? {
2899
+ primary: shop.brand.colors.primary?.background,
2900
+ secondary: shop.brand.colors.secondary?.background
2901
+ } : void 0
2902
+ } : void 0,
2903
+ metafields
2904
+ };
2905
+ }
2906
+ function useSite(options = {}) {
2907
+ const { client, locale } = useShopify();
2908
+ const { metafieldIdentifiers, ...swrOptions } = options;
2909
+ return useSWR(
2910
+ ["site", locale, metafieldIdentifiers],
2911
+ () => getSiteInfo(client, locale, metafieldIdentifiers),
2912
+ swrOptions
2864
2913
  );
2865
- };
2914
+ }
2866
2915
  function useIntersection(targetRef, options) {
2867
2916
  const {
2868
2917
  callback,
@@ -3043,6 +3092,6 @@ function clearGeoLocationCache(cacheKey = "geoLocation") {
3043
3092
  }
3044
3093
  }
3045
3094
 
3046
- export { BuyRuleType, CODE_AMOUNT_KEY, CUSTOMER_ATTRIBUTE_KEY, CUSTOMER_SCRIPT_GIFT_KEY, DeliveryPlusType, MAIN_PRODUCT_CODE, MEMBER_PRICE_ATTRIBUTE_KEY, OrderBasePriceType, OrderDiscountType, PLUS_MEMBER_TYPE, PlusMemberContext, PlusMemberMode, PlusMemberProvider, PriceBasePriceType, PriceDiscountType, RuleType, SCRIPT_CODE_AMOUNT_KEY, ShippingMethodMode, SpendMoneyType, checkAttributesUpdateNeeded, clearGeoLocationCache, createMockCartFromLines, currencyCodeMapping, defaultSWRMutationConfiguration, formatFunctionAutoFreeGift, formatScriptAutoFreeGift, getCachedGeoLocation, getDiscountEnvAttributeValue, getMatchedMainProductSubTotal, getQuery, getReferralAttributes, hasPlusMemberInCart, normalizeAddToCartLines, preCheck, safeParse, useAddCartLines, useAddToCart, useAllBlogs, useAllCollections, useAllProducts, useApplyCartCodes, useArticle, useArticles, useArticlesInBlog, useAutoRemovePlusMemberInCart, useAvailableDeliveryCoupon, useBlog, useBuyNow, useCalcAutoFreeGift, useCalcGiftsFromLines, useCalcOrderDiscount, useCartAttributes, useCartItemQuantityLimit, useCollection, useCollections, useCreateCart, useExposure, useGeoLocation, useHasPlusMemberInCart, useIntersection, usePlusMemberCheckoutCustomAttributes, usePlusMemberContext, usePlusMemberDeliveryCodes, usePlusMemberNeedAddToCart, usePlusMemberVariants, usePrice, useProduct, useProductUrl, useProductsByHandles, useRemoveCartCodes, useRemoveCartLines, useReplaceCartPlusMember, useScriptAutoFreeGift, useSearch, useSelectedOptions, useShippingMethods, useSite, useUpdateCartAttributes, useUpdateCartLines, useUpdateLineCodeAmountAttributes, useUpdateVariantQuery, useVariant, useVariantMedia };
3095
+ export { BuyRuleType, CODE_AMOUNT_KEY, CUSTOMER_ATTRIBUTE_KEY, CUSTOMER_SCRIPT_GIFT_KEY, DeliveryPlusType, MAIN_PRODUCT_CODE, MEMBER_PRICE_ATTRIBUTE_KEY, OrderBasePriceType, OrderDiscountType, PLUS_MEMBER_TYPE, PlusMemberContext, PlusMemberMode, PlusMemberProvider, PriceBasePriceType, PriceDiscountType, RuleType, SCRIPT_CODE_AMOUNT_KEY, ShippingMethodMode, SpendMoneyType, checkAttributesUpdateNeeded, clearGeoLocationCache, createMockCartFromLines, currencyCodeMapping, defaultSWRMutationConfiguration, formatFunctionAutoFreeGift, formatScriptAutoFreeGift, getCachedGeoLocation, getCartAttributes, getDiscountEnvAttributeValue, getMatchedMainProductSubTotal, getQuery, getReferralAttributes, getUserType, hasPlusMemberInCart, hasPlusMemberInLines, normalizeAddToCartLines, preCheck, safeParse, useAddCartLines, useAddToCart, useAllBlogs, useAllCollections, useAllProducts, useApplyCartCodes, useArticle, useArticles, useArticlesInBlog, useAutoRemovePlusMemberInCart, useAvailableDeliveryCoupon, useBlog, useBuyNow, useCalcAutoFreeGift, useCalcGiftsFromLines, useCalcOrderDiscount, useCartAttributes, useCartItemQuantityLimit, useCollection, useCollections, useCreateCart, useExposure, useGeoLocation, useHasPlusMemberInCart, useHasPlusMemberInLines, useIntersection, usePlusMemberCheckoutCustomAttributes, usePlusMemberContext, usePlusMemberNeedAddToCart, usePlusMemberVariants, usePrice, useProduct, useProductUrl, useProductsByHandles, useRemoveCartCodes, useRemoveCartLines, useReplaceCartPlusMember, useScriptAutoFreeGift, useSearch, useSelectedOptions, useShippingMethods, useSite, useUpdateCartAttributes, useUpdateCartLines, useUpdateLineCodeAmountAttributes, useUpdateVariantQuery, useVariant, useVariantMedia };
3047
3096
  //# sourceMappingURL=index.mjs.map
3048
3097
  //# sourceMappingURL=index.mjs.map