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

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