@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.
@@ -115,12 +115,14 @@ function createMockCartFromLines(lines, existingCart) {
115
115
  const normalizedLines = normalizeAddToCartLines(lines);
116
116
  const subtotalPrice = normalizedLines.reduce((sum, line) => sum + line.subtotalAmount, 0);
117
117
  const totalPrice = normalizedLines.reduce((sum, line) => sum + line.totalAmount, 0);
118
+ console.log("lines createMockCartFromLines", lines);
119
+ const currency = lines[0]?.variant?.price?.currencyCode;
118
120
  return {
119
121
  id: existingCart?.id || "temp-cart-id",
120
122
  customerId: existingCart?.customerId,
121
123
  email: existingCart?.email,
122
124
  createdAt: existingCart?.createdAt || (/* @__PURE__ */ new Date()).toISOString(),
123
- currency: existingCart?.currency || { code: "USD" },
125
+ currency: existingCart?.currency?.code || { code: currency },
124
126
  taxesIncluded: existingCart?.taxesIncluded,
125
127
  lineItems: normalizedLines,
126
128
  totalLineItemsDiscount: 0,
@@ -390,11 +392,20 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
390
392
  return { qualifyingGift: null, nextTierGoal: null };
391
393
  }
392
394
  const giftTiers = activeCampaign.rule_result.spend_get_reward.gift_product;
393
- const qualifyingTier = [...giftTiers].sort((a, b) => Number(b.spend_sum_money) - Number(a.spend_sum_money)).find((tier) => subtotal >= Number(tier.spend_sum_money));
394
- const nextGoal = giftTiers.find((tier) => subtotal < Number(tier.spend_sum_money));
395
+ const currentCurrency = effectiveCart?.currency?.code || "";
396
+ console.log("currentCurrency useCalcAutoFreeGift", effectiveCart, currentCurrency);
397
+ const getThresholdAmount = (tier) => {
398
+ if (tier.spend_sum_money_multi_markets?.[currentCurrency]?.value) {
399
+ return Number(tier.spend_sum_money_multi_markets[currentCurrency].value);
400
+ }
401
+ return Number(tier.spend_sum_money || 0);
402
+ };
403
+ const qualifyingTier = [...giftTiers].sort((a, b) => getThresholdAmount(b) - getThresholdAmount(a)).find((tier) => subtotal >= getThresholdAmount(tier));
404
+ const nextGoal = giftTiers.find((tier) => subtotal < getThresholdAmount(tier));
395
405
  if (!qualifyingTier) {
396
406
  return { qualifyingGift: null, nextTierGoal: nextGoal || null };
397
407
  }
408
+ const actualThreshold = getThresholdAmount(qualifyingTier);
398
409
  const formattedGift = {
399
410
  tier: qualifyingTier,
400
411
  itemsToAdd: qualifyingTier.reward_list?.map((reward) => {
@@ -413,7 +424,10 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
413
424
  value: JSON.stringify({
414
425
  is_gift: true,
415
426
  rule_id: activeCampaign.rule_id,
416
- spend_sum_money: qualifyingTier.spend_sum_money
427
+ spend_sum_money: actualThreshold,
428
+ // 使用实际的门槛金额(多币种支持)
429
+ currency_code: currentCurrency
430
+ // 记录当前币种
417
431
  })
418
432
  }
419
433
  ]
@@ -421,7 +435,7 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
421
435
  }).filter((item) => item !== null)
422
436
  };
423
437
  return { qualifyingGift: formattedGift, nextTierGoal: nextGoal || null };
424
- }, [activeCampaign, subtotal]);
438
+ }, [activeCampaign, subtotal, effectiveCart]);
425
439
  const giftHandles = useMemo(() => {
426
440
  const giftVariant = autoFreeGiftConfig.map(
427
441
  (item) => item.rule_result?.spend_get_reward?.gift_product?.map(
@@ -847,6 +861,12 @@ function useApplyCartCodes(options) {
847
861
  cookieAdapter: cartCookieAdapter,
848
862
  metafieldIdentifiers
849
863
  });
864
+ const unApplicableCodes = discountCodes.filter(
865
+ (code) => updatedCart?.discountCodes?.find((item) => item.code === code && !item.applicable)
866
+ );
867
+ if (unApplicableCodes.length) {
868
+ throw new Error(`${unApplicableCodes.join(", ")} is not applicable to the cart`);
869
+ }
850
870
  if (updatedCart) {
851
871
  mutateCart(updatedCart);
852
872
  }
@@ -1203,9 +1223,12 @@ var useCalcOrderDiscount = (cart, orderDiscountConfig, customer) => {
1203
1223
  discountAmount: 0
1204
1224
  };
1205
1225
  }
1206
- const tieredDiscounts = activeCampaign.result_detail.order_discount_conf.tiered_discounts;
1207
- const qualifyingTier = [...tieredDiscounts].reverse().find((tier) => subtotal >= Number(tier.amount));
1208
- const nextGoal = tieredDiscounts.find((tier) => subtotal < Number(tier.amount));
1226
+ const currentCurrency = cart?.currency?.code || "";
1227
+ console.log("currentCurrency", cart, currentCurrency);
1228
+ const orderDiscountConf = activeCampaign.result_detail.order_discount_conf;
1229
+ const tieredDiscounts = orderDiscountConf.tiered_discounts_markets?.[currentCurrency] || orderDiscountConf.tiered_discounts;
1230
+ const qualifyingTier = [...tieredDiscounts].sort((a, b) => Number(b.amount) - Number(a.amount)).find((tier) => subtotal >= Number(tier.amount));
1231
+ const nextGoal = [...tieredDiscounts].sort((a, b) => Number(a.amount) - Number(b.amount)).find((tier) => subtotal < Number(tier.amount));
1209
1232
  if (!qualifyingTier) {
1210
1233
  return {
1211
1234
  qualifyingDiscount: null,