@anker-in/shopify-react 0.1.1-beta.18 → 0.1.1-beta.19
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.js +49 -34
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +49 -34
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/index.js +55 -35
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +55 -35
- package/dist/index.mjs.map +1 -1
- package/dist/provider/index.js +50 -31
- package/dist/provider/index.js.map +1 -1
- package/dist/provider/index.mjs +50 -31
- package/dist/provider/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/provider/index.js
CHANGED
|
@@ -486,18 +486,24 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
|
|
|
486
486
|
}
|
|
487
487
|
return true;
|
|
488
488
|
}, [giftHandles]);
|
|
489
|
-
const { data: giftProductsResult } = useSWR__default.default(
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
489
|
+
const { data: giftProductsResult } = useSWR__default.default(
|
|
490
|
+
shouldFetch ? giftHandles : null,
|
|
491
|
+
async () => {
|
|
492
|
+
const res = await shopifySdk.getProductsByHandles(client, {
|
|
493
|
+
handles: giftHandles,
|
|
494
|
+
locale
|
|
495
|
+
});
|
|
496
|
+
const result = Array.isArray(res) ? res : [];
|
|
497
|
+
giftProductsCache.current = {
|
|
498
|
+
data: result,
|
|
499
|
+
giftHandles: [...giftHandles]
|
|
500
|
+
};
|
|
501
|
+
return result;
|
|
502
|
+
},
|
|
503
|
+
{
|
|
504
|
+
revalidateOnFocus: false
|
|
505
|
+
}
|
|
506
|
+
);
|
|
501
507
|
const finalGiftProductsResult = react.useMemo(() => {
|
|
502
508
|
if (giftProductsCache.current && !shouldFetch) {
|
|
503
509
|
return giftProductsCache.current.data || void 0;
|
|
@@ -550,12 +556,14 @@ var useScriptAutoFreeGift = ({
|
|
|
550
556
|
upgrade_multiple2 = 1.2;
|
|
551
557
|
upgrade_value2 = 40;
|
|
552
558
|
}
|
|
553
|
-
effectiveCart?.lineItems?.forEach(
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
+
effectiveCart?.lineItems?.forEach(
|
|
560
|
+
({ customAttributes }) => {
|
|
561
|
+
customAttributes?.forEach(({ key, value }) => {
|
|
562
|
+
if (key === "_amount_upgrade_multiple") upgrade_multiple2 = Number(value) || 1;
|
|
563
|
+
if (key === "_amount_upgrade_value") upgrade_value2 = Number(value) || 0;
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
);
|
|
559
567
|
return [upgrade_multiple2, upgrade_value2];
|
|
560
568
|
}, [effectiveCart?.lineItems, points_subscribe]);
|
|
561
569
|
const breakpoints = react.useMemo(() => {
|
|
@@ -620,18 +628,24 @@ var useScriptAutoFreeGift = ({
|
|
|
620
628
|
const nextLevel = levelIndex > 0 ? sortedLevels[levelIndex - 1] ?? null : null;
|
|
621
629
|
return [currentLevel, nextLevel];
|
|
622
630
|
}, [breakpoints, involvedSubTotal, involvedLines.length]);
|
|
623
|
-
const { data: giftProductsResult } = useSWR__default.default(
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
631
|
+
const { data: giftProductsResult } = useSWR__default.default(
|
|
632
|
+
shouldFetch ? giftHandles : null,
|
|
633
|
+
async () => {
|
|
634
|
+
const res = await shopifySdk.getProductsByHandles(client, {
|
|
635
|
+
handles: giftHandles,
|
|
636
|
+
locale
|
|
637
|
+
});
|
|
638
|
+
const result = Array.isArray(res) ? res : [];
|
|
639
|
+
giftProductsCache.current = {
|
|
640
|
+
data: result,
|
|
641
|
+
giftHandles: [...giftHandles]
|
|
642
|
+
};
|
|
643
|
+
return result;
|
|
644
|
+
},
|
|
645
|
+
{
|
|
646
|
+
revalidateOnFocus: false
|
|
647
|
+
}
|
|
648
|
+
);
|
|
635
649
|
const finalGiftProductsResult = react.useMemo(() => {
|
|
636
650
|
if (giftProductsCache.current && !shouldFetch) {
|
|
637
651
|
return giftProductsCache.current.data || void 0;
|
|
@@ -1100,7 +1114,12 @@ function CartProvider({
|
|
|
1100
1114
|
const { attributes } = useCartAttributes({ profile, customer, cart, memberSetting });
|
|
1101
1115
|
ahooks.useRequest(
|
|
1102
1116
|
() => {
|
|
1103
|
-
const newAttributes = [...attributes
|
|
1117
|
+
const newAttributes = [...attributes];
|
|
1118
|
+
customAttributes.forEach((item) => {
|
|
1119
|
+
if (item.value && !newAttributes.some((attr) => attr.key === item.key)) {
|
|
1120
|
+
newAttributes.push(item);
|
|
1121
|
+
}
|
|
1122
|
+
});
|
|
1104
1123
|
const needUpdate = cart && checkAttributesUpdateNeeded(
|
|
1105
1124
|
cart.customAttributes,
|
|
1106
1125
|
newAttributes,
|