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