@anker-in/shopify-react 0.1.1-beta.35 → 0.1.1-beta.36

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.
@@ -421,54 +421,28 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
421
421
  }
422
422
  return { activeCampaign: null, subtotal: 0 };
423
423
  }, [autoFreeGiftConfig, effectiveCart, tags, dealsType]);
424
- const { qualifyingGift, nextTierGoal } = useMemo(() => {
424
+ const { qualifyingTier, nextTierGoal, actualThreshold, currentCurrency } = useMemo(() => {
425
425
  if (!activeCampaign || !activeCampaign.rule_result?.spend_get_reward?.gift_product) {
426
- return { qualifyingGift: null, nextTierGoal: null };
426
+ return { qualifyingTier: null, nextTierGoal: null, actualThreshold: 0, currentCurrency: "" };
427
427
  }
428
428
  const giftTiers = activeCampaign.rule_result.spend_get_reward.gift_product;
429
- const currentCurrency = effectiveCart?.currency?.code || "";
430
- console.log("currentCurrency useCalcAutoFreeGift", effectiveCart, currentCurrency);
429
+ const currentCurrency2 = effectiveCart?.currency?.code || "";
430
+ console.log("currentCurrency useCalcAutoFreeGift", effectiveCart, currentCurrency2);
431
431
  const getThresholdAmount = (tier) => {
432
- if (tier.spend_sum_money_multi_markets?.[currentCurrency]?.value) {
433
- return Number(tier.spend_sum_money_multi_markets[currentCurrency].value);
432
+ if (tier.spend_sum_money_multi_markets?.[currentCurrency2]?.value) {
433
+ return Number(tier.spend_sum_money_multi_markets[currentCurrency2].value);
434
434
  }
435
435
  return Number(tier.spend_sum_money || 0);
436
436
  };
437
- const qualifyingTier = [...giftTiers].sort((a, b) => getThresholdAmount(b) - getThresholdAmount(a)).find((tier) => subtotal >= getThresholdAmount(tier));
437
+ const qualifyingTier2 = [...giftTiers].sort((a, b) => getThresholdAmount(b) - getThresholdAmount(a)).find((tier) => subtotal >= getThresholdAmount(tier));
438
438
  const nextGoal = giftTiers.find((tier) => subtotal < getThresholdAmount(tier));
439
- if (!qualifyingTier) {
440
- return { qualifyingGift: null, nextTierGoal: nextGoal || null };
441
- }
442
- const actualThreshold = getThresholdAmount(qualifyingTier);
443
- const formattedGift = {
444
- tier: qualifyingTier,
445
- itemsToAdd: qualifyingTier.reward_list?.map((reward) => {
446
- const giftProduct = reward?.variant_list?.[0];
447
- if (!giftProduct) return null;
448
- return {
449
- variant: {
450
- id: btoaID(giftProduct.variant_id),
451
- handle: giftProduct.handle,
452
- sku: giftProduct.sku
453
- },
454
- quantity: reward?.get_unit || 1,
455
- attributes: [
456
- {
457
- key: CUSTOMER_ATTRIBUTE_KEY,
458
- value: JSON.stringify({
459
- is_gift: true,
460
- rule_id: activeCampaign.rule_id,
461
- spend_sum_money: actualThreshold,
462
- // 使用实际的门槛金额(多币种支持)
463
- currency_code: currentCurrency
464
- // 记录当前币种
465
- })
466
- }
467
- ]
468
- };
469
- }).filter((item) => item !== null)
439
+ const actualThreshold2 = qualifyingTier2 ? getThresholdAmount(qualifyingTier2) : 0;
440
+ return {
441
+ qualifyingTier: qualifyingTier2,
442
+ nextTierGoal: nextGoal || null,
443
+ actualThreshold: actualThreshold2,
444
+ currentCurrency: currentCurrency2
470
445
  };
471
- return { qualifyingGift: formattedGift, nextTierGoal: nextGoal || null };
472
446
  }, [activeCampaign, subtotal, effectiveCart]);
473
447
  const giftHandles = useMemo(() => {
474
448
  const giftVariant = autoFreeGiftConfig.map(
@@ -509,6 +483,58 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
509
483
  }
510
484
  return giftProductsResult;
511
485
  }, [giftProductsResult, shouldFetch]);
486
+ const qualifyingGift = useMemo(() => {
487
+ if (!qualifyingTier || !activeCampaign) {
488
+ return null;
489
+ }
490
+ const itemsToAdd = qualifyingTier.reward_list?.map((reward) => {
491
+ if (!reward.variant_list || reward.variant_list.length === 0) {
492
+ return null;
493
+ }
494
+ let selectedGiftProduct = null;
495
+ for (const giftVariant of reward.variant_list) {
496
+ const productInfo = finalGiftProductsResult?.find(
497
+ (p) => p.handle === giftVariant.handle
498
+ );
499
+ if (productInfo) {
500
+ const variantInfo = productInfo.variants?.find((v) => v.sku === giftVariant.sku);
501
+ if (variantInfo?.availableForSale) {
502
+ selectedGiftProduct = giftVariant;
503
+ break;
504
+ }
505
+ }
506
+ }
507
+ if (!selectedGiftProduct) {
508
+ selectedGiftProduct = reward.variant_list[0];
509
+ }
510
+ return {
511
+ variant: {
512
+ id: btoaID(selectedGiftProduct.variant_id),
513
+ handle: selectedGiftProduct.handle,
514
+ sku: selectedGiftProduct.sku
515
+ },
516
+ quantity: reward?.get_unit || 1,
517
+ attributes: [
518
+ {
519
+ key: CUSTOMER_ATTRIBUTE_KEY,
520
+ value: JSON.stringify({
521
+ is_gift: true,
522
+ rule_id: activeCampaign.rule_id,
523
+ spend_sum_money: actualThreshold,
524
+ // 使用实际的门槛金额(多币种支持)
525
+ currency_code: currentCurrency
526
+ // 记录当前币种
527
+ })
528
+ }
529
+ ]
530
+ };
531
+ }).filter((item) => item !== null);
532
+ const formattedGift = {
533
+ tier: qualifyingTier,
534
+ itemsToAdd
535
+ };
536
+ return formattedGift;
537
+ }, [qualifyingTier, activeCampaign, finalGiftProductsResult, actualThreshold, currentCurrency]);
512
538
  return {
513
539
  qualifyingGift,
514
540
  nextTierGoal,