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

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