@anker-in/shopify-react 0.1.1-beta.34 → 0.1.1-beta.36
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 +3 -3
package/dist/index.mjs
CHANGED
|
@@ -477,54 +477,28 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
|
|
|
477
477
|
}
|
|
478
478
|
return { activeCampaign: null, subtotal: 0 };
|
|
479
479
|
}, [autoFreeGiftConfig, effectiveCart, tags, dealsType]);
|
|
480
|
-
const {
|
|
480
|
+
const { qualifyingTier, nextTierGoal, actualThreshold, currentCurrency } = useMemo(() => {
|
|
481
481
|
if (!activeCampaign || !activeCampaign.rule_result?.spend_get_reward?.gift_product) {
|
|
482
|
-
return {
|
|
482
|
+
return { qualifyingTier: null, nextTierGoal: null, actualThreshold: 0, currentCurrency: "" };
|
|
483
483
|
}
|
|
484
484
|
const giftTiers = activeCampaign.rule_result.spend_get_reward.gift_product;
|
|
485
|
-
const
|
|
486
|
-
console.log("currentCurrency useCalcAutoFreeGift", effectiveCart,
|
|
485
|
+
const currentCurrency2 = effectiveCart?.currency?.code || "";
|
|
486
|
+
console.log("currentCurrency useCalcAutoFreeGift", effectiveCart, currentCurrency2);
|
|
487
487
|
const getThresholdAmount = (tier) => {
|
|
488
|
-
if (tier.spend_sum_money_multi_markets?.[
|
|
489
|
-
return Number(tier.spend_sum_money_multi_markets[
|
|
488
|
+
if (tier.spend_sum_money_multi_markets?.[currentCurrency2]?.value) {
|
|
489
|
+
return Number(tier.spend_sum_money_multi_markets[currentCurrency2].value);
|
|
490
490
|
}
|
|
491
491
|
return Number(tier.spend_sum_money || 0);
|
|
492
492
|
};
|
|
493
|
-
const
|
|
493
|
+
const qualifyingTier2 = [...giftTiers].sort((a, b) => getThresholdAmount(b) - getThresholdAmount(a)).find((tier) => subtotal >= getThresholdAmount(tier));
|
|
494
494
|
const nextGoal = giftTiers.find((tier) => subtotal < getThresholdAmount(tier));
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
itemsToAdd: qualifyingTier.reward_list?.map((reward) => {
|
|
502
|
-
const giftProduct = reward?.variant_list?.[0];
|
|
503
|
-
if (!giftProduct) return null;
|
|
504
|
-
return {
|
|
505
|
-
variant: {
|
|
506
|
-
id: btoaID(giftProduct.variant_id),
|
|
507
|
-
handle: giftProduct.handle,
|
|
508
|
-
sku: giftProduct.sku
|
|
509
|
-
},
|
|
510
|
-
quantity: reward?.get_unit || 1,
|
|
511
|
-
attributes: [
|
|
512
|
-
{
|
|
513
|
-
key: CUSTOMER_ATTRIBUTE_KEY,
|
|
514
|
-
value: JSON.stringify({
|
|
515
|
-
is_gift: true,
|
|
516
|
-
rule_id: activeCampaign.rule_id,
|
|
517
|
-
spend_sum_money: actualThreshold,
|
|
518
|
-
// 使用实际的门槛金额(多币种支持)
|
|
519
|
-
currency_code: currentCurrency
|
|
520
|
-
// 记录当前币种
|
|
521
|
-
})
|
|
522
|
-
}
|
|
523
|
-
]
|
|
524
|
-
};
|
|
525
|
-
}).filter((item) => item !== null)
|
|
495
|
+
const actualThreshold2 = qualifyingTier2 ? getThresholdAmount(qualifyingTier2) : 0;
|
|
496
|
+
return {
|
|
497
|
+
qualifyingTier: qualifyingTier2,
|
|
498
|
+
nextTierGoal: nextGoal || null,
|
|
499
|
+
actualThreshold: actualThreshold2,
|
|
500
|
+
currentCurrency: currentCurrency2
|
|
526
501
|
};
|
|
527
|
-
return { qualifyingGift: formattedGift, nextTierGoal: nextGoal || null };
|
|
528
502
|
}, [activeCampaign, subtotal, effectiveCart]);
|
|
529
503
|
const giftHandles = useMemo(() => {
|
|
530
504
|
const giftVariant = autoFreeGiftConfig.map(
|
|
@@ -565,6 +539,58 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
|
|
|
565
539
|
}
|
|
566
540
|
return giftProductsResult;
|
|
567
541
|
}, [giftProductsResult, shouldFetch]);
|
|
542
|
+
const qualifyingGift = useMemo(() => {
|
|
543
|
+
if (!qualifyingTier || !activeCampaign) {
|
|
544
|
+
return null;
|
|
545
|
+
}
|
|
546
|
+
const itemsToAdd = qualifyingTier.reward_list?.map((reward) => {
|
|
547
|
+
if (!reward.variant_list || reward.variant_list.length === 0) {
|
|
548
|
+
return null;
|
|
549
|
+
}
|
|
550
|
+
let selectedGiftProduct = null;
|
|
551
|
+
for (const giftVariant of reward.variant_list) {
|
|
552
|
+
const productInfo = finalGiftProductsResult?.find(
|
|
553
|
+
(p) => p.handle === giftVariant.handle
|
|
554
|
+
);
|
|
555
|
+
if (productInfo) {
|
|
556
|
+
const variantInfo = productInfo.variants?.find((v) => v.sku === giftVariant.sku);
|
|
557
|
+
if (variantInfo?.availableForSale) {
|
|
558
|
+
selectedGiftProduct = giftVariant;
|
|
559
|
+
break;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
if (!selectedGiftProduct) {
|
|
564
|
+
selectedGiftProduct = reward.variant_list[0];
|
|
565
|
+
}
|
|
566
|
+
return {
|
|
567
|
+
variant: {
|
|
568
|
+
id: btoaID(selectedGiftProduct.variant_id),
|
|
569
|
+
handle: selectedGiftProduct.handle,
|
|
570
|
+
sku: selectedGiftProduct.sku
|
|
571
|
+
},
|
|
572
|
+
quantity: reward?.get_unit || 1,
|
|
573
|
+
attributes: [
|
|
574
|
+
{
|
|
575
|
+
key: CUSTOMER_ATTRIBUTE_KEY,
|
|
576
|
+
value: JSON.stringify({
|
|
577
|
+
is_gift: true,
|
|
578
|
+
rule_id: activeCampaign.rule_id,
|
|
579
|
+
spend_sum_money: actualThreshold,
|
|
580
|
+
// 使用实际的门槛金额(多币种支持)
|
|
581
|
+
currency_code: currentCurrency
|
|
582
|
+
// 记录当前币种
|
|
583
|
+
})
|
|
584
|
+
}
|
|
585
|
+
]
|
|
586
|
+
};
|
|
587
|
+
}).filter((item) => item !== null);
|
|
588
|
+
const formattedGift = {
|
|
589
|
+
tier: qualifyingTier,
|
|
590
|
+
itemsToAdd
|
|
591
|
+
};
|
|
592
|
+
return formattedGift;
|
|
593
|
+
}, [qualifyingTier, activeCampaign, finalGiftProductsResult, actualThreshold, currentCurrency]);
|
|
568
594
|
return {
|
|
569
595
|
qualifyingGift,
|
|
570
596
|
nextTierGoal,
|
|
@@ -2531,15 +2557,27 @@ function usePlusAnnualProductVariant() {
|
|
|
2531
2557
|
}, [plusMemberProducts, plusAnnual]);
|
|
2532
2558
|
return plusAnnualProductVariant;
|
|
2533
2559
|
}
|
|
2534
|
-
|
|
2535
|
-
const {
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2560
|
+
var useAvailableDeliveryCoupon = ({ profile }) => {
|
|
2561
|
+
const { data: availableDeliveryCoupon, isLoading } = useSWR(
|
|
2562
|
+
profile?.email ? ["/api/multipass/subsrv/v1/prime/delivery_coupons/current/available", profile?.email] : void 0,
|
|
2563
|
+
async ([apiPath]) => {
|
|
2564
|
+
return fetch(apiPath).then((res) => res.json());
|
|
2565
|
+
}
|
|
2566
|
+
);
|
|
2567
|
+
console.log("availableDeliveryCoupon", availableDeliveryCoupon);
|
|
2568
|
+
const { ndd_coupon: nddCoupon, tdd_coupon: tddCoupon } = availableDeliveryCoupon?.data?.data || {};
|
|
2569
|
+
return {
|
|
2540
2570
|
nddCoupon,
|
|
2541
|
-
tddCoupon
|
|
2542
|
-
|
|
2571
|
+
tddCoupon,
|
|
2572
|
+
isLoading
|
|
2573
|
+
};
|
|
2574
|
+
};
|
|
2575
|
+
|
|
2576
|
+
// src/hooks/member/plus/use-shipping-methods.ts
|
|
2577
|
+
function useShippingMethods(options) {
|
|
2578
|
+
const { variant, plusMemberMetafields, selectedPlusMemberMode, isPlus = false, profile } = options;
|
|
2579
|
+
const { nddCoupon, tddCoupon, isLoading } = useAvailableDeliveryCoupon({ profile });
|
|
2580
|
+
console.log("nddCoupon", nddCoupon);
|
|
2543
2581
|
const { plus_shipping, shippingMethod } = plusMemberMetafields || {};
|
|
2544
2582
|
const nddOverweight = useMemo(() => {
|
|
2545
2583
|
return (variant?.weight || 0) > (shippingMethod?.overWeight_ndd || Infinity);
|
|
@@ -2549,12 +2587,10 @@ function useShippingMethods(options) {
|
|
|
2549
2587
|
}, [shippingMethod?.overWeight_tdd, variant?.weight]);
|
|
2550
2588
|
const paymentShippingMethods = useMemo(() => {
|
|
2551
2589
|
const weight = variant?.weight || 0;
|
|
2552
|
-
const methods = plus_shipping?.shipping_methods?.filter(
|
|
2553
|
-
(
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
}
|
|
2557
|
-
) || [];
|
|
2590
|
+
const methods = plus_shipping?.shipping_methods?.filter(({ weight_low, weight_high, __mode, __plus }) => {
|
|
2591
|
+
const fitWeight = (!weight_low || weight >= weight_low) && (!weight_high || weight <= weight_high);
|
|
2592
|
+
return __mode !== "free" /* FREE */ && !__plus && fitWeight;
|
|
2593
|
+
}) || [];
|
|
2558
2594
|
return methods.map((method) => {
|
|
2559
2595
|
let disabled = false;
|
|
2560
2596
|
const selectedFreeMember = selectedPlusMemberMode === "free";
|
|
@@ -2581,40 +2617,34 @@ function useShippingMethods(options) {
|
|
|
2581
2617
|
]);
|
|
2582
2618
|
const nddPrice = useMemo(() => {
|
|
2583
2619
|
const weight = variant?.weight || 0;
|
|
2584
|
-
const nddMethod = paymentShippingMethods.find(
|
|
2585
|
-
(
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
}
|
|
2589
|
-
);
|
|
2620
|
+
const nddMethod = paymentShippingMethods.find(({ __mode, weight_high, weight_low }) => {
|
|
2621
|
+
const fitWeight = (!weight_low || weight >= weight_low) && (!weight_high || weight <= weight_high);
|
|
2622
|
+
return __mode === "ndd" && fitWeight;
|
|
2623
|
+
});
|
|
2590
2624
|
return nddMethod?.price || 0;
|
|
2591
2625
|
}, [variant?.weight, paymentShippingMethods]);
|
|
2592
2626
|
const tddPrice = useMemo(() => {
|
|
2593
2627
|
const weight = variant?.weight || 0;
|
|
2594
|
-
const tddMethod = paymentShippingMethods.find(
|
|
2595
|
-
(
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
}
|
|
2599
|
-
);
|
|
2628
|
+
const tddMethod = paymentShippingMethods.find(({ __mode, weight_high, weight_low }) => {
|
|
2629
|
+
const fitWeight = (!weight_low || weight >= weight_low) && (!weight_high || weight <= weight_high);
|
|
2630
|
+
return __mode === "tdd" && fitWeight;
|
|
2631
|
+
});
|
|
2600
2632
|
return tddMethod?.price || 0;
|
|
2601
2633
|
}, [variant?.weight, paymentShippingMethods]);
|
|
2602
2634
|
const freeShippingMethods = useMemo(() => {
|
|
2603
2635
|
const weight = variant?.weight || 0;
|
|
2604
|
-
let methods = plus_shipping?.shipping_methods?.filter(
|
|
2605
|
-
(
|
|
2606
|
-
|
|
2607
|
-
return true;
|
|
2608
|
-
}
|
|
2609
|
-
if (isPlus) {
|
|
2610
|
-
const hasCoupon = isPlus && __mode === "ndd" /* NDD */ && nddCoupon || isPlus && __mode === "tdd" /* TDD */ && (tddCoupon || nddCoupon);
|
|
2611
|
-
const fitWeight = (!weight_low || weight >= weight_low) && (!weight_high || weight <= weight_high);
|
|
2612
|
-
return hasCoupon && fitWeight && !__plus;
|
|
2613
|
-
} else {
|
|
2614
|
-
return __plus;
|
|
2615
|
-
}
|
|
2636
|
+
let methods = plus_shipping?.shipping_methods?.filter(({ __mode, __plus, weight_low, weight_high }) => {
|
|
2637
|
+
if (__mode === "free" /* FREE */) {
|
|
2638
|
+
return true;
|
|
2616
2639
|
}
|
|
2617
|
-
|
|
2640
|
+
if (isPlus) {
|
|
2641
|
+
const hasCoupon = isPlus && __mode === "ndd" /* NDD */ && nddCoupon || isPlus && __mode === "tdd" /* TDD */ && (tddCoupon || nddCoupon);
|
|
2642
|
+
const fitWeight = (!weight_low || weight >= weight_low) && (!weight_high || weight <= weight_high);
|
|
2643
|
+
return hasCoupon && fitWeight && !__plus;
|
|
2644
|
+
} else {
|
|
2645
|
+
return __plus;
|
|
2646
|
+
}
|
|
2647
|
+
}) || [];
|
|
2618
2648
|
if (isPlus) {
|
|
2619
2649
|
methods = methods.sort((a, b) => {
|
|
2620
2650
|
if (b.__mode === "free" /* FREE */) return -1;
|
|
@@ -2668,7 +2698,10 @@ function useShippingMethods(options) {
|
|
|
2668
2698
|
freeShippingMethods,
|
|
2669
2699
|
paymentShippingMethods,
|
|
2670
2700
|
nddOverweight,
|
|
2671
|
-
tddOverweight
|
|
2701
|
+
tddOverweight,
|
|
2702
|
+
nddCoupon,
|
|
2703
|
+
tddCoupon,
|
|
2704
|
+
isLoadingCoupon: isLoading
|
|
2672
2705
|
};
|
|
2673
2706
|
}
|
|
2674
2707
|
function useShippingMethodAvailableCheck() {
|
|
@@ -2958,9 +2991,9 @@ var PlusMemberProvider = ({
|
|
|
2958
2991
|
memberSetting,
|
|
2959
2992
|
initialSelectedPlusMemberMode = "free",
|
|
2960
2993
|
profile,
|
|
2961
|
-
locale,
|
|
2962
2994
|
children
|
|
2963
2995
|
}) => {
|
|
2996
|
+
const { locale } = useShopify();
|
|
2964
2997
|
const [zipCode, setZipCode] = useState("");
|
|
2965
2998
|
const [showTip, setShowTip] = useState(false);
|
|
2966
2999
|
const [selectedPlusMemberMode, setSelectedPlusMemberMode] = useState(
|
|
@@ -2976,7 +3009,11 @@ var PlusMemberProvider = ({
|
|
|
2976
3009
|
const shippingMethodsContext = useShippingMethods({
|
|
2977
3010
|
variant,
|
|
2978
3011
|
plusMemberMetafields: memberSetting,
|
|
2979
|
-
selectedPlusMemberMode
|
|
3012
|
+
selectedPlusMemberMode,
|
|
3013
|
+
profile,
|
|
3014
|
+
isPlus: profile?.isPlus || false
|
|
3015
|
+
});
|
|
3016
|
+
console.log("shippingMethodsContext", shippingMethodsContext);
|
|
2980
3017
|
const plusMemberHandles = useMemo(() => {
|
|
2981
3018
|
return [
|
|
2982
3019
|
memberSetting?.plus_monthly_product?.handle,
|
|
@@ -3437,6 +3474,6 @@ function useCartContext(options) {
|
|
|
3437
3474
|
return context;
|
|
3438
3475
|
}
|
|
3439
3476
|
|
|
3440
|
-
export { BrowserPerformanceAdapter, BuyRuleType, CODE_AMOUNT_KEY, CUSTOMER_ATTRIBUTE_KEY, CUSTOMER_SCRIPT_GIFT_KEY, CartProvider, DeliveryPlusType, MAIN_PRODUCT_CODE, OrderBasePriceType, OrderDiscountType, PLUS_MEMBER_TYPE, PlusMemberContext, PlusMemberMode, PlusMemberProvider, PriceBasePriceType, PriceDiscountType, RuleType, SCRIPT_CODE_AMOUNT_KEY, ShippingMethodMode, ShopifyContext, ShopifyProvider, SpendMoneyType, browserCartCookieAdapter, browserCookieAdapter, checkAttributesUpdateNeeded, clearGeoLocationCache, createMockCartFromLines, currencyCodeMapping, defaultSWRMutationConfiguration, formatFunctionAutoFreeGift, formatScriptAutoFreeGift, gaTrack, getCachedGeoLocation, getDiscountEnvAttributeValue, getMatchedMainProductSubTotal, getQuery, getReferralAttributes, normalizeAddToCartLines, preCheck, safeParse, trackAddToCartFBQ, trackAddToCartGA, trackBeginCheckoutGA, trackBuyNowFBQ, trackBuyNowGA, useAddCartLines, useAddToCart, useAllBlogs, useAllCollections, useAllProducts, useApplyCartCodes, useArticle, useArticles, useArticlesInBlog, useAutoRemovePlusMemberInCart, useBlog, useBuyNow, useCalcAutoFreeGift, useCalcGiftsFromLines, useCalcOrderDiscount, useCartAttributes, useCartContext, 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, useShopify, useSite, useUpdateCartAttributes, useUpdateCartLines, useUpdateLineCodeAmountAttributes, useUpdatePlusMemberDeliveryOptions, useUpdateVariantQuery, useVariant, useVariantMedia };
|
|
3477
|
+
export { BrowserPerformanceAdapter, BuyRuleType, CODE_AMOUNT_KEY, CUSTOMER_ATTRIBUTE_KEY, CUSTOMER_SCRIPT_GIFT_KEY, CartProvider, DeliveryPlusType, MAIN_PRODUCT_CODE, OrderBasePriceType, OrderDiscountType, PLUS_MEMBER_TYPE, PlusMemberContext, PlusMemberMode, PlusMemberProvider, PriceBasePriceType, PriceDiscountType, RuleType, SCRIPT_CODE_AMOUNT_KEY, ShippingMethodMode, ShopifyContext, ShopifyProvider, SpendMoneyType, browserCartCookieAdapter, browserCookieAdapter, checkAttributesUpdateNeeded, clearGeoLocationCache, createMockCartFromLines, currencyCodeMapping, defaultSWRMutationConfiguration, formatFunctionAutoFreeGift, formatScriptAutoFreeGift, gaTrack, getCachedGeoLocation, getDiscountEnvAttributeValue, getMatchedMainProductSubTotal, getQuery, getReferralAttributes, normalizeAddToCartLines, preCheck, safeParse, trackAddToCartFBQ, trackAddToCartGA, trackBeginCheckoutGA, trackBuyNowFBQ, trackBuyNowGA, useAddCartLines, useAddToCart, useAllBlogs, useAllCollections, useAllProducts, useApplyCartCodes, useArticle, useArticles, useArticlesInBlog, useAutoRemovePlusMemberInCart, useAvailableDeliveryCoupon, useBlog, useBuyNow, useCalcAutoFreeGift, useCalcGiftsFromLines, useCalcOrderDiscount, useCartAttributes, useCartContext, useCartItemQuantityLimit, useCollection, useCollections, useCreateCart, useExposure, useGeoLocation, useHasPlusMemberInCart, useIntersection, usePlusAnnualProductVariant, usePlusMemberCheckoutCustomAttributes, usePlusMemberContext, usePlusMemberDeliveryCodes, usePlusMemberItemCustomAttributes, usePlusMemberNeedAddToCart, usePlusMonthlyProductVariant, usePrice, useProduct, useProductUrl, useProductsByHandles, useRemoveCartCodes, useRemoveCartLines, useReplaceCartPlusMember, useScriptAutoFreeGift, useSearch, useSelectedOptions, useShippingMethodAvailableCheck, useShippingMethods, useShopify, useSite, useUpdateCartAttributes, useUpdateCartLines, useUpdateLineCodeAmountAttributes, useUpdatePlusMemberDeliveryOptions, useUpdateVariantQuery, useVariant, useVariantMedia };
|
|
3441
3478
|
//# sourceMappingURL=index.mjs.map
|
|
3442
3479
|
//# sourceMappingURL=index.mjs.map
|