@anker-in/shopify-react 0.1.1-beta.35 → 0.1.1-beta.37
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 +16 -13
- package/dist/hooks/index.d.ts +16 -13
- package/dist/hooks/index.js +119 -81
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +119 -82
- 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 +119 -81
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +119 -82
- package/dist/index.mjs.map +1 -1
- package/dist/provider/index.js +65 -39
- package/dist/provider/index.js.map +1 -1
- package/dist/provider/index.mjs +65 -39
- package/dist/provider/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/hooks/index.mjs
CHANGED
|
@@ -388,54 +388,28 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
|
|
|
388
388
|
}
|
|
389
389
|
return { activeCampaign: null, subtotal: 0 };
|
|
390
390
|
}, [autoFreeGiftConfig, effectiveCart, tags, dealsType]);
|
|
391
|
-
const {
|
|
391
|
+
const { qualifyingTier, nextTierGoal, actualThreshold, currentCurrency } = useMemo(() => {
|
|
392
392
|
if (!activeCampaign || !activeCampaign.rule_result?.spend_get_reward?.gift_product) {
|
|
393
|
-
return {
|
|
393
|
+
return { qualifyingTier: null, nextTierGoal: null, actualThreshold: 0, currentCurrency: "" };
|
|
394
394
|
}
|
|
395
395
|
const giftTiers = activeCampaign.rule_result.spend_get_reward.gift_product;
|
|
396
|
-
const
|
|
397
|
-
console.log("currentCurrency useCalcAutoFreeGift", effectiveCart,
|
|
396
|
+
const currentCurrency2 = effectiveCart?.currency?.code || "";
|
|
397
|
+
console.log("currentCurrency useCalcAutoFreeGift", effectiveCart, currentCurrency2);
|
|
398
398
|
const getThresholdAmount = (tier) => {
|
|
399
|
-
if (tier.spend_sum_money_multi_markets?.[
|
|
400
|
-
return Number(tier.spend_sum_money_multi_markets[
|
|
399
|
+
if (tier.spend_sum_money_multi_markets?.[currentCurrency2]?.value) {
|
|
400
|
+
return Number(tier.spend_sum_money_multi_markets[currentCurrency2].value);
|
|
401
401
|
}
|
|
402
402
|
return Number(tier.spend_sum_money || 0);
|
|
403
403
|
};
|
|
404
|
-
const
|
|
404
|
+
const qualifyingTier2 = [...giftTiers].sort((a, b) => getThresholdAmount(b) - getThresholdAmount(a)).find((tier) => subtotal >= getThresholdAmount(tier));
|
|
405
405
|
const nextGoal = giftTiers.find((tier) => subtotal < getThresholdAmount(tier));
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
itemsToAdd: qualifyingTier.reward_list?.map((reward) => {
|
|
413
|
-
const giftProduct = reward?.variant_list?.[0];
|
|
414
|
-
if (!giftProduct) return null;
|
|
415
|
-
return {
|
|
416
|
-
variant: {
|
|
417
|
-
id: btoaID(giftProduct.variant_id),
|
|
418
|
-
handle: giftProduct.handle,
|
|
419
|
-
sku: giftProduct.sku
|
|
420
|
-
},
|
|
421
|
-
quantity: reward?.get_unit || 1,
|
|
422
|
-
attributes: [
|
|
423
|
-
{
|
|
424
|
-
key: CUSTOMER_ATTRIBUTE_KEY,
|
|
425
|
-
value: JSON.stringify({
|
|
426
|
-
is_gift: true,
|
|
427
|
-
rule_id: activeCampaign.rule_id,
|
|
428
|
-
spend_sum_money: actualThreshold,
|
|
429
|
-
// 使用实际的门槛金额(多币种支持)
|
|
430
|
-
currency_code: currentCurrency
|
|
431
|
-
// 记录当前币种
|
|
432
|
-
})
|
|
433
|
-
}
|
|
434
|
-
]
|
|
435
|
-
};
|
|
436
|
-
}).filter((item) => item !== null)
|
|
406
|
+
const actualThreshold2 = qualifyingTier2 ? getThresholdAmount(qualifyingTier2) : 0;
|
|
407
|
+
return {
|
|
408
|
+
qualifyingTier: qualifyingTier2,
|
|
409
|
+
nextTierGoal: nextGoal || null,
|
|
410
|
+
actualThreshold: actualThreshold2,
|
|
411
|
+
currentCurrency: currentCurrency2
|
|
437
412
|
};
|
|
438
|
-
return { qualifyingGift: formattedGift, nextTierGoal: nextGoal || null };
|
|
439
413
|
}, [activeCampaign, subtotal, effectiveCart]);
|
|
440
414
|
const giftHandles = useMemo(() => {
|
|
441
415
|
const giftVariant = autoFreeGiftConfig.map(
|
|
@@ -476,6 +450,58 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
|
|
|
476
450
|
}
|
|
477
451
|
return giftProductsResult;
|
|
478
452
|
}, [giftProductsResult, shouldFetch]);
|
|
453
|
+
const qualifyingGift = useMemo(() => {
|
|
454
|
+
if (!qualifyingTier || !activeCampaign) {
|
|
455
|
+
return null;
|
|
456
|
+
}
|
|
457
|
+
const itemsToAdd = qualifyingTier.reward_list?.map((reward) => {
|
|
458
|
+
if (!reward.variant_list || reward.variant_list.length === 0) {
|
|
459
|
+
return null;
|
|
460
|
+
}
|
|
461
|
+
let selectedGiftProduct = null;
|
|
462
|
+
for (const giftVariant of reward.variant_list) {
|
|
463
|
+
const productInfo = finalGiftProductsResult?.find(
|
|
464
|
+
(p) => p.handle === giftVariant.handle
|
|
465
|
+
);
|
|
466
|
+
if (productInfo) {
|
|
467
|
+
const variantInfo = productInfo.variants?.find((v) => v.sku === giftVariant.sku);
|
|
468
|
+
if (variantInfo?.availableForSale) {
|
|
469
|
+
selectedGiftProduct = giftVariant;
|
|
470
|
+
break;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
if (!selectedGiftProduct) {
|
|
475
|
+
selectedGiftProduct = reward.variant_list[0];
|
|
476
|
+
}
|
|
477
|
+
return {
|
|
478
|
+
variant: {
|
|
479
|
+
id: btoaID(selectedGiftProduct.variant_id),
|
|
480
|
+
handle: selectedGiftProduct.handle,
|
|
481
|
+
sku: selectedGiftProduct.sku
|
|
482
|
+
},
|
|
483
|
+
quantity: reward?.get_unit || 1,
|
|
484
|
+
attributes: [
|
|
485
|
+
{
|
|
486
|
+
key: CUSTOMER_ATTRIBUTE_KEY,
|
|
487
|
+
value: JSON.stringify({
|
|
488
|
+
is_gift: true,
|
|
489
|
+
rule_id: activeCampaign.rule_id,
|
|
490
|
+
spend_sum_money: actualThreshold,
|
|
491
|
+
// 使用实际的门槛金额(多币种支持)
|
|
492
|
+
currency_code: currentCurrency
|
|
493
|
+
// 记录当前币种
|
|
494
|
+
})
|
|
495
|
+
}
|
|
496
|
+
]
|
|
497
|
+
};
|
|
498
|
+
}).filter((item) => item !== null);
|
|
499
|
+
const formattedGift = {
|
|
500
|
+
tier: qualifyingTier,
|
|
501
|
+
itemsToAdd
|
|
502
|
+
};
|
|
503
|
+
return formattedGift;
|
|
504
|
+
}, [qualifyingTier, activeCampaign, finalGiftProductsResult, actualThreshold, currentCurrency]);
|
|
479
505
|
return {
|
|
480
506
|
qualifyingGift,
|
|
481
507
|
nextTierGoal,
|
|
@@ -2417,15 +2443,27 @@ function usePlusAnnualProductVariant() {
|
|
|
2417
2443
|
}, [plusMemberProducts, plusAnnual]);
|
|
2418
2444
|
return plusAnnualProductVariant;
|
|
2419
2445
|
}
|
|
2420
|
-
|
|
2421
|
-
const {
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2446
|
+
var useAvailableDeliveryCoupon = ({ profile }) => {
|
|
2447
|
+
const { data: availableDeliveryCoupon, isLoading } = useSWR(
|
|
2448
|
+
profile?.email ? ["/api/multipass/subsrv/v1/prime/delivery_coupons/current/available", profile?.email] : void 0,
|
|
2449
|
+
async ([apiPath]) => {
|
|
2450
|
+
return fetch(apiPath).then((res) => res.json());
|
|
2451
|
+
}
|
|
2452
|
+
);
|
|
2453
|
+
console.log("availableDeliveryCoupon", availableDeliveryCoupon);
|
|
2454
|
+
const { ndd_coupon: nddCoupon, tdd_coupon: tddCoupon } = availableDeliveryCoupon?.data?.data || {};
|
|
2455
|
+
return {
|
|
2426
2456
|
nddCoupon,
|
|
2427
|
-
tddCoupon
|
|
2428
|
-
|
|
2457
|
+
tddCoupon,
|
|
2458
|
+
isLoading
|
|
2459
|
+
};
|
|
2460
|
+
};
|
|
2461
|
+
|
|
2462
|
+
// src/hooks/member/plus/use-shipping-methods.ts
|
|
2463
|
+
function useShippingMethods(options) {
|
|
2464
|
+
const { variant, plusMemberMetafields, selectedPlusMemberMode, isPlus = false, profile } = options;
|
|
2465
|
+
const { nddCoupon, tddCoupon, isLoading } = useAvailableDeliveryCoupon({ profile });
|
|
2466
|
+
console.log("nddCoupon", nddCoupon);
|
|
2429
2467
|
const { plus_shipping, shippingMethod } = plusMemberMetafields || {};
|
|
2430
2468
|
const nddOverweight = useMemo(() => {
|
|
2431
2469
|
return (variant?.weight || 0) > (shippingMethod?.overWeight_ndd || Infinity);
|
|
@@ -2435,12 +2473,10 @@ function useShippingMethods(options) {
|
|
|
2435
2473
|
}, [shippingMethod?.overWeight_tdd, variant?.weight]);
|
|
2436
2474
|
const paymentShippingMethods = useMemo(() => {
|
|
2437
2475
|
const weight = variant?.weight || 0;
|
|
2438
|
-
const methods = plus_shipping?.shipping_methods?.filter(
|
|
2439
|
-
(
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
}
|
|
2443
|
-
) || [];
|
|
2476
|
+
const methods = plus_shipping?.shipping_methods?.filter(({ weight_low, weight_high, __mode, __plus }) => {
|
|
2477
|
+
const fitWeight = (!weight_low || weight >= weight_low) && (!weight_high || weight <= weight_high);
|
|
2478
|
+
return __mode !== "free" /* FREE */ && !__plus && fitWeight;
|
|
2479
|
+
}) || [];
|
|
2444
2480
|
return methods.map((method) => {
|
|
2445
2481
|
let disabled = false;
|
|
2446
2482
|
const selectedFreeMember = selectedPlusMemberMode === "free";
|
|
@@ -2467,40 +2503,34 @@ function useShippingMethods(options) {
|
|
|
2467
2503
|
]);
|
|
2468
2504
|
const nddPrice = useMemo(() => {
|
|
2469
2505
|
const weight = variant?.weight || 0;
|
|
2470
|
-
const nddMethod = paymentShippingMethods.find(
|
|
2471
|
-
(
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
}
|
|
2475
|
-
);
|
|
2506
|
+
const nddMethod = paymentShippingMethods.find(({ __mode, weight_high, weight_low }) => {
|
|
2507
|
+
const fitWeight = (!weight_low || weight >= weight_low) && (!weight_high || weight <= weight_high);
|
|
2508
|
+
return __mode === "ndd" && fitWeight;
|
|
2509
|
+
});
|
|
2476
2510
|
return nddMethod?.price || 0;
|
|
2477
2511
|
}, [variant?.weight, paymentShippingMethods]);
|
|
2478
2512
|
const tddPrice = useMemo(() => {
|
|
2479
2513
|
const weight = variant?.weight || 0;
|
|
2480
|
-
const tddMethod = paymentShippingMethods.find(
|
|
2481
|
-
(
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
}
|
|
2485
|
-
);
|
|
2514
|
+
const tddMethod = paymentShippingMethods.find(({ __mode, weight_high, weight_low }) => {
|
|
2515
|
+
const fitWeight = (!weight_low || weight >= weight_low) && (!weight_high || weight <= weight_high);
|
|
2516
|
+
return __mode === "tdd" && fitWeight;
|
|
2517
|
+
});
|
|
2486
2518
|
return tddMethod?.price || 0;
|
|
2487
2519
|
}, [variant?.weight, paymentShippingMethods]);
|
|
2488
2520
|
const freeShippingMethods = useMemo(() => {
|
|
2489
2521
|
const weight = variant?.weight || 0;
|
|
2490
|
-
let methods = plus_shipping?.shipping_methods?.filter(
|
|
2491
|
-
(
|
|
2492
|
-
|
|
2493
|
-
return true;
|
|
2494
|
-
}
|
|
2495
|
-
if (isPlus) {
|
|
2496
|
-
const hasCoupon = isPlus && __mode === "ndd" /* NDD */ && nddCoupon || isPlus && __mode === "tdd" /* TDD */ && (tddCoupon || nddCoupon);
|
|
2497
|
-
const fitWeight = (!weight_low || weight >= weight_low) && (!weight_high || weight <= weight_high);
|
|
2498
|
-
return hasCoupon && fitWeight && !__plus;
|
|
2499
|
-
} else {
|
|
2500
|
-
return __plus;
|
|
2501
|
-
}
|
|
2522
|
+
let methods = plus_shipping?.shipping_methods?.filter(({ __mode, __plus, weight_low, weight_high }) => {
|
|
2523
|
+
if (__mode === "free" /* FREE */) {
|
|
2524
|
+
return true;
|
|
2502
2525
|
}
|
|
2503
|
-
|
|
2526
|
+
if (isPlus) {
|
|
2527
|
+
const hasCoupon = isPlus && __mode === "ndd" /* NDD */ && nddCoupon || isPlus && __mode === "tdd" /* TDD */ && (tddCoupon || nddCoupon);
|
|
2528
|
+
const fitWeight = (!weight_low || weight >= weight_low) && (!weight_high || weight <= weight_high);
|
|
2529
|
+
return hasCoupon && fitWeight && !__plus;
|
|
2530
|
+
} else {
|
|
2531
|
+
return __plus;
|
|
2532
|
+
}
|
|
2533
|
+
}) || [];
|
|
2504
2534
|
if (isPlus) {
|
|
2505
2535
|
methods = methods.sort((a, b) => {
|
|
2506
2536
|
if (b.__mode === "free" /* FREE */) return -1;
|
|
@@ -2554,7 +2584,10 @@ function useShippingMethods(options) {
|
|
|
2554
2584
|
freeShippingMethods,
|
|
2555
2585
|
paymentShippingMethods,
|
|
2556
2586
|
nddOverweight,
|
|
2557
|
-
tddOverweight
|
|
2587
|
+
tddOverweight,
|
|
2588
|
+
nddCoupon,
|
|
2589
|
+
tddCoupon,
|
|
2590
|
+
isLoadingCoupon: isLoading
|
|
2558
2591
|
};
|
|
2559
2592
|
}
|
|
2560
2593
|
function useShippingMethodAvailableCheck() {
|
|
@@ -2844,9 +2877,9 @@ var PlusMemberProvider = ({
|
|
|
2844
2877
|
memberSetting,
|
|
2845
2878
|
initialSelectedPlusMemberMode = "free",
|
|
2846
2879
|
profile,
|
|
2847
|
-
locale,
|
|
2848
2880
|
children
|
|
2849
2881
|
}) => {
|
|
2882
|
+
const { locale } = useShopify();
|
|
2850
2883
|
const [zipCode, setZipCode] = useState("");
|
|
2851
2884
|
const [showTip, setShowTip] = useState(false);
|
|
2852
2885
|
const [selectedPlusMemberMode, setSelectedPlusMemberMode] = useState(
|
|
@@ -2862,7 +2895,11 @@ var PlusMemberProvider = ({
|
|
|
2862
2895
|
const shippingMethodsContext = useShippingMethods({
|
|
2863
2896
|
variant,
|
|
2864
2897
|
plusMemberMetafields: memberSetting,
|
|
2865
|
-
selectedPlusMemberMode
|
|
2898
|
+
selectedPlusMemberMode,
|
|
2899
|
+
profile,
|
|
2900
|
+
isPlus: profile?.isPlus || false
|
|
2901
|
+
});
|
|
2902
|
+
console.log("shippingMethodsContext", shippingMethodsContext);
|
|
2866
2903
|
const plusMemberHandles = useMemo(() => {
|
|
2867
2904
|
return [
|
|
2868
2905
|
memberSetting?.plus_monthly_product?.handle,
|
|
@@ -3099,6 +3136,6 @@ function clearGeoLocationCache(cacheKey = "geoLocation") {
|
|
|
3099
3136
|
}
|
|
3100
3137
|
}
|
|
3101
3138
|
|
|
3102
|
-
export { BuyRuleType, CODE_AMOUNT_KEY, CUSTOMER_ATTRIBUTE_KEY, CUSTOMER_SCRIPT_GIFT_KEY, DeliveryPlusType, MAIN_PRODUCT_CODE, OrderBasePriceType, OrderDiscountType, PLUS_MEMBER_TYPE, PlusMemberContext, PlusMemberMode, PlusMemberProvider, PriceBasePriceType, PriceDiscountType, RuleType, SCRIPT_CODE_AMOUNT_KEY, ShippingMethodMode, SpendMoneyType, checkAttributesUpdateNeeded, clearGeoLocationCache, createMockCartFromLines, currencyCodeMapping, defaultSWRMutationConfiguration, formatFunctionAutoFreeGift, formatScriptAutoFreeGift, getCachedGeoLocation, getDiscountEnvAttributeValue, getMatchedMainProductSubTotal, getQuery, getReferralAttributes, normalizeAddToCartLines, preCheck, safeParse, useAddCartLines, useAddToCart, useAllBlogs, useAllCollections, useAllProducts, useApplyCartCodes, useArticle, useArticles, useArticlesInBlog, useAutoRemovePlusMemberInCart, useBlog, useBuyNow, useCalcAutoFreeGift, useCalcGiftsFromLines, useCalcOrderDiscount, useCartAttributes, useCartItemQuantityLimit, useCollection, useCollections, useCreateCart, useExposure, useGeoLocation, useHasPlusMemberInCart, useIntersection, usePlusAnnualProductVariant, usePlusMemberCheckoutCustomAttributes, usePlusMemberContext, usePlusMemberDeliveryCodes, usePlusMemberItemCustomAttributes, usePlusMemberNeedAddToCart, usePlusMonthlyProductVariant, usePrice, useProduct, useProductUrl, useProductsByHandles, useRemoveCartCodes, useRemoveCartLines, useReplaceCartPlusMember, useScriptAutoFreeGift, useSearch, useSelectedOptions, useShippingMethodAvailableCheck, useShippingMethods, useSite, useUpdateCartAttributes, useUpdateCartLines, useUpdateLineCodeAmountAttributes, useUpdatePlusMemberDeliveryOptions, useUpdateVariantQuery, useVariant, useVariantMedia };
|
|
3139
|
+
export { BuyRuleType, CODE_AMOUNT_KEY, CUSTOMER_ATTRIBUTE_KEY, CUSTOMER_SCRIPT_GIFT_KEY, DeliveryPlusType, MAIN_PRODUCT_CODE, OrderBasePriceType, OrderDiscountType, PLUS_MEMBER_TYPE, PlusMemberContext, PlusMemberMode, PlusMemberProvider, PriceBasePriceType, PriceDiscountType, RuleType, SCRIPT_CODE_AMOUNT_KEY, ShippingMethodMode, SpendMoneyType, checkAttributesUpdateNeeded, clearGeoLocationCache, createMockCartFromLines, currencyCodeMapping, defaultSWRMutationConfiguration, formatFunctionAutoFreeGift, formatScriptAutoFreeGift, getCachedGeoLocation, getDiscountEnvAttributeValue, getMatchedMainProductSubTotal, getQuery, getReferralAttributes, normalizeAddToCartLines, preCheck, safeParse, useAddCartLines, useAddToCart, useAllBlogs, useAllCollections, useAllProducts, useApplyCartCodes, useArticle, useArticles, useArticlesInBlog, useAutoRemovePlusMemberInCart, useAvailableDeliveryCoupon, useBlog, useBuyNow, useCalcAutoFreeGift, useCalcGiftsFromLines, useCalcOrderDiscount, useCartAttributes, useCartItemQuantityLimit, useCollection, useCollections, useCreateCart, useExposure, useGeoLocation, useHasPlusMemberInCart, useIntersection, usePlusAnnualProductVariant, usePlusMemberCheckoutCustomAttributes, usePlusMemberContext, usePlusMemberDeliveryCodes, usePlusMemberItemCustomAttributes, usePlusMemberNeedAddToCart, usePlusMonthlyProductVariant, usePrice, useProduct, useProductUrl, useProductsByHandles, useRemoveCartCodes, useRemoveCartLines, useReplaceCartPlusMember, useScriptAutoFreeGift, useSearch, useSelectedOptions, useShippingMethodAvailableCheck, useShippingMethods, useSite, useUpdateCartAttributes, useUpdateCartLines, useUpdateLineCodeAmountAttributes, useUpdatePlusMemberDeliveryOptions, useUpdateVariantQuery, useVariant, useVariantMedia };
|
|
3103
3140
|
//# sourceMappingURL=index.mjs.map
|
|
3104
3141
|
//# sourceMappingURL=index.mjs.map
|