@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.
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createContext, useMemo, useContext, useRef, useState, useEffect, useCallback } from 'react';
2
- import { createShopifyClient, getProductsByHandles, createCart, updateCartCodes, addCartLines, updateCartLines, removeCartLines, updateCartAttributes, getLocalStorage, getProduct, getAllProducts, getCollection, getAllCollections, getCollections, getBlog, getAllBlogs, getArticle, getArticles, getArticlesInBlog, getCart, setLocalStorage } from '@anker-in/shopify-sdk';
2
+ import { createShopifyClient, getProductsByHandles, createCart, updateCartCodes, addCartLines, getLocalStorage, updateCartLines, removeCartLines, updateCartAttributes, getProduct, getAllProducts, getCollection, getAllCollections, getCollections, getBlog, getAllBlogs, getArticle, getArticles, getArticlesInBlog, getCart, setLocalStorage } from '@anker-in/shopify-sdk';
3
3
  export * from '@anker-in/shopify-sdk';
4
4
  import Cookies5 from 'js-cookie';
5
5
  import { jsx } from 'react/jsx-runtime';
@@ -605,7 +605,8 @@ var useScriptAutoFreeGift = ({
605
605
  _giveaway,
606
606
  cart,
607
607
  locale: providedLocale,
608
- lines
608
+ lines,
609
+ profile
609
610
  }) => {
610
611
  const { client, locale: contextLocale } = useShopify();
611
612
  const locale = providedLocale || contextLocale;
@@ -629,8 +630,9 @@ var useScriptAutoFreeGift = ({
629
630
  const utmCampaign = Cookies5.get("utm_campaign") || query?.utm_campaign;
630
631
  if (campaign.activityAvailableQuery && !utmCampaign?.includes(campaign.activityAvailableQuery))
631
632
  return false;
633
+ if (campaign.requireLogin && !profile?.email) return false;
632
634
  return true;
633
- }, [campaign]);
635
+ }, [campaign, profile]);
634
636
  const [upgrade_multiple, upgrade_value] = useMemo(() => {
635
637
  let upgrade_multiple2 = 1;
636
638
  let upgrade_value2 = 0;
@@ -759,7 +761,10 @@ var useScriptAutoFreeGift = ({
759
761
  giftProductsResult: finalGiftProductsResult
760
762
  };
761
763
  };
762
- function useCreateCart(options) {
764
+ function useCreateCart({
765
+ updateCookie = false,
766
+ options
767
+ }) {
763
768
  const { client, locale, cartCookieAdapter } = useShopify();
764
769
  const { mutateCart, metafieldIdentifiers } = useCartContext();
765
770
  const createNewCart = useCallback(
@@ -767,7 +772,8 @@ function useCreateCart(options) {
767
772
  let newCart = await createCart(client, {
768
773
  ...arg,
769
774
  metafieldIdentifiers,
770
- cookieAdapter: cartCookieAdapter
775
+ cookieAdapter: cartCookieAdapter,
776
+ updateCookie
771
777
  });
772
778
  if (newCart) {
773
779
  const unApplicableCodes = newCart.discountCodes.filter((item) => !item.applicable).map((item) => item.code);
@@ -1140,260 +1146,6 @@ var getLinesWithAttributes = ({
1140
1146
  return functionLine;
1141
1147
  });
1142
1148
  };
1143
-
1144
- // src/hooks/cart/use-add-to-cart.ts
1145
- function useAddToCart({ withTrack = true } = {}, swrOptions) {
1146
- const { client, config, locale, cartCookieAdapter, userAdapter, performanceAdapter } = useShopify();
1147
- const { cart, addCustomAttributes } = useCartContext();
1148
- const { trigger: applyCartCodes } = useApplyCartCodes();
1149
- const { trigger: removeInvalidCodes } = useRemoveCartCodes();
1150
- const { trigger: addCartLines2 } = useAddCartLines();
1151
- const { trigger: createCart4 } = useCreateCart();
1152
- const addToCart = useCallback(
1153
- async (_key, { arg }) => {
1154
- const {
1155
- lineItems,
1156
- cartId: providedCartId,
1157
- discountCodes,
1158
- gtmParams = {},
1159
- buyerIdentity,
1160
- needCreateCart = false,
1161
- onCodesInvalid,
1162
- replaceExistingCodes,
1163
- customAttributes
1164
- } = arg;
1165
- if (!lineItems || lineItems.length === 0) {
1166
- return;
1167
- }
1168
- performanceAdapter?.addToCartStart();
1169
- const linesWithFunctionAttributes = getLinesWithAttributes({ cart, lineItems });
1170
- const lines = linesWithFunctionAttributes.map((item) => ({
1171
- merchandiseId: item.variant?.id || "",
1172
- quantity: item.quantity || 1,
1173
- attributes: item.attributes,
1174
- sellingPlanId: item.sellingPlanId
1175
- })).filter((item) => item.merchandiseId && item.quantity);
1176
- if (lines.length === 0) {
1177
- return;
1178
- }
1179
- let cartId = needCreateCart ? void 0 : providedCartId || cart?.id;
1180
- let resultCart = null;
1181
- if (!cartId) {
1182
- resultCart = await createCart4({
1183
- lines,
1184
- buyerIdentity,
1185
- discountCodes,
1186
- customAttributes
1187
- });
1188
- } else {
1189
- resultCart = await addCartLines2({
1190
- cartId,
1191
- lines
1192
- });
1193
- console.log("npm addCartLines resultCart", resultCart);
1194
- if (resultCart && resultCart.discountCodes && resultCart.discountCodes.length > 0) {
1195
- const unapplicableCodes = resultCart.discountCodes.filter((item) => !item.applicable).map((item) => item.code);
1196
- if (unapplicableCodes.length > 0) {
1197
- if (onCodesInvalid) {
1198
- const handledCart = await onCodesInvalid(resultCart, unapplicableCodes);
1199
- if (handledCart) {
1200
- resultCart = handledCart;
1201
- }
1202
- } else {
1203
- await removeInvalidCodes({
1204
- discountCodes: unapplicableCodes
1205
- });
1206
- }
1207
- }
1208
- }
1209
- if (resultCart && discountCodes && discountCodes.length > 0) {
1210
- applyCartCodes({
1211
- replaceExistingCodes,
1212
- discountCodes
1213
- });
1214
- }
1215
- if (customAttributes && customAttributes.length > 0) {
1216
- addCustomAttributes(customAttributes);
1217
- }
1218
- }
1219
- if (withTrack) {
1220
- trackAddToCartGA({
1221
- lineItems,
1222
- gtmParams: { ...gtmParams, brand: config.getBrand() }
1223
- });
1224
- trackAddToCartFBQ({ lineItems });
1225
- }
1226
- performanceAdapter?.addToCartEnd();
1227
- return resultCart;
1228
- },
1229
- [
1230
- client,
1231
- locale,
1232
- cartCookieAdapter,
1233
- userAdapter,
1234
- cart,
1235
- withTrack,
1236
- performanceAdapter,
1237
- createCart4,
1238
- addCartLines2,
1239
- applyCartCodes,
1240
- removeInvalidCodes,
1241
- addCustomAttributes,
1242
- config
1243
- ]
1244
- );
1245
- return useSWRMutation("add-to-cart", addToCart, swrOptions);
1246
- }
1247
- function useUpdateCartLines(options) {
1248
- const { client, locale, cartCookieAdapter } = useShopify();
1249
- const { mutateCart, metafieldIdentifiers } = useCartContext();
1250
- const updateLines = useCallback(
1251
- async (_key, { arg }) => {
1252
- const updatedCart = await updateCartLines(client, {
1253
- ...arg,
1254
- metafieldIdentifiers,
1255
- cookieAdapter: cartCookieAdapter
1256
- });
1257
- if (updatedCart) {
1258
- mutateCart(updatedCart);
1259
- }
1260
- console.log("use-update-cart-lines updatedCart", metafieldIdentifiers, updatedCart);
1261
- return updatedCart;
1262
- },
1263
- [client, locale, cartCookieAdapter, mutateCart, metafieldIdentifiers]
1264
- );
1265
- return useSWRMutation("update-cart-lines", updateLines, options);
1266
- }
1267
- function useRemoveCartLines(options) {
1268
- const { client, locale, cartCookieAdapter } = useShopify();
1269
- const { mutateCart, metafieldIdentifiers } = useCartContext();
1270
- const removeLines = useCallback(
1271
- async (_key, { arg }) => {
1272
- const { autoRemoveInvalidCodes = true, onCodesRemoved, cartId, lineIds } = arg;
1273
- let updatedCart = await removeCartLines(client, {
1274
- cartId,
1275
- lineIds,
1276
- metafieldIdentifiers,
1277
- cookieAdapter: cartCookieAdapter
1278
- });
1279
- if (updatedCart && autoRemoveInvalidCodes) {
1280
- const unApplicableCodes = updatedCart.discountCodes.filter((item) => !item.applicable).map((item) => item.code);
1281
- if (unApplicableCodes.length > 0) {
1282
- if (onCodesRemoved) {
1283
- const handledCart = await onCodesRemoved(updatedCart, unApplicableCodes);
1284
- if (handledCart) {
1285
- updatedCart = handledCart;
1286
- }
1287
- } else {
1288
- updatedCart = await updateCartCodes(client, {
1289
- cartId: updatedCart.id,
1290
- discountCodes: updatedCart.discountCodes.filter((item) => item.applicable).map((item) => item.code),
1291
- metafieldIdentifiers,
1292
- cookieAdapter: cartCookieAdapter
1293
- }) || updatedCart;
1294
- }
1295
- }
1296
- }
1297
- if (updatedCart) {
1298
- mutateCart(updatedCart);
1299
- }
1300
- return updatedCart;
1301
- },
1302
- [client, locale, cartCookieAdapter, mutateCart, metafieldIdentifiers]
1303
- );
1304
- return useSWRMutation("remove-cart-lines", removeLines, options);
1305
- }
1306
- function useUpdateCartAttributes({
1307
- mutate,
1308
- metafieldIdentifiers,
1309
- disabled = false,
1310
- swrOptions
1311
- }) {
1312
- const { client, locale, cartCookieAdapter } = useShopify();
1313
- const updateAttributes = useCallback(
1314
- async (_key, { arg }) => {
1315
- if (disabled || !cartCookieAdapter?.getCartId(locale)) {
1316
- return void 0;
1317
- }
1318
- const updatedCart = await updateCartAttributes(client, {
1319
- ...arg,
1320
- metafieldIdentifiers,
1321
- cookieAdapter: cartCookieAdapter
1322
- });
1323
- if (updatedCart) {
1324
- mutate(updatedCart);
1325
- }
1326
- return updatedCart;
1327
- },
1328
- [client, locale, cartCookieAdapter, mutate, metafieldIdentifiers, disabled]
1329
- );
1330
- return useSWRMutation("update-cart-attributes", updateAttributes, swrOptions);
1331
- }
1332
- function useBuyNow({ withTrack = true } = {}, swrOptions) {
1333
- const { client, config, locale, cartCookieAdapter, userAdapter } = useShopify();
1334
- const isLoggedIn = userAdapter?.isLoggedIn || false;
1335
- const buyNow = useCallback(
1336
- async (_key, { arg }) => {
1337
- const {
1338
- lineItems,
1339
- discountCodes,
1340
- gtmParams = {},
1341
- buyerIdentity,
1342
- fbqTrackConfig,
1343
- customAttributes,
1344
- metafieldIdentifiers,
1345
- redirectToCheckout
1346
- } = arg;
1347
- if (!lineItems || lineItems.length === 0) {
1348
- return;
1349
- }
1350
- const linesWithFunctionAttributes = getLinesWithAttributes({
1351
- lineItems
1352
- });
1353
- const lines = linesWithFunctionAttributes.map((item) => ({
1354
- merchandiseId: item.variant?.id || "",
1355
- quantity: item.quantity || 1,
1356
- attributes: item.attributes,
1357
- sellingPlanId: item.sellingPlanId
1358
- })).filter((item) => item.merchandiseId);
1359
- if (lines.length === 0) {
1360
- return;
1361
- }
1362
- const resultCart = await createCart(client, {
1363
- lines,
1364
- metafieldIdentifiers,
1365
- cookieAdapter: cartCookieAdapter,
1366
- buyerIdentity,
1367
- discountCodes,
1368
- customAttributes
1369
- });
1370
- if (!resultCart) {
1371
- throw new Error("Failed to create cart for buy now");
1372
- }
1373
- if (withTrack && resultCart.lineItems) {
1374
- trackBuyNowGA({
1375
- lineItems,
1376
- gtmParams: { ...gtmParams, brand: config.getBrand() }
1377
- });
1378
- if (fbqTrackConfig) {
1379
- trackBuyNowFBQ({ trackConfig: fbqTrackConfig });
1380
- }
1381
- }
1382
- if (redirectToCheckout) {
1383
- if (resultCart.url) {
1384
- if (typeof window !== "undefined") {
1385
- window.location.href = resultCart.url;
1386
- }
1387
- } else {
1388
- throw new Error("Failed to get checkout URL");
1389
- }
1390
- }
1391
- return resultCart;
1392
- },
1393
- [client, locale, isLoggedIn, cartCookieAdapter, withTrack]
1394
- );
1395
- return useSWRMutation("buy-now", buyNow, swrOptions);
1396
- }
1397
1149
  function useCalcGiftsFromLines({
1398
1150
  lines,
1399
1151
  customer,
@@ -1565,47 +1317,6 @@ var useCalcOrderDiscount = (cart, orderDiscountConfig, customer) => {
1565
1317
  isLoading: isCustomerLoading
1566
1318
  };
1567
1319
  };
1568
- function hasPlusMemberInCart({
1569
- memberSetting,
1570
- cart
1571
- }) {
1572
- const { plus_monthly_product, plus_annual_product } = memberSetting || {};
1573
- if (!cart?.lineItems) {
1574
- return {
1575
- hasPlusMember: false,
1576
- hasMonthlyPlus: false,
1577
- hasAnnualPlus: false
1578
- };
1579
- }
1580
- const monthlyPlusItem = cart.lineItems.find(
1581
- (item) => item.product?.handle === plus_monthly_product?.handle && item.variant?.sku === plus_monthly_product?.sku
1582
- );
1583
- const annualPlusItem = cart.lineItems.find(
1584
- (item) => item.product?.handle === plus_annual_product?.handle && item.variant?.sku === plus_annual_product?.sku
1585
- );
1586
- const hasMonthlyPlus = !!monthlyPlusItem;
1587
- const hasAnnualPlus = !!annualPlusItem;
1588
- const hasPlusMember = hasMonthlyPlus || hasAnnualPlus;
1589
- return {
1590
- hasPlusMember,
1591
- hasMonthlyPlus,
1592
- hasAnnualPlus,
1593
- monthlyPlusItem,
1594
- annualPlusItem
1595
- };
1596
- }
1597
- function useHasPlusMemberInCart({
1598
- memberSetting,
1599
- cart
1600
- }) {
1601
- return useMemo(
1602
- () => hasPlusMemberInCart({
1603
- memberSetting,
1604
- cart
1605
- }),
1606
- [memberSetting, cart]
1607
- );
1608
- }
1609
1320
  var getReferralAttributes = () => {
1610
1321
  const inviteCode = getLocalStorage("inviteCode") || Cookies5.get("inviteCode");
1611
1322
  const playModeId = getLocalStorage("playModeId") || Cookies5.get("playModeId");
@@ -1622,158 +1333,130 @@ var getReferralAttributes = () => {
1622
1333
  }
1623
1334
  return [];
1624
1335
  };
1336
+ var getUserType = (customer) => {
1337
+ let userInfo = Cookies5.get("userInfo");
1338
+ if (userInfo) {
1339
+ userInfo = JSON.parse(userInfo);
1340
+ let arr = typeof userInfo?.id == "string" && userInfo?.id.split("/");
1341
+ userInfo.setId = arr[arr.length - 1];
1342
+ }
1343
+ const customerInfo = userInfo || customer;
1344
+ if (!customerInfo) {
1345
+ return "new_user_unlogin";
1346
+ }
1347
+ if (customer) {
1348
+ const { orders = {} } = customer;
1349
+ if (orders?.edges?.length === 1) {
1350
+ return "old_user_orders_once";
1351
+ } else if (orders?.edges?.length > 1) {
1352
+ return "old_user_orders_twice";
1353
+ }
1354
+ }
1355
+ return "new_user_login";
1356
+ };
1357
+ function getCartAttributes({
1358
+ profile,
1359
+ customer,
1360
+ cart,
1361
+ memberType,
1362
+ currentUrl = ""
1363
+ }) {
1364
+ const userType = getUserType(customer);
1365
+ const memberAttributes = [
1366
+ {
1367
+ key: "_token",
1368
+ value: profile?.token
1369
+ },
1370
+ {
1371
+ key: "_member_type",
1372
+ value: memberType ?? String(profile?.memberType)
1373
+ },
1374
+ {
1375
+ key: "_user_type",
1376
+ value: userType
1377
+ },
1378
+ {
1379
+ key: "_is_login",
1380
+ value: profile?.token ? "true" : "false"
1381
+ }
1382
+ ];
1383
+ if (profile?.token) {
1384
+ memberAttributes.push({
1385
+ key: "_login_user",
1386
+ value: "1"
1387
+ });
1388
+ }
1389
+ const discountCodes = cart?.discountCodes.map((item) => item.code).filter((code) => code) || [];
1390
+ const functionAttributes = [
1391
+ {
1392
+ key: CUSTOMER_ATTRIBUTE_KEY,
1393
+ value: JSON.stringify({
1394
+ discount_code: discountCodes,
1395
+ user_tags: customer?.tags || []
1396
+ })
1397
+ }
1398
+ ];
1399
+ const presellAttributes = [
1400
+ {
1401
+ key: "_presale",
1402
+ value: cart?.lineItems.some((item) => item?.variant?.metafields?.presell === "presell")
1403
+ }
1404
+ ];
1405
+ const weightAttributes = [
1406
+ {
1407
+ key: "_weight",
1408
+ value: cart?.lineItems.reduce((acc, item) => {
1409
+ return new Decimal2(acc).plus(item.variant.weight ?? 0).toNumber();
1410
+ }, 0).toString()
1411
+ },
1412
+ {
1413
+ key: "_app_source_name",
1414
+ value: "dtc"
1415
+ }
1416
+ ];
1417
+ const trackingAttributes = [
1418
+ {
1419
+ key: "utm_params",
1420
+ value: currentUrl
1421
+ }
1422
+ ];
1423
+ const commonAttributes = [
1424
+ ...memberAttributes,
1425
+ ...functionAttributes,
1426
+ ...presellAttributes,
1427
+ ...weightAttributes,
1428
+ ...trackingAttributes,
1429
+ ...getReferralAttributes()
1430
+ ].filter((item) => item?.value);
1431
+ const extraAttributesInCart = cart?.customAttributes?.filter(
1432
+ (item) => !commonAttributes.some((attr) => attr.key === item.key)
1433
+ ) || [];
1434
+ return [...commonAttributes, ...extraAttributesInCart].filter((item) => item?.value);
1435
+ }
1625
1436
  var useCartAttributes = ({
1626
1437
  profile,
1627
1438
  customer,
1628
1439
  cart,
1629
- memberSetting
1440
+ memberType
1630
1441
  }) => {
1631
1442
  const [currentUrl, setCurrentUrl] = useState("");
1632
- const { hasPlusMember } = useHasPlusMemberInCart({
1633
- memberSetting,
1634
- cart
1635
- });
1636
1443
  useEffect(() => {
1637
1444
  setCurrentUrl(window.location.href);
1638
1445
  }, []);
1639
- const userType = useMemo(() => {
1640
- let userInfo = Cookies5.get("userInfo");
1641
- if (userInfo) {
1642
- userInfo = JSON.parse(userInfo);
1643
- let arr = typeof userInfo?.id == "string" && userInfo?.id.split("/");
1644
- userInfo.setId = arr[arr.length - 1];
1645
- }
1646
- const customerInfo = userInfo || customer;
1647
- if (!customerInfo) {
1648
- return "new_user_unlogin";
1649
- }
1650
- if (customer) {
1651
- const { orders = {} } = customer;
1652
- if (orders?.edges?.length === 1) {
1653
- return "old_user_orders_once";
1654
- } else if (orders?.edges?.length > 1) {
1655
- return "old_user_orders_twice";
1656
- }
1657
- }
1658
- return "new_user_login";
1659
- }, [customer]);
1660
- const memberAttributes = useMemo(() => {
1661
- const attributes = [
1662
- {
1663
- key: "_token",
1664
- value: profile?.token
1665
- //是否登录
1666
- },
1667
- {
1668
- key: "_member_type",
1669
- value: hasPlusMember ? "2" : profile?.memberType
1670
- //:0(游客),1(普通会员),2(付费会员)
1671
- },
1672
- {
1673
- key: "_user_type",
1674
- value: userType
1675
- // n
1676
- },
1677
- {
1678
- key: "_is_login",
1679
- value: profile?.token ? "true" : "false"
1680
- }
1681
- ];
1682
- if (profile?.token) {
1683
- attributes.push({
1684
- key: "_login_user",
1685
- value: "1"
1686
- });
1687
- }
1688
- return attributes;
1689
- }, [profile?.memberType, profile?.token, userType, hasPlusMember]);
1690
- const functionAttributes = useMemo(() => {
1691
- const hasFunctionEnvAttribute = cart?.lineItems.some(
1692
- (item) => item.customAttributes?.some((attr) => attr.key === CUSTOMER_ATTRIBUTE_KEY)
1693
- );
1694
- const discountCodes = cart?.discountCodes.map((item) => item.code).filter((code) => code) || [];
1695
- return hasFunctionEnvAttribute ? [
1696
- {
1697
- key: "_discounts_function_env",
1698
- value: JSON.stringify({
1699
- discount_code: discountCodes,
1700
- user_tags: customer?.tags || []
1701
- })
1702
- }
1703
- ] : [];
1704
- }, [cart, customer]);
1705
- const presellAttributes = useMemo(() => {
1706
- return [
1707
- {
1708
- key: "_presale",
1709
- value: cart?.lineItems.some((item) => item?.variant?.metafields?.presell === "presell")
1710
- }
1711
- ];
1712
- }, [cart]);
1713
- const weightAttributes = useMemo(() => {
1714
- return [
1715
- {
1716
- key: "_weight",
1717
- value: cart?.lineItems.reduce((acc, item) => {
1718
- return new Decimal2(acc).plus(item.variant.weight ?? 0).toNumber();
1719
- }, 0).toString()
1720
- },
1721
- {
1722
- key: "_app_source_name",
1723
- value: "dtc"
1724
- }
1725
- ];
1726
- }, [cart]);
1727
- const trackingAttributes = useMemo(() => {
1728
- return [
1729
- {
1730
- key: "utm_params",
1731
- value: currentUrl
1732
- }
1733
- ];
1734
- }, [currentUrl]);
1735
- const commonAttributes = useMemo(
1736
- () => [
1737
- ...memberAttributes,
1738
- ...functionAttributes,
1739
- ...presellAttributes,
1740
- ...weightAttributes,
1741
- ...trackingAttributes,
1742
- ...getReferralAttributes()
1743
- ].filter((item) => item?.value),
1744
- [memberAttributes, functionAttributes, presellAttributes, weightAttributes, trackingAttributes]
1745
- );
1746
- const extraAttributesInCart = useMemo(() => {
1747
- const commonAttributeKeys = [
1748
- // member attributes
1749
- "_token",
1750
- "_member_type",
1751
- "_user_type",
1752
- "_is_login",
1753
- "_login_user",
1754
- // function attributes
1755
- "_discounts_function_env",
1756
- // presell attributes
1757
- "_presale",
1758
- // weight attributes
1759
- "_weight",
1760
- "_app_source_name",
1761
- // tracking attributes
1762
- "utm_params",
1763
- // referral attributes
1764
- "_invite_code",
1765
- "_play_mode_id",
1766
- "_popup"
1767
- ];
1768
- return cart?.customAttributes?.filter((item) => !commonAttributeKeys.includes(item.key)) || [];
1769
- }, [cart]);
1446
+ const attributes = useMemo(() => {
1447
+ return getCartAttributes({
1448
+ profile,
1449
+ customer,
1450
+ cart,
1451
+ memberType,
1452
+ currentUrl
1453
+ });
1454
+ }, [profile, customer, cart, memberType, currentUrl]);
1770
1455
  return useMemo(
1771
1456
  () => ({
1772
- attributes: [...commonAttributes, ...extraAttributesInCart].filter(
1773
- (item) => item?.value
1774
- )
1457
+ attributes
1775
1458
  }),
1776
- [commonAttributes, extraAttributesInCart]
1459
+ [attributes]
1777
1460
  );
1778
1461
  };
1779
1462
  var DEFAULT_MIN = 1;
@@ -1925,45 +1608,61 @@ var useUpdateLineCodeAmountAttributes = ({
1925
1608
  }, [loading, setLoadingState]);
1926
1609
  };
1927
1610
 
1928
- // src/hooks/cart/types/price-discount.ts
1929
- var PriceDiscountType = /* @__PURE__ */ ((PriceDiscountType2) => {
1930
- PriceDiscountType2[PriceDiscountType2["PERCENTAGE"] = 1] = "PERCENTAGE";
1931
- PriceDiscountType2[PriceDiscountType2["FIXED_AMOUNT"] = 2] = "FIXED_AMOUNT";
1932
- return PriceDiscountType2;
1933
- })(PriceDiscountType || {});
1934
- var PriceBasePriceType = /* @__PURE__ */ ((PriceBasePriceType2) => {
1935
- PriceBasePriceType2[PriceBasePriceType2["MIN_DISCOUNTED_PRICE"] = 1] = "MIN_DISCOUNTED_PRICE";
1936
- PriceBasePriceType2[PriceBasePriceType2["MIN_TOTAL_PRICE"] = 2] = "MIN_TOTAL_PRICE";
1937
- return PriceBasePriceType2;
1938
- })(PriceBasePriceType || {});
1939
- function useProduct(options = {}) {
1940
- const { client, locale } = useShopify();
1941
- const { handle, metafieldIdentifiers, ...swrOptions } = options;
1942
- return useSWR(
1943
- handle ? ["product", locale, handle, metafieldIdentifiers] : null,
1944
- () => getProduct(client, {
1945
- handle,
1946
- locale,
1947
- metafieldIdentifiers
1948
- }),
1949
- swrOptions
1950
- );
1951
- }
1952
- function useAllProducts(options = {}) {
1953
- const { client, locale } = useShopify();
1954
- const { first, query, sortKey, reverse, metafieldIdentifiers, ...swrOptions } = options;
1955
- return useSWR(
1956
- ["all-products", locale, first, query, sortKey, reverse, metafieldIdentifiers],
1957
- () => getAllProducts(client, {
1958
- locale,
1959
- first,
1960
- query,
1961
- sortKey,
1962
- reverse,
1963
- metafieldIdentifiers
1964
- }),
1965
- swrOptions
1966
- );
1611
+ // src/hooks/member/plus/types.ts
1612
+ var PLUS_MEMBER_TYPE = /* @__PURE__ */ ((PLUS_MEMBER_TYPE2) => {
1613
+ PLUS_MEMBER_TYPE2[PLUS_MEMBER_TYPE2["FREE"] = 0] = "FREE";
1614
+ PLUS_MEMBER_TYPE2[PLUS_MEMBER_TYPE2["MONTHLY"] = 1] = "MONTHLY";
1615
+ PLUS_MEMBER_TYPE2[PLUS_MEMBER_TYPE2["ANNUAL"] = 2] = "ANNUAL";
1616
+ return PLUS_MEMBER_TYPE2;
1617
+ })(PLUS_MEMBER_TYPE || {});
1618
+ var PlusMemberMode = /* @__PURE__ */ ((PlusMemberMode2) => {
1619
+ PlusMemberMode2["MONTHLY"] = "monthly";
1620
+ PlusMemberMode2["ANNUAL"] = "annual";
1621
+ return PlusMemberMode2;
1622
+ })(PlusMemberMode || {});
1623
+ var DeliveryPlusType = /* @__PURE__ */ ((DeliveryPlusType2) => {
1624
+ DeliveryPlusType2["FREE"] = "free";
1625
+ DeliveryPlusType2["MONTHLY"] = "monthly";
1626
+ DeliveryPlusType2["ANNUAL"] = "annual";
1627
+ return DeliveryPlusType2;
1628
+ })(DeliveryPlusType || {});
1629
+ var ShippingMethodMode = /* @__PURE__ */ ((ShippingMethodMode2) => {
1630
+ ShippingMethodMode2["FREE"] = "free";
1631
+ ShippingMethodMode2["TDD"] = "tdd";
1632
+ ShippingMethodMode2["NDD"] = "ndd";
1633
+ return ShippingMethodMode2;
1634
+ })(ShippingMethodMode || {});
1635
+ var createInitialValue = () => ({
1636
+ plusMemberMetafields: {},
1637
+ selectedPlusMemberMode: "free",
1638
+ setSelectedPlusMemberMode: () => {
1639
+ },
1640
+ selectedShippingMethod: void 0,
1641
+ setSelectedShippingMethod: () => {
1642
+ },
1643
+ showMoreShippingMethod: false,
1644
+ setShowMoreShippingMethod: () => {
1645
+ },
1646
+ variant: {},
1647
+ product: {},
1648
+ shippingMethodsContext: {
1649
+ freeShippingMethods: [],
1650
+ paymentShippingMethods: [],
1651
+ nddOverweight: false,
1652
+ tddOverweight: false,
1653
+ nddCoupon: void 0,
1654
+ tddCoupon: void 0,
1655
+ isLoadingCoupon: false
1656
+ },
1657
+ selectedPlusMemberVariant: void 0,
1658
+ showPlusMemberBenefit: false,
1659
+ setShowPlusMemberBenefit: () => {
1660
+ },
1661
+ profile: void 0
1662
+ });
1663
+ var PlusMemberContext = createContext(createInitialValue());
1664
+ function usePlusMemberContext() {
1665
+ return useContext(PlusMemberContext);
1967
1666
  }
1968
1667
  function useProductsByHandles(options = {}) {
1969
1668
  const { client, locale } = useShopify();
@@ -1989,994 +1688,1344 @@ function useProductsByHandles(options = {}) {
1989
1688
  }
1990
1689
  );
1991
1690
  }
1992
- function getFirstAvailableVariant(product) {
1993
- const availableVariant = product.variants.find((v) => v.availableForSale);
1994
- return availableVariant || product.variants[0];
1995
- }
1996
- function getVariantFromSelectedOptions(product, selectedOptions) {
1997
- return product.variants.find((variant) => {
1998
- return variant.selectedOptions.every((option) => {
1999
- return selectedOptions[option.name] === option.value;
2000
- });
1691
+
1692
+ // src/hooks/member/plus/use-plus-member-variants.ts
1693
+ function usePlusMemberVariants({
1694
+ memberSetting
1695
+ }) {
1696
+ const plusMonthly = memberSetting?.plus_monthly_product;
1697
+ const plusAnnual = memberSetting?.plus_annual_product;
1698
+ const plusMemberHandles = useMemo(() => {
1699
+ return [plusMonthly?.handle, plusAnnual?.handle].filter(Boolean);
1700
+ }, [plusMonthly?.handle, plusAnnual?.handle]);
1701
+ const { data: plusMemberProducts = [] } = useProductsByHandles({
1702
+ handles: plusMemberHandles
2001
1703
  });
1704
+ const monthlyProduct = useMemo(() => {
1705
+ return plusMemberProducts?.find((item) => item?.handle === plusMonthly?.handle);
1706
+ }, [plusMemberProducts, plusMonthly]);
1707
+ const annualProduct = useMemo(() => {
1708
+ return plusMemberProducts?.find((item) => item?.handle === plusAnnual?.handle);
1709
+ }, [plusMemberProducts, plusAnnual]);
1710
+ const monthlyVariant = useMemo(() => {
1711
+ return monthlyProduct?.variants?.find((item) => item.sku === plusMonthly?.sku);
1712
+ }, [monthlyProduct, plusMonthly]);
1713
+ const annualVariant = useMemo(() => {
1714
+ return annualProduct?.variants?.find((item) => item.sku === plusAnnual?.sku);
1715
+ }, [annualProduct, plusAnnual]);
1716
+ return {
1717
+ monthlyVariant: monthlyVariant ? {
1718
+ ...monthlyVariant,
1719
+ product: monthlyProduct
1720
+ } : void 0,
1721
+ annualVariant: annualVariant ? {
1722
+ ...annualVariant,
1723
+ product: annualProduct
1724
+ } : void 0
1725
+ };
2002
1726
  }
2003
- function useVariant({
2004
- product,
2005
- selectedOptions
2006
- }) {
2007
- const [variant, setVariant] = useState(
2008
- product ? getFirstAvailableVariant(product) : void 0
2009
- );
2010
- useEffect(() => {
2011
- if (!product) {
2012
- setVariant(void 0);
2013
- return;
2014
- }
2015
- const newVariant = getVariantFromSelectedOptions(product, selectedOptions);
2016
- if (newVariant && newVariant.id !== variant?.id) {
2017
- setVariant(newVariant);
2018
- } else if (!newVariant) {
2019
- setVariant(getFirstAvailableVariant(product));
1727
+ var useAvailableDeliveryCoupon = ({
1728
+ profile
1729
+ }) => {
1730
+ const { data: availableDeliveryCoupon, isLoading } = useSWR(
1731
+ profile?.email ? ["/api/multipass/subsrv/v1/prime/delivery_coupons/current/available", profile?.email] : void 0,
1732
+ async ([apiPath]) => {
1733
+ return fetch(apiPath).then((res) => res.json());
2020
1734
  }
2021
- }, [selectedOptions, product, variant?.id]);
2022
- return variant;
2023
- }
2024
- var FAKE_PRICE = 999999999e-2;
2025
- function formatPrice({
2026
- amount,
2027
- currencyCode,
2028
- locale,
2029
- maximumFractionDigits,
2030
- minimumFractionDigits,
2031
- removeTrailingZeros
2032
- }) {
2033
- const formatter = new Intl.NumberFormat(locale, {
2034
- style: "currency",
2035
- currency: currencyCode,
2036
- maximumFractionDigits: maximumFractionDigits ?? 2,
2037
- minimumFractionDigits: minimumFractionDigits ?? 2
2038
- });
2039
- let formatted = formatter.format(amount);
2040
- if (removeTrailingZeros) {
2041
- formatted = formatted.replace(/\.00$/, "");
2042
- }
2043
- return formatted;
2044
- }
2045
- function formatVariantPrice({
2046
- amount,
2047
- baseAmount,
2048
- currencyCode,
2049
- locale,
2050
- maximumFractionDigits,
2051
- minimumFractionDigits,
2052
- removeTrailingZeros
2053
- }) {
1735
+ );
1736
+ console.log("availableDeliveryCoupon", availableDeliveryCoupon);
1737
+ const { ndd_coupon: nddCoupon, tdd_coupon: tddCoupon } = availableDeliveryCoupon?.data?.data || {};
2054
1738
  return {
2055
- price: formatPrice({
2056
- amount,
2057
- currencyCode,
2058
- locale,
2059
- maximumFractionDigits,
2060
- minimumFractionDigits,
2061
- removeTrailingZeros
2062
- }),
2063
- basePrice: formatPrice({
2064
- amount: baseAmount,
2065
- currencyCode,
2066
- locale,
2067
- maximumFractionDigits,
2068
- minimumFractionDigits,
2069
- removeTrailingZeros
2070
- })
1739
+ nddCoupon,
1740
+ tddCoupon,
1741
+ isLoading
2071
1742
  };
2072
- }
2073
- function usePrice({
2074
- amount,
2075
- baseAmount,
2076
- currencyCode,
2077
- soldOutDescription = "",
2078
- maximumFractionDigits,
2079
- minimumFractionDigits,
2080
- removeTrailingZeros
2081
- }) {
2082
- const { locale } = useShopify();
2083
- const value = useMemo(() => {
2084
- if (typeof amount !== "number" || !currencyCode) {
2085
- return "";
2086
- }
2087
- if (soldOutDescription && amount >= FAKE_PRICE) {
2088
- return soldOutDescription;
2089
- }
2090
- return baseAmount ? formatVariantPrice({
2091
- amount,
2092
- baseAmount,
2093
- currencyCode,
2094
- locale,
2095
- maximumFractionDigits,
2096
- minimumFractionDigits,
2097
- removeTrailingZeros
2098
- }) : formatPrice({
2099
- amount,
2100
- currencyCode,
2101
- locale,
2102
- maximumFractionDigits,
2103
- minimumFractionDigits,
2104
- removeTrailingZeros
1743
+ };
1744
+
1745
+ // src/hooks/member/plus/use-shipping-methods.ts
1746
+ function useShippingMethods(options) {
1747
+ const { variant, plusMemberMetafields, selectedPlusMemberMode, profile } = options;
1748
+ const isPlus = profile?.isPlus || false;
1749
+ const { nddCoupon, tddCoupon, isLoading } = useAvailableDeliveryCoupon({ profile });
1750
+ const { plus_shipping, shippingMethod } = plusMemberMetafields || {};
1751
+ const nddOverweight = useMemo(() => {
1752
+ return (variant?.weight || 0) > (shippingMethod?.overWeight_ndd || Infinity);
1753
+ }, [shippingMethod?.overWeight_ndd, variant?.weight]);
1754
+ const tddOverweight = useMemo(() => {
1755
+ return (variant?.weight || 0) > (shippingMethod?.overWeight_tdd || Infinity);
1756
+ }, [shippingMethod?.overWeight_tdd, variant?.weight]);
1757
+ const paymentShippingMethods = useMemo(() => {
1758
+ const weight = variant?.weight || 0;
1759
+ const methods = plus_shipping?.shipping_methods?.filter(({ weight_low, weight_high, __mode, __plus }) => {
1760
+ const fitWeight = (!weight_low || weight >= weight_low) && (!weight_high || weight <= weight_high);
1761
+ return __mode !== "free" /* FREE */ && !__plus && fitWeight;
1762
+ }) || [];
1763
+ return methods.map((method) => {
1764
+ let disabled = false;
1765
+ const selectedFreeMember = selectedPlusMemberMode === "free";
1766
+ if (method.__mode === "ndd" /* NDD */) {
1767
+ disabled = selectedFreeMember || nddOverweight;
1768
+ } else if (method.__mode === "tdd" /* TDD */) {
1769
+ disabled = selectedFreeMember || tddOverweight;
1770
+ }
1771
+ return {
1772
+ ...method,
1773
+ id: method.__mode + method.__code,
1774
+ useCoupon: false,
1775
+ subtitle: plus_shipping?.directly || "",
1776
+ disabled
1777
+ };
2105
1778
  });
2106
1779
  }, [
2107
- amount,
2108
- baseAmount,
2109
- currencyCode,
2110
- locale,
2111
- maximumFractionDigits,
2112
- minimumFractionDigits,
2113
- soldOutDescription,
2114
- removeTrailingZeros
1780
+ nddOverweight,
1781
+ plus_shipping?.directly,
1782
+ plus_shipping?.shipping_methods,
1783
+ selectedPlusMemberMode,
1784
+ tddOverweight,
1785
+ variant?.weight
2115
1786
  ]);
2116
- const result = useMemo(() => {
2117
- const free = Boolean(amount && amount <= 0);
2118
- return typeof value === "string" ? { price: value, basePrice: value, free } : { ...value, free };
2119
- }, [value, amount]);
2120
- return result;
2121
- }
2122
- function optionsConstructor(selectedOptions) {
2123
- return selectedOptions.reduce((acc, option) => {
2124
- acc[option.name] = option.value;
2125
- return acc;
2126
- }, {});
2127
- }
2128
- function decodeShopifyId(gid) {
2129
- try {
2130
- const base64 = gid.split("/").pop() || "";
2131
- return atob(base64);
2132
- } catch {
2133
- return gid;
2134
- }
2135
- }
2136
- function useSelectedOptions(product, sku) {
2137
- const [options, setOptions] = useState({});
2138
- useEffect(() => {
2139
- if (!product || !product.variants.length) {
2140
- setOptions({});
2141
- return;
1787
+ const nddPrice = useMemo(() => {
1788
+ const weight = variant?.weight || 0;
1789
+ const nddMethod = paymentShippingMethods.find(({ __mode, weight_high, weight_low }) => {
1790
+ const fitWeight = (!weight_low || weight >= weight_low) && (!weight_high || weight <= weight_high);
1791
+ return __mode === "ndd" && fitWeight;
1792
+ });
1793
+ return nddMethod?.price || 0;
1794
+ }, [variant?.weight, paymentShippingMethods]);
1795
+ const tddPrice = useMemo(() => {
1796
+ const weight = variant?.weight || 0;
1797
+ const tddMethod = paymentShippingMethods.find(({ __mode, weight_high, weight_low }) => {
1798
+ const fitWeight = (!weight_low || weight >= weight_low) && (!weight_high || weight <= weight_high);
1799
+ return __mode === "tdd" && fitWeight;
1800
+ });
1801
+ return tddMethod?.price || 0;
1802
+ }, [variant?.weight, paymentShippingMethods]);
1803
+ const freeShippingMethods = useMemo(() => {
1804
+ const weight = variant?.weight || 0;
1805
+ let methods = plus_shipping?.shipping_methods?.filter(({ __mode, __plus, weight_low, weight_high }) => {
1806
+ if (__mode === "free" /* FREE */) {
1807
+ return true;
1808
+ }
1809
+ if (isPlus) {
1810
+ const hasCoupon = isPlus && __mode === "ndd" /* NDD */ && nddCoupon || isPlus && __mode === "tdd" /* TDD */ && (tddCoupon || nddCoupon);
1811
+ const fitWeight = (!weight_low || weight >= weight_low) && (!weight_high || weight <= weight_high);
1812
+ return hasCoupon && fitWeight && !__plus;
1813
+ } else {
1814
+ return __plus;
1815
+ }
1816
+ }) || [];
1817
+ if (isPlus) {
1818
+ methods = methods.sort((a, b) => {
1819
+ if (b.__mode === "free" /* FREE */) return -1;
1820
+ return 0;
1821
+ });
2142
1822
  }
2143
- let variant = product.variants[0];
2144
- if (typeof window !== "undefined") {
2145
- const searchParams = new URLSearchParams(window.location.search);
2146
- const variantIdParam = searchParams.get("variant");
2147
- if (variantIdParam) {
2148
- const foundVariant = product.variants.find((v) => {
2149
- if (sku) return v.sku === sku;
2150
- return v.id === variantIdParam || v.id.includes(variantIdParam) || decodeShopifyId(v.id) === variantIdParam;
2151
- });
2152
- if (foundVariant) {
2153
- variant = foundVariant;
1823
+ return methods.map((method) => {
1824
+ let price = 0;
1825
+ let coupon;
1826
+ let disabled;
1827
+ if (method.__mode !== "free" /* FREE */) {
1828
+ switch (method.__mode) {
1829
+ case "tdd":
1830
+ price = tddPrice;
1831
+ coupon = tddCoupon || nddCoupon;
1832
+ break;
1833
+ case "ndd":
1834
+ price = nddPrice;
1835
+ coupon = nddCoupon;
1836
+ break;
1837
+ }
1838
+ disabled = selectedPlusMemberMode === "free";
1839
+ if (method.__mode === "ndd" /* NDD */) {
1840
+ disabled = disabled || nddOverweight;
1841
+ } else if (method.__mode === "tdd" /* TDD */) {
1842
+ disabled = disabled || tddOverweight;
2154
1843
  }
2155
1844
  }
2156
- }
2157
- if (variant) {
2158
- const newOptions = optionsConstructor(variant.selectedOptions);
2159
- setOptions(newOptions);
2160
- }
2161
- }, [product, sku]);
2162
- return [options, setOptions];
2163
- }
2164
- function decodeShopifyId2(gid) {
2165
- try {
2166
- const parts = gid.split("/");
2167
- return parts[parts.length - 1] || gid;
2168
- } catch {
2169
- return gid;
2170
- }
1845
+ return {
1846
+ ...method,
1847
+ id: method.__mode + method.__code,
1848
+ useCoupon: true,
1849
+ disabled,
1850
+ coupon,
1851
+ price
1852
+ };
1853
+ });
1854
+ }, [
1855
+ variant?.weight,
1856
+ plus_shipping?.shipping_methods,
1857
+ isPlus,
1858
+ nddCoupon,
1859
+ tddCoupon,
1860
+ selectedPlusMemberMode,
1861
+ tddPrice,
1862
+ nddPrice,
1863
+ nddOverweight,
1864
+ tddOverweight
1865
+ ]);
1866
+ return {
1867
+ freeShippingMethods,
1868
+ paymentShippingMethods,
1869
+ nddOverweight,
1870
+ tddOverweight,
1871
+ nddCoupon,
1872
+ tddCoupon,
1873
+ isLoadingCoupon: isLoading
1874
+ };
2171
1875
  }
2172
- function useProductUrl(otherQuery) {
2173
- const { routerAdapter } = useShopify();
2174
- return useCallback(
2175
- ({ product, variant }) => {
2176
- if (!product) return "";
2177
- const queryParams = new URLSearchParams();
2178
- if (variant?.id) {
2179
- const variantId = decodeShopifyId2(variant.id);
2180
- if (variantId) {
2181
- queryParams.set("variant", variantId);
2182
- }
1876
+ var useReplaceCartPlusMember = () => {
1877
+ const { plusMemberMetafields, selectedPlusMemberMode } = usePlusMemberContext();
1878
+ const { trigger: removeCartLines2 } = useRemoveCartLines();
1879
+ const { cart } = useCartContext();
1880
+ const plusMonthly = plusMemberMetafields?.plus_monthly_product;
1881
+ const plusAnnual = plusMemberMetafields?.plus_annual_product;
1882
+ const handler = useCallback(async () => {
1883
+ const plusMonthlyInCart = cart?.lineItems.find(
1884
+ (item) => item.variant?.sku === plusMonthly?.sku
1885
+ );
1886
+ const plusAnnualInCart = cart?.lineItems.find(
1887
+ (item) => item.variant?.sku === plusAnnual?.sku
1888
+ );
1889
+ if (selectedPlusMemberMode === "annual" /* ANNUAL */ && plusMonthlyInCart) {
1890
+ await removeCartLines2({
1891
+ lineIds: [plusMonthlyInCart.id]
1892
+ });
1893
+ } else if (selectedPlusMemberMode === "monthly" /* MONTHLY */ && plusAnnualInCart) {
1894
+ await removeCartLines2({
1895
+ lineIds: [plusAnnualInCart.id]
1896
+ });
1897
+ }
1898
+ }, [
1899
+ cart?.lineItems,
1900
+ selectedPlusMemberMode,
1901
+ plusMonthly?.sku,
1902
+ plusAnnual?.sku,
1903
+ removeCartLines2
1904
+ ]);
1905
+ return handler;
1906
+ };
1907
+ var usePlusMemberCheckoutCustomAttributes = ({
1908
+ disableShipping = false,
1909
+ isPresaleContains = false
1910
+ }) => {
1911
+ const { profile, selectedShippingMethod, selectedPlusMemberMode } = usePlusMemberContext();
1912
+ return useMemo(() => {
1913
+ const checkoutCustomAttributes = [
1914
+ {
1915
+ key: "_last_url",
1916
+ value: typeof window !== "undefined" ? window.location.origin + window.location.pathname : ""
2183
1917
  }
2184
- if (otherQuery) {
2185
- Object.entries(otherQuery).forEach(([key, value]) => {
2186
- queryParams.set(key, value);
2187
- });
1918
+ ];
1919
+ checkoutCustomAttributes.push({
1920
+ key: "_checkout_delivery_custom",
1921
+ value: JSON.stringify({
1922
+ allow_nextday_delivery: true,
1923
+ allow_thirdday_delivery: true,
1924
+ selected_delivery_option: {
1925
+ code: selectedShippingMethod?.__code,
1926
+ mode: selectedShippingMethod?.__mode
1927
+ },
1928
+ is_presale: isPresaleContains,
1929
+ discount_code: selectedShippingMethod?.coupon ? [selectedShippingMethod.coupon] : [],
1930
+ plus_type: profile?.isPlus ? "free" /* FREE */ : selectedPlusMemberMode,
1931
+ is_prime: profile?.isPlus
1932
+ })
1933
+ });
1934
+ if (disableShipping) {
1935
+ checkoutCustomAttributes.push({
1936
+ key: "_hide_shipping",
1937
+ value: "true"
1938
+ });
1939
+ }
1940
+ return checkoutCustomAttributes;
1941
+ }, [profile, selectedShippingMethod, selectedPlusMemberMode, isPresaleContains]);
1942
+ };
1943
+ function useRemoveCartLines(options) {
1944
+ const { client, locale, cartCookieAdapter } = useShopify();
1945
+ const { mutateCart, metafieldIdentifiers } = useCartContext();
1946
+ const removeLines = useCallback(
1947
+ async (_key, { arg }) => {
1948
+ const { autoRemoveInvalidCodes = true, onCodesRemoved, cartId, lineIds } = arg;
1949
+ let updatedCart = await removeCartLines(client, {
1950
+ cartId,
1951
+ lineIds,
1952
+ metafieldIdentifiers,
1953
+ cookieAdapter: cartCookieAdapter
1954
+ });
1955
+ if (updatedCart && autoRemoveInvalidCodes) {
1956
+ const unApplicableCodes = updatedCart.discountCodes.filter((item) => !item.applicable).map((item) => item.code);
1957
+ if (unApplicableCodes.length > 0) {
1958
+ if (onCodesRemoved) {
1959
+ const handledCart = await onCodesRemoved(updatedCart, unApplicableCodes);
1960
+ if (handledCart) {
1961
+ updatedCart = handledCart;
1962
+ }
1963
+ } else {
1964
+ updatedCart = await updateCartCodes(client, {
1965
+ cartId: updatedCart.id,
1966
+ discountCodes: updatedCart.discountCodes.filter((item) => item.applicable).map((item) => item.code),
1967
+ metafieldIdentifiers,
1968
+ cookieAdapter: cartCookieAdapter
1969
+ }) || updatedCart;
1970
+ }
1971
+ }
2188
1972
  }
2189
- const queryString = queryParams.toString();
2190
- const path = `/products/${product.handle}${queryString ? `?${queryString}` : ""}`;
2191
- if (routerAdapter?.getLocalizedPath) {
2192
- return routerAdapter.getLocalizedPath(path);
1973
+ if (updatedCart) {
1974
+ mutateCart(updatedCart);
2193
1975
  }
2194
- return path;
1976
+ return updatedCart;
2195
1977
  },
2196
- [routerAdapter, otherQuery]
1978
+ [client, locale, cartCookieAdapter, mutateCart, metafieldIdentifiers]
2197
1979
  );
1980
+ return useSWRMutation("remove-cart-lines", removeLines, options);
2198
1981
  }
2199
- function decodeShopifyId3(gid) {
2200
- try {
2201
- const parts = gid.split("/");
2202
- return parts[parts.length - 1] || gid;
2203
- } catch {
2204
- return gid;
2205
- }
2206
- }
2207
- function useUpdateVariantQuery(variant) {
1982
+
1983
+ // src/hooks/member/plus/use-auto-remove-plus-member-in-cart.ts
1984
+ function useAutoRemovePlusMemberInCart({
1985
+ cart,
1986
+ profile,
1987
+ memberSetting
1988
+ }) {
1989
+ const { plus_monthly_product, plus_annual_product } = memberSetting || {};
1990
+ const { trigger: removeCartLines2 } = useRemoveCartLines();
2208
1991
  useEffect(() => {
2209
- if (!variant || typeof window === "undefined") {
2210
- return;
1992
+ if (!cart || !plus_monthly_product || !plus_annual_product) return;
1993
+ const removePlusProduct = async (productType) => {
1994
+ if (!productType) return;
1995
+ const product = cart.lineItems?.find(
1996
+ (item) => item.product?.handle === productType?.handle && item.variant?.sku === productType?.sku
1997
+ );
1998
+ if (product) {
1999
+ await removeCartLines2({
2000
+ lineIds: [product.id]
2001
+ });
2002
+ }
2003
+ };
2004
+ if (profile?.isMonthlyPlus) {
2005
+ removePlusProduct(plus_monthly_product);
2211
2006
  }
2212
- const searchParams = new URLSearchParams(window.location.search);
2213
- const currentVariantId = searchParams.get("variant");
2214
- const newVariantId = decodeShopifyId3(variant.id);
2215
- if (newVariantId && currentVariantId !== newVariantId) {
2216
- searchParams.set("variant", newVariantId);
2217
- const newUrl = `${window.location.pathname}?${searchParams.toString()}${window.location.hash}`;
2218
- window.history.replaceState({}, "", newUrl);
2007
+ if (profile?.isAnnualPlus) {
2008
+ removePlusProduct(plus_annual_product);
2219
2009
  }
2220
- }, [variant]);
2010
+ }, [cart, plus_annual_product, plus_monthly_product, profile, removeCartLines2]);
2221
2011
  }
2222
- function getVariantMediaList({
2223
- product,
2224
- variant
2012
+ function hasPlusMemberInCart({
2013
+ memberSetting,
2014
+ cart
2225
2015
  }) {
2226
- if (variant.image?.url) {
2227
- const variantMediaId = variant.image.url;
2228
- const variantMedia = product.media.filter((media) => {
2229
- if (media.mediaContentType === "IMAGE" && media.previewImage) {
2230
- return media.previewImage?.url === variantMediaId;
2231
- }
2232
- return false;
2233
- });
2234
- if (variantMedia.length > 0) {
2235
- const otherMedia = product.media.filter((media) => {
2236
- if (media.mediaContentType === "IMAGE" && media.previewImage) {
2237
- return media.previewImage.url !== variantMediaId;
2238
- }
2239
- return true;
2240
- });
2241
- return [...variantMedia, ...otherMedia];
2242
- }
2016
+ const { plus_monthly_product, plus_annual_product } = memberSetting || {};
2017
+ if (!cart?.lineItems) {
2018
+ return {
2019
+ hasPlusMember: false,
2020
+ hasMonthlyPlus: false,
2021
+ hasAnnualPlus: false
2022
+ };
2243
2023
  }
2244
- return product.media;
2024
+ const monthlyPlusItem = cart.lineItems.find(
2025
+ (item) => item.product?.handle === plus_monthly_product?.handle && item.variant?.sku === plus_monthly_product?.sku
2026
+ );
2027
+ const annualPlusItem = cart.lineItems.find(
2028
+ (item) => item.product?.handle === plus_annual_product?.handle && item.variant?.sku === plus_annual_product?.sku
2029
+ );
2030
+ const hasMonthlyPlus = !!monthlyPlusItem;
2031
+ const hasAnnualPlus = !!annualPlusItem;
2032
+ const hasPlusMember = hasMonthlyPlus || hasAnnualPlus;
2033
+ return {
2034
+ hasPlusMember,
2035
+ hasMonthlyPlus,
2036
+ hasAnnualPlus,
2037
+ monthlyPlusItem,
2038
+ annualPlusItem
2039
+ };
2245
2040
  }
2246
- function useVariantMedia({
2247
- product,
2248
- variant
2041
+ function useHasPlusMemberInCart({
2042
+ memberSetting,
2043
+ cart
2249
2044
  }) {
2250
- const [imageList, setImageList] = useState([]);
2251
- const [sceneList, setSceneList] = useState([]);
2252
- const [videoList, setVideoList] = useState([]);
2253
- useEffect(() => {
2254
- if (!product || !variant) {
2255
- setImageList([]);
2256
- setSceneList([]);
2257
- setVideoList([]);
2258
- return;
2259
- }
2260
- const mediaList = getVariantMediaList({ product, variant });
2261
- const images = mediaList.filter((media) => media.mediaContentType === "IMAGE");
2262
- const videos = mediaList.filter(
2263
- (media) => media.mediaContentType === "VIDEO" || media.mediaContentType === "EXTERNAL_VIDEO"
2264
- );
2265
- setImageList(images.length > 0 && images[0] ? [images[0]] : []);
2266
- setSceneList(images.length > 1 ? images.slice(1) : []);
2267
- setVideoList(videos);
2268
- }, [product, variant]);
2269
- return {
2270
- productList: imageList,
2271
- sceneList,
2272
- videoList
2273
- };
2274
- }
2275
- function useCollection(options = {}) {
2276
- const { client, locale } = useShopify();
2277
- const { handle, metafieldIdentifiers, ...swrOptions } = options;
2278
- return useSWR(
2279
- handle ? ["collection", locale, handle, metafieldIdentifiers] : null,
2280
- () => getCollection(client, {
2281
- handle,
2282
- locale,
2283
- metafieldIdentifiers
2284
- }),
2285
- swrOptions
2286
- );
2287
- }
2288
- function useAllCollections(options = {}) {
2289
- const { client, locale } = useShopify();
2290
- const { first, query, sortKey, reverse, metafieldIdentifiers, ...swrOptions } = options;
2291
- return useSWR(
2292
- ["all-collections", locale, first, query, sortKey, reverse, metafieldIdentifiers],
2293
- () => getAllCollections(client, {
2294
- locale,
2295
- first,
2296
- query,
2297
- sortKey,
2298
- reverse,
2299
- metafieldIdentifiers
2300
- }),
2301
- swrOptions
2302
- );
2303
- }
2304
- function useCollections(options = {}) {
2305
- const { client, locale } = useShopify();
2306
- const { first, after, query, sortKey, reverse, metafieldIdentifiers, ...swrOptions } = options;
2307
- return useSWR(
2308
- ["collections", locale, first, after, query, sortKey, reverse, metafieldIdentifiers],
2309
- () => getCollections(client, {
2310
- locale,
2311
- first,
2312
- after,
2313
- query,
2314
- sortKey,
2315
- reverse,
2316
- metafieldIdentifiers
2317
- }),
2318
- swrOptions
2319
- );
2320
- }
2321
- function useBlog(options = {}) {
2322
- const { client, locale } = useShopify();
2323
- const { handle, metafieldIdentifiers, ...swrOptions } = options;
2324
- return useSWR(
2325
- handle ? ["blog", locale, handle, metafieldIdentifiers] : null,
2326
- () => getBlog(client, { handle, locale, metafieldIdentifiers }),
2327
- swrOptions
2328
- );
2329
- }
2330
- function useAllBlogs(options = {}) {
2331
- const { client, locale } = useShopify();
2332
- const { first, query, metafieldIdentifiers, ...swrOptions } = options;
2333
- return useSWR(
2334
- ["all-blogs", locale, first, query, metafieldIdentifiers],
2335
- () => getAllBlogs(client, {
2336
- locale,
2337
- first,
2338
- query,
2339
- metafieldIdentifiers
2340
- }),
2341
- swrOptions
2342
- );
2343
- }
2344
- function useArticle(options = {}) {
2345
- const { client, locale } = useShopify();
2346
- const { blogHandle, articleHandle, metafieldIdentifiers, ...swrOptions } = options;
2347
- return useSWR(
2348
- blogHandle && articleHandle ? ["article", locale, blogHandle, articleHandle, metafieldIdentifiers] : null,
2349
- () => getArticle(client, {
2350
- blogHandle,
2351
- articleHandle,
2352
- locale,
2353
- metafieldIdentifiers
2354
- }),
2355
- swrOptions
2356
- );
2357
- }
2358
- function useArticles(options = {}) {
2359
- const { client, locale } = useShopify();
2360
- const { first, query, sortKey, reverse, metafieldIdentifiers, ...swrOptions } = options;
2361
- return useSWR(
2362
- ["articles", locale, first, query, sortKey, reverse, metafieldIdentifiers],
2363
- () => getArticles(client, {
2364
- locale,
2365
- first,
2366
- query,
2367
- sortKey,
2368
- reverse,
2369
- metafieldIdentifiers
2370
- }),
2371
- swrOptions
2372
- );
2373
- }
2374
- function useArticlesInBlog(options = {}) {
2375
- const { client, locale } = useShopify();
2376
- const { blogHandle, first, sortKey, reverse, metafieldIdentifiers, ...swrOptions } = options;
2377
- return useSWR(
2378
- blogHandle ? ["articles-in-blog", locale, blogHandle, first, sortKey, reverse, metafieldIdentifiers] : null,
2379
- () => getArticlesInBlog(client, {
2380
- blogHandle,
2381
- locale,
2382
- first,
2383
- sortKey,
2384
- reverse,
2385
- metafieldIdentifiers
2045
+ return useMemo(
2046
+ () => hasPlusMemberInCart({
2047
+ memberSetting,
2048
+ cart
2386
2049
  }),
2387
- swrOptions
2050
+ [memberSetting, cart]
2388
2051
  );
2389
2052
  }
2390
- async function performSearch(client, locale, searchQuery, first = 20, types = ["PRODUCT", "ARTICLE", "PAGE"]) {
2391
- if (!searchQuery) {
2392
- return void 0;
2053
+ function hasPlusMemberInLines({
2054
+ memberSetting,
2055
+ lines
2056
+ }) {
2057
+ const { plus_monthly_product, plus_annual_product } = memberSetting || {};
2058
+ if (!lines || lines.length === 0) {
2059
+ return {
2060
+ hasPlusMember: false,
2061
+ hasMonthlyPlus: false,
2062
+ hasAnnualPlus: false
2063
+ };
2393
2064
  }
2394
- const query = (
2395
- /* GraphQL */
2396
- `
2397
- query search($query: String!, $first: Int!, $types: [SearchType!])
2398
- @inContext(language: $language) {
2399
- search(query: $query, first: $first, types: $types, unavailableProducts: HIDE) {
2400
- totalCount
2401
- edges {
2402
- node {
2403
- ... on Article {
2404
- __typename
2405
- id
2406
- handle
2407
- title
2408
- excerpt
2409
- image {
2410
- url
2411
- altText
2412
- }
2413
- }
2414
- ... on Page {
2415
- __typename
2416
- id
2417
- handle
2418
- title
2419
- }
2420
- ... on Product {
2421
- __typename
2422
- id
2423
- handle
2424
- title
2425
- description
2426
- featuredImage {
2427
- url
2428
- altText
2429
- }
2430
- }
2431
- }
2432
- }
2433
- pageInfo {
2434
- hasNextPage
2435
- endCursor
2436
- }
2437
- }
2438
- }
2439
- `
2440
- );
2441
- const data = await client.query(query, {
2442
- query: searchQuery,
2443
- first,
2444
- types
2065
+ const monthlyPlusLine = lines.find((line) => {
2066
+ const variantHandle = line.variant?.product?.handle;
2067
+ const variantSku = line.variant?.sku;
2068
+ return variantHandle === plus_monthly_product?.handle && variantSku === plus_monthly_product?.sku;
2445
2069
  });
2446
- if (!data || !data.search) {
2447
- return void 0;
2448
- }
2449
- const items = data.search.edges?.map((edge) => {
2450
- const node = edge.node;
2451
- const item = {
2452
- type: node.__typename.toUpperCase(),
2453
- id: node.id,
2454
- handle: node.handle,
2455
- title: node.title
2456
- };
2457
- if (node.__typename === "Product") {
2458
- item.description = node.description;
2459
- item.image = node.featuredImage ? {
2460
- url: node.featuredImage.url,
2461
- altText: node.featuredImage.altText
2462
- } : void 0;
2463
- } else if (node.__typename === "Article") {
2464
- item.description = node.excerpt;
2465
- item.image = node.image ? {
2466
- url: node.image.url,
2467
- altText: node.image.altText
2468
- } : void 0;
2469
- }
2470
- return item;
2471
- }) || [];
2070
+ const annualPlusLine = lines.find((line) => {
2071
+ const variantHandle = line.variant?.product?.handle;
2072
+ const variantSku = line.variant?.sku;
2073
+ return variantHandle === plus_annual_product?.handle && variantSku === plus_annual_product?.sku;
2074
+ });
2075
+ const hasMonthlyPlus = !!monthlyPlusLine;
2076
+ const hasAnnualPlus = !!annualPlusLine;
2077
+ const hasPlusMember = hasMonthlyPlus || hasAnnualPlus;
2472
2078
  return {
2473
- items,
2474
- totalCount: data.search.totalCount || 0,
2475
- pageInfo: data.search.pageInfo
2079
+ hasPlusMember,
2080
+ hasMonthlyPlus,
2081
+ hasAnnualPlus,
2082
+ monthlyPlusLine,
2083
+ annualPlusLine
2476
2084
  };
2477
2085
  }
2478
- function useSearch(options = {}) {
2479
- const { client, locale } = useShopify();
2480
- const { query, first = 20, types = ["PRODUCT", "ARTICLE", "PAGE"], ...swrOptions } = options;
2481
- return useSWR(
2482
- query ? ["search", locale, query, first, types] : null,
2483
- () => performSearch(client, locale, query, first, types),
2484
- swrOptions
2086
+ function useHasPlusMemberInLines({
2087
+ memberSetting,
2088
+ lines
2089
+ }) {
2090
+ return useMemo(
2091
+ () => hasPlusMemberInLines({
2092
+ memberSetting,
2093
+ lines
2094
+ }),
2095
+ [memberSetting, lines]
2485
2096
  );
2486
2097
  }
2487
- async function getSiteInfo(client, locale, metafieldIdentifiers) {
2488
- const hasMetafields = metafieldIdentifiers && metafieldIdentifiers.length > 0;
2489
- const query = (
2490
- /* GraphQL */
2491
- `
2492
- query getSiteInfo(
2493
- ${hasMetafields ? "$shopMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
2494
- ) @inContext(language: $language) {
2495
- shop {
2496
- name
2497
- description
2498
- primaryDomain {
2499
- url
2500
- host
2501
- }
2502
- brand {
2503
- logo {
2504
- image {
2505
- url
2506
- }
2507
- }
2508
- colors {
2509
- primary {
2510
- background
2511
- }
2512
- secondary {
2513
- background
2514
- }
2515
- }
2516
- }
2517
- ${hasMetafields ? "metafields(identifiers: $shopMetafieldIdentifiers) { key value }" : ""}
2518
- }
2098
+ function usePlusMemberNeedAddToCart({
2099
+ cart,
2100
+ profile
2101
+ }) {
2102
+ const { selectedPlusMemberMode, selectedPlusMemberVariant, plusMemberMetafields } = usePlusMemberContext();
2103
+ const { hasMonthlyPlus, hasAnnualPlus } = useHasPlusMemberInCart({
2104
+ memberSetting: plusMemberMetafields,
2105
+ cart
2106
+ });
2107
+ const plusMemberVariant = useMemo(() => {
2108
+ if (!selectedPlusMemberVariant || selectedPlusMemberMode === "free" /* FREE */) {
2109
+ return void 0;
2519
2110
  }
2520
- `
2521
- );
2522
- const variables = {};
2523
- if (hasMetafields) {
2524
- variables.shopMetafieldIdentifiers = metafieldIdentifiers;
2525
- }
2526
- const data = await client.query(query, variables);
2527
- if (!data || !data.shop) {
2528
- return void 0;
2529
- }
2530
- const shop = data.shop;
2531
- const metafields = shop.metafields?.reduce((acc, mf) => {
2532
- if (mf && mf.key) {
2533
- acc[mf.key] = mf.value;
2111
+ if (selectedPlusMemberMode === "monthly" /* MONTHLY */ && hasMonthlyPlus) {
2112
+ return void 0;
2534
2113
  }
2535
- return acc;
2536
- }, {});
2537
- return {
2538
- name: shop.name,
2539
- description: shop.description,
2540
- primaryDomain: shop.primaryDomain,
2541
- brand: shop.brand ? {
2542
- logo: shop.brand.logo,
2543
- colors: shop.brand.colors ? {
2544
- primary: shop.brand.colors.primary?.background,
2545
- secondary: shop.brand.colors.secondary?.background
2546
- } : void 0
2547
- } : void 0,
2548
- metafields
2549
- };
2114
+ if (selectedPlusMemberMode === "annual" /* ANNUAL */ && hasAnnualPlus) {
2115
+ return void 0;
2116
+ }
2117
+ if (profile?.isMonthlyPlus && selectedPlusMemberMode === "monthly" /* MONTHLY */) {
2118
+ return void 0;
2119
+ }
2120
+ if (profile?.isAnnualPlus && selectedPlusMemberMode === "annual" /* ANNUAL */) {
2121
+ return void 0;
2122
+ }
2123
+ return selectedPlusMemberVariant;
2124
+ }, [selectedPlusMemberMode, selectedPlusMemberVariant, hasMonthlyPlus, hasAnnualPlus]);
2125
+ return plusMemberVariant;
2550
2126
  }
2551
- function useSite(options = {}) {
2552
- const { client, locale } = useShopify();
2553
- const { metafieldIdentifiers, ...swrOptions } = options;
2554
- return useSWR(
2555
- ["site", locale, metafieldIdentifiers],
2556
- () => getSiteInfo(client, locale, metafieldIdentifiers),
2557
- swrOptions
2127
+ var PlusMemberProvider = ({
2128
+ variant,
2129
+ product,
2130
+ memberSetting,
2131
+ initialSelectedPlusMemberMode = "free",
2132
+ profile,
2133
+ children
2134
+ }) => {
2135
+ const [selectedPlusMemberMode, setSelectedPlusMemberMode] = useState(
2136
+ initialSelectedPlusMemberMode
2558
2137
  );
2559
- }
2560
-
2561
- // src/hooks/member/plus/types.ts
2562
- var PLUS_MEMBER_TYPE = /* @__PURE__ */ ((PLUS_MEMBER_TYPE2) => {
2563
- PLUS_MEMBER_TYPE2[PLUS_MEMBER_TYPE2["FREE"] = 0] = "FREE";
2564
- PLUS_MEMBER_TYPE2[PLUS_MEMBER_TYPE2["MONTHLY"] = 1] = "MONTHLY";
2565
- PLUS_MEMBER_TYPE2[PLUS_MEMBER_TYPE2["ANNUAL"] = 2] = "ANNUAL";
2566
- return PLUS_MEMBER_TYPE2;
2567
- })(PLUS_MEMBER_TYPE || {});
2568
- var PlusMemberMode = /* @__PURE__ */ ((PlusMemberMode2) => {
2569
- PlusMemberMode2["MONTHLY"] = "monthly";
2570
- PlusMemberMode2["ANNUAL"] = "annual";
2571
- return PlusMemberMode2;
2572
- })(PlusMemberMode || {});
2573
- var DeliveryPlusType = /* @__PURE__ */ ((DeliveryPlusType2) => {
2574
- DeliveryPlusType2["FREE"] = "free";
2575
- DeliveryPlusType2["MONTHLY"] = "monthly";
2576
- DeliveryPlusType2["ANNUAL"] = "annual";
2577
- return DeliveryPlusType2;
2578
- })(DeliveryPlusType || {});
2579
- var ShippingMethodMode = /* @__PURE__ */ ((ShippingMethodMode2) => {
2580
- ShippingMethodMode2["FREE"] = "free";
2581
- ShippingMethodMode2["TDD"] = "tdd";
2582
- ShippingMethodMode2["NDD"] = "ndd";
2583
- return ShippingMethodMode2;
2584
- })(ShippingMethodMode || {});
2585
- var createInitialValue = () => ({
2586
- plusMemberMetafields: {},
2587
- selectedPlusMemberMode: "free",
2588
- setSelectedPlusMemberMode: () => {
2589
- },
2590
- selectedShippingMethod: void 0,
2591
- setSelectedShippingMethod: () => {
2592
- },
2593
- showMoreShippingMethod: false,
2594
- setShowMoreShippingMethod: () => {
2595
- },
2596
- variant: {},
2597
- product: {},
2598
- shippingMethodsContext: {
2599
- freeShippingMethods: [],
2600
- paymentShippingMethods: [],
2601
- nddOverweight: false,
2602
- tddOverweight: false,
2603
- nddCoupon: void 0,
2604
- tddCoupon: void 0,
2605
- isLoadingCoupon: false
2606
- },
2607
- selectedPlusMemberVariant: void 0,
2608
- showPlusMemberBenefit: false,
2609
- setShowPlusMemberBenefit: () => {
2610
- },
2611
- profile: void 0
2612
- });
2613
- var PlusMemberContext = createContext(createInitialValue());
2614
- function usePlusMemberContext() {
2615
- return useContext(PlusMemberContext);
2616
- }
2617
- function usePlusMemberVariants({
2618
- memberSetting
2619
- }) {
2620
- const plusMonthly = memberSetting?.plus_monthly_product;
2621
- const plusAnnual = memberSetting?.plus_annual_product;
2622
- const plusMemberHandles = useMemo(() => {
2623
- return [plusMonthly?.handle, plusAnnual?.handle].filter(Boolean);
2624
- }, [plusMonthly?.handle, plusAnnual?.handle]);
2625
- const { data: plusMemberProducts = [] } = useProductsByHandles({
2626
- handles: plusMemberHandles
2138
+ const [selectedShippingMethod, setSelectedShippingMethod] = useState();
2139
+ const [showMoreShippingMethod, setShowMoreShippingMethod] = useState(false);
2140
+ const [showPlusMemberBenefit, setShowPlusMemberBenefit] = useState(false);
2141
+ const shippingMethodsContext = useShippingMethods({
2142
+ variant,
2143
+ plusMemberMetafields: memberSetting,
2144
+ selectedPlusMemberMode,
2145
+ profile
2627
2146
  });
2628
- const monthlyProduct = useMemo(() => {
2629
- return plusMemberProducts?.find((item) => item?.handle === plusMonthly?.handle);
2630
- }, [plusMemberProducts, plusMonthly]);
2631
- const annualProduct = useMemo(() => {
2632
- return plusMemberProducts?.find((item) => item?.handle === plusAnnual?.handle);
2633
- }, [plusMemberProducts, plusAnnual]);
2634
- const monthlyVariant = useMemo(() => {
2635
- return monthlyProduct?.variants?.find((item) => item.sku === plusMonthly?.sku);
2636
- }, [monthlyProduct, plusMonthly]);
2637
- const annualVariant = useMemo(() => {
2638
- return annualProduct?.variants?.find((item) => item.sku === plusAnnual?.sku);
2639
- }, [annualProduct, plusAnnual]);
2640
- return {
2641
- monthlyVariant: monthlyVariant ? {
2642
- ...monthlyVariant,
2643
- product: monthlyProduct
2644
- } : void 0,
2645
- annualVariant: annualVariant ? {
2646
- ...annualVariant,
2647
- product: annualProduct
2648
- } : void 0
2649
- };
2650
- }
2651
- var useAvailableDeliveryCoupon = ({
2652
- profile
2653
- }) => {
2654
- const { data: availableDeliveryCoupon, isLoading } = useSWR(
2655
- profile?.email ? ["/api/multipass/subsrv/v1/prime/delivery_coupons/current/available", profile?.email] : void 0,
2656
- async ([apiPath]) => {
2657
- return fetch(apiPath).then((res) => res.json());
2147
+ const { monthlyVariant, annualVariant } = usePlusMemberVariants({
2148
+ memberSetting
2149
+ });
2150
+ const selectedPlusMemberVariant = useMemo(() => {
2151
+ if (selectedPlusMemberMode === "free" /* FREE */) {
2152
+ return void 0;
2153
+ }
2154
+ return selectedPlusMemberMode === "monthly" /* MONTHLY */ ? monthlyVariant : annualVariant;
2155
+ }, [monthlyVariant, annualVariant, selectedPlusMemberMode]);
2156
+ return /* @__PURE__ */ jsx(
2157
+ PlusMemberContext.Provider,
2158
+ {
2159
+ value: {
2160
+ variant,
2161
+ plusMemberMetafields: memberSetting,
2162
+ selectedPlusMemberMode,
2163
+ setSelectedPlusMemberMode,
2164
+ selectedShippingMethod,
2165
+ setSelectedShippingMethod,
2166
+ shippingMethodsContext,
2167
+ showMoreShippingMethod,
2168
+ setShowMoreShippingMethod,
2169
+ selectedPlusMemberVariant,
2170
+ product,
2171
+ showPlusMemberBenefit,
2172
+ setShowPlusMemberBenefit,
2173
+ profile
2174
+ },
2175
+ children
2658
2176
  }
2659
2177
  );
2660
- console.log("availableDeliveryCoupon", availableDeliveryCoupon);
2661
- const { ndd_coupon: nddCoupon, tdd_coupon: tddCoupon } = availableDeliveryCoupon?.data?.data || {};
2662
- return {
2663
- nddCoupon,
2664
- tddCoupon,
2665
- isLoading
2666
- };
2667
2178
  };
2668
2179
 
2669
- // src/hooks/member/plus/use-shipping-methods.ts
2670
- function useShippingMethods(options) {
2671
- const { variant, plusMemberMetafields, selectedPlusMemberMode, profile } = options;
2672
- const isPlus = profile?.isPlus || false;
2673
- const { nddCoupon, tddCoupon, isLoading } = useAvailableDeliveryCoupon({ profile });
2674
- const { plus_shipping, shippingMethod } = plusMemberMetafields || {};
2675
- const nddOverweight = useMemo(() => {
2676
- return (variant?.weight || 0) > (shippingMethod?.overWeight_ndd || Infinity);
2677
- }, [shippingMethod?.overWeight_ndd, variant?.weight]);
2678
- const tddOverweight = useMemo(() => {
2679
- return (variant?.weight || 0) > (shippingMethod?.overWeight_tdd || Infinity);
2680
- }, [shippingMethod?.overWeight_tdd, variant?.weight]);
2681
- const paymentShippingMethods = useMemo(() => {
2682
- const weight = variant?.weight || 0;
2683
- const methods = plus_shipping?.shipping_methods?.filter(({ weight_low, weight_high, __mode, __plus }) => {
2684
- const fitWeight = (!weight_low || weight >= weight_low) && (!weight_high || weight <= weight_high);
2685
- return __mode !== "free" /* FREE */ && !__plus && fitWeight;
2686
- }) || [];
2687
- return methods.map((method) => {
2688
- let disabled = false;
2689
- const selectedFreeMember = selectedPlusMemberMode === "free";
2690
- if (method.__mode === "ndd" /* NDD */) {
2691
- disabled = selectedFreeMember || nddOverweight;
2692
- } else if (method.__mode === "tdd" /* TDD */) {
2693
- disabled = selectedFreeMember || tddOverweight;
2180
+ // src/hooks/cart/use-add-to-cart.ts
2181
+ function useAddToCart({ withTrack = true } = {}, swrOptions) {
2182
+ const { client, config, locale, cartCookieAdapter, userAdapter, performanceAdapter } = useShopify();
2183
+ const { cart, addCustomAttributes, memberSetting, profile, customer } = useCartContext();
2184
+ const { trigger: applyCartCodes } = useApplyCartCodes();
2185
+ const { trigger: removeInvalidCodes } = useRemoveCartCodes();
2186
+ const { trigger: addCartLines2 } = useAddCartLines();
2187
+ const { trigger: createCart4 } = useCreateCart({
2188
+ updateCookie: true
2189
+ });
2190
+ const { hasPlusMember } = useHasPlusMemberInCart({
2191
+ memberSetting,
2192
+ cart
2193
+ });
2194
+ const { attributes: cartAttributes } = useCartAttributes({
2195
+ profile,
2196
+ customer,
2197
+ cart,
2198
+ memberType: hasPlusMember ? "2" : String(profile?.memberType ?? 0)
2199
+ });
2200
+ const addToCart = useCallback(
2201
+ async (_key, { arg }) => {
2202
+ const {
2203
+ lineItems,
2204
+ cartId: providedCartId,
2205
+ discountCodes,
2206
+ gtmParams = {},
2207
+ buyerIdentity,
2208
+ needCreateCart = false,
2209
+ onCodesInvalid,
2210
+ replaceExistingCodes,
2211
+ customAttributes
2212
+ } = arg;
2213
+ if (!lineItems || lineItems.length === 0) {
2214
+ return;
2694
2215
  }
2695
- return {
2696
- ...method,
2697
- id: method.__mode + method.__code,
2698
- useCoupon: false,
2699
- subtitle: plus_shipping?.directly || "",
2700
- disabled
2701
- };
2702
- });
2703
- }, [
2704
- nddOverweight,
2705
- plus_shipping?.directly,
2706
- plus_shipping?.shipping_methods,
2707
- selectedPlusMemberMode,
2708
- tddOverweight,
2709
- variant?.weight
2710
- ]);
2711
- const nddPrice = useMemo(() => {
2712
- const weight = variant?.weight || 0;
2713
- const nddMethod = paymentShippingMethods.find(({ __mode, weight_high, weight_low }) => {
2714
- const fitWeight = (!weight_low || weight >= weight_low) && (!weight_high || weight <= weight_high);
2715
- return __mode === "ndd" && fitWeight;
2716
- });
2717
- return nddMethod?.price || 0;
2718
- }, [variant?.weight, paymentShippingMethods]);
2719
- const tddPrice = useMemo(() => {
2720
- const weight = variant?.weight || 0;
2721
- const tddMethod = paymentShippingMethods.find(({ __mode, weight_high, weight_low }) => {
2722
- const fitWeight = (!weight_low || weight >= weight_low) && (!weight_high || weight <= weight_high);
2723
- return __mode === "tdd" && fitWeight;
2724
- });
2725
- return tddMethod?.price || 0;
2726
- }, [variant?.weight, paymentShippingMethods]);
2727
- const freeShippingMethods = useMemo(() => {
2728
- const weight = variant?.weight || 0;
2729
- let methods = plus_shipping?.shipping_methods?.filter(({ __mode, __plus, weight_low, weight_high }) => {
2730
- if (__mode === "free" /* FREE */) {
2731
- return true;
2216
+ performanceAdapter?.addToCartStart();
2217
+ const linesWithFunctionAttributes = getLinesWithAttributes({ cart, lineItems });
2218
+ const lines = linesWithFunctionAttributes.map((item) => ({
2219
+ merchandiseId: item.variant?.id || "",
2220
+ quantity: item.quantity || 1,
2221
+ attributes: item.attributes,
2222
+ sellingPlanId: item.sellingPlanId
2223
+ })).filter((item) => item.merchandiseId && item.quantity);
2224
+ if (lines.length === 0) {
2225
+ return;
2732
2226
  }
2733
- if (isPlus) {
2734
- const hasCoupon = isPlus && __mode === "ndd" /* NDD */ && nddCoupon || isPlus && __mode === "tdd" /* TDD */ && (tddCoupon || nddCoupon);
2735
- const fitWeight = (!weight_low || weight >= weight_low) && (!weight_high || weight <= weight_high);
2736
- return hasCoupon && fitWeight && !__plus;
2227
+ let cartId = needCreateCart ? void 0 : providedCartId || cart?.id;
2228
+ let resultCart = null;
2229
+ if (!cartId) {
2230
+ resultCart = await createCart4({
2231
+ lines,
2232
+ buyerIdentity,
2233
+ discountCodes,
2234
+ customAttributes: [...cartAttributes, ...customAttributes || []]
2235
+ // 初次加购时,就把所有 cart attributes 带上
2236
+ });
2737
2237
  } else {
2738
- return __plus;
2739
- }
2740
- }) || [];
2741
- if (isPlus) {
2742
- methods = methods.sort((a, b) => {
2743
- if (b.__mode === "free" /* FREE */) return -1;
2744
- return 0;
2745
- });
2746
- }
2747
- return methods.map((method) => {
2748
- let price = 0;
2749
- let coupon;
2750
- let disabled;
2751
- if (method.__mode !== "free" /* FREE */) {
2752
- switch (method.__mode) {
2753
- case "tdd":
2754
- price = tddPrice;
2755
- coupon = tddCoupon || nddCoupon;
2756
- break;
2757
- case "ndd":
2758
- price = nddPrice;
2759
- coupon = nddCoupon;
2760
- break;
2238
+ resultCart = await addCartLines2({
2239
+ cartId,
2240
+ lines
2241
+ });
2242
+ console.log("npm addCartLines resultCart", resultCart);
2243
+ if (resultCart && resultCart.discountCodes && resultCart.discountCodes.length > 0) {
2244
+ const unapplicableCodes = resultCart.discountCodes.filter((item) => !item.applicable).map((item) => item.code);
2245
+ if (unapplicableCodes.length > 0) {
2246
+ if (onCodesInvalid) {
2247
+ const handledCart = await onCodesInvalid(resultCart, unapplicableCodes);
2248
+ if (handledCart) {
2249
+ resultCart = handledCart;
2250
+ }
2251
+ } else {
2252
+ await removeInvalidCodes({
2253
+ discountCodes: unapplicableCodes
2254
+ });
2255
+ }
2256
+ }
2761
2257
  }
2762
- disabled = selectedPlusMemberMode === "free";
2763
- if (method.__mode === "ndd" /* NDD */) {
2764
- disabled = disabled || nddOverweight;
2765
- } else if (method.__mode === "tdd" /* TDD */) {
2766
- disabled = disabled || tddOverweight;
2258
+ if (resultCart && discountCodes && discountCodes.length > 0) {
2259
+ applyCartCodes({
2260
+ replaceExistingCodes,
2261
+ discountCodes
2262
+ });
2263
+ }
2264
+ if (customAttributes && customAttributes.length > 0) {
2265
+ addCustomAttributes(customAttributes);
2767
2266
  }
2768
2267
  }
2769
- return {
2770
- ...method,
2771
- id: method.__mode + method.__code,
2772
- useCoupon: true,
2773
- disabled,
2774
- coupon,
2775
- price
2776
- };
2777
- });
2778
- }, [
2779
- variant?.weight,
2780
- plus_shipping?.shipping_methods,
2781
- isPlus,
2782
- nddCoupon,
2783
- tddCoupon,
2784
- selectedPlusMemberMode,
2785
- tddPrice,
2786
- nddPrice,
2787
- nddOverweight,
2788
- tddOverweight
2789
- ]);
2790
- return {
2791
- freeShippingMethods,
2792
- paymentShippingMethods,
2793
- nddOverweight,
2794
- tddOverweight,
2795
- nddCoupon,
2796
- tddCoupon,
2797
- isLoadingCoupon: isLoading
2798
- };
2268
+ if (withTrack) {
2269
+ trackAddToCartGA({
2270
+ lineItems,
2271
+ gtmParams: { ...gtmParams, brand: config.getBrand() }
2272
+ });
2273
+ trackAddToCartFBQ({ lineItems });
2274
+ }
2275
+ performanceAdapter?.addToCartEnd();
2276
+ return resultCart;
2277
+ },
2278
+ [
2279
+ client,
2280
+ locale,
2281
+ cartCookieAdapter,
2282
+ userAdapter,
2283
+ cart,
2284
+ withTrack,
2285
+ performanceAdapter,
2286
+ createCart4,
2287
+ addCartLines2,
2288
+ applyCartCodes,
2289
+ removeInvalidCodes,
2290
+ addCustomAttributes,
2291
+ config
2292
+ ]
2293
+ );
2294
+ return useSWRMutation("add-to-cart", addToCart, swrOptions);
2799
2295
  }
2800
- var useReplaceCartPlusMember = () => {
2801
- const { plusMemberMetafields, selectedPlusMemberMode } = usePlusMemberContext();
2802
- const { trigger: removeCartLines2 } = useRemoveCartLines();
2803
- const { cart } = useCartContext();
2804
- const plusMonthly = plusMemberMetafields?.plus_monthly_product;
2805
- const plusAnnual = plusMemberMetafields?.plus_annual_product;
2806
- const handler = useCallback(async () => {
2807
- const plusMonthlyInCart = cart?.lineItems.find(
2808
- (item) => item.variant?.sku === plusMonthly?.sku
2809
- );
2810
- const plusAnnualInCart = cart?.lineItems.find(
2811
- (item) => item.variant?.sku === plusAnnual?.sku
2812
- );
2813
- if (selectedPlusMemberMode === "annual" /* ANNUAL */ && plusMonthlyInCart) {
2814
- await removeCartLines2({
2815
- lineIds: [plusMonthlyInCart.id]
2816
- });
2817
- } else if (selectedPlusMemberMode === "monthly" /* MONTHLY */ && plusAnnualInCart) {
2818
- await removeCartLines2({
2819
- lineIds: [plusAnnualInCart.id]
2296
+ function useUpdateCartLines(options) {
2297
+ const { client, locale, cartCookieAdapter } = useShopify();
2298
+ const { mutateCart, metafieldIdentifiers } = useCartContext();
2299
+ const updateLines = useCallback(
2300
+ async (_key, { arg }) => {
2301
+ const updatedCart = await updateCartLines(client, {
2302
+ ...arg,
2303
+ metafieldIdentifiers,
2304
+ cookieAdapter: cartCookieAdapter
2820
2305
  });
2821
- }
2822
- }, [
2823
- cart?.lineItems,
2824
- selectedPlusMemberMode,
2825
- plusMonthly?.sku,
2826
- plusAnnual?.sku,
2827
- removeCartLines2
2828
- ]);
2829
- return handler;
2830
- };
2831
- var usePlusMemberDeliveryCodes = () => {
2832
- const { selectedShippingMethod } = usePlusMemberContext();
2833
- return useMemo(() => [selectedShippingMethod?.coupon], [selectedShippingMethod?.coupon]);
2834
- };
2835
- var usePlusMemberCheckoutCustomAttributes = ({
2836
- disableShipping = false,
2837
- isPresaleContains = false
2838
- }) => {
2839
- const { profile, selectedShippingMethod, selectedPlusMemberMode } = usePlusMemberContext();
2840
- return useMemo(() => {
2841
- const checkoutCustomAttributes = [
2842
- {
2843
- key: "_last_url",
2844
- value: typeof window !== "undefined" ? window.location.origin + window.location.pathname : ""
2306
+ if (updatedCart) {
2307
+ mutateCart(updatedCart);
2845
2308
  }
2846
- ];
2847
- checkoutCustomAttributes.push({
2848
- key: "_checkout_delivery_custom",
2849
- value: JSON.stringify({
2850
- allow_nextday_delivery: true,
2851
- allow_thirdday_delivery: true,
2852
- selected_delivery_option: {
2853
- code: selectedShippingMethod?.__code,
2854
- mode: selectedShippingMethod?.__mode
2855
- },
2856
- is_presale: isPresaleContains,
2857
- discount_code: selectedShippingMethod?.coupon ? [selectedShippingMethod.coupon] : [],
2858
- plus_type: profile?.isPlus ? "free" /* FREE */ : selectedPlusMemberMode,
2859
- is_prime: profile?.isPlus
2860
- })
2309
+ console.log("use-update-cart-lines updatedCart", metafieldIdentifiers, updatedCart);
2310
+ return updatedCart;
2311
+ },
2312
+ [client, locale, cartCookieAdapter, mutateCart, metafieldIdentifiers]
2313
+ );
2314
+ return useSWRMutation("update-cart-lines", updateLines, options);
2315
+ }
2316
+ function useUpdateCartAttributes({
2317
+ mutate,
2318
+ metafieldIdentifiers,
2319
+ disabled = false,
2320
+ swrOptions
2321
+ }) {
2322
+ const { client, locale, cartCookieAdapter } = useShopify();
2323
+ const updateAttributes = useCallback(
2324
+ async (_key, { arg }) => {
2325
+ if (disabled) {
2326
+ return void 0;
2327
+ }
2328
+ const updatedCart = await updateCartAttributes(client, {
2329
+ ...arg,
2330
+ metafieldIdentifiers,
2331
+ cookieAdapter: cartCookieAdapter
2332
+ });
2333
+ if (updatedCart) {
2334
+ mutate(updatedCart);
2335
+ }
2336
+ return updatedCart;
2337
+ },
2338
+ [client, locale, cartCookieAdapter, mutate, metafieldIdentifiers, disabled]
2339
+ );
2340
+ return useSWRMutation("update-cart-attributes", updateAttributes, swrOptions);
2341
+ }
2342
+ function useBuyNow({ withTrack = true } = {}, swrOptions) {
2343
+ const { client, config, locale, cartCookieAdapter, userAdapter } = useShopify();
2344
+ const { profile, customer, memberSetting } = useCartContext();
2345
+ const isLoggedIn = userAdapter?.isLoggedIn || false;
2346
+ const buyNow = useCallback(
2347
+ async (_key, { arg }) => {
2348
+ const {
2349
+ lineItems,
2350
+ discountCodes,
2351
+ gtmParams = {},
2352
+ buyerIdentity,
2353
+ fbqTrackConfig,
2354
+ customAttributes,
2355
+ metafieldIdentifiers,
2356
+ redirectToCheckout
2357
+ } = arg;
2358
+ if (!lineItems || lineItems.length === 0) {
2359
+ return;
2360
+ }
2361
+ const { hasPlusMember } = hasPlusMemberInLines({
2362
+ memberSetting,
2363
+ lines: lineItems
2364
+ });
2365
+ const memberType = hasPlusMember ? "2" : String(profile?.memberType ?? 0);
2366
+ console.log("customer", customer);
2367
+ const cartAttributes = getCartAttributes({
2368
+ profile,
2369
+ customer,
2370
+ memberType,
2371
+ currentUrl: window.location.href
2372
+ });
2373
+ const linesWithFunctionAttributes = getLinesWithAttributes({
2374
+ lineItems
2375
+ });
2376
+ const lines = linesWithFunctionAttributes.map((item) => ({
2377
+ merchandiseId: item.variant?.id || "",
2378
+ quantity: item.quantity || 1,
2379
+ attributes: item.attributes,
2380
+ sellingPlanId: item.sellingPlanId
2381
+ })).filter((item) => item.merchandiseId);
2382
+ if (lines.length === 0) {
2383
+ return;
2384
+ }
2385
+ const resultCart = await createCart(client, {
2386
+ lines,
2387
+ metafieldIdentifiers,
2388
+ cookieAdapter: cartCookieAdapter,
2389
+ buyerIdentity,
2390
+ discountCodes,
2391
+ customAttributes: [...cartAttributes, ...customAttributes || []]
2392
+ });
2393
+ if (!resultCart) {
2394
+ throw new Error("Failed to create cart for buy now");
2395
+ }
2396
+ if (withTrack && resultCart.lineItems) {
2397
+ trackBuyNowGA({
2398
+ lineItems,
2399
+ gtmParams: { ...gtmParams, brand: config.getBrand() }
2400
+ });
2401
+ if (fbqTrackConfig) {
2402
+ trackBuyNowFBQ({ trackConfig: fbqTrackConfig });
2403
+ }
2404
+ }
2405
+ if (redirectToCheckout) {
2406
+ if (resultCart.url) {
2407
+ if (typeof window !== "undefined") {
2408
+ window.location.href = resultCart.url;
2409
+ }
2410
+ } else {
2411
+ throw new Error("Failed to get checkout URL");
2412
+ }
2413
+ }
2414
+ return resultCart;
2415
+ },
2416
+ [client, locale, isLoggedIn, cartCookieAdapter, withTrack]
2417
+ );
2418
+ return useSWRMutation("buy-now", buyNow, swrOptions);
2419
+ }
2420
+
2421
+ // src/hooks/cart/types/price-discount.ts
2422
+ var PriceDiscountType = /* @__PURE__ */ ((PriceDiscountType2) => {
2423
+ PriceDiscountType2[PriceDiscountType2["PERCENTAGE"] = 1] = "PERCENTAGE";
2424
+ PriceDiscountType2[PriceDiscountType2["FIXED_AMOUNT"] = 2] = "FIXED_AMOUNT";
2425
+ return PriceDiscountType2;
2426
+ })(PriceDiscountType || {});
2427
+ var PriceBasePriceType = /* @__PURE__ */ ((PriceBasePriceType2) => {
2428
+ PriceBasePriceType2[PriceBasePriceType2["MIN_DISCOUNTED_PRICE"] = 1] = "MIN_DISCOUNTED_PRICE";
2429
+ PriceBasePriceType2[PriceBasePriceType2["MIN_TOTAL_PRICE"] = 2] = "MIN_TOTAL_PRICE";
2430
+ return PriceBasePriceType2;
2431
+ })(PriceBasePriceType || {});
2432
+ function useProduct(options = {}) {
2433
+ const { client, locale } = useShopify();
2434
+ const { handle, metafieldIdentifiers, ...swrOptions } = options;
2435
+ return useSWR(
2436
+ handle ? ["product", locale, handle, metafieldIdentifiers] : null,
2437
+ () => getProduct(client, {
2438
+ handle,
2439
+ locale,
2440
+ metafieldIdentifiers
2441
+ }),
2442
+ swrOptions
2443
+ );
2444
+ }
2445
+ function useAllProducts(options = {}) {
2446
+ const { client, locale } = useShopify();
2447
+ const { first, query, sortKey, reverse, metafieldIdentifiers, ...swrOptions } = options;
2448
+ return useSWR(
2449
+ ["all-products", locale, first, query, sortKey, reverse, metafieldIdentifiers],
2450
+ () => getAllProducts(client, {
2451
+ locale,
2452
+ first,
2453
+ query,
2454
+ sortKey,
2455
+ reverse,
2456
+ metafieldIdentifiers
2457
+ }),
2458
+ swrOptions
2459
+ );
2460
+ }
2461
+ function getFirstAvailableVariant(product) {
2462
+ const availableVariant = product.variants.find((v) => v.availableForSale);
2463
+ return availableVariant || product.variants[0];
2464
+ }
2465
+ function getVariantFromSelectedOptions(product, selectedOptions) {
2466
+ return product.variants.find((variant) => {
2467
+ return variant.selectedOptions.every((option) => {
2468
+ return selectedOptions[option.name] === option.value;
2469
+ });
2470
+ });
2471
+ }
2472
+ function useVariant({
2473
+ product,
2474
+ selectedOptions
2475
+ }) {
2476
+ const [variant, setVariant] = useState(
2477
+ product ? getFirstAvailableVariant(product) : void 0
2478
+ );
2479
+ useEffect(() => {
2480
+ if (!product) {
2481
+ setVariant(void 0);
2482
+ return;
2483
+ }
2484
+ const newVariant = getVariantFromSelectedOptions(product, selectedOptions);
2485
+ if (newVariant && newVariant.id !== variant?.id) {
2486
+ setVariant(newVariant);
2487
+ } else if (!newVariant) {
2488
+ setVariant(getFirstAvailableVariant(product));
2489
+ }
2490
+ }, [selectedOptions, product, variant?.id]);
2491
+ return variant;
2492
+ }
2493
+ var FAKE_PRICE = 999999999e-2;
2494
+ function formatPrice({
2495
+ amount,
2496
+ currencyCode,
2497
+ locale,
2498
+ maximumFractionDigits,
2499
+ minimumFractionDigits,
2500
+ removeTrailingZeros
2501
+ }) {
2502
+ const formatter = new Intl.NumberFormat(locale, {
2503
+ style: "currency",
2504
+ currency: currencyCode,
2505
+ maximumFractionDigits: maximumFractionDigits ?? 2,
2506
+ minimumFractionDigits: minimumFractionDigits ?? 2
2507
+ });
2508
+ let formatted = formatter.format(amount);
2509
+ if (removeTrailingZeros) {
2510
+ formatted = formatted.replace(/\.00$/, "");
2511
+ }
2512
+ return formatted;
2513
+ }
2514
+ function formatVariantPrice({
2515
+ amount,
2516
+ baseAmount,
2517
+ currencyCode,
2518
+ locale,
2519
+ maximumFractionDigits,
2520
+ minimumFractionDigits,
2521
+ removeTrailingZeros
2522
+ }) {
2523
+ return {
2524
+ price: formatPrice({
2525
+ amount,
2526
+ currencyCode,
2527
+ locale,
2528
+ maximumFractionDigits,
2529
+ minimumFractionDigits,
2530
+ removeTrailingZeros
2531
+ }),
2532
+ basePrice: formatPrice({
2533
+ amount: baseAmount,
2534
+ currencyCode,
2535
+ locale,
2536
+ maximumFractionDigits,
2537
+ minimumFractionDigits,
2538
+ removeTrailingZeros
2539
+ })
2540
+ };
2541
+ }
2542
+ function usePrice({
2543
+ amount,
2544
+ baseAmount,
2545
+ currencyCode,
2546
+ soldOutDescription = "",
2547
+ maximumFractionDigits,
2548
+ minimumFractionDigits,
2549
+ removeTrailingZeros
2550
+ }) {
2551
+ const { locale } = useShopify();
2552
+ const value = useMemo(() => {
2553
+ if (typeof amount !== "number" || !currencyCode) {
2554
+ return "";
2555
+ }
2556
+ if (soldOutDescription && amount >= FAKE_PRICE) {
2557
+ return soldOutDescription;
2558
+ }
2559
+ return baseAmount ? formatVariantPrice({
2560
+ amount,
2561
+ baseAmount,
2562
+ currencyCode,
2563
+ locale,
2564
+ maximumFractionDigits,
2565
+ minimumFractionDigits,
2566
+ removeTrailingZeros
2567
+ }) : formatPrice({
2568
+ amount,
2569
+ currencyCode,
2570
+ locale,
2571
+ maximumFractionDigits,
2572
+ minimumFractionDigits,
2573
+ removeTrailingZeros
2574
+ });
2575
+ }, [
2576
+ amount,
2577
+ baseAmount,
2578
+ currencyCode,
2579
+ locale,
2580
+ maximumFractionDigits,
2581
+ minimumFractionDigits,
2582
+ soldOutDescription,
2583
+ removeTrailingZeros
2584
+ ]);
2585
+ const result = useMemo(() => {
2586
+ const free = Boolean(amount && amount <= 0);
2587
+ return typeof value === "string" ? { price: value, basePrice: value, free } : { ...value, free };
2588
+ }, [value, amount]);
2589
+ return result;
2590
+ }
2591
+ function optionsConstructor(selectedOptions) {
2592
+ return selectedOptions.reduce((acc, option) => {
2593
+ acc[option.name] = option.value;
2594
+ return acc;
2595
+ }, {});
2596
+ }
2597
+ function decodeShopifyId(gid) {
2598
+ try {
2599
+ const base64 = gid.split("/").pop() || "";
2600
+ return atob(base64);
2601
+ } catch {
2602
+ return gid;
2603
+ }
2604
+ }
2605
+ function useSelectedOptions(product, sku) {
2606
+ const [options, setOptions] = useState({});
2607
+ useEffect(() => {
2608
+ if (!product || !product.variants.length) {
2609
+ setOptions({});
2610
+ return;
2611
+ }
2612
+ let variant = product.variants[0];
2613
+ if (typeof window !== "undefined") {
2614
+ const searchParams = new URLSearchParams(window.location.search);
2615
+ const variantIdParam = searchParams.get("variant");
2616
+ if (variantIdParam) {
2617
+ const foundVariant = product.variants.find((v) => {
2618
+ if (sku) return v.sku === sku;
2619
+ return v.id === variantIdParam || v.id.includes(variantIdParam) || decodeShopifyId(v.id) === variantIdParam;
2620
+ });
2621
+ if (foundVariant) {
2622
+ variant = foundVariant;
2623
+ }
2624
+ }
2625
+ }
2626
+ if (variant) {
2627
+ const newOptions = optionsConstructor(variant.selectedOptions);
2628
+ setOptions(newOptions);
2629
+ }
2630
+ }, [product, sku]);
2631
+ return [options, setOptions];
2632
+ }
2633
+ function decodeShopifyId2(gid) {
2634
+ try {
2635
+ const parts = gid.split("/");
2636
+ return parts[parts.length - 1] || gid;
2637
+ } catch {
2638
+ return gid;
2639
+ }
2640
+ }
2641
+ function useProductUrl(otherQuery) {
2642
+ const { routerAdapter } = useShopify();
2643
+ return useCallback(
2644
+ ({ product, variant }) => {
2645
+ if (!product) return "";
2646
+ const queryParams = new URLSearchParams();
2647
+ if (variant?.id) {
2648
+ const variantId = decodeShopifyId2(variant.id);
2649
+ if (variantId) {
2650
+ queryParams.set("variant", variantId);
2651
+ }
2652
+ }
2653
+ if (otherQuery) {
2654
+ Object.entries(otherQuery).forEach(([key, value]) => {
2655
+ queryParams.set(key, value);
2656
+ });
2657
+ }
2658
+ const queryString = queryParams.toString();
2659
+ const path = `/products/${product.handle}${queryString ? `?${queryString}` : ""}`;
2660
+ if (routerAdapter?.getLocalizedPath) {
2661
+ return routerAdapter.getLocalizedPath(path);
2662
+ }
2663
+ return path;
2664
+ },
2665
+ [routerAdapter, otherQuery]
2666
+ );
2667
+ }
2668
+ function decodeShopifyId3(gid) {
2669
+ try {
2670
+ const parts = gid.split("/");
2671
+ return parts[parts.length - 1] || gid;
2672
+ } catch {
2673
+ return gid;
2674
+ }
2675
+ }
2676
+ function useUpdateVariantQuery(variant) {
2677
+ useEffect(() => {
2678
+ if (!variant || typeof window === "undefined") {
2679
+ return;
2680
+ }
2681
+ const searchParams = new URLSearchParams(window.location.search);
2682
+ const currentVariantId = searchParams.get("variant");
2683
+ const newVariantId = decodeShopifyId3(variant.id);
2684
+ if (newVariantId && currentVariantId !== newVariantId) {
2685
+ searchParams.set("variant", newVariantId);
2686
+ const newUrl = `${window.location.pathname}?${searchParams.toString()}${window.location.hash}`;
2687
+ window.history.replaceState({}, "", newUrl);
2688
+ }
2689
+ }, [variant]);
2690
+ }
2691
+ function getVariantMediaList({
2692
+ product,
2693
+ variant
2694
+ }) {
2695
+ if (variant.image?.url) {
2696
+ const variantMediaId = variant.image.url;
2697
+ const variantMedia = product.media.filter((media) => {
2698
+ if (media.mediaContentType === "IMAGE" && media.previewImage) {
2699
+ return media.previewImage?.url === variantMediaId;
2700
+ }
2701
+ return false;
2861
2702
  });
2862
- if (disableShipping) {
2863
- checkoutCustomAttributes.push({
2864
- key: "_hide_shipping",
2865
- value: "true"
2703
+ if (variantMedia.length > 0) {
2704
+ const otherMedia = product.media.filter((media) => {
2705
+ if (media.mediaContentType === "IMAGE" && media.previewImage) {
2706
+ return media.previewImage.url !== variantMediaId;
2707
+ }
2708
+ return true;
2866
2709
  });
2710
+ return [...variantMedia, ...otherMedia];
2867
2711
  }
2868
- return checkoutCustomAttributes;
2869
- }, [profile, selectedShippingMethod, selectedPlusMemberMode, isPresaleContains]);
2870
- };
2871
- function useAutoRemovePlusMemberInCart({
2872
- cart,
2873
- profile,
2874
- memberSetting
2712
+ }
2713
+ return product.media;
2714
+ }
2715
+ function useVariantMedia({
2716
+ product,
2717
+ variant
2875
2718
  }) {
2876
- const { plus_monthly_product, plus_annual_product } = memberSetting || {};
2877
- const { trigger: removeCartLines2 } = useRemoveCartLines();
2719
+ const [imageList, setImageList] = useState([]);
2720
+ const [sceneList, setSceneList] = useState([]);
2721
+ const [videoList, setVideoList] = useState([]);
2878
2722
  useEffect(() => {
2879
- if (!cart || !plus_monthly_product || !plus_annual_product) return;
2880
- const removePlusProduct = async (productType) => {
2881
- if (!productType) return;
2882
- const product = cart.lineItems?.find(
2883
- (item) => item.product?.handle === productType?.handle && item.variant?.sku === productType?.sku
2884
- );
2885
- if (product) {
2886
- await removeCartLines2({
2887
- lineIds: [product.id]
2888
- });
2723
+ if (!product || !variant) {
2724
+ setImageList([]);
2725
+ setSceneList([]);
2726
+ setVideoList([]);
2727
+ return;
2728
+ }
2729
+ const mediaList = getVariantMediaList({ product, variant });
2730
+ const images = mediaList.filter((media) => media.mediaContentType === "IMAGE");
2731
+ const videos = mediaList.filter(
2732
+ (media) => media.mediaContentType === "VIDEO" || media.mediaContentType === "EXTERNAL_VIDEO"
2733
+ );
2734
+ setImageList(images.length > 0 && images[0] ? [images[0]] : []);
2735
+ setSceneList(images.length > 1 ? images.slice(1) : []);
2736
+ setVideoList(videos);
2737
+ }, [product, variant]);
2738
+ return {
2739
+ productList: imageList,
2740
+ sceneList,
2741
+ videoList
2742
+ };
2743
+ }
2744
+ function useCollection(options = {}) {
2745
+ const { client, locale } = useShopify();
2746
+ const { handle, metafieldIdentifiers, ...swrOptions } = options;
2747
+ return useSWR(
2748
+ handle ? ["collection", locale, handle, metafieldIdentifiers] : null,
2749
+ () => getCollection(client, {
2750
+ handle,
2751
+ locale,
2752
+ metafieldIdentifiers
2753
+ }),
2754
+ swrOptions
2755
+ );
2756
+ }
2757
+ function useAllCollections(options = {}) {
2758
+ const { client, locale } = useShopify();
2759
+ const { first, query, sortKey, reverse, metafieldIdentifiers, ...swrOptions } = options;
2760
+ return useSWR(
2761
+ ["all-collections", locale, first, query, sortKey, reverse, metafieldIdentifiers],
2762
+ () => getAllCollections(client, {
2763
+ locale,
2764
+ first,
2765
+ query,
2766
+ sortKey,
2767
+ reverse,
2768
+ metafieldIdentifiers
2769
+ }),
2770
+ swrOptions
2771
+ );
2772
+ }
2773
+ function useCollections(options = {}) {
2774
+ const { client, locale } = useShopify();
2775
+ const { first, after, query, sortKey, reverse, metafieldIdentifiers, ...swrOptions } = options;
2776
+ return useSWR(
2777
+ ["collections", locale, first, after, query, sortKey, reverse, metafieldIdentifiers],
2778
+ () => getCollections(client, {
2779
+ locale,
2780
+ first,
2781
+ after,
2782
+ query,
2783
+ sortKey,
2784
+ reverse,
2785
+ metafieldIdentifiers
2786
+ }),
2787
+ swrOptions
2788
+ );
2789
+ }
2790
+ function useBlog(options = {}) {
2791
+ const { client, locale } = useShopify();
2792
+ const { handle, metafieldIdentifiers, ...swrOptions } = options;
2793
+ return useSWR(
2794
+ handle ? ["blog", locale, handle, metafieldIdentifiers] : null,
2795
+ () => getBlog(client, { handle, locale, metafieldIdentifiers }),
2796
+ swrOptions
2797
+ );
2798
+ }
2799
+ function useAllBlogs(options = {}) {
2800
+ const { client, locale } = useShopify();
2801
+ const { first, query, metafieldIdentifiers, ...swrOptions } = options;
2802
+ return useSWR(
2803
+ ["all-blogs", locale, first, query, metafieldIdentifiers],
2804
+ () => getAllBlogs(client, {
2805
+ locale,
2806
+ first,
2807
+ query,
2808
+ metafieldIdentifiers
2809
+ }),
2810
+ swrOptions
2811
+ );
2812
+ }
2813
+ function useArticle(options = {}) {
2814
+ const { client, locale } = useShopify();
2815
+ const { blogHandle, articleHandle, metafieldIdentifiers, ...swrOptions } = options;
2816
+ return useSWR(
2817
+ blogHandle && articleHandle ? ["article", locale, blogHandle, articleHandle, metafieldIdentifiers] : null,
2818
+ () => getArticle(client, {
2819
+ blogHandle,
2820
+ articleHandle,
2821
+ locale,
2822
+ metafieldIdentifiers
2823
+ }),
2824
+ swrOptions
2825
+ );
2826
+ }
2827
+ function useArticles(options = {}) {
2828
+ const { client, locale } = useShopify();
2829
+ const { first, query, sortKey, reverse, metafieldIdentifiers, ...swrOptions } = options;
2830
+ return useSWR(
2831
+ ["articles", locale, first, query, sortKey, reverse, metafieldIdentifiers],
2832
+ () => getArticles(client, {
2833
+ locale,
2834
+ first,
2835
+ query,
2836
+ sortKey,
2837
+ reverse,
2838
+ metafieldIdentifiers
2839
+ }),
2840
+ swrOptions
2841
+ );
2842
+ }
2843
+ function useArticlesInBlog(options = {}) {
2844
+ const { client, locale } = useShopify();
2845
+ const { blogHandle, first, sortKey, reverse, metafieldIdentifiers, ...swrOptions } = options;
2846
+ return useSWR(
2847
+ blogHandle ? ["articles-in-blog", locale, blogHandle, first, sortKey, reverse, metafieldIdentifiers] : null,
2848
+ () => getArticlesInBlog(client, {
2849
+ blogHandle,
2850
+ locale,
2851
+ first,
2852
+ sortKey,
2853
+ reverse,
2854
+ metafieldIdentifiers
2855
+ }),
2856
+ swrOptions
2857
+ );
2858
+ }
2859
+ async function performSearch(client, locale, searchQuery, first = 20, types = ["PRODUCT", "ARTICLE", "PAGE"]) {
2860
+ if (!searchQuery) {
2861
+ return void 0;
2862
+ }
2863
+ const query = (
2864
+ /* GraphQL */
2865
+ `
2866
+ query search($query: String!, $first: Int!, $types: [SearchType!])
2867
+ @inContext(language: $language) {
2868
+ search(query: $query, first: $first, types: $types, unavailableProducts: HIDE) {
2869
+ totalCount
2870
+ edges {
2871
+ node {
2872
+ ... on Article {
2873
+ __typename
2874
+ id
2875
+ handle
2876
+ title
2877
+ excerpt
2878
+ image {
2879
+ url
2880
+ altText
2881
+ }
2882
+ }
2883
+ ... on Page {
2884
+ __typename
2885
+ id
2886
+ handle
2887
+ title
2888
+ }
2889
+ ... on Product {
2890
+ __typename
2891
+ id
2892
+ handle
2893
+ title
2894
+ description
2895
+ featuredImage {
2896
+ url
2897
+ altText
2898
+ }
2899
+ }
2900
+ }
2901
+ }
2902
+ pageInfo {
2903
+ hasNextPage
2904
+ endCursor
2905
+ }
2889
2906
  }
2890
- };
2891
- if (profile?.isMonthlyPlus) {
2892
- removePlusProduct(plus_monthly_product);
2893
2907
  }
2894
- if (profile?.isAnnualPlus) {
2895
- removePlusProduct(plus_annual_product);
2896
- }
2897
- }, [cart, plus_annual_product, plus_monthly_product, profile, removeCartLines2]);
2898
- }
2899
- function usePlusMemberNeedAddToCart({
2900
- cart,
2901
- profile
2902
- }) {
2903
- const { selectedPlusMemberMode, selectedPlusMemberVariant, plusMemberMetafields } = usePlusMemberContext();
2904
- const { hasMonthlyPlus, hasAnnualPlus } = useHasPlusMemberInCart({
2905
- memberSetting: plusMemberMetafields,
2906
- cart
2908
+ `
2909
+ );
2910
+ const data = await client.query(query, {
2911
+ query: searchQuery,
2912
+ first,
2913
+ types
2907
2914
  });
2908
- const plusMemberVariant = useMemo(() => {
2909
- if (!selectedPlusMemberVariant || selectedPlusMemberMode === "free" /* FREE */) {
2910
- return void 0;
2911
- }
2912
- if (selectedPlusMemberMode === "monthly" /* MONTHLY */ && hasMonthlyPlus) {
2913
- return void 0;
2914
- }
2915
- if (selectedPlusMemberMode === "annual" /* ANNUAL */ && hasAnnualPlus) {
2916
- return void 0;
2917
- }
2918
- if (profile?.isMonthlyPlus && selectedPlusMemberMode === "monthly" /* MONTHLY */) {
2919
- return void 0;
2920
- }
2921
- if (profile?.isAnnualPlus && selectedPlusMemberMode === "annual" /* ANNUAL */) {
2922
- return void 0;
2915
+ if (!data || !data.search) {
2916
+ return void 0;
2917
+ }
2918
+ const items = data.search.edges?.map((edge) => {
2919
+ const node = edge.node;
2920
+ const item = {
2921
+ type: node.__typename.toUpperCase(),
2922
+ id: node.id,
2923
+ handle: node.handle,
2924
+ title: node.title
2925
+ };
2926
+ if (node.__typename === "Product") {
2927
+ item.description = node.description;
2928
+ item.image = node.featuredImage ? {
2929
+ url: node.featuredImage.url,
2930
+ altText: node.featuredImage.altText
2931
+ } : void 0;
2932
+ } else if (node.__typename === "Article") {
2933
+ item.description = node.excerpt;
2934
+ item.image = node.image ? {
2935
+ url: node.image.url,
2936
+ altText: node.image.altText
2937
+ } : void 0;
2923
2938
  }
2924
- return selectedPlusMemberVariant;
2925
- }, [selectedPlusMemberMode, selectedPlusMemberVariant, hasMonthlyPlus, hasAnnualPlus]);
2926
- return plusMemberVariant;
2939
+ return item;
2940
+ }) || [];
2941
+ return {
2942
+ items,
2943
+ totalCount: data.search.totalCount || 0,
2944
+ pageInfo: data.search.pageInfo
2945
+ };
2927
2946
  }
2928
- var PlusMemberProvider = ({
2929
- variant,
2930
- product,
2931
- memberSetting,
2932
- initialSelectedPlusMemberMode = "free",
2933
- profile,
2934
- children
2935
- }) => {
2936
- const [selectedPlusMemberMode, setSelectedPlusMemberMode] = useState(
2937
- initialSelectedPlusMemberMode
2947
+ function useSearch(options = {}) {
2948
+ const { client, locale } = useShopify();
2949
+ const { query, first = 20, types = ["PRODUCT", "ARTICLE", "PAGE"], ...swrOptions } = options;
2950
+ return useSWR(
2951
+ query ? ["search", locale, query, first, types] : null,
2952
+ () => performSearch(client, locale, query, first, types),
2953
+ swrOptions
2938
2954
  );
2939
- const [selectedShippingMethod, setSelectedShippingMethod] = useState();
2940
- const [showMoreShippingMethod, setShowMoreShippingMethod] = useState(false);
2941
- const [showPlusMemberBenefit, setShowPlusMemberBenefit] = useState(false);
2942
- const shippingMethodsContext = useShippingMethods({
2943
- variant,
2944
- plusMemberMetafields: memberSetting,
2945
- selectedPlusMemberMode,
2946
- profile
2947
- });
2948
- const { monthlyVariant, annualVariant } = usePlusMemberVariants({
2949
- memberSetting
2950
- });
2951
- const selectedPlusMemberVariant = useMemo(() => {
2952
- if (selectedPlusMemberMode === "free" /* FREE */) {
2953
- return void 0;
2955
+ }
2956
+ async function getSiteInfo(client, locale, metafieldIdentifiers) {
2957
+ const hasMetafields = metafieldIdentifiers && metafieldIdentifiers.length > 0;
2958
+ const query = (
2959
+ /* GraphQL */
2960
+ `
2961
+ query getSiteInfo(
2962
+ ${hasMetafields ? "$shopMetafieldIdentifiers: [HasMetafieldsIdentifier!]!" : ""}
2963
+ ) @inContext(language: $language) {
2964
+ shop {
2965
+ name
2966
+ description
2967
+ primaryDomain {
2968
+ url
2969
+ host
2970
+ }
2971
+ brand {
2972
+ logo {
2973
+ image {
2974
+ url
2975
+ }
2976
+ }
2977
+ colors {
2978
+ primary {
2979
+ background
2980
+ }
2981
+ secondary {
2982
+ background
2983
+ }
2984
+ }
2985
+ }
2986
+ ${hasMetafields ? "metafields(identifiers: $shopMetafieldIdentifiers) { key value }" : ""}
2987
+ }
2954
2988
  }
2955
- return selectedPlusMemberMode === "monthly" /* MONTHLY */ ? monthlyVariant : annualVariant;
2956
- }, [monthlyVariant, annualVariant, selectedPlusMemberMode]);
2957
- return /* @__PURE__ */ jsx(
2958
- PlusMemberContext.Provider,
2959
- {
2960
- value: {
2961
- variant,
2962
- plusMemberMetafields: memberSetting,
2963
- selectedPlusMemberMode,
2964
- setSelectedPlusMemberMode,
2965
- selectedShippingMethod,
2966
- setSelectedShippingMethod,
2967
- shippingMethodsContext,
2968
- showMoreShippingMethod,
2969
- setShowMoreShippingMethod,
2970
- selectedPlusMemberVariant,
2971
- product,
2972
- showPlusMemberBenefit,
2973
- setShowPlusMemberBenefit,
2974
- profile
2975
- },
2976
- children
2989
+ `
2990
+ );
2991
+ const variables = {};
2992
+ if (hasMetafields) {
2993
+ variables.shopMetafieldIdentifiers = metafieldIdentifiers;
2994
+ }
2995
+ const data = await client.query(query, variables);
2996
+ if (!data || !data.shop) {
2997
+ return void 0;
2998
+ }
2999
+ const shop = data.shop;
3000
+ const metafields = shop.metafields?.reduce((acc, mf) => {
3001
+ if (mf && mf.key) {
3002
+ acc[mf.key] = mf.value;
2977
3003
  }
3004
+ return acc;
3005
+ }, {});
3006
+ return {
3007
+ name: shop.name,
3008
+ description: shop.description,
3009
+ primaryDomain: shop.primaryDomain,
3010
+ brand: shop.brand ? {
3011
+ logo: shop.brand.logo,
3012
+ colors: shop.brand.colors ? {
3013
+ primary: shop.brand.colors.primary?.background,
3014
+ secondary: shop.brand.colors.secondary?.background
3015
+ } : void 0
3016
+ } : void 0,
3017
+ metafields
3018
+ };
3019
+ }
3020
+ function useSite(options = {}) {
3021
+ const { client, locale } = useShopify();
3022
+ const { metafieldIdentifiers, ...swrOptions } = options;
3023
+ return useSWR(
3024
+ ["site", locale, metafieldIdentifiers],
3025
+ () => getSiteInfo(client, locale, metafieldIdentifiers),
3026
+ swrOptions
2978
3027
  );
2979
- };
3028
+ }
2980
3029
  function useIntersection(targetRef, options) {
2981
3030
  const {
2982
3031
  callback,
@@ -3203,7 +3252,17 @@ function CartProvider({
3203
3252
  metafieldIdentifiers,
3204
3253
  disabled: isCartLoading
3205
3254
  });
3206
- const { attributes } = useCartAttributes({ profile, customer, cart, memberSetting });
3255
+ console.log("isCartLoading", isCartLoading);
3256
+ const { hasPlusMember } = useHasPlusMemberInCart({
3257
+ memberSetting,
3258
+ cart
3259
+ });
3260
+ const { attributes } = useCartAttributes({
3261
+ profile,
3262
+ customer,
3263
+ cart,
3264
+ memberType: hasPlusMember ? "2" : profile?.memberType
3265
+ });
3207
3266
  useRequest(
3208
3267
  () => {
3209
3268
  const newAttributes = [...attributes];
@@ -3266,7 +3325,8 @@ function CartProvider({
3266
3325
  const scriptAutoFreeGiftResult = useScriptAutoFreeGift({
3267
3326
  campaign: gradientGiftsConfig || null,
3268
3327
  _giveaway: CUSTOMER_SCRIPT_GIFT_KEY,
3269
- cart
3328
+ cart,
3329
+ profile
3270
3330
  });
3271
3331
  const formattedScriptGifts = useMemo(() => {
3272
3332
  return formatScriptAutoFreeGift({
@@ -3333,6 +3393,8 @@ function CartProvider({
3333
3393
  removeCustomAttributes,
3334
3394
  setCustomAttributes,
3335
3395
  locale,
3396
+ profile,
3397
+ customer,
3336
3398
  isCodeChanging,
3337
3399
  setIsCodeChanging,
3338
3400
  autoFreeGiftConfig,
@@ -3348,7 +3410,8 @@ function CartProvider({
3348
3410
  scriptAutoFreeGiftResult,
3349
3411
  setScriptAutoFreeGift,
3350
3412
  giftNeedAddToCartLines,
3351
- metafieldIdentifiers
3413
+ metafieldIdentifiers,
3414
+ memberSetting
3352
3415
  }),
3353
3416
  [
3354
3417
  cart,
@@ -3372,7 +3435,10 @@ function CartProvider({
3372
3435
  scriptAutoFreeGiftResult,
3373
3436
  setScriptAutoFreeGift,
3374
3437
  giftNeedAddToCartLines,
3375
- metafieldIdentifiers
3438
+ metafieldIdentifiers,
3439
+ customer,
3440
+ profile,
3441
+ memberSetting
3376
3442
  ]
3377
3443
  );
3378
3444
  return /* @__PURE__ */ jsx(CartContext.Provider, { value, children });
@@ -3385,6 +3451,6 @@ function useCartContext(options) {
3385
3451
  return context;
3386
3452
  }
3387
3453
 
3388
- export { BrowserPerformanceAdapter, BuyRuleType, CODE_AMOUNT_KEY, CUSTOMER_ATTRIBUTE_KEY, CUSTOMER_SCRIPT_GIFT_KEY, CartProvider, DeliveryPlusType, MAIN_PRODUCT_CODE, MEMBER_PRICE_ATTRIBUTE_KEY, OrderBasePriceType, OrderDiscountType, PLUS_MEMBER_TYPE, PlusMemberContext, PlusMemberMode, PlusMemberProvider, PriceBasePriceType, PriceDiscountType, RuleType, SCRIPT_CODE_AMOUNT_KEY, ShippingMethodMode, ShopifyContext, ShopifyProvider, SpendMoneyType, browserCartCookieAdapter, browserCookieAdapter, checkAttributesUpdateNeeded, clearGeoLocationCache, createMockCartFromLines, currencyCodeMapping, defaultSWRMutationConfiguration, formatFunctionAutoFreeGift, formatScriptAutoFreeGift, gaTrack, getCachedGeoLocation, getDiscountEnvAttributeValue, getMatchedMainProductSubTotal, getQuery, getReferralAttributes, hasPlusMemberInCart, normalizeAddToCartLines, preCheck, safeParse, trackAddToCartFBQ, trackAddToCartGA, trackBeginCheckoutGA, trackBuyNowFBQ, trackBuyNowGA, useAddCartLines, useAddToCart, useAllBlogs, useAllCollections, useAllProducts, useApplyCartCodes, useArticle, useArticles, useArticlesInBlog, useAutoRemovePlusMemberInCart, useAvailableDeliveryCoupon, useBlog, useBuyNow, useCalcAutoFreeGift, useCalcGiftsFromLines, useCalcOrderDiscount, useCartAttributes, useCartContext, useCartItemQuantityLimit, useCollection, useCollections, useCreateCart, useExposure, useGeoLocation, useHasPlusMemberInCart, useIntersection, usePlusMemberCheckoutCustomAttributes, usePlusMemberContext, usePlusMemberDeliveryCodes, usePlusMemberNeedAddToCart, usePlusMemberVariants, usePrice, useProduct, useProductUrl, useProductsByHandles, useRemoveCartCodes, useRemoveCartLines, useReplaceCartPlusMember, useScriptAutoFreeGift, useSearch, useSelectedOptions, useShippingMethods, useShopify, useSite, useUpdateCartAttributes, useUpdateCartLines, useUpdateLineCodeAmountAttributes, useUpdateVariantQuery, useVariant, useVariantMedia };
3454
+ export { BrowserPerformanceAdapter, BuyRuleType, CODE_AMOUNT_KEY, CUSTOMER_ATTRIBUTE_KEY, CUSTOMER_SCRIPT_GIFT_KEY, CartProvider, DeliveryPlusType, MAIN_PRODUCT_CODE, MEMBER_PRICE_ATTRIBUTE_KEY, OrderBasePriceType, OrderDiscountType, PLUS_MEMBER_TYPE, PlusMemberContext, PlusMemberMode, PlusMemberProvider, PriceBasePriceType, PriceDiscountType, RuleType, SCRIPT_CODE_AMOUNT_KEY, ShippingMethodMode, ShopifyContext, ShopifyProvider, SpendMoneyType, browserCartCookieAdapter, browserCookieAdapter, checkAttributesUpdateNeeded, clearGeoLocationCache, createMockCartFromLines, currencyCodeMapping, defaultSWRMutationConfiguration, formatFunctionAutoFreeGift, formatScriptAutoFreeGift, gaTrack, getCachedGeoLocation, getCartAttributes, getDiscountEnvAttributeValue, getMatchedMainProductSubTotal, getQuery, getReferralAttributes, getUserType, hasPlusMemberInCart, hasPlusMemberInLines, normalizeAddToCartLines, preCheck, safeParse, trackAddToCartFBQ, trackAddToCartGA, trackBeginCheckoutGA, trackBuyNowFBQ, trackBuyNowGA, useAddCartLines, useAddToCart, useAllBlogs, useAllCollections, useAllProducts, useApplyCartCodes, useArticle, useArticles, useArticlesInBlog, useAutoRemovePlusMemberInCart, useAvailableDeliveryCoupon, useBlog, useBuyNow, useCalcAutoFreeGift, useCalcGiftsFromLines, useCalcOrderDiscount, useCartAttributes, useCartContext, useCartItemQuantityLimit, useCollection, useCollections, useCreateCart, useExposure, useGeoLocation, useHasPlusMemberInCart, useHasPlusMemberInLines, useIntersection, usePlusMemberCheckoutCustomAttributes, usePlusMemberContext, usePlusMemberNeedAddToCart, usePlusMemberVariants, usePrice, useProduct, useProductUrl, useProductsByHandles, useRemoveCartCodes, useRemoveCartLines, useReplaceCartPlusMember, useScriptAutoFreeGift, useSearch, useSelectedOptions, useShippingMethods, useShopify, useSite, useUpdateCartAttributes, useUpdateCartLines, useUpdateLineCodeAmountAttributes, useUpdateVariantQuery, useVariant, useVariantMedia };
3389
3455
  //# sourceMappingURL=index.mjs.map
3390
3456
  //# sourceMappingURL=index.mjs.map