@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/hooks/index.d.mts
CHANGED
|
@@ -558,12 +558,32 @@ type OrderDiscountConfig = {
|
|
|
558
558
|
handle: string;
|
|
559
559
|
}>;
|
|
560
560
|
all_store_variant: boolean;
|
|
561
|
+
skip_variants?: Array<{
|
|
562
|
+
variant_id: string;
|
|
563
|
+
sku: string;
|
|
564
|
+
handle: string;
|
|
565
|
+
}>;
|
|
561
566
|
};
|
|
562
567
|
order_discount_conf: {
|
|
563
568
|
base_price: OrderBasePriceType;
|
|
564
569
|
tiered_discounts: TieredDiscount[];
|
|
570
|
+
tiered_discounts_markets?: Record<string, TieredDiscount[]>;
|
|
571
|
+
is_reusable?: boolean;
|
|
572
|
+
min_quantity_items?: number;
|
|
573
|
+
max_apply_times_of_per_order?: number;
|
|
565
574
|
};
|
|
566
575
|
};
|
|
576
|
+
discount_label?: {
|
|
577
|
+
cart_checkout_label?: string;
|
|
578
|
+
product_label?: string;
|
|
579
|
+
sold_out_label?: string;
|
|
580
|
+
};
|
|
581
|
+
frontend_labels?: any[];
|
|
582
|
+
discount_combinations?: {
|
|
583
|
+
other_order_discounts?: boolean;
|
|
584
|
+
other_product_discounts?: boolean;
|
|
585
|
+
shipping_discounts?: boolean;
|
|
586
|
+
};
|
|
567
587
|
};
|
|
568
588
|
|
|
569
589
|
interface OrderDiscountResult {
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -558,12 +558,32 @@ type OrderDiscountConfig = {
|
|
|
558
558
|
handle: string;
|
|
559
559
|
}>;
|
|
560
560
|
all_store_variant: boolean;
|
|
561
|
+
skip_variants?: Array<{
|
|
562
|
+
variant_id: string;
|
|
563
|
+
sku: string;
|
|
564
|
+
handle: string;
|
|
565
|
+
}>;
|
|
561
566
|
};
|
|
562
567
|
order_discount_conf: {
|
|
563
568
|
base_price: OrderBasePriceType;
|
|
564
569
|
tiered_discounts: TieredDiscount[];
|
|
570
|
+
tiered_discounts_markets?: Record<string, TieredDiscount[]>;
|
|
571
|
+
is_reusable?: boolean;
|
|
572
|
+
min_quantity_items?: number;
|
|
573
|
+
max_apply_times_of_per_order?: number;
|
|
565
574
|
};
|
|
566
575
|
};
|
|
576
|
+
discount_label?: {
|
|
577
|
+
cart_checkout_label?: string;
|
|
578
|
+
product_label?: string;
|
|
579
|
+
sold_out_label?: string;
|
|
580
|
+
};
|
|
581
|
+
frontend_labels?: any[];
|
|
582
|
+
discount_combinations?: {
|
|
583
|
+
other_order_discounts?: boolean;
|
|
584
|
+
other_product_discounts?: boolean;
|
|
585
|
+
shipping_discounts?: boolean;
|
|
586
|
+
};
|
|
567
587
|
};
|
|
568
588
|
|
|
569
589
|
interface OrderDiscountResult {
|
package/dist/hooks/index.js
CHANGED
|
@@ -124,12 +124,14 @@ function createMockCartFromLines(lines, existingCart) {
|
|
|
124
124
|
const normalizedLines = normalizeAddToCartLines(lines);
|
|
125
125
|
const subtotalPrice = normalizedLines.reduce((sum, line) => sum + line.subtotalAmount, 0);
|
|
126
126
|
const totalPrice = normalizedLines.reduce((sum, line) => sum + line.totalAmount, 0);
|
|
127
|
+
console.log("lines createMockCartFromLines", lines);
|
|
128
|
+
const currency = lines[0]?.variant?.price?.currencyCode;
|
|
127
129
|
return {
|
|
128
130
|
id: existingCart?.id || "temp-cart-id",
|
|
129
131
|
customerId: existingCart?.customerId,
|
|
130
132
|
email: existingCart?.email,
|
|
131
133
|
createdAt: existingCart?.createdAt || (/* @__PURE__ */ new Date()).toISOString(),
|
|
132
|
-
currency: existingCart?.currency || { code:
|
|
134
|
+
currency: existingCart?.currency?.code || { code: currency },
|
|
133
135
|
taxesIncluded: existingCart?.taxesIncluded,
|
|
134
136
|
lineItems: normalizedLines,
|
|
135
137
|
totalLineItemsDiscount: 0,
|
|
@@ -399,11 +401,20 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
|
|
|
399
401
|
return { qualifyingGift: null, nextTierGoal: null };
|
|
400
402
|
}
|
|
401
403
|
const giftTiers = activeCampaign.rule_result.spend_get_reward.gift_product;
|
|
402
|
-
const
|
|
403
|
-
|
|
404
|
+
const currentCurrency = effectiveCart?.currency?.code || "";
|
|
405
|
+
console.log("currentCurrency useCalcAutoFreeGift", effectiveCart, currentCurrency);
|
|
406
|
+
const getThresholdAmount = (tier) => {
|
|
407
|
+
if (tier.spend_sum_money_multi_markets?.[currentCurrency]?.value) {
|
|
408
|
+
return Number(tier.spend_sum_money_multi_markets[currentCurrency].value);
|
|
409
|
+
}
|
|
410
|
+
return Number(tier.spend_sum_money || 0);
|
|
411
|
+
};
|
|
412
|
+
const qualifyingTier = [...giftTiers].sort((a, b) => getThresholdAmount(b) - getThresholdAmount(a)).find((tier) => subtotal >= getThresholdAmount(tier));
|
|
413
|
+
const nextGoal = giftTiers.find((tier) => subtotal < getThresholdAmount(tier));
|
|
404
414
|
if (!qualifyingTier) {
|
|
405
415
|
return { qualifyingGift: null, nextTierGoal: nextGoal || null };
|
|
406
416
|
}
|
|
417
|
+
const actualThreshold = getThresholdAmount(qualifyingTier);
|
|
407
418
|
const formattedGift = {
|
|
408
419
|
tier: qualifyingTier,
|
|
409
420
|
itemsToAdd: qualifyingTier.reward_list?.map((reward) => {
|
|
@@ -422,7 +433,10 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
|
|
|
422
433
|
value: JSON.stringify({
|
|
423
434
|
is_gift: true,
|
|
424
435
|
rule_id: activeCampaign.rule_id,
|
|
425
|
-
spend_sum_money:
|
|
436
|
+
spend_sum_money: actualThreshold,
|
|
437
|
+
// 使用实际的门槛金额(多币种支持)
|
|
438
|
+
currency_code: currentCurrency
|
|
439
|
+
// 记录当前币种
|
|
426
440
|
})
|
|
427
441
|
}
|
|
428
442
|
]
|
|
@@ -430,7 +444,7 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
|
|
|
430
444
|
}).filter((item) => item !== null)
|
|
431
445
|
};
|
|
432
446
|
return { qualifyingGift: formattedGift, nextTierGoal: nextGoal || null };
|
|
433
|
-
}, [activeCampaign, subtotal]);
|
|
447
|
+
}, [activeCampaign, subtotal, effectiveCart]);
|
|
434
448
|
const giftHandles = react.useMemo(() => {
|
|
435
449
|
const giftVariant = autoFreeGiftConfig.map(
|
|
436
450
|
(item) => item.rule_result?.spend_get_reward?.gift_product?.map(
|
|
@@ -856,6 +870,12 @@ function useApplyCartCodes(options) {
|
|
|
856
870
|
cookieAdapter: cartCookieAdapter,
|
|
857
871
|
metafieldIdentifiers
|
|
858
872
|
});
|
|
873
|
+
const unApplicableCodes = discountCodes.filter(
|
|
874
|
+
(code) => updatedCart?.discountCodes?.find((item) => item.code === code && !item.applicable)
|
|
875
|
+
);
|
|
876
|
+
if (unApplicableCodes.length) {
|
|
877
|
+
throw new Error(`${unApplicableCodes.join(", ")} is not applicable to the cart`);
|
|
878
|
+
}
|
|
859
879
|
if (updatedCart) {
|
|
860
880
|
mutateCart(updatedCart);
|
|
861
881
|
}
|
|
@@ -1212,9 +1232,12 @@ var useCalcOrderDiscount = (cart, orderDiscountConfig, customer) => {
|
|
|
1212
1232
|
discountAmount: 0
|
|
1213
1233
|
};
|
|
1214
1234
|
}
|
|
1215
|
-
const
|
|
1216
|
-
|
|
1217
|
-
const
|
|
1235
|
+
const currentCurrency = cart?.currency?.code || "";
|
|
1236
|
+
console.log("currentCurrency", cart, currentCurrency);
|
|
1237
|
+
const orderDiscountConf = activeCampaign.result_detail.order_discount_conf;
|
|
1238
|
+
const tieredDiscounts = orderDiscountConf.tiered_discounts_markets?.[currentCurrency] || orderDiscountConf.tiered_discounts;
|
|
1239
|
+
const qualifyingTier = [...tieredDiscounts].sort((a, b) => Number(b.amount) - Number(a.amount)).find((tier) => subtotal >= Number(tier.amount));
|
|
1240
|
+
const nextGoal = [...tieredDiscounts].sort((a, b) => Number(a.amount) - Number(b.amount)).find((tier) => subtotal < Number(tier.amount));
|
|
1218
1241
|
if (!qualifyingTier) {
|
|
1219
1242
|
return {
|
|
1220
1243
|
qualifyingDiscount: null,
|