@anker-in/shopify-react 0.1.1-beta.20 → 0.1.1-beta.21

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.
@@ -148,12 +148,14 @@ function createMockCartFromLines(lines, existingCart) {
148
148
  const normalizedLines = normalizeAddToCartLines(lines);
149
149
  const subtotalPrice = normalizedLines.reduce((sum, line) => sum + line.subtotalAmount, 0);
150
150
  const totalPrice = normalizedLines.reduce((sum, line) => sum + line.totalAmount, 0);
151
+ console.log("lines createMockCartFromLines", lines);
152
+ const currency = lines[0]?.variant?.price?.currencyCode;
151
153
  return {
152
154
  id: existingCart?.id || "temp-cart-id",
153
155
  customerId: existingCart?.customerId,
154
156
  email: existingCart?.email,
155
157
  createdAt: existingCart?.createdAt || (/* @__PURE__ */ new Date()).toISOString(),
156
- currency: existingCart?.currency || { code: "USD" },
158
+ currency: existingCart?.currency?.code || { code: currency },
157
159
  taxesIncluded: existingCart?.taxesIncluded,
158
160
  lineItems: normalizedLines,
159
161
  totalLineItemsDiscount: 0,
@@ -420,11 +422,20 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
420
422
  return { qualifyingGift: null, nextTierGoal: null };
421
423
  }
422
424
  const giftTiers = activeCampaign.rule_result.spend_get_reward.gift_product;
423
- const qualifyingTier = [...giftTiers].sort((a, b) => Number(b.spend_sum_money) - Number(a.spend_sum_money)).find((tier) => subtotal >= Number(tier.spend_sum_money));
424
- const nextGoal = giftTiers.find((tier) => subtotal < Number(tier.spend_sum_money));
425
+ const currentCurrency = effectiveCart?.currency?.code || "";
426
+ console.log("currentCurrency useCalcAutoFreeGift", effectiveCart, currentCurrency);
427
+ const getThresholdAmount = (tier) => {
428
+ if (tier.spend_sum_money_multi_markets?.[currentCurrency]?.value) {
429
+ return Number(tier.spend_sum_money_multi_markets[currentCurrency].value);
430
+ }
431
+ return Number(tier.spend_sum_money || 0);
432
+ };
433
+ const qualifyingTier = [...giftTiers].sort((a, b) => getThresholdAmount(b) - getThresholdAmount(a)).find((tier) => subtotal >= getThresholdAmount(tier));
434
+ const nextGoal = giftTiers.find((tier) => subtotal < getThresholdAmount(tier));
425
435
  if (!qualifyingTier) {
426
436
  return { qualifyingGift: null, nextTierGoal: nextGoal || null };
427
437
  }
438
+ const actualThreshold = getThresholdAmount(qualifyingTier);
428
439
  const formattedGift = {
429
440
  tier: qualifyingTier,
430
441
  itemsToAdd: qualifyingTier.reward_list?.map((reward) => {
@@ -443,7 +454,10 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
443
454
  value: JSON.stringify({
444
455
  is_gift: true,
445
456
  rule_id: activeCampaign.rule_id,
446
- spend_sum_money: qualifyingTier.spend_sum_money
457
+ spend_sum_money: actualThreshold,
458
+ // 使用实际的门槛金额(多币种支持)
459
+ currency_code: currentCurrency
460
+ // 记录当前币种
447
461
  })
448
462
  }
449
463
  ]
@@ -451,7 +465,7 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
451
465
  }).filter((item) => item !== null)
452
466
  };
453
467
  return { qualifyingGift: formattedGift, nextTierGoal: nextGoal || null };
454
- }, [activeCampaign, subtotal]);
468
+ }, [activeCampaign, subtotal, effectiveCart]);
455
469
  const giftHandles = useMemo(() => {
456
470
  const giftVariant = autoFreeGiftConfig.map(
457
471
  (item) => item.rule_result?.spend_get_reward?.gift_product?.map(