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