@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.
package/dist/index.mjs CHANGED
@@ -187,12 +187,14 @@ function createMockCartFromLines(lines, existingCart) {
187
187
  const normalizedLines = normalizeAddToCartLines(lines);
188
188
  const subtotalPrice = normalizedLines.reduce((sum, line) => sum + line.subtotalAmount, 0);
189
189
  const totalPrice = normalizedLines.reduce((sum, line) => sum + line.totalAmount, 0);
190
+ console.log("lines createMockCartFromLines", lines);
191
+ const currency = lines[0]?.variant?.price?.currencyCode;
190
192
  return {
191
193
  id: existingCart?.id || "temp-cart-id",
192
194
  customerId: existingCart?.customerId,
193
195
  email: existingCart?.email,
194
196
  createdAt: existingCart?.createdAt || (/* @__PURE__ */ new Date()).toISOString(),
195
- currency: existingCart?.currency || { code: "USD" },
197
+ currency: existingCart?.currency?.code || { code: currency },
196
198
  taxesIncluded: existingCart?.taxesIncluded,
197
199
  lineItems: normalizedLines,
198
200
  totalLineItemsDiscount: 0,
@@ -462,11 +464,20 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
462
464
  return { qualifyingGift: null, nextTierGoal: null };
463
465
  }
464
466
  const giftTiers = activeCampaign.rule_result.spend_get_reward.gift_product;
465
- const qualifyingTier = [...giftTiers].sort((a, b) => Number(b.spend_sum_money) - Number(a.spend_sum_money)).find((tier) => subtotal >= Number(tier.spend_sum_money));
466
- const nextGoal = giftTiers.find((tier) => subtotal < Number(tier.spend_sum_money));
467
+ const currentCurrency = effectiveCart?.currency?.code || "";
468
+ console.log("currentCurrency useCalcAutoFreeGift", effectiveCart, currentCurrency);
469
+ const getThresholdAmount = (tier) => {
470
+ if (tier.spend_sum_money_multi_markets?.[currentCurrency]?.value) {
471
+ return Number(tier.spend_sum_money_multi_markets[currentCurrency].value);
472
+ }
473
+ return Number(tier.spend_sum_money || 0);
474
+ };
475
+ const qualifyingTier = [...giftTiers].sort((a, b) => getThresholdAmount(b) - getThresholdAmount(a)).find((tier) => subtotal >= getThresholdAmount(tier));
476
+ const nextGoal = giftTiers.find((tier) => subtotal < getThresholdAmount(tier));
467
477
  if (!qualifyingTier) {
468
478
  return { qualifyingGift: null, nextTierGoal: nextGoal || null };
469
479
  }
480
+ const actualThreshold = getThresholdAmount(qualifyingTier);
470
481
  const formattedGift = {
471
482
  tier: qualifyingTier,
472
483
  itemsToAdd: qualifyingTier.reward_list?.map((reward) => {
@@ -485,7 +496,10 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
485
496
  value: JSON.stringify({
486
497
  is_gift: true,
487
498
  rule_id: activeCampaign.rule_id,
488
- spend_sum_money: qualifyingTier.spend_sum_money
499
+ spend_sum_money: actualThreshold,
500
+ // 使用实际的门槛金额(多币种支持)
501
+ currency_code: currentCurrency
502
+ // 记录当前币种
489
503
  })
490
504
  }
491
505
  ]
@@ -493,7 +507,7 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
493
507
  }).filter((item) => item !== null)
494
508
  };
495
509
  return { qualifyingGift: formattedGift, nextTierGoal: nextGoal || null };
496
- }, [activeCampaign, subtotal]);
510
+ }, [activeCampaign, subtotal, effectiveCart]);
497
511
  const giftHandles = useMemo(() => {
498
512
  const giftVariant = autoFreeGiftConfig.map(
499
513
  (item) => item.rule_result?.spend_get_reward?.gift_product?.map(
@@ -944,6 +958,12 @@ function useApplyCartCodes(options) {
944
958
  cookieAdapter: cartCookieAdapter,
945
959
  metafieldIdentifiers
946
960
  });
961
+ const unApplicableCodes = discountCodes.filter(
962
+ (code) => updatedCart?.discountCodes?.find((item) => item.code === code && !item.applicable)
963
+ );
964
+ if (unApplicableCodes.length) {
965
+ throw new Error(`${unApplicableCodes.join(", ")} is not applicable to the cart`);
966
+ }
947
967
  if (updatedCart) {
948
968
  mutateCart(updatedCart);
949
969
  }
@@ -1300,9 +1320,12 @@ var useCalcOrderDiscount = (cart, orderDiscountConfig, customer) => {
1300
1320
  discountAmount: 0
1301
1321
  };
1302
1322
  }
1303
- const tieredDiscounts = activeCampaign.result_detail.order_discount_conf.tiered_discounts;
1304
- const qualifyingTier = [...tieredDiscounts].reverse().find((tier) => subtotal >= Number(tier.amount));
1305
- const nextGoal = tieredDiscounts.find((tier) => subtotal < Number(tier.amount));
1323
+ const currentCurrency = cart?.currency?.code || "";
1324
+ console.log("currentCurrency", cart, currentCurrency);
1325
+ const orderDiscountConf = activeCampaign.result_detail.order_discount_conf;
1326
+ const tieredDiscounts = orderDiscountConf.tiered_discounts_markets?.[currentCurrency] || orderDiscountConf.tiered_discounts;
1327
+ const qualifyingTier = [...tieredDiscounts].sort((a, b) => Number(b.amount) - Number(a.amount)).find((tier) => subtotal >= Number(tier.amount));
1328
+ const nextGoal = [...tieredDiscounts].sort((a, b) => Number(a.amount) - Number(b.amount)).find((tier) => subtotal < Number(tier.amount));
1306
1329
  if (!qualifyingTier) {
1307
1330
  return {
1308
1331
  qualifyingDiscount: null,