@anker-in/shopify-react 0.1.1-beta.35 → 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 +5 -5
package/dist/provider/index.js
CHANGED
|
@@ -430,54 +430,28 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
|
|
|
430
430
|
}
|
|
431
431
|
return { activeCampaign: null, subtotal: 0 };
|
|
432
432
|
}, [autoFreeGiftConfig, effectiveCart, tags, dealsType]);
|
|
433
|
-
const {
|
|
433
|
+
const { qualifyingTier, nextTierGoal, actualThreshold, currentCurrency } = react.useMemo(() => {
|
|
434
434
|
if (!activeCampaign || !activeCampaign.rule_result?.spend_get_reward?.gift_product) {
|
|
435
|
-
return {
|
|
435
|
+
return { qualifyingTier: null, nextTierGoal: null, actualThreshold: 0, currentCurrency: "" };
|
|
436
436
|
}
|
|
437
437
|
const giftTiers = activeCampaign.rule_result.spend_get_reward.gift_product;
|
|
438
|
-
const
|
|
439
|
-
console.log("currentCurrency useCalcAutoFreeGift", effectiveCart,
|
|
438
|
+
const currentCurrency2 = effectiveCart?.currency?.code || "";
|
|
439
|
+
console.log("currentCurrency useCalcAutoFreeGift", effectiveCart, currentCurrency2);
|
|
440
440
|
const getThresholdAmount = (tier) => {
|
|
441
|
-
if (tier.spend_sum_money_multi_markets?.[
|
|
442
|
-
return Number(tier.spend_sum_money_multi_markets[
|
|
441
|
+
if (tier.spend_sum_money_multi_markets?.[currentCurrency2]?.value) {
|
|
442
|
+
return Number(tier.spend_sum_money_multi_markets[currentCurrency2].value);
|
|
443
443
|
}
|
|
444
444
|
return Number(tier.spend_sum_money || 0);
|
|
445
445
|
};
|
|
446
|
-
const
|
|
446
|
+
const qualifyingTier2 = [...giftTiers].sort((a, b) => getThresholdAmount(b) - getThresholdAmount(a)).find((tier) => subtotal >= getThresholdAmount(tier));
|
|
447
447
|
const nextGoal = giftTiers.find((tier) => subtotal < getThresholdAmount(tier));
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
itemsToAdd: qualifyingTier.reward_list?.map((reward) => {
|
|
455
|
-
const giftProduct = reward?.variant_list?.[0];
|
|
456
|
-
if (!giftProduct) return null;
|
|
457
|
-
return {
|
|
458
|
-
variant: {
|
|
459
|
-
id: shopifyCore.btoaID(giftProduct.variant_id),
|
|
460
|
-
handle: giftProduct.handle,
|
|
461
|
-
sku: giftProduct.sku
|
|
462
|
-
},
|
|
463
|
-
quantity: reward?.get_unit || 1,
|
|
464
|
-
attributes: [
|
|
465
|
-
{
|
|
466
|
-
key: CUSTOMER_ATTRIBUTE_KEY,
|
|
467
|
-
value: JSON.stringify({
|
|
468
|
-
is_gift: true,
|
|
469
|
-
rule_id: activeCampaign.rule_id,
|
|
470
|
-
spend_sum_money: actualThreshold,
|
|
471
|
-
// 使用实际的门槛金额(多币种支持)
|
|
472
|
-
currency_code: currentCurrency
|
|
473
|
-
// 记录当前币种
|
|
474
|
-
})
|
|
475
|
-
}
|
|
476
|
-
]
|
|
477
|
-
};
|
|
478
|
-
}).filter((item) => item !== null)
|
|
448
|
+
const actualThreshold2 = qualifyingTier2 ? getThresholdAmount(qualifyingTier2) : 0;
|
|
449
|
+
return {
|
|
450
|
+
qualifyingTier: qualifyingTier2,
|
|
451
|
+
nextTierGoal: nextGoal || null,
|
|
452
|
+
actualThreshold: actualThreshold2,
|
|
453
|
+
currentCurrency: currentCurrency2
|
|
479
454
|
};
|
|
480
|
-
return { qualifyingGift: formattedGift, nextTierGoal: nextGoal || null };
|
|
481
455
|
}, [activeCampaign, subtotal, effectiveCart]);
|
|
482
456
|
const giftHandles = react.useMemo(() => {
|
|
483
457
|
const giftVariant = autoFreeGiftConfig.map(
|
|
@@ -518,6 +492,58 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
|
|
|
518
492
|
}
|
|
519
493
|
return giftProductsResult;
|
|
520
494
|
}, [giftProductsResult, shouldFetch]);
|
|
495
|
+
const qualifyingGift = react.useMemo(() => {
|
|
496
|
+
if (!qualifyingTier || !activeCampaign) {
|
|
497
|
+
return null;
|
|
498
|
+
}
|
|
499
|
+
const itemsToAdd = qualifyingTier.reward_list?.map((reward) => {
|
|
500
|
+
if (!reward.variant_list || reward.variant_list.length === 0) {
|
|
501
|
+
return null;
|
|
502
|
+
}
|
|
503
|
+
let selectedGiftProduct = null;
|
|
504
|
+
for (const giftVariant of reward.variant_list) {
|
|
505
|
+
const productInfo = finalGiftProductsResult?.find(
|
|
506
|
+
(p) => p.handle === giftVariant.handle
|
|
507
|
+
);
|
|
508
|
+
if (productInfo) {
|
|
509
|
+
const variantInfo = productInfo.variants?.find((v) => v.sku === giftVariant.sku);
|
|
510
|
+
if (variantInfo?.availableForSale) {
|
|
511
|
+
selectedGiftProduct = giftVariant;
|
|
512
|
+
break;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
if (!selectedGiftProduct) {
|
|
517
|
+
selectedGiftProduct = reward.variant_list[0];
|
|
518
|
+
}
|
|
519
|
+
return {
|
|
520
|
+
variant: {
|
|
521
|
+
id: shopifyCore.btoaID(selectedGiftProduct.variant_id),
|
|
522
|
+
handle: selectedGiftProduct.handle,
|
|
523
|
+
sku: selectedGiftProduct.sku
|
|
524
|
+
},
|
|
525
|
+
quantity: reward?.get_unit || 1,
|
|
526
|
+
attributes: [
|
|
527
|
+
{
|
|
528
|
+
key: CUSTOMER_ATTRIBUTE_KEY,
|
|
529
|
+
value: JSON.stringify({
|
|
530
|
+
is_gift: true,
|
|
531
|
+
rule_id: activeCampaign.rule_id,
|
|
532
|
+
spend_sum_money: actualThreshold,
|
|
533
|
+
// 使用实际的门槛金额(多币种支持)
|
|
534
|
+
currency_code: currentCurrency
|
|
535
|
+
// 记录当前币种
|
|
536
|
+
})
|
|
537
|
+
}
|
|
538
|
+
]
|
|
539
|
+
};
|
|
540
|
+
}).filter((item) => item !== null);
|
|
541
|
+
const formattedGift = {
|
|
542
|
+
tier: qualifyingTier,
|
|
543
|
+
itemsToAdd
|
|
544
|
+
};
|
|
545
|
+
return formattedGift;
|
|
546
|
+
}, [qualifyingTier, activeCampaign, finalGiftProductsResult, actualThreshold, currentCurrency]);
|
|
521
547
|
return {
|
|
522
548
|
qualifyingGift,
|
|
523
549
|
nextTierGoal,
|