@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.js CHANGED
@@ -195,12 +195,14 @@ function createMockCartFromLines(lines, existingCart) {
195
195
  const normalizedLines = normalizeAddToCartLines(lines);
196
196
  const subtotalPrice = normalizedLines.reduce((sum, line) => sum + line.subtotalAmount, 0);
197
197
  const totalPrice = normalizedLines.reduce((sum, line) => sum + line.totalAmount, 0);
198
+ console.log("lines createMockCartFromLines", lines);
199
+ const currency = lines[0]?.variant?.price?.currencyCode;
198
200
  return {
199
201
  id: existingCart?.id || "temp-cart-id",
200
202
  customerId: existingCart?.customerId,
201
203
  email: existingCart?.email,
202
204
  createdAt: existingCart?.createdAt || (/* @__PURE__ */ new Date()).toISOString(),
203
- currency: existingCart?.currency || { code: "USD" },
205
+ currency: existingCart?.currency?.code || { code: currency },
204
206
  taxesIncluded: existingCart?.taxesIncluded,
205
207
  lineItems: normalizedLines,
206
208
  totalLineItemsDiscount: 0,
@@ -470,11 +472,20 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
470
472
  return { qualifyingGift: null, nextTierGoal: null };
471
473
  }
472
474
  const giftTiers = activeCampaign.rule_result.spend_get_reward.gift_product;
473
- const qualifyingTier = [...giftTiers].sort((a, b) => Number(b.spend_sum_money) - Number(a.spend_sum_money)).find((tier) => subtotal >= Number(tier.spend_sum_money));
474
- const nextGoal = giftTiers.find((tier) => subtotal < Number(tier.spend_sum_money));
475
+ const currentCurrency = effectiveCart?.currency?.code || "";
476
+ console.log("currentCurrency useCalcAutoFreeGift", effectiveCart, currentCurrency);
477
+ const getThresholdAmount = (tier) => {
478
+ if (tier.spend_sum_money_multi_markets?.[currentCurrency]?.value) {
479
+ return Number(tier.spend_sum_money_multi_markets[currentCurrency].value);
480
+ }
481
+ return Number(tier.spend_sum_money || 0);
482
+ };
483
+ const qualifyingTier = [...giftTiers].sort((a, b) => getThresholdAmount(b) - getThresholdAmount(a)).find((tier) => subtotal >= getThresholdAmount(tier));
484
+ const nextGoal = giftTiers.find((tier) => subtotal < getThresholdAmount(tier));
475
485
  if (!qualifyingTier) {
476
486
  return { qualifyingGift: null, nextTierGoal: nextGoal || null };
477
487
  }
488
+ const actualThreshold = getThresholdAmount(qualifyingTier);
478
489
  const formattedGift = {
479
490
  tier: qualifyingTier,
480
491
  itemsToAdd: qualifyingTier.reward_list?.map((reward) => {
@@ -493,7 +504,10 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
493
504
  value: JSON.stringify({
494
505
  is_gift: true,
495
506
  rule_id: activeCampaign.rule_id,
496
- spend_sum_money: qualifyingTier.spend_sum_money
507
+ spend_sum_money: actualThreshold,
508
+ // 使用实际的门槛金额(多币种支持)
509
+ currency_code: currentCurrency
510
+ // 记录当前币种
497
511
  })
498
512
  }
499
513
  ]
@@ -501,7 +515,7 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
501
515
  }).filter((item) => item !== null)
502
516
  };
503
517
  return { qualifyingGift: formattedGift, nextTierGoal: nextGoal || null };
504
- }, [activeCampaign, subtotal]);
518
+ }, [activeCampaign, subtotal, effectiveCart]);
505
519
  const giftHandles = react.useMemo(() => {
506
520
  const giftVariant = autoFreeGiftConfig.map(
507
521
  (item) => item.rule_result?.spend_get_reward?.gift_product?.map(
@@ -952,6 +966,12 @@ function useApplyCartCodes(options) {
952
966
  cookieAdapter: cartCookieAdapter,
953
967
  metafieldIdentifiers
954
968
  });
969
+ const unApplicableCodes = discountCodes.filter(
970
+ (code) => updatedCart?.discountCodes?.find((item) => item.code === code && !item.applicable)
971
+ );
972
+ if (unApplicableCodes.length) {
973
+ throw new Error(`${unApplicableCodes.join(", ")} is not applicable to the cart`);
974
+ }
955
975
  if (updatedCart) {
956
976
  mutateCart(updatedCart);
957
977
  }
@@ -1308,9 +1328,12 @@ var useCalcOrderDiscount = (cart, orderDiscountConfig, customer) => {
1308
1328
  discountAmount: 0
1309
1329
  };
1310
1330
  }
1311
- const tieredDiscounts = activeCampaign.result_detail.order_discount_conf.tiered_discounts;
1312
- const qualifyingTier = [...tieredDiscounts].reverse().find((tier) => subtotal >= Number(tier.amount));
1313
- const nextGoal = tieredDiscounts.find((tier) => subtotal < Number(tier.amount));
1331
+ const currentCurrency = cart?.currency?.code || "";
1332
+ console.log("currentCurrency", cart, currentCurrency);
1333
+ const orderDiscountConf = activeCampaign.result_detail.order_discount_conf;
1334
+ const tieredDiscounts = orderDiscountConf.tiered_discounts_markets?.[currentCurrency] || orderDiscountConf.tiered_discounts;
1335
+ const qualifyingTier = [...tieredDiscounts].sort((a, b) => Number(b.amount) - Number(a.amount)).find((tier) => subtotal >= Number(tier.amount));
1336
+ const nextGoal = [...tieredDiscounts].sort((a, b) => Number(a.amount) - Number(b.amount)).find((tier) => subtotal < Number(tier.amount));
1314
1337
  if (!qualifyingTier) {
1315
1338
  return {
1316
1339
  qualifyingDiscount: null,