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