@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/hooks/index.d.mts +20 -0
- package/dist/hooks/index.d.ts +20 -0
- package/dist/hooks/index.js +31 -8
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +31 -8
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/index.js +31 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +31 -8
- package/dist/index.mjs.map +1 -1
- package/dist/provider/index.js +19 -5
- package/dist/provider/index.js.map +1 -1
- package/dist/provider/index.mjs +19 -5
- package/dist/provider/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/provider/index.js
CHANGED
|
@@ -157,12 +157,14 @@ function createMockCartFromLines(lines, existingCart) {
|
|
|
157
157
|
const normalizedLines = normalizeAddToCartLines(lines);
|
|
158
158
|
const subtotalPrice = normalizedLines.reduce((sum, line) => sum + line.subtotalAmount, 0);
|
|
159
159
|
const totalPrice = normalizedLines.reduce((sum, line) => sum + line.totalAmount, 0);
|
|
160
|
+
console.log("lines createMockCartFromLines", lines);
|
|
161
|
+
const currency = lines[0]?.variant?.price?.currencyCode;
|
|
160
162
|
return {
|
|
161
163
|
id: existingCart?.id || "temp-cart-id",
|
|
162
164
|
customerId: existingCart?.customerId,
|
|
163
165
|
email: existingCart?.email,
|
|
164
166
|
createdAt: existingCart?.createdAt || (/* @__PURE__ */ new Date()).toISOString(),
|
|
165
|
-
currency: existingCart?.currency || { code:
|
|
167
|
+
currency: existingCart?.currency?.code || { code: currency },
|
|
166
168
|
taxesIncluded: existingCart?.taxesIncluded,
|
|
167
169
|
lineItems: normalizedLines,
|
|
168
170
|
totalLineItemsDiscount: 0,
|
|
@@ -429,11 +431,20 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
|
|
|
429
431
|
return { qualifyingGift: null, nextTierGoal: null };
|
|
430
432
|
}
|
|
431
433
|
const giftTiers = activeCampaign.rule_result.spend_get_reward.gift_product;
|
|
432
|
-
const
|
|
433
|
-
|
|
434
|
+
const currentCurrency = effectiveCart?.currency?.code || "";
|
|
435
|
+
console.log("currentCurrency useCalcAutoFreeGift", effectiveCart, currentCurrency);
|
|
436
|
+
const getThresholdAmount = (tier) => {
|
|
437
|
+
if (tier.spend_sum_money_multi_markets?.[currentCurrency]?.value) {
|
|
438
|
+
return Number(tier.spend_sum_money_multi_markets[currentCurrency].value);
|
|
439
|
+
}
|
|
440
|
+
return Number(tier.spend_sum_money || 0);
|
|
441
|
+
};
|
|
442
|
+
const qualifyingTier = [...giftTiers].sort((a, b) => getThresholdAmount(b) - getThresholdAmount(a)).find((tier) => subtotal >= getThresholdAmount(tier));
|
|
443
|
+
const nextGoal = giftTiers.find((tier) => subtotal < getThresholdAmount(tier));
|
|
434
444
|
if (!qualifyingTier) {
|
|
435
445
|
return { qualifyingGift: null, nextTierGoal: nextGoal || null };
|
|
436
446
|
}
|
|
447
|
+
const actualThreshold = getThresholdAmount(qualifyingTier);
|
|
437
448
|
const formattedGift = {
|
|
438
449
|
tier: qualifyingTier,
|
|
439
450
|
itemsToAdd: qualifyingTier.reward_list?.map((reward) => {
|
|
@@ -452,7 +463,10 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
|
|
|
452
463
|
value: JSON.stringify({
|
|
453
464
|
is_gift: true,
|
|
454
465
|
rule_id: activeCampaign.rule_id,
|
|
455
|
-
spend_sum_money:
|
|
466
|
+
spend_sum_money: actualThreshold,
|
|
467
|
+
// 使用实际的门槛金额(多币种支持)
|
|
468
|
+
currency_code: currentCurrency
|
|
469
|
+
// 记录当前币种
|
|
456
470
|
})
|
|
457
471
|
}
|
|
458
472
|
]
|
|
@@ -460,7 +474,7 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
|
|
|
460
474
|
}).filter((item) => item !== null)
|
|
461
475
|
};
|
|
462
476
|
return { qualifyingGift: formattedGift, nextTierGoal: nextGoal || null };
|
|
463
|
-
}, [activeCampaign, subtotal]);
|
|
477
|
+
}, [activeCampaign, subtotal, effectiveCart]);
|
|
464
478
|
const giftHandles = react.useMemo(() => {
|
|
465
479
|
const giftVariant = autoFreeGiftConfig.map(
|
|
466
480
|
(item) => item.rule_result?.spend_get_reward?.gift_product?.map(
|