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

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 || 0)
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;
@@ -1696,6 +1379,51 @@ var useCartItemQuantityLimit = ({
1696
1379
  }, [cartItem, cart]);
1697
1380
  return quantityLimit;
1698
1381
  };
1382
+ function hasPlusMemberInLines({
1383
+ memberSetting,
1384
+ lines
1385
+ }) {
1386
+ const { plus_monthly_product, plus_annual_product } = memberSetting || {};
1387
+ if (!lines || lines.length === 0) {
1388
+ return {
1389
+ hasPlusMember: false,
1390
+ hasMonthlyPlus: false,
1391
+ hasAnnualPlus: false
1392
+ };
1393
+ }
1394
+ const monthlyPlusLine = lines.find((line) => {
1395
+ const variantHandle = line.variant?.product?.handle;
1396
+ const variantSku = line.variant?.sku;
1397
+ return variantHandle === plus_monthly_product?.handle && variantSku === plus_monthly_product?.sku;
1398
+ });
1399
+ const annualPlusLine = lines.find((line) => {
1400
+ const variantHandle = line.variant?.product?.handle;
1401
+ const variantSku = line.variant?.sku;
1402
+ return variantHandle === plus_annual_product?.handle && variantSku === plus_annual_product?.sku;
1403
+ });
1404
+ const hasMonthlyPlus = !!monthlyPlusLine;
1405
+ const hasAnnualPlus = !!annualPlusLine;
1406
+ const hasPlusMember = hasMonthlyPlus || hasAnnualPlus;
1407
+ return {
1408
+ hasPlusMember,
1409
+ hasMonthlyPlus,
1410
+ hasAnnualPlus,
1411
+ monthlyPlusLine,
1412
+ annualPlusLine
1413
+ };
1414
+ }
1415
+ function useHasPlusMemberInLines({
1416
+ memberSetting,
1417
+ lines
1418
+ }) {
1419
+ return useMemo(
1420
+ () => hasPlusMemberInLines({
1421
+ memberSetting,
1422
+ lines
1423
+ }),
1424
+ [memberSetting, lines]
1425
+ );
1426
+ }
1699
1427
  var useUpdateLineCodeAmountAttributes = ({
1700
1428
  cart,
1701
1429
  mutateCart,
@@ -1811,45 +1539,61 @@ var useUpdateLineCodeAmountAttributes = ({
1811
1539
  }, [loading, setLoadingState]);
1812
1540
  };
1813
1541
 
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
- );
1542
+ // src/hooks/member/plus/types.ts
1543
+ var PLUS_MEMBER_TYPE = /* @__PURE__ */ ((PLUS_MEMBER_TYPE2) => {
1544
+ PLUS_MEMBER_TYPE2[PLUS_MEMBER_TYPE2["FREE"] = 0] = "FREE";
1545
+ PLUS_MEMBER_TYPE2[PLUS_MEMBER_TYPE2["MONTHLY"] = 1] = "MONTHLY";
1546
+ PLUS_MEMBER_TYPE2[PLUS_MEMBER_TYPE2["ANNUAL"] = 2] = "ANNUAL";
1547
+ return PLUS_MEMBER_TYPE2;
1548
+ })(PLUS_MEMBER_TYPE || {});
1549
+ var PlusMemberMode = /* @__PURE__ */ ((PlusMemberMode2) => {
1550
+ PlusMemberMode2["MONTHLY"] = "monthly";
1551
+ PlusMemberMode2["ANNUAL"] = "annual";
1552
+ return PlusMemberMode2;
1553
+ })(PlusMemberMode || {});
1554
+ var DeliveryPlusType = /* @__PURE__ */ ((DeliveryPlusType2) => {
1555
+ DeliveryPlusType2["FREE"] = "free";
1556
+ DeliveryPlusType2["MONTHLY"] = "monthly";
1557
+ DeliveryPlusType2["ANNUAL"] = "annual";
1558
+ return DeliveryPlusType2;
1559
+ })(DeliveryPlusType || {});
1560
+ var ShippingMethodMode = /* @__PURE__ */ ((ShippingMethodMode2) => {
1561
+ ShippingMethodMode2["FREE"] = "free";
1562
+ ShippingMethodMode2["TDD"] = "tdd";
1563
+ ShippingMethodMode2["NDD"] = "ndd";
1564
+ return ShippingMethodMode2;
1565
+ })(ShippingMethodMode || {});
1566
+ var createInitialValue = () => ({
1567
+ plusMemberMetafields: {},
1568
+ selectedPlusMemberMode: "free",
1569
+ setSelectedPlusMemberMode: () => {
1570
+ },
1571
+ selectedShippingMethod: void 0,
1572
+ setSelectedShippingMethod: () => {
1573
+ },
1574
+ showMoreShippingMethod: false,
1575
+ setShowMoreShippingMethod: () => {
1576
+ },
1577
+ variant: {},
1578
+ product: {},
1579
+ shippingMethodsContext: {
1580
+ freeShippingMethods: [],
1581
+ paymentShippingMethods: [],
1582
+ nddOverweight: false,
1583
+ tddOverweight: false,
1584
+ nddCoupon: void 0,
1585
+ tddCoupon: void 0,
1586
+ isLoadingCoupon: false
1587
+ },
1588
+ selectedPlusMemberVariant: void 0,
1589
+ showPlusMemberBenefit: false,
1590
+ setShowPlusMemberBenefit: () => {
1591
+ },
1592
+ profile: void 0
1593
+ });
1594
+ var PlusMemberContext = createContext(createInitialValue());
1595
+ function usePlusMemberContext() {
1596
+ return useContext(PlusMemberContext);
1853
1597
  }
1854
1598
  function useProductsByHandles(options = {}) {
1855
1599
  const { client, locale } = useShopify();
@@ -1875,994 +1619,1298 @@ function useProductsByHandles(options = {}) {
1875
1619
  }
1876
1620
  );
1877
1621
  }
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
- });
1887
- });
1888
- }
1889
- function useVariant({
1890
- product,
1891
- selectedOptions
1622
+
1623
+ // src/hooks/member/plus/use-plus-member-variants.ts
1624
+ function usePlusMemberVariants({
1625
+ memberSetting
1892
1626
  }) {
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));
1906
- }
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
1627
+ const plusMonthly = memberSetting?.plus_monthly_product;
1628
+ const plusAnnual = memberSetting?.plus_annual_product;
1629
+ const plusMemberHandles = useMemo(() => {
1630
+ return [plusMonthly?.handle, plusAnnual?.handle].filter(Boolean);
1631
+ }, [plusMonthly?.handle, plusAnnual?.handle]);
1632
+ const { data: plusMemberProducts = [] } = useProductsByHandles({
1633
+ handles: plusMemberHandles
1924
1634
  });
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
- }) {
1635
+ const monthlyProduct = useMemo(() => {
1636
+ return plusMemberProducts?.find((item) => item?.handle === plusMonthly?.handle);
1637
+ }, [plusMemberProducts, plusMonthly]);
1638
+ const annualProduct = useMemo(() => {
1639
+ return plusMemberProducts?.find((item) => item?.handle === plusAnnual?.handle);
1640
+ }, [plusMemberProducts, plusAnnual]);
1641
+ const monthlyVariant = useMemo(() => {
1642
+ return monthlyProduct?.variants?.find((item) => item.sku === plusMonthly?.sku);
1643
+ }, [monthlyProduct, plusMonthly]);
1644
+ const annualVariant = useMemo(() => {
1645
+ return annualProduct?.variants?.find((item) => item.sku === plusAnnual?.sku);
1646
+ }, [annualProduct, plusAnnual]);
1940
1647
  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
- })
1648
+ monthlyVariant: monthlyVariant ? {
1649
+ ...monthlyVariant,
1650
+ product: monthlyProduct
1651
+ } : void 0,
1652
+ annualVariant: annualVariant ? {
1653
+ ...annualVariant,
1654
+ product: annualProduct
1655
+ } : void 0
1957
1656
  };
1958
1657
  }
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;
1658
+ var useAvailableDeliveryCoupon = ({
1659
+ profile
1660
+ }) => {
1661
+ const { data: availableDeliveryCoupon, isLoading } = useSWR(
1662
+ profile?.email ? ["/api/multipass/subsrv/v1/prime/delivery_coupons/current/available", profile?.email] : void 0,
1663
+ async ([apiPath]) => {
1664
+ return fetch(apiPath).then((res) => res.json());
1975
1665
  }
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
1666
+ );
1667
+ console.log("availableDeliveryCoupon", availableDeliveryCoupon);
1668
+ const { ndd_coupon: nddCoupon, tdd_coupon: tddCoupon } = availableDeliveryCoupon?.data?.data || {};
1669
+ return {
1670
+ nddCoupon,
1671
+ tddCoupon,
1672
+ isLoading
1673
+ };
1674
+ };
1675
+
1676
+ // src/hooks/member/plus/use-shipping-methods.ts
1677
+ function useShippingMethods(options) {
1678
+ const { variant, plusMemberMetafields, selectedPlusMemberMode, profile } = options;
1679
+ const isPlus = profile?.isPlus || false;
1680
+ const { nddCoupon, tddCoupon, isLoading } = useAvailableDeliveryCoupon({ profile });
1681
+ const { plus_shipping, shippingMethod } = plusMemberMetafields || {};
1682
+ const nddOverweight = useMemo(() => {
1683
+ return (variant?.weight || 0) > (shippingMethod?.overWeight_ndd || Infinity);
1684
+ }, [shippingMethod?.overWeight_ndd, variant?.weight]);
1685
+ const tddOverweight = useMemo(() => {
1686
+ return (variant?.weight || 0) > (shippingMethod?.overWeight_tdd || Infinity);
1687
+ }, [shippingMethod?.overWeight_tdd, variant?.weight]);
1688
+ const paymentShippingMethods = useMemo(() => {
1689
+ const weight = variant?.weight || 0;
1690
+ const methods = plus_shipping?.shipping_methods?.filter(({ weight_low, weight_high, __mode, __plus }) => {
1691
+ const fitWeight = (!weight_low || weight >= weight_low) && (!weight_high || weight <= weight_high);
1692
+ return __mode !== "free" /* FREE */ && !__plus && fitWeight;
1693
+ }) || [];
1694
+ return methods.map((method) => {
1695
+ let disabled = false;
1696
+ const selectedFreeMember = selectedPlusMemberMode === "free";
1697
+ if (method.__mode === "ndd" /* NDD */) {
1698
+ disabled = selectedFreeMember || nddOverweight;
1699
+ } else if (method.__mode === "tdd" /* TDD */) {
1700
+ disabled = selectedFreeMember || tddOverweight;
1701
+ }
1702
+ return {
1703
+ ...method,
1704
+ id: method.__mode + method.__code,
1705
+ useCoupon: false,
1706
+ subtitle: plus_shipping?.directly || "",
1707
+ disabled
1708
+ };
1991
1709
  });
1992
1710
  }, [
1993
- amount,
1994
- baseAmount,
1995
- currencyCode,
1996
- locale,
1997
- maximumFractionDigits,
1998
- minimumFractionDigits,
1999
- soldOutDescription,
2000
- removeTrailingZeros
1711
+ nddOverweight,
1712
+ plus_shipping?.directly,
1713
+ plus_shipping?.shipping_methods,
1714
+ selectedPlusMemberMode,
1715
+ tddOverweight,
1716
+ variant?.weight
2001
1717
  ]);
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;
2028
- }
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;
2040
- }
1718
+ const nddPrice = useMemo(() => {
1719
+ const weight = variant?.weight || 0;
1720
+ const nddMethod = paymentShippingMethods.find(({ __mode, weight_high, weight_low }) => {
1721
+ const fitWeight = (!weight_low || weight >= weight_low) && (!weight_high || weight <= weight_high);
1722
+ return __mode === "ndd" && fitWeight;
1723
+ });
1724
+ return nddMethod?.price || 0;
1725
+ }, [variant?.weight, paymentShippingMethods]);
1726
+ const tddPrice = useMemo(() => {
1727
+ const weight = variant?.weight || 0;
1728
+ const tddMethod = paymentShippingMethods.find(({ __mode, weight_high, weight_low }) => {
1729
+ const fitWeight = (!weight_low || weight >= weight_low) && (!weight_high || weight <= weight_high);
1730
+ return __mode === "tdd" && fitWeight;
1731
+ });
1732
+ return tddMethod?.price || 0;
1733
+ }, [variant?.weight, paymentShippingMethods]);
1734
+ const freeShippingMethods = useMemo(() => {
1735
+ const weight = variant?.weight || 0;
1736
+ let methods = plus_shipping?.shipping_methods?.filter(({ __mode, __plus, weight_low, weight_high }) => {
1737
+ if (__mode === "free" /* FREE */) {
1738
+ return true;
2041
1739
  }
1740
+ if (isPlus) {
1741
+ const hasCoupon = isPlus && __mode === "ndd" /* NDD */ && nddCoupon || isPlus && __mode === "tdd" /* TDD */ && (tddCoupon || nddCoupon);
1742
+ const fitWeight = (!weight_low || weight >= weight_low) && (!weight_high || weight <= weight_high);
1743
+ return hasCoupon && fitWeight && !__plus;
1744
+ } else {
1745
+ return __plus;
1746
+ }
1747
+ }) || [];
1748
+ if (isPlus) {
1749
+ methods = methods.sort((a, b) => {
1750
+ if (b.__mode === "free" /* FREE */) return -1;
1751
+ return 0;
1752
+ });
2042
1753
  }
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
- }
2057
- }
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);
1754
+ return methods.map((method) => {
1755
+ let price = 0;
1756
+ let coupon;
1757
+ let disabled;
1758
+ if (method.__mode !== "free" /* FREE */) {
1759
+ switch (method.__mode) {
1760
+ case "tdd":
1761
+ price = tddPrice;
1762
+ coupon = tddCoupon || nddCoupon;
1763
+ break;
1764
+ case "ndd":
1765
+ price = nddPrice;
1766
+ coupon = nddCoupon;
1767
+ break;
1768
+ }
1769
+ disabled = selectedPlusMemberMode === "free";
1770
+ if (method.__mode === "ndd" /* NDD */) {
1771
+ disabled = disabled || nddOverweight;
1772
+ } else if (method.__mode === "tdd" /* TDD */) {
1773
+ disabled = disabled || tddOverweight;
2068
1774
  }
2069
1775
  }
2070
- if (otherQuery) {
2071
- Object.entries(otherQuery).forEach(([key, value]) => {
2072
- queryParams.set(key, value);
2073
- });
1776
+ return {
1777
+ ...method,
1778
+ id: method.__mode + method.__code,
1779
+ useCoupon: true,
1780
+ disabled,
1781
+ coupon,
1782
+ price
1783
+ };
1784
+ });
1785
+ }, [
1786
+ variant?.weight,
1787
+ plus_shipping?.shipping_methods,
1788
+ isPlus,
1789
+ nddCoupon,
1790
+ tddCoupon,
1791
+ selectedPlusMemberMode,
1792
+ tddPrice,
1793
+ nddPrice,
1794
+ nddOverweight,
1795
+ tddOverweight
1796
+ ]);
1797
+ return {
1798
+ freeShippingMethods,
1799
+ paymentShippingMethods,
1800
+ nddOverweight,
1801
+ tddOverweight,
1802
+ nddCoupon,
1803
+ tddCoupon,
1804
+ isLoadingCoupon: isLoading
1805
+ };
1806
+ }
1807
+ var useReplaceCartPlusMember = () => {
1808
+ const { plusMemberMetafields, selectedPlusMemberMode } = usePlusMemberContext();
1809
+ const { trigger: removeCartLines2 } = useRemoveCartLines();
1810
+ const { cart } = useCartContext();
1811
+ const plusMonthly = plusMemberMetafields?.plus_monthly_product;
1812
+ const plusAnnual = plusMemberMetafields?.plus_annual_product;
1813
+ const handler = useCallback(async () => {
1814
+ const plusMonthlyInCart = cart?.lineItems.find(
1815
+ (item) => item.variant?.sku === plusMonthly?.sku
1816
+ );
1817
+ const plusAnnualInCart = cart?.lineItems.find(
1818
+ (item) => item.variant?.sku === plusAnnual?.sku
1819
+ );
1820
+ if (selectedPlusMemberMode === "annual" /* ANNUAL */ && plusMonthlyInCart) {
1821
+ await removeCartLines2({
1822
+ lineIds: [plusMonthlyInCart.id]
1823
+ });
1824
+ } else if (selectedPlusMemberMode === "monthly" /* MONTHLY */ && plusAnnualInCart) {
1825
+ await removeCartLines2({
1826
+ lineIds: [plusAnnualInCart.id]
1827
+ });
1828
+ }
1829
+ }, [
1830
+ cart?.lineItems,
1831
+ selectedPlusMemberMode,
1832
+ plusMonthly?.sku,
1833
+ plusAnnual?.sku,
1834
+ removeCartLines2
1835
+ ]);
1836
+ return handler;
1837
+ };
1838
+ var usePlusMemberCheckoutCustomAttributes = ({
1839
+ disableShipping = false,
1840
+ isPresaleContains = false
1841
+ }) => {
1842
+ const { profile, selectedShippingMethod, selectedPlusMemberMode } = usePlusMemberContext();
1843
+ return useMemo(() => {
1844
+ const checkoutCustomAttributes = [
1845
+ {
1846
+ key: "_last_url",
1847
+ value: typeof window !== "undefined" ? window.location.origin + window.location.pathname : ""
2074
1848
  }
2075
- const queryString = queryParams.toString();
2076
- const path = `/products/${product.handle}${queryString ? `?${queryString}` : ""}`;
2077
- if (routerAdapter?.getLocalizedPath) {
2078
- return routerAdapter.getLocalizedPath(path);
1849
+ ];
1850
+ checkoutCustomAttributes.push({
1851
+ key: "_checkout_delivery_custom",
1852
+ value: JSON.stringify({
1853
+ allow_nextday_delivery: true,
1854
+ allow_thirdday_delivery: true,
1855
+ selected_delivery_option: {
1856
+ code: selectedShippingMethod?.__code,
1857
+ mode: selectedShippingMethod?.__mode
1858
+ },
1859
+ is_presale: isPresaleContains,
1860
+ discount_code: selectedShippingMethod?.coupon ? [selectedShippingMethod.coupon] : [],
1861
+ plus_type: profile?.isPlus ? "free" /* FREE */ : selectedPlusMemberMode,
1862
+ is_prime: profile?.isPlus
1863
+ })
1864
+ });
1865
+ if (disableShipping) {
1866
+ checkoutCustomAttributes.push({
1867
+ key: "_hide_shipping",
1868
+ value: "true"
1869
+ });
1870
+ }
1871
+ return checkoutCustomAttributes;
1872
+ }, [profile, selectedShippingMethod, selectedPlusMemberMode, isPresaleContains]);
1873
+ };
1874
+ function useRemoveCartLines(options) {
1875
+ const { client, locale, cartCookieAdapter } = useShopify();
1876
+ const { mutateCart, metafieldIdentifiers } = useCartContext();
1877
+ const removeLines = useCallback(
1878
+ async (_key, { arg }) => {
1879
+ const { autoRemoveInvalidCodes = true, onCodesRemoved, cartId, lineIds } = arg;
1880
+ let updatedCart = await removeCartLines(client, {
1881
+ cartId,
1882
+ lineIds,
1883
+ metafieldIdentifiers,
1884
+ cookieAdapter: cartCookieAdapter
1885
+ });
1886
+ if (updatedCart && autoRemoveInvalidCodes) {
1887
+ const unApplicableCodes = updatedCart.discountCodes.filter((item) => !item.applicable).map((item) => item.code);
1888
+ if (unApplicableCodes.length > 0) {
1889
+ if (onCodesRemoved) {
1890
+ const handledCart = await onCodesRemoved(updatedCart, unApplicableCodes);
1891
+ if (handledCart) {
1892
+ updatedCart = handledCart;
1893
+ }
1894
+ } else {
1895
+ updatedCart = await updateCartCodes(client, {
1896
+ cartId: updatedCart.id,
1897
+ discountCodes: updatedCart.discountCodes.filter((item) => item.applicable).map((item) => item.code),
1898
+ metafieldIdentifiers,
1899
+ cookieAdapter: cartCookieAdapter
1900
+ }) || updatedCart;
1901
+ }
1902
+ }
2079
1903
  }
2080
- return path;
1904
+ if (updatedCart) {
1905
+ mutateCart(updatedCart);
1906
+ }
1907
+ return updatedCart;
2081
1908
  },
2082
- [routerAdapter, otherQuery]
1909
+ [client, locale, cartCookieAdapter, mutateCart, metafieldIdentifiers]
2083
1910
  );
1911
+ return useSWRMutation("remove-cart-lines", removeLines, options);
2084
1912
  }
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) {
1913
+
1914
+ // src/hooks/member/plus/use-auto-remove-plus-member-in-cart.ts
1915
+ function useAutoRemovePlusMemberInCart({
1916
+ cart,
1917
+ profile,
1918
+ memberSetting
1919
+ }) {
1920
+ const { plus_monthly_product, plus_annual_product } = memberSetting || {};
1921
+ const { trigger: removeCartLines2 } = useRemoveCartLines();
2094
1922
  useEffect(() => {
2095
- if (!variant || typeof window === "undefined") {
2096
- return;
1923
+ if (!cart || !plus_monthly_product || !plus_annual_product) return;
1924
+ const removePlusProduct = async (productType) => {
1925
+ if (!productType) return;
1926
+ const product = cart.lineItems?.find(
1927
+ (item) => item.product?.handle === productType?.handle && item.variant?.sku === productType?.sku
1928
+ );
1929
+ if (product) {
1930
+ await removeCartLines2({
1931
+ lineIds: [product.id]
1932
+ });
1933
+ }
1934
+ };
1935
+ if (profile?.isMonthlyPlus) {
1936
+ removePlusProduct(plus_monthly_product);
2097
1937
  }
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);
1938
+ if (profile?.isAnnualPlus) {
1939
+ removePlusProduct(plus_annual_product);
2105
1940
  }
2106
- }, [variant]);
1941
+ }, [cart, plus_annual_product, plus_monthly_product, profile, removeCartLines2]);
2107
1942
  }
2108
- function getVariantMediaList({
2109
- product,
2110
- variant
1943
+ function hasPlusMemberInCart({
1944
+ memberSetting,
1945
+ cart
2111
1946
  }) {
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
- }
1947
+ const { plus_monthly_product, plus_annual_product } = memberSetting || {};
1948
+ if (!cart?.lineItems) {
1949
+ return {
1950
+ hasPlusMember: false,
1951
+ hasMonthlyPlus: false,
1952
+ hasAnnualPlus: false
1953
+ };
2129
1954
  }
2130
- return product.media;
2131
- }
2132
- function useVariantMedia({
2133
- product,
2134
- variant
2135
- }) {
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
1955
+ const monthlyPlusItem = cart.lineItems.find(
1956
+ (item) => item.product?.handle === plus_monthly_product?.handle && item.variant?.sku === plus_monthly_product?.sku
2205
1957
  );
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
1958
+ const annualPlusItem = cart.lineItems.find(
1959
+ (item) => item.product?.handle === plus_annual_product?.handle && item.variant?.sku === plus_annual_product?.sku
2214
1960
  );
1961
+ const hasMonthlyPlus = !!monthlyPlusItem;
1962
+ const hasAnnualPlus = !!annualPlusItem;
1963
+ const hasPlusMember = hasMonthlyPlus || hasAnnualPlus;
1964
+ return {
1965
+ hasPlusMember,
1966
+ hasMonthlyPlus,
1967
+ hasAnnualPlus,
1968
+ monthlyPlusItem,
1969
+ annualPlusItem
1970
+ };
2215
1971
  }
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
1972
+ function useHasPlusMemberInCart({
1973
+ memberSetting,
1974
+ cart
1975
+ }) {
1976
+ return useMemo(
1977
+ () => hasPlusMemberInCart({
1978
+ memberSetting,
1979
+ cart
2226
1980
  }),
2227
- swrOptions
1981
+ [memberSetting, cart]
2228
1982
  );
2229
1983
  }
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
- );
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;
1996
+ }
1997
+ if (selectedPlusMemberMode === "monthly" /* MONTHLY */ && hasMonthlyPlus) {
1998
+ return void 0;
1999
+ }
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;
2243
2012
  }
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
2013
+ var PlusMemberProvider = ({
2014
+ variant,
2015
+ product,
2016
+ memberSetting,
2017
+ initialSelectedPlusMemberMode = "free",
2018
+ profile,
2019
+ children
2020
+ }) => {
2021
+ const [selectedPlusMemberMode, setSelectedPlusMemberMode] = useState(
2022
+ initialSelectedPlusMemberMode
2258
2023
  );
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
2272
- }),
2273
- swrOptions
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
2032
+ });
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
2062
+ }
2274
2063
  );
2275
- }
2276
- async function performSearch(client, locale, searchQuery, first = 20, types = ["PRODUCT", "ARTICLE", "PAGE"]) {
2277
- if (!searchQuery) {
2278
- return void 0;
2279
- }
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
2064
+ };
2065
+
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;
2101
+ }
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;
2112
+ }
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
+ });
2123
+ } else {
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;
2315
2136
  }
2137
+ } else {
2138
+ await removeInvalidCodes({
2139
+ discountCodes: unapplicableCodes
2140
+ });
2316
2141
  }
2317
2142
  }
2318
2143
  }
2319
- pageInfo {
2320
- hasNextPage
2321
- endCursor
2144
+ if (resultCart && discountCodes && discountCodes.length > 0) {
2145
+ applyCartCodes({
2146
+ replaceExistingCodes,
2147
+ discountCodes
2148
+ });
2149
+ }
2150
+ if (customAttributes && customAttributes.length > 0) {
2151
+ addCustomAttributes(customAttributes);
2322
2152
  }
2323
2153
  }
2324
- }
2325
- `
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
+ ]
2326
2179
  );
2327
- const data = await client.query(query, {
2328
- query: searchQuery,
2329
- first,
2330
- types
2331
- });
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
- }) || [];
2358
- return {
2359
- items,
2360
- totalCount: data.search.totalCount || 0,
2361
- pageInfo: data.search.pageInfo
2362
- };
2180
+ return useSWRMutation("add-to-cart", addToCart, swrOptions);
2363
2181
  }
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
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
2191
+ });
2192
+ if (updatedCart) {
2193
+ mutateCart(updatedCart);
2194
+ }
2195
+ console.log("use-update-cart-lines updatedCart", metafieldIdentifiers, updatedCart);
2196
+ return updatedCart;
2197
+ },
2198
+ [client, locale, cartCookieAdapter, mutateCart, metafieldIdentifiers]
2371
2199
  );
2200
+ return useSWRMutation("update-cart-lines", updateLines, options);
2372
2201
  }
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 }" : ""}
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;
2404
2213
  }
2405
- }
2406
- `
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]
2407
2225
  );
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;
2420
- }
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
- };
2226
+ return useSWRMutation("update-cart-attributes", updateAttributes, swrOptions);
2436
2227
  }
2437
- function useSite(options = {}) {
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 } = useHasPlusMemberInLines({
2248
+ memberSetting,
2249
+ lines: lineItems
2250
+ });
2251
+ const memberType = hasPlusMember ? "2" : String(profile?.memberType ?? 0);
2252
+ const cartAttributes = getCartAttributes({
2253
+ profile,
2254
+ customer,
2255
+ memberType,
2256
+ currentUrl: window.location.href
2257
+ });
2258
+ const linesWithFunctionAttributes = getLinesWithAttributes({
2259
+ lineItems
2260
+ });
2261
+ const lines = linesWithFunctionAttributes.map((item) => ({
2262
+ merchandiseId: item.variant?.id || "",
2263
+ quantity: item.quantity || 1,
2264
+ attributes: item.attributes,
2265
+ sellingPlanId: item.sellingPlanId
2266
+ })).filter((item) => item.merchandiseId);
2267
+ if (lines.length === 0) {
2268
+ return;
2269
+ }
2270
+ const resultCart = await createCart(client, {
2271
+ lines,
2272
+ metafieldIdentifiers,
2273
+ cookieAdapter: cartCookieAdapter,
2274
+ buyerIdentity,
2275
+ discountCodes,
2276
+ customAttributes: [...cartAttributes, ...customAttributes || []]
2277
+ });
2278
+ if (!resultCart) {
2279
+ throw new Error("Failed to create cart for buy now");
2280
+ }
2281
+ if (withTrack && resultCart.lineItems) {
2282
+ trackBuyNowGA({
2283
+ lineItems,
2284
+ gtmParams: { ...gtmParams, brand: config.getBrand() }
2285
+ });
2286
+ if (fbqTrackConfig) {
2287
+ trackBuyNowFBQ({ trackConfig: fbqTrackConfig });
2288
+ }
2289
+ }
2290
+ if (redirectToCheckout) {
2291
+ if (resultCart.url) {
2292
+ if (typeof window !== "undefined") {
2293
+ window.location.href = resultCart.url;
2294
+ }
2295
+ } else {
2296
+ throw new Error("Failed to get checkout URL");
2297
+ }
2298
+ }
2299
+ return resultCart;
2300
+ },
2301
+ [client, locale, isLoggedIn, cartCookieAdapter, withTrack]
2302
+ );
2303
+ return useSWRMutation("buy-now", buyNow, swrOptions);
2304
+ }
2305
+
2306
+ // src/hooks/cart/types/price-discount.ts
2307
+ var PriceDiscountType = /* @__PURE__ */ ((PriceDiscountType2) => {
2308
+ PriceDiscountType2[PriceDiscountType2["PERCENTAGE"] = 1] = "PERCENTAGE";
2309
+ PriceDiscountType2[PriceDiscountType2["FIXED_AMOUNT"] = 2] = "FIXED_AMOUNT";
2310
+ return PriceDiscountType2;
2311
+ })(PriceDiscountType || {});
2312
+ var PriceBasePriceType = /* @__PURE__ */ ((PriceBasePriceType2) => {
2313
+ PriceBasePriceType2[PriceBasePriceType2["MIN_DISCOUNTED_PRICE"] = 1] = "MIN_DISCOUNTED_PRICE";
2314
+ PriceBasePriceType2[PriceBasePriceType2["MIN_TOTAL_PRICE"] = 2] = "MIN_TOTAL_PRICE";
2315
+ return PriceBasePriceType2;
2316
+ })(PriceBasePriceType || {});
2317
+ function useProduct(options = {}) {
2438
2318
  const { client, locale } = useShopify();
2439
- const { metafieldIdentifiers, ...swrOptions } = options;
2319
+ const { handle, metafieldIdentifiers, ...swrOptions } = options;
2440
2320
  return useSWR(
2441
- ["site", locale, metafieldIdentifiers],
2442
- () => getSiteInfo(client, locale, metafieldIdentifiers),
2321
+ handle ? ["product", locale, handle, metafieldIdentifiers] : null,
2322
+ () => getProduct(client, {
2323
+ handle,
2324
+ locale,
2325
+ metafieldIdentifiers
2326
+ }),
2443
2327
  swrOptions
2444
2328
  );
2445
2329
  }
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);
2330
+ function useAllProducts(options = {}) {
2331
+ const { client, locale } = useShopify();
2332
+ const { first, query, sortKey, reverse, metafieldIdentifiers, ...swrOptions } = options;
2333
+ return useSWR(
2334
+ ["all-products", locale, first, query, sortKey, reverse, metafieldIdentifiers],
2335
+ () => getAllProducts(client, {
2336
+ locale,
2337
+ first,
2338
+ query,
2339
+ sortKey,
2340
+ reverse,
2341
+ metafieldIdentifiers
2342
+ }),
2343
+ swrOptions
2344
+ );
2502
2345
  }
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
2346
+ function getFirstAvailableVariant(product) {
2347
+ const availableVariant = product.variants.find((v) => v.availableForSale);
2348
+ return availableVariant || product.variants[0];
2349
+ }
2350
+ function getVariantFromSelectedOptions(product, selectedOptions) {
2351
+ return product.variants.find((variant) => {
2352
+ return variant.selectedOptions.every((option) => {
2353
+ return selectedOptions[option.name] === option.value;
2354
+ });
2513
2355
  });
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
2356
  }
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());
2544
- }
2357
+ function useVariant({
2358
+ product,
2359
+ selectedOptions
2360
+ }) {
2361
+ const [variant, setVariant] = useState(
2362
+ product ? getFirstAvailableVariant(product) : void 0
2545
2363
  );
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
- };
2554
-
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;
2580
- }
2581
- return {
2582
- ...method,
2583
- id: method.__mode + method.__code,
2584
- useCoupon: false,
2585
- subtitle: plus_shipping?.directly || "",
2586
- disabled
2587
- };
2364
+ useEffect(() => {
2365
+ if (!product) {
2366
+ setVariant(void 0);
2367
+ return;
2368
+ }
2369
+ const newVariant = getVariantFromSelectedOptions(product, selectedOptions);
2370
+ if (newVariant && newVariant.id !== variant?.id) {
2371
+ setVariant(newVariant);
2372
+ } else if (!newVariant) {
2373
+ setVariant(getFirstAvailableVariant(product));
2374
+ }
2375
+ }, [selectedOptions, product, variant?.id]);
2376
+ return variant;
2377
+ }
2378
+ var FAKE_PRICE = 999999999e-2;
2379
+ function formatPrice({
2380
+ amount,
2381
+ currencyCode,
2382
+ locale,
2383
+ maximumFractionDigits,
2384
+ minimumFractionDigits,
2385
+ removeTrailingZeros
2386
+ }) {
2387
+ const formatter = new Intl.NumberFormat(locale, {
2388
+ style: "currency",
2389
+ currency: currencyCode,
2390
+ maximumFractionDigits: maximumFractionDigits ?? 2,
2391
+ minimumFractionDigits: minimumFractionDigits ?? 2
2392
+ });
2393
+ let formatted = formatter.format(amount);
2394
+ if (removeTrailingZeros) {
2395
+ formatted = formatted.replace(/\.00$/, "");
2396
+ }
2397
+ return formatted;
2398
+ }
2399
+ function formatVariantPrice({
2400
+ amount,
2401
+ baseAmount,
2402
+ currencyCode,
2403
+ locale,
2404
+ maximumFractionDigits,
2405
+ minimumFractionDigits,
2406
+ removeTrailingZeros
2407
+ }) {
2408
+ return {
2409
+ price: formatPrice({
2410
+ amount,
2411
+ currencyCode,
2412
+ locale,
2413
+ maximumFractionDigits,
2414
+ minimumFractionDigits,
2415
+ removeTrailingZeros
2416
+ }),
2417
+ basePrice: formatPrice({
2418
+ amount: baseAmount,
2419
+ currencyCode,
2420
+ locale,
2421
+ maximumFractionDigits,
2422
+ minimumFractionDigits,
2423
+ removeTrailingZeros
2424
+ })
2425
+ };
2426
+ }
2427
+ function usePrice({
2428
+ amount,
2429
+ baseAmount,
2430
+ currencyCode,
2431
+ soldOutDescription = "",
2432
+ maximumFractionDigits,
2433
+ minimumFractionDigits,
2434
+ removeTrailingZeros
2435
+ }) {
2436
+ const { locale } = useShopify();
2437
+ const value = useMemo(() => {
2438
+ if (typeof amount !== "number" || !currencyCode) {
2439
+ return "";
2440
+ }
2441
+ if (soldOutDescription && amount >= FAKE_PRICE) {
2442
+ return soldOutDescription;
2443
+ }
2444
+ return baseAmount ? formatVariantPrice({
2445
+ amount,
2446
+ baseAmount,
2447
+ currencyCode,
2448
+ locale,
2449
+ maximumFractionDigits,
2450
+ minimumFractionDigits,
2451
+ removeTrailingZeros
2452
+ }) : formatPrice({
2453
+ amount,
2454
+ currencyCode,
2455
+ locale,
2456
+ maximumFractionDigits,
2457
+ minimumFractionDigits,
2458
+ removeTrailingZeros
2588
2459
  });
2589
2460
  }, [
2590
- nddOverweight,
2591
- plus_shipping?.directly,
2592
- plus_shipping?.shipping_methods,
2593
- selectedPlusMemberMode,
2594
- tddOverweight,
2595
- variant?.weight
2461
+ amount,
2462
+ baseAmount,
2463
+ currencyCode,
2464
+ locale,
2465
+ maximumFractionDigits,
2466
+ minimumFractionDigits,
2467
+ soldOutDescription,
2468
+ removeTrailingZeros
2596
2469
  ]);
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;
2618
- }
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;
2623
- } 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
- });
2470
+ const result = useMemo(() => {
2471
+ const free = Boolean(amount && amount <= 0);
2472
+ return typeof value === "string" ? { price: value, basePrice: value, free } : { ...value, free };
2473
+ }, [value, amount]);
2474
+ return result;
2475
+ }
2476
+ function optionsConstructor(selectedOptions) {
2477
+ return selectedOptions.reduce((acc, option) => {
2478
+ acc[option.name] = option.value;
2479
+ return acc;
2480
+ }, {});
2481
+ }
2482
+ function decodeShopifyId(gid) {
2483
+ try {
2484
+ const base64 = gid.split("/").pop() || "";
2485
+ return atob(base64);
2486
+ } catch {
2487
+ return gid;
2488
+ }
2489
+ }
2490
+ function useSelectedOptions(product, sku) {
2491
+ const [options, setOptions] = useState({});
2492
+ useEffect(() => {
2493
+ if (!product || !product.variants.length) {
2494
+ setOptions({});
2495
+ return;
2632
2496
  }
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;
2497
+ let variant = product.variants[0];
2498
+ if (typeof window !== "undefined") {
2499
+ const searchParams = new URLSearchParams(window.location.search);
2500
+ const variantIdParam = searchParams.get("variant");
2501
+ if (variantIdParam) {
2502
+ const foundVariant = product.variants.find((v) => {
2503
+ if (sku) return v.sku === sku;
2504
+ return v.id === variantIdParam || v.id.includes(variantIdParam) || decodeShopifyId(v.id) === variantIdParam;
2505
+ });
2506
+ if (foundVariant) {
2507
+ variant = foundVariant;
2647
2508
  }
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;
2509
+ }
2510
+ }
2511
+ if (variant) {
2512
+ const newOptions = optionsConstructor(variant.selectedOptions);
2513
+ setOptions(newOptions);
2514
+ }
2515
+ }, [product, sku]);
2516
+ return [options, setOptions];
2517
+ }
2518
+ function decodeShopifyId2(gid) {
2519
+ try {
2520
+ const parts = gid.split("/");
2521
+ return parts[parts.length - 1] || gid;
2522
+ } catch {
2523
+ return gid;
2524
+ }
2525
+ }
2526
+ function useProductUrl(otherQuery) {
2527
+ const { routerAdapter } = useShopify();
2528
+ return useCallback(
2529
+ ({ product, variant }) => {
2530
+ if (!product) return "";
2531
+ const queryParams = new URLSearchParams();
2532
+ if (variant?.id) {
2533
+ const variantId = decodeShopifyId2(variant.id);
2534
+ if (variantId) {
2535
+ queryParams.set("variant", variantId);
2653
2536
  }
2654
2537
  }
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
- };
2538
+ if (otherQuery) {
2539
+ Object.entries(otherQuery).forEach(([key, value]) => {
2540
+ queryParams.set(key, value);
2541
+ });
2542
+ }
2543
+ const queryString = queryParams.toString();
2544
+ const path = `/products/${product.handle}${queryString ? `?${queryString}` : ""}`;
2545
+ if (routerAdapter?.getLocalizedPath) {
2546
+ return routerAdapter.getLocalizedPath(path);
2547
+ }
2548
+ return path;
2549
+ },
2550
+ [routerAdapter, otherQuery]
2551
+ );
2685
2552
  }
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]
2706
- });
2553
+ function decodeShopifyId3(gid) {
2554
+ try {
2555
+ const parts = gid.split("/");
2556
+ return parts[parts.length - 1] || gid;
2557
+ } catch {
2558
+ return gid;
2559
+ }
2560
+ }
2561
+ function useUpdateVariantQuery(variant) {
2562
+ useEffect(() => {
2563
+ if (!variant || typeof window === "undefined") {
2564
+ return;
2707
2565
  }
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 : ""
2566
+ const searchParams = new URLSearchParams(window.location.search);
2567
+ const currentVariantId = searchParams.get("variant");
2568
+ const newVariantId = decodeShopifyId3(variant.id);
2569
+ if (newVariantId && currentVariantId !== newVariantId) {
2570
+ searchParams.set("variant", newVariantId);
2571
+ const newUrl = `${window.location.pathname}?${searchParams.toString()}${window.location.hash}`;
2572
+ window.history.replaceState({}, "", newUrl);
2573
+ }
2574
+ }, [variant]);
2575
+ }
2576
+ function getVariantMediaList({
2577
+ product,
2578
+ variant
2579
+ }) {
2580
+ if (variant.image?.url) {
2581
+ const variantMediaId = variant.image.url;
2582
+ const variantMedia = product.media.filter((media) => {
2583
+ if (media.mediaContentType === "IMAGE" && media.previewImage) {
2584
+ return media.previewImage?.url === variantMediaId;
2731
2585
  }
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
- })
2586
+ return false;
2747
2587
  });
2748
- if (disableShipping) {
2749
- checkoutCustomAttributes.push({
2750
- key: "_hide_shipping",
2751
- value: "true"
2588
+ if (variantMedia.length > 0) {
2589
+ const otherMedia = product.media.filter((media) => {
2590
+ if (media.mediaContentType === "IMAGE" && media.previewImage) {
2591
+ return media.previewImage.url !== variantMediaId;
2592
+ }
2593
+ return true;
2752
2594
  });
2595
+ return [...variantMedia, ...otherMedia];
2753
2596
  }
2754
- return checkoutCustomAttributes;
2755
- }, [profile, selectedShippingMethod, selectedPlusMemberMode, isPresaleContains]);
2756
- };
2757
- function useAutoRemovePlusMemberInCart({
2758
- cart,
2759
- profile,
2760
- memberSetting
2597
+ }
2598
+ return product.media;
2599
+ }
2600
+ function useVariantMedia({
2601
+ product,
2602
+ variant
2761
2603
  }) {
2762
- const { plus_monthly_product, plus_annual_product } = memberSetting || {};
2763
- const { trigger: removeCartLines2 } = useRemoveCartLines();
2604
+ const [imageList, setImageList] = useState([]);
2605
+ const [sceneList, setSceneList] = useState([]);
2606
+ const [videoList, setVideoList] = useState([]);
2764
2607
  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
- });
2608
+ if (!product || !variant) {
2609
+ setImageList([]);
2610
+ setSceneList([]);
2611
+ setVideoList([]);
2612
+ return;
2613
+ }
2614
+ const mediaList = getVariantMediaList({ product, variant });
2615
+ const images = mediaList.filter((media) => media.mediaContentType === "IMAGE");
2616
+ const videos = mediaList.filter(
2617
+ (media) => media.mediaContentType === "VIDEO" || media.mediaContentType === "EXTERNAL_VIDEO"
2618
+ );
2619
+ setImageList(images.length > 0 && images[0] ? [images[0]] : []);
2620
+ setSceneList(images.length > 1 ? images.slice(1) : []);
2621
+ setVideoList(videos);
2622
+ }, [product, variant]);
2623
+ return {
2624
+ productList: imageList,
2625
+ sceneList,
2626
+ videoList
2627
+ };
2628
+ }
2629
+ function useCollection(options = {}) {
2630
+ const { client, locale } = useShopify();
2631
+ const { handle, metafieldIdentifiers, ...swrOptions } = options;
2632
+ return useSWR(
2633
+ handle ? ["collection", locale, handle, metafieldIdentifiers] : null,
2634
+ () => getCollection(client, {
2635
+ handle,
2636
+ locale,
2637
+ metafieldIdentifiers
2638
+ }),
2639
+ swrOptions
2640
+ );
2641
+ }
2642
+ function useAllCollections(options = {}) {
2643
+ const { client, locale } = useShopify();
2644
+ const { first, query, sortKey, reverse, metafieldIdentifiers, ...swrOptions } = options;
2645
+ return useSWR(
2646
+ ["all-collections", locale, first, query, sortKey, reverse, metafieldIdentifiers],
2647
+ () => getAllCollections(client, {
2648
+ locale,
2649
+ first,
2650
+ query,
2651
+ sortKey,
2652
+ reverse,
2653
+ metafieldIdentifiers
2654
+ }),
2655
+ swrOptions
2656
+ );
2657
+ }
2658
+ function useCollections(options = {}) {
2659
+ const { client, locale } = useShopify();
2660
+ const { first, after, query, sortKey, reverse, metafieldIdentifiers, ...swrOptions } = options;
2661
+ return useSWR(
2662
+ ["collections", locale, first, after, query, sortKey, reverse, metafieldIdentifiers],
2663
+ () => getCollections(client, {
2664
+ locale,
2665
+ first,
2666
+ after,
2667
+ query,
2668
+ sortKey,
2669
+ reverse,
2670
+ metafieldIdentifiers
2671
+ }),
2672
+ swrOptions
2673
+ );
2674
+ }
2675
+ function useBlog(options = {}) {
2676
+ const { client, locale } = useShopify();
2677
+ const { handle, metafieldIdentifiers, ...swrOptions } = options;
2678
+ return useSWR(
2679
+ handle ? ["blog", locale, handle, metafieldIdentifiers] : null,
2680
+ () => getBlog(client, { handle, locale, metafieldIdentifiers }),
2681
+ swrOptions
2682
+ );
2683
+ }
2684
+ function useAllBlogs(options = {}) {
2685
+ const { client, locale } = useShopify();
2686
+ const { first, query, metafieldIdentifiers, ...swrOptions } = options;
2687
+ return useSWR(
2688
+ ["all-blogs", locale, first, query, metafieldIdentifiers],
2689
+ () => getAllBlogs(client, {
2690
+ locale,
2691
+ first,
2692
+ query,
2693
+ metafieldIdentifiers
2694
+ }),
2695
+ swrOptions
2696
+ );
2697
+ }
2698
+ function useArticle(options = {}) {
2699
+ const { client, locale } = useShopify();
2700
+ const { blogHandle, articleHandle, metafieldIdentifiers, ...swrOptions } = options;
2701
+ return useSWR(
2702
+ blogHandle && articleHandle ? ["article", locale, blogHandle, articleHandle, metafieldIdentifiers] : null,
2703
+ () => getArticle(client, {
2704
+ blogHandle,
2705
+ articleHandle,
2706
+ locale,
2707
+ metafieldIdentifiers
2708
+ }),
2709
+ swrOptions
2710
+ );
2711
+ }
2712
+ function useArticles(options = {}) {
2713
+ const { client, locale } = useShopify();
2714
+ const { first, query, sortKey, reverse, metafieldIdentifiers, ...swrOptions } = options;
2715
+ return useSWR(
2716
+ ["articles", locale, first, query, sortKey, reverse, metafieldIdentifiers],
2717
+ () => getArticles(client, {
2718
+ locale,
2719
+ first,
2720
+ query,
2721
+ sortKey,
2722
+ reverse,
2723
+ metafieldIdentifiers
2724
+ }),
2725
+ swrOptions
2726
+ );
2727
+ }
2728
+ function useArticlesInBlog(options = {}) {
2729
+ const { client, locale } = useShopify();
2730
+ const { blogHandle, first, sortKey, reverse, metafieldIdentifiers, ...swrOptions } = options;
2731
+ return useSWR(
2732
+ blogHandle ? ["articles-in-blog", locale, blogHandle, first, sortKey, reverse, metafieldIdentifiers] : null,
2733
+ () => getArticlesInBlog(client, {
2734
+ blogHandle,
2735
+ locale,
2736
+ first,
2737
+ sortKey,
2738
+ reverse,
2739
+ metafieldIdentifiers
2740
+ }),
2741
+ swrOptions
2742
+ );
2743
+ }
2744
+ async function performSearch(client, locale, searchQuery, first = 20, types = ["PRODUCT", "ARTICLE", "PAGE"]) {
2745
+ if (!searchQuery) {
2746
+ return void 0;
2747
+ }
2748
+ const query = (
2749
+ /* GraphQL */
2750
+ `
2751
+ query search($query: String!, $first: Int!, $types: [SearchType!])
2752
+ @inContext(language: $language) {
2753
+ search(query: $query, first: $first, types: $types, unavailableProducts: HIDE) {
2754
+ totalCount
2755
+ edges {
2756
+ node {
2757
+ ... on Article {
2758
+ __typename
2759
+ id
2760
+ handle
2761
+ title
2762
+ excerpt
2763
+ image {
2764
+ url
2765
+ altText
2766
+ }
2767
+ }
2768
+ ... on Page {
2769
+ __typename
2770
+ id
2771
+ handle
2772
+ title
2773
+ }
2774
+ ... on Product {
2775
+ __typename
2776
+ id
2777
+ handle
2778
+ title
2779
+ description
2780
+ featuredImage {
2781
+ url
2782
+ altText
2783
+ }
2784
+ }
2785
+ }
2786
+ }
2787
+ pageInfo {
2788
+ hasNextPage
2789
+ endCursor
2790
+ }
2775
2791
  }
2776
- };
2777
- if (profile?.isMonthlyPlus) {
2778
- removePlusProduct(plus_monthly_product);
2779
- }
2780
- if (profile?.isAnnualPlus) {
2781
- removePlusProduct(plus_annual_product);
2782
2792
  }
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
2793
+ `
2794
+ );
2795
+ const data = await client.query(query, {
2796
+ query: searchQuery,
2797
+ first,
2798
+ types
2793
2799
  });
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;
2800
+ if (!data || !data.search) {
2801
+ return void 0;
2802
+ }
2803
+ const items = data.search.edges?.map((edge) => {
2804
+ const node = edge.node;
2805
+ const item = {
2806
+ type: node.__typename.toUpperCase(),
2807
+ id: node.id,
2808
+ handle: node.handle,
2809
+ title: node.title
2810
+ };
2811
+ if (node.__typename === "Product") {
2812
+ item.description = node.description;
2813
+ item.image = node.featuredImage ? {
2814
+ url: node.featuredImage.url,
2815
+ altText: node.featuredImage.altText
2816
+ } : void 0;
2817
+ } else if (node.__typename === "Article") {
2818
+ item.description = node.excerpt;
2819
+ item.image = node.image ? {
2820
+ url: node.image.url,
2821
+ altText: node.image.altText
2822
+ } : void 0;
2809
2823
  }
2810
- return selectedPlusMemberVariant;
2811
- }, [selectedPlusMemberMode, selectedPlusMemberVariant, hasMonthlyPlus, hasAnnualPlus]);
2812
- return plusMemberVariant;
2824
+ return item;
2825
+ }) || [];
2826
+ return {
2827
+ items,
2828
+ totalCount: data.search.totalCount || 0,
2829
+ pageInfo: data.search.pageInfo
2830
+ };
2813
2831
  }
2814
- var PlusMemberProvider = ({
2815
- variant,
2816
- product,
2817
- memberSetting,
2818
- initialSelectedPlusMemberMode = "free",
2819
- profile,
2820
- children
2821
- }) => {
2822
- const [selectedPlusMemberMode, setSelectedPlusMemberMode] = useState(
2823
- initialSelectedPlusMemberMode
2832
+ function useSearch(options = {}) {
2833
+ const { client, locale } = useShopify();
2834
+ const { query, first = 20, types = ["PRODUCT", "ARTICLE", "PAGE"], ...swrOptions } = options;
2835
+ return useSWR(
2836
+ query ? ["search", locale, query, first, types] : null,
2837
+ () => performSearch(client, locale, query, first, types),
2838
+ swrOptions
2824
2839
  );
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;
2840
+ }
2841
+ async function getSiteInfo(client, locale, metafieldIdentifiers) {
2842
+ const hasMetafields = metafieldIdentifiers && metafieldIdentifiers.length > 0;
2843
+ const query = (
2844
+ /* GraphQL */
2845
+ `
2846
+ query getSiteInfo(
2847
+ ${hasMetafields ? "$shopMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
2848
+ ) @inContext(language: $language) {
2849
+ shop {
2850
+ name
2851
+ description
2852
+ primaryDomain {
2853
+ url
2854
+ host
2855
+ }
2856
+ brand {
2857
+ logo {
2858
+ image {
2859
+ url
2860
+ }
2861
+ }
2862
+ colors {
2863
+ primary {
2864
+ background
2865
+ }
2866
+ secondary {
2867
+ background
2868
+ }
2869
+ }
2870
+ }
2871
+ ${hasMetafields ? "metafields(identifiers: $shopMetafieldIdentifiers) { key value }" : ""}
2872
+ }
2840
2873
  }
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
2874
+ `
2875
+ );
2876
+ const variables = {};
2877
+ if (hasMetafields) {
2878
+ variables.shopMetafieldIdentifiers = metafieldIdentifiers;
2879
+ }
2880
+ const data = await client.query(query, variables);
2881
+ if (!data || !data.shop) {
2882
+ return void 0;
2883
+ }
2884
+ const shop = data.shop;
2885
+ const metafields = shop.metafields?.reduce((acc, mf) => {
2886
+ if (mf && mf.key) {
2887
+ acc[mf.key] = mf.value;
2863
2888
  }
2889
+ return acc;
2890
+ }, {});
2891
+ return {
2892
+ name: shop.name,
2893
+ description: shop.description,
2894
+ primaryDomain: shop.primaryDomain,
2895
+ brand: shop.brand ? {
2896
+ logo: shop.brand.logo,
2897
+ colors: shop.brand.colors ? {
2898
+ primary: shop.brand.colors.primary?.background,
2899
+ secondary: shop.brand.colors.secondary?.background
2900
+ } : void 0
2901
+ } : void 0,
2902
+ metafields
2903
+ };
2904
+ }
2905
+ function useSite(options = {}) {
2906
+ const { client, locale } = useShopify();
2907
+ const { metafieldIdentifiers, ...swrOptions } = options;
2908
+ return useSWR(
2909
+ ["site", locale, metafieldIdentifiers],
2910
+ () => getSiteInfo(client, locale, metafieldIdentifiers),
2911
+ swrOptions
2864
2912
  );
2865
- };
2913
+ }
2866
2914
  function useIntersection(targetRef, options) {
2867
2915
  const {
2868
2916
  callback,
@@ -3043,6 +3091,6 @@ function clearGeoLocationCache(cacheKey = "geoLocation") {
3043
3091
  }
3044
3092
  }
3045
3093
 
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 };
3094
+ 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
3095
  //# sourceMappingURL=index.mjs.map
3048
3096
  //# sourceMappingURL=index.mjs.map